Cong Wang
53f523f305
bpf: Clear percpu pointers in bpf_prog_clone_free()
Similar to bpf_prog_realloc(), bpf_prog_clone_create() also copies
the percpu pointers, but the clone still shares them with the original
prog, so we have to clear these two percpu pointers in
bpf_prog_clone_free(). Otherwise we would get a double free:
BUG: kernel NULL pointer dereference, address: 0000000000000000
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 0 P4D 0
Oops: 0000 [#1] SMP PTI
CPU: 13 PID: 8140 Comm: kworker/13:247 Kdump: loaded Tainted: G W OE
5.11.0-rc4.bm.1-amd64+ #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014
test_bpf: #1 TXA
Workqueue: events bpf_prog_free_deferred
RIP: 0010:percpu_ref_get_many.constprop.97+0x42/0xf0
Code: [...]
RSP: 0018:ffffa6bce1f9bda0 EFLAGS: 00010002
RAX: 0000000000000001 RBX: 0000000000000000 RCX: 00000000021dfc7b
RDX: ffffffffae2eeb90 RSI: 867f92637e338da5 RDI: 0000000000000046
RBP: ffffa6bce1f9bda8 R08: 0000000000000000 R09: 0000000000000001
R10: 0000000000000046 R11: 0000000000000000 R12: 0000000000000280
R13: 0000000000000000 R14: 0000000000000000 R15: ffff9b5f3ffdedc0
FS: 0000000000000000(0000) GS:ffff9b5f2fb40000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 000000027c36c002 CR4: 00000000003706e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
refill_obj_stock+0x5e/0xd0
free_percpu+0xee/0x550
__bpf_prog_free+0x4d/0x60
process_one_work+0x26a/0x590
worker_thread+0x3c/0x390
? process_one_work+0x590/0x590
kthread+0x130/0x150
? kthread_park+0x80/0x80
ret_from_fork+0x1f/0x30
This bug is 100% reproducible with test_kmod.sh.
Fixes: 700d4796ef
("bpf: Optimize program stats")
Fixes: ca06f55b90
("bpf: Add per-program recursion prevention mechanism")
Reported-by: Jiang Wang <jiang.wang@bytedance.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210218001647.71631-1-xiyou.wangcong@gmail.com
2021-02-22 18:08:35 +01:00
..
2021-02-22 18:08:35 +01:00
2021-01-19 11:37:05 -05:00
2021-01-06 17:39:38 +01:00
2020-11-24 16:47:49 +01:00
2021-02-05 12:48:46 +01:00
2021-02-17 14:12:43 +01:00
2021-02-21 12:49:32 -08:00
2021-02-05 11:03:47 -08:00
2021-02-21 11:53:06 -08:00
2021-01-04 14:39:07 -08:00
2020-11-13 12:15:28 -05:00
2021-02-21 12:35:04 -08:00
2021-02-15 18:50:01 +01:00
2021-01-25 14:29:35 +01:00
2021-02-21 12:35:04 -08:00
2021-02-21 12:35:04 -08:00
2021-02-21 12:04:41 -08:00
2021-02-21 11:02:48 -08:00
2020-12-15 22:46:15 -08:00
2020-07-16 12:35:15 -07:00
2020-12-03 14:58:35 +01:00
2020-12-03 14:58:35 +01:00
2020-12-03 14:58:35 +01:00
2020-12-02 22:52:16 -05:00
2020-08-17 20:26:58 -04:00
2020-08-23 17:36:59 -05:00
2020-12-16 10:54:03 -08:00
2020-07-30 11:15:58 -07:00
2020-10-13 09:17:34 -07:00
2020-08-23 17:36:59 -05:00
2020-06-11 15:14:36 +02:00
2020-09-01 09:58:03 +02:00
2021-01-06 16:24:59 -08:00
2020-12-15 22:46:18 -08:00
2020-12-30 19:36:54 -07:00
2020-12-15 22:46:19 -08:00
2021-01-11 12:55:01 +01:00
2021-02-12 12:54:58 +01:00
2020-06-06 23:42:01 +09:00
2020-10-13 09:17:34 -07:00
2020-11-02 12:14:19 -08:00
2020-11-24 16:47:49 +01:00
2020-12-18 16:53:12 +01:00
2020-10-25 14:51:49 -07:00
2020-12-15 19:36:48 -08:00
2021-02-17 14:12:24 +01:00
2020-11-02 18:00:20 -08:00
2021-02-21 09:29:23 -08:00
2020-11-20 14:45:33 +11:00
2020-10-05 13:37:03 +02:00
2020-08-12 10:58:01 -07:00
2021-01-29 17:29:16 -05:00
2021-01-24 10:09:20 -08:00
2020-12-15 22:46:19 -08:00
2020-12-17 13:01:31 -08:00
2020-09-01 09:58:03 +02:00
2020-12-14 16:40:27 -08:00
2020-09-04 17:51:55 +10:00
2020-11-14 11:26:04 -08:00
2020-12-17 13:01:31 -08:00
2020-12-14 16:40:27 -08:00
2020-12-15 19:36:48 -08:00
2020-12-15 12:53:37 -08:00
2020-10-16 11:11:19 -07:00
2020-12-15 22:46:19 -08:00
2020-07-27 14:31:12 -04:00
2020-12-15 22:46:18 -08:00
2020-11-25 18:52:35 +01:00
2020-12-15 22:46:18 -08:00
2021-01-04 13:53:41 -08:00
2020-12-01 10:30:28 +00:00
2020-12-16 11:30:10 -08:00
2021-01-24 09:35:28 -08:00
2021-02-17 14:12:42 +01:00
2021-01-22 15:09:42 +01:00
2020-12-27 09:06:10 -08:00
2020-09-19 13:13:39 -07:00
2020-09-18 14:24:16 +01:00
2021-02-17 14:12:42 +01:00
2020-11-27 11:10:50 +01:00
2020-12-19 11:18:38 -08:00
2021-01-29 10:06:46 +05:30
2020-11-19 19:37:16 -08:00
2020-12-12 09:17:38 -07:00
2020-11-16 08:08:54 -08:00
2021-01-06 17:17:22 -08:00
2020-11-16 21:53:15 +01:00
2020-10-06 10:31:52 -07:00
2020-12-14 16:40:27 -08:00
2020-08-19 14:14:12 +02:00
2020-07-07 11:58:59 -05:00
2020-08-19 14:13:20 +02:00
2020-08-17 09:39:18 -07:00
2020-11-14 11:26:03 -08:00
2021-01-22 15:09:43 +01:00