Pu Lehui
b11a9b4f28
bpf: cpumap: Fix memory leak in cpu_map_update_elem
...
[ Upstream commit 4369016497319a9635702da010d02af1ebb1849d ]
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>] __cpu_map_entry_alloc+0xf7/0xb00
[<ffffffffadd28d8e>] cpu_map_update_elem+0x2fe/0x3d0
[<ffffffffadc6d0fd>] bpf_map_update_value.isra.0+0x2bd/0x520
[<ffffffffadc7349b>] map_update_elem+0x4cb/0x720
[<ffffffffadc7d983>] __se_sys_bpf+0x8c3/0xb90
[<ffffffffb029cc80>] do_syscall_64+0x30/0x40
[<ffffffffb0400099>] entry_SYSCALL_64_after_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>] __cpu_map_entry_alloc+0x260/0xb00
[<ffffffffadd28d8e>] cpu_map_update_elem+0x2fe/0x3d0
[<ffffffffadc6d0fd>] bpf_map_update_value.isra.0+0x2bd/0x520
[<ffffffffadc7349b>] map_update_elem+0x4cb/0x720
[<ffffffffadc7d983>] __se_sys_bpf+0x8c3/0xb90
[<ffffffffb029cc80>] do_syscall_64+0x30/0x40
[<ffffffffb0400099>] entry_SYSCALL_64_after_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>] kvmalloc_node+0x11e/0x170
[<ffffffffadd28280>] __cpu_map_entry_alloc+0x2f0/0xb00
[<ffffffffadd28d8e>] cpu_map_update_elem+0x2fe/0x3d0
[<ffffffffadc6d0fd>] bpf_map_update_value.isra.0+0x2bd/0x520
[<ffffffffadc7349b>] map_update_elem+0x4cb/0x720
[<ffffffffadc7d983>] __se_sys_bpf+0x8c3/0xb90
[<ffffffffb029cc80>] do_syscall_64+0x30/0x40
[<ffffffffb0400099>] entry_SYSCALL_64_after_hwframe+0x61/0xc6
In the cpu_map_update_elem flow, when kthread_stop is called before
calling the threadfn of rcpu->kthread, since the KTHREAD_SHOULD_STOP 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.
Fixes: 6710e1126934 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP")
Signed-off-by: Pu Lehui <pulehui@huawei.com>
Acked-by: Jesper Dangaard Brouer <hawk@kernel.org>
Acked-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20230711115848.2701559-1-pulehui@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-07-23 13:49:26 +02:00
..
2022-07-15 12:01:30 -07:00
2022-09-07 11:46:08 -07:00
2022-10-11 17:42:58 -06:00
2022-04-26 11:35:21 -07:00
2022-08-18 17:06:13 -07:00
2023-05-24 17:32:36 +01:00
2021-02-10 15:54:26 -08:00
2022-05-13 07:20:07 -07:00
2023-02-09 11:28:02 +01:00
2021-11-01 14:10:00 -07:00
2022-07-11 21:04:58 +02:00
2022-09-01 12:16:12 -07:00
2023-07-19 16:22:05 +02:00
2023-06-21 16:00:51 +02:00
2023-07-19 16:21:05 +02:00
2023-03-30 12:49:08 +02:00
2023-07-23 13:49:26 +02:00
2022-08-10 11:50:43 -07:00
2021-09-02 14:49:23 +02:00
2021-09-02 14:49:23 +02:00
2022-11-07 16:07:35 -08:00
2023-05-30 14:03:21 +01:00
2022-10-03 17:44:18 -07:00
2022-02-10 23:31:51 +01:00
2022-04-20 16:52:58 -07:00
2022-05-10 11:20:45 -07:00
2023-06-21 16:00:51 +02:00
2022-08-10 11:50:43 -07:00
2022-09-05 15:33:05 +02:00
2023-06-14 11:15:17 +02:00
2021-12-18 13:27:41 -08:00
2023-03-10 09:33:06 +01:00
2021-11-07 11:54:51 -08:00
2021-12-29 20:03:05 -08:00
2023-01-24 07:24:37 +01:00
2022-11-11 12:05:14 -08:00
2020-10-06 00:04:11 +02:00
2022-08-10 11:48:22 -07:00
2022-08-17 16:42:59 -07:00
2022-09-21 16:24:58 -07:00
2022-09-13 15:03:22 +02:00
2023-06-28 11:12:33 +02:00
2020-11-10 15:25:53 -08:00
2023-01-24 07:24:31 +01:00
2021-06-01 13:34:15 +02:00
2023-07-19 16:21:05 +02:00
2023-07-23 13:49:22 +02:00