In the Linux kernel, the following vulnerability has been resolved:
bpf: cpumap: Fix memory leak in cpumapupdate_elem
Syzkaller reported a memory leak as follows:
BUG: memory leak unreferenced object 0xff110001198ef748 (size 192): comm "syz-executor.3", pid 17672, jiffies 4298118891 (age 9.906s) hex dump (first 32 bytes): 00 00 00 00 4a 19 00 00 80 ad e3 e4 fe ff c0 00 ....J........... 00 b2 d3 0c 01 00 11 ff 28 f5 8e 19 01 00 11 ff ........(....... backtrace: [<ffffffffadd28087>] _cpumapentryalloc+0xf7/0xb00 [<ffffffffadd28d8e>] cpumapupdateelem+0x2fe/0x3d0 [<ffffffffadc6d0fd>] bpfmapupdatevalue.isra.0+0x2bd/0x520 [<ffffffffadc7349b>] mapupdateelem+0x4cb/0x720 [<ffffffffadc7d983>] _sesysbpf+0x8c3/0xb90 [<ffffffffb029cc80>] dosyscall64+0x30/0x40 [<ffffffffb0400099>] entrySYSCALL64after_hwframe+0x61/0xc6
BUG: memory leak unreferenced object 0xff110001198ef528 (size 192): comm "syz-executor.3", pid 17672, jiffies 4298118891 (age 9.906s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<ffffffffadd281f0>] _cpumapentryalloc+0x260/0xb00 [<ffffffffadd28d8e>] cpumapupdateelem+0x2fe/0x3d0 [<ffffffffadc6d0fd>] bpfmapupdatevalue.isra.0+0x2bd/0x520 [<ffffffffadc7349b>] mapupdateelem+0x4cb/0x720 [<ffffffffadc7d983>] _sesysbpf+0x8c3/0xb90 [<ffffffffb029cc80>] dosyscall64+0x30/0x40 [<ffffffffb0400099>] entrySYSCALL64after_hwframe+0x61/0xc6
BUG: memory leak unreferenced object 0xff1100010fd93d68 (size 8): comm "syz-executor.3", pid 17672, jiffies 4298118891 (age 9.906s) hex dump (first 8 bytes): 00 00 00 00 00 00 00 00 ........ backtrace: [<ffffffffade5db3e>] kvmallocnode+0x11e/0x170 [<ffffffffadd28280>] _cpumapentryalloc+0x2f0/0xb00 [<ffffffffadd28d8e>] cpumapupdateelem+0x2fe/0x3d0 [<ffffffffadc6d0fd>] bpfmapupdatevalue.isra.0+0x2bd/0x520 [<ffffffffadc7349b>] mapupdateelem+0x4cb/0x720 [<ffffffffadc7d983>] _sesysbpf+0x8c3/0xb90 [<ffffffffb029cc80>] dosyscall64+0x30/0x40 [<ffffffffb0400099>] entrySYSCALL64afterhwframe+0x61/0xc6
In the cpumapupdateelem flow, when kthreadstop is called before calling the threadfn of rcpu->kthread, since the KTHREADSHOULDSTOP bit of kthread has been set by kthread_stop, the threadfn of rcpu->kthread will never be executed, and rcpu->refcnt will never be 0, which will lead to the allocated rcpu, rcpu->queue and rcpu->queue->queue cannot be released.
Calling kthread_stop before executing kthread's threadfn will return -EINTR. We can complete the release of memory resources in this state.
[
{
"id": "CVE-2023-53441-10b3c6f4",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "kernel/bpf/cpumap.c"
},
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"117596097130762509685664731228722414340",
"141622749049746817341601100068270612784",
"180423174139730170697485980255620134210",
"224323528898940082504293966865041915556",
"66310575467758321232216728123932861979",
"267904503701731693636235204515977058544",
"74453712574611448139386527119769301302",
"93354889748663370896842658254478800621",
"189554373819476506230802361456756850969",
"191875032485332689162434363438638062432",
"173489280393807144487877290617859853198",
"65755660034969066084273626766704169226",
"75205956036839555049635717989216301816"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@a957ac8e0b5ffb5797382a6adbafd005a5f72851"
},
{
"id": "CVE-2023-53441-1c787bbf",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "kernel/bpf/cpumap.c"
},
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"117596097130762509685664731228722414340",
"141622749049746817341601100068270612784",
"180423174139730170697485980255620134210",
"224323528898940082504293966865041915556",
"66310575467758321232216728123932861979",
"267904503701731693636235204515977058544",
"74453712574611448139386527119769301302",
"93354889748663370896842658254478800621",
"189554373819476506230802361456756850969",
"191875032485332689162434363438638062432",
"173489280393807144487877290617859853198",
"65755660034969066084273626766704169226",
"75205956036839555049635717989216301816"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@4369016497319a9635702da010d02af1ebb1849d"
},
{
"id": "CVE-2023-53441-5b796605",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "cpu_map_kthread_stop",
"file": "kernel/bpf/cpumap.c"
},
"signature_type": "Function",
"digest": {
"length": 159.0,
"function_hash": "44379404666335512705885713086467440211"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@4369016497319a9635702da010d02af1ebb1849d"
},
{
"id": "CVE-2023-53441-78b85149",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "kernel/bpf/cpumap.c"
},
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"117596097130762509685664731228722414340",
"141622749049746817341601100068270612784",
"180423174139730170697485980255620134210",
"224323528898940082504293966865041915556",
"66310575467758321232216728123932861979",
"267904503701731693636235204515977058544",
"74453712574611448139386527119769301302",
"93354889748663370896842658254478800621",
"189554373819476506230802361456756850969",
"191875032485332689162434363438638062432",
"173489280393807144487877290617859853198",
"65755660034969066084273626766704169226",
"75205956036839555049635717989216301816"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@b11a9b4f28cb6ff69ef7e69809e5f7fffeac9030"
},
{
"id": "CVE-2023-53441-9796a45f",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "cpu_map_kthread_stop",
"file": "kernel/bpf/cpumap.c"
},
"signature_type": "Function",
"digest": {
"length": 159.0,
"function_hash": "44379404666335512705885713086467440211"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d26299f50f5ea8f0aeb5d49e659c31f64233c816"
},
{
"id": "CVE-2023-53441-bc7b360a",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "cpu_map_kthread_stop",
"file": "kernel/bpf/cpumap.c"
},
"signature_type": "Function",
"digest": {
"length": 159.0,
"function_hash": "44379404666335512705885713086467440211"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@b11a9b4f28cb6ff69ef7e69809e5f7fffeac9030"
},
{
"id": "CVE-2023-53441-e7e527bc",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "kernel/bpf/cpumap.c"
},
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"117596097130762509685664731228722414340",
"141622749049746817341601100068270612784",
"180423174139730170697485980255620134210",
"224323528898940082504293966865041915556",
"66310575467758321232216728123932861979",
"267904503701731693636235204515977058544",
"74453712574611448139386527119769301302",
"93354889748663370896842658254478800621",
"189554373819476506230802361456756850969",
"191875032485332689162434363438638062432",
"173489280393807144487877290617859853198",
"65755660034969066084273626766704169226",
"75205956036839555049635717989216301816"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d26299f50f5ea8f0aeb5d49e659c31f64233c816"
},
{
"id": "CVE-2023-53441-ef296e49",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "cpu_map_kthread_stop",
"file": "kernel/bpf/cpumap.c"
},
"signature_type": "Function",
"digest": {
"length": 159.0,
"function_hash": "44379404666335512705885713086467440211"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@a957ac8e0b5ffb5797382a6adbafd005a5f72851"
}
]