summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorNoorain Eqbal <nooraineqbal@gmail.com>2025-10-20 23:33:01 +0530
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-11-24 10:29:13 +0100
commit6451141103547f4efd774e912418a3b4318046c6 (patch)
treecd7871a371044b7ceb99648f7e8adbcfb97a7744 /kernel
parentc898547ed64ee76e1d8c1c0403518561563ac785 (diff)
downloadlinux-6451141103547f4efd774e912418a3b4318046c6.tar.gz
linux-6451141103547f4efd774e912418a3b4318046c6.tar.bz2
linux-6451141103547f4efd774e912418a3b4318046c6.zip
bpf: Sync pending IRQ work before freeing ring buffer
[ Upstream commit 4e9077638301816a7d73fa1e1b4c1db4a7e3b59c ] Fix a race where irq_work can be queued in bpf_ringbuf_commit() but the ring buffer is freed before the work executes. In the syzbot reproducer, a BPF program attached to sched_switch triggers bpf_ringbuf_commit(), queuing an irq_work. If the ring buffer is freed before this work executes, the irq_work thread may accesses freed memory. Calling `irq_work_sync(&rb->work)` ensures that all pending irq_work complete before freeing the buffer. Fixes: 457f44363a88 ("bpf: Implement BPF ring buffer and verifier support for it") Reported-by: syzbot+2617fc732430968b45d2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=2617fc732430968b45d2 Tested-by: syzbot+2617fc732430968b45d2@syzkaller.appspotmail.com Signed-off-by: Noorain Eqbal <nooraineqbal@gmail.com> Link: https://lore.kernel.org/r/20251020180301.103366-1-nooraineqbal@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/ringbuf.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
index 6aff5ee483b6..c0c5e9b313e4 100644
--- a/kernel/bpf/ringbuf.c
+++ b/kernel/bpf/ringbuf.c
@@ -215,6 +215,8 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
static void bpf_ringbuf_free(struct bpf_ringbuf *rb)
{
+ irq_work_sync(&rb->work);
+
/* copy pages pointer and nr_pages to local variable, as we are going
* to unmap rb itself with vunmap() below
*/