[PATCH] bpf: sync pending IRQ work before freeing ring buffer

neqbal posted 1 patch 3 months, 3 weeks ago
There is a newer version of this series
kernel/bpf/ringbuf.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] bpf: sync pending IRQ work before freeing ring buffer
Posted by neqbal 3 months, 3 weeks ago
#syz test

Fix a possible vmalloc out-of-bounds access caused by pending IRQ work

Reported-by: syzbot+2617fc732430968b45d2@syzkaller.appspotmail.com
Signed-off-by: neqbal <nooraineqbal@gmail.com>
---
 kernel/bpf/ringbuf.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
index 719d73299397..a6597417412f 100644
--- a/kernel/bpf/ringbuf.c
+++ b/kernel/bpf/ringbuf.c
@@ -216,6 +216,12 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
 
 static void bpf_ringbuf_free(struct bpf_ringbuf *rb)
 {
+	/* Ensure all pending IRQ work completes before freeing.
+	 * In PREEMPT_RT, IRQ work runs in thread context and can
+	 * race with ring buffer destruction.
+	 */
+	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
Re: [syzbot] [kernel?] KASAN: vmalloc-out-of-bounds Read in run_irq_workd
Posted by syzbot 3 months, 3 weeks ago
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: syzbot+2617fc732430968b45d2@syzkaller.appspotmail.com
Tested-by: syzbot+2617fc732430968b45d2@syzkaller.appspotmail.com

Tested on:

commit:         6f3b6e91 Merge tag 'io_uring-6.18-20251016' of git://g..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1217cb04580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=af9170887d81dea1
dashboard link: https://syzkaller.appspot.com/bug?extid=2617fc732430968b45d2
compiler:       Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8
patch:          https://syzkaller.appspot.com/x/patch.diff?x=12e5ede2580000

Note: testing is done by a robot and is best-effort only.