Skip to content

Commit 4e90776

Browse files
neqbalAlexei Starovoitov
authored andcommitted
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: 457f443 ("bpf: Implement BPF ring buffer and verifier support for it") Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=2617fc732430968b45d2 Tested-by: [email protected] Signed-off-by: Noorain Eqbal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 6548d36 commit 4e90776

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/bpf/ringbuf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
216216

217217
static void bpf_ringbuf_free(struct bpf_ringbuf *rb)
218218
{
219+
irq_work_sync(&rb->work);
220+
219221
/* copy pages pointer and nr_pages to local variable, as we are going
220222
* to unmap rb itself with vunmap() below
221223
*/

0 commit comments

Comments
 (0)