Pu Lehui
d26299f50f
bpf: cpumap: Fix memory leak in cpu_map_update_elem
[ Upstream commit 4369016497 ]
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: 6710e11269 ("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:47:45 +02:00
..
2023-07-23 13:47:45 +02:00
2023-06-28 10:29:43 +02:00
2021-05-07 00:26:34 -07:00
2022-05-25 09:57:37 +02:00
2022-10-05 10:39:40 +02:00
2023-03-30 12:47:51 +02:00
2023-05-11 23:00:35 +09:00
2022-12-31 13:14:04 +01:00
2022-12-31 13:14:47 +01:00
2023-03-17 08:48:58 +01:00
2023-07-23 13:47:12 +02:00
2022-10-26 12:34:30 +02:00
2023-05-17 11:50:29 +02:00
2023-05-11 23:00:35 +09:00
2023-03-11 13:57:32 +01:00
2023-07-23 13:46:47 +02:00
2023-05-11 23:00:40 +09:00
2023-07-23 13:46:45 +02:00
2023-07-23 13:47:43 +02:00
2021-05-02 00:43:35 +09:00
2022-12-31 13:14:40 +01:00
2022-02-23 12:03:07 +01:00
2022-08-31 17:16:33 +02:00
2021-08-24 18:52:36 -04:00
2020-12-03 14:58:35 +01:00
2022-02-08 18:34:03 +01:00
2022-04-08 14:23:06 +02:00
2021-03-22 15:23:32 -04:00
2022-04-08 14:23:06 +02:00
2020-07-30 11:15:58 -07:00
2021-01-24 14:27:16 +01:00
2022-06-22 14:22:04 +02:00
2023-04-05 11:24:53 +02:00
2020-02-04 03:05:26 +00:00
2020-06-11 15:14:36 +02:00
2021-08-16 18:55:32 +02:00
2022-12-31 13:14:04 +01:00
2021-12-29 12:28:49 +01:00
2020-04-15 11:21:54 +02:00
2022-02-23 12:03:20 +01:00
2021-05-12 11:43:25 +02:00
2023-02-01 08:27:22 +01:00
2020-04-07 10:43:42 -07:00
2023-03-11 13:57:38 +01:00
2023-06-14 11:13:01 +02:00
2021-06-18 11:43:08 +02:00
2021-05-27 04:01:50 +09:00
2021-02-26 09:41:03 -08:00
2021-07-02 12:08:10 -07:00
2021-06-10 10:00:08 +02:00
2021-07-05 10:46:20 +02:00
2021-07-08 11:48:22 -07:00
2020-12-15 19:36:48 -08:00
2021-08-17 17:50:51 +02:00
2021-06-28 22:43:05 +02:00
2020-11-02 18:00:20 -08:00
2023-07-23 13:46:52 +02:00
2023-06-21 15:59:14 +02:00
2023-04-20 12:13:57 +02:00
2023-04-20 12:13:57 +02:00
2023-05-11 23:00:17 +09:00
2021-05-07 00:26:33 -07:00
2023-03-10 09:40:01 +01:00
2023-04-20 12:13:57 +02:00
2023-03-30 12:47:42 +02:00
2020-04-27 02:07:40 -04:00
2022-12-31 13:14:04 +01:00
2021-01-19 10:24:45 +01:00
2021-01-19 10:24:45 +01:00
2023-02-01 08:27:23 +01:00
2021-08-16 18:55:32 +02:00
2021-09-03 09:58:12 -07:00
2022-12-31 13:14:24 +01:00
2023-02-01 08:27:22 +01:00
2021-08-16 14:42:22 +02:00
2023-03-10 09:39:09 +01:00
2021-08-10 12:53:07 +02:00
2022-08-17 14:24:04 +02:00
2022-06-09 10:22:29 +02:00
2020-10-16 11:11:19 -07:00
2021-06-21 13:08:36 +01:00
2020-07-27 14:31:12 -04:00
2023-05-11 23:00:18 +09:00
2020-11-25 18:52:35 +01:00
2023-03-10 09:40:08 +01:00
2022-04-08 14:23:10 +02:00
2022-06-09 10:22:46 +02:00
2021-11-18 19:16:29 +01:00
2022-02-16 12:56:38 +01:00
2022-07-21 21:24:42 +02:00
2022-08-17 14:24:24 +02:00
2021-08-10 14:57:42 +02:00
2021-08-10 22:50:07 +02:00
2022-02-23 12:03:07 +01:00
2022-04-13 20:59:28 +02:00
2022-04-13 20:59:28 +02:00
2022-04-13 20:59:28 +02:00
2021-03-23 16:01:58 +01:00
2022-08-31 17:16:33 +02:00
2023-04-26 13:51:52 +02:00
2021-06-23 16:41:24 -06:00
2023-02-01 08:27:20 +01:00
2021-04-30 11:20:42 -07:00
2020-11-16 08:08:54 -08:00
2021-08-10 10:48:07 -07:00
2021-08-16 11:39:51 -04:00
2022-01-27 11:05:35 +01:00
2022-02-23 12:03:20 +01:00
2021-05-07 00:26:34 -07:00
2021-05-09 13:07:03 -07:00
2022-03-08 19:12:42 +01:00
2021-09-08 11:50:27 -07:00
2021-07-03 11:41:14 -07:00
2020-04-27 02:07:40 -04:00
2020-08-19 14:13:20 +02:00
2023-03-17 08:48:59 +01:00
2023-07-23 13:46:52 +02:00
2022-08-25 11:40:43 +02:00
2021-08-17 07:49:10 -10:00
2023-07-23 13:47:38 +02:00