[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251020180301.103366-1-nooraineqbal@gmail.com>
Date: Mon, 20 Oct 2025 23:33:01 +0530
From: Noorain Eqbal <nooraineqbal@...il.com>
To: andrii.nakryiko@...il.com
Cc: alexei.starovoitov@...il.com,
andrii@...nel.org,
ast@...nel.org,
bpf@...r.kernel.org,
daniel@...earbox.net,
david.hunter@...uxfoundation.org,
eddyz87@...il.com,
haoluo@...gle.com,
john.fastabend@...il.com,
jolsa@...nel.org,
kpsingh@...nel.org,
linux-kernel-mentees@...ts.linux.dev,
linux-kernel@...r.kernel.org,
martin.lau@...ux.dev,
nooraineqbal@...il.com,
sdf@...ichev.me,
skhan@...uxfoundation.org,
song@...nel.org,
syzbot+2617fc732430968b45d2@...kaller.appspotmail.com,
yonghong.song@...ux.dev
Subject: [PATCH v2] bpf: sync pending IRQ work before freeing ring buffer
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@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=2617fc732430968b45d2
Tested-by: syzbot+2617fc732430968b45d2@...kaller.appspotmail.com
Signed-off-by: Noorain Eqbal <nooraineqbal@...il.com>
---
v2: Updated the commit message for clarity.
---
kernel/bpf/ringbuf.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
index 719d73299397..d706c4b7f532 100644
--- a/kernel/bpf/ringbuf.c
+++ b/kernel/bpf/ringbuf.c
@@ -216,6 +216,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
*/
--
2.51.0
Powered by blists - more mailing lists