Re: [PATCH] perf/bpf: Fix data race in __perf_event_overflow
| Newsgroups | org.kernel.vger.linux-perf-users,org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kernel.vger.linux-trace-kernel |
|---|---|
| Message-ID | <42d2df770e6e5f9134476509f690ec9b7d68f0da4cd1ffadcf3f9c1b75f0adf2@mail.kernel.org> |
> commit ffa161d3558e4937793a0c3e98e19e4b22e58bd9 > Author: Deepanshu Kartikey <[email protected]> > Date: Wed Aug 12 05:23:31 2026 +0530 > > perf/bpf: Fix data race in __perf_event_overflow > > perf_event_detach_bpf_prog() writes event->prog = NULL > under bpf_event_mutex, while __perf_event_overflow() reads > event->prog concurrently without any lock protection. This > causes a data race detected by KCSAN. > > __perf_event_overflow() can be called from interrupt/NMI > context, so it cannot acquire bpf_event_mutex. Fix the race > by using WRITE_ONCE() in perf_event_detach_bpf_prog() and > READ_ONCE() in __perf_event_overflow(). Also store the result > of READ_ONCE() in a local variable to avoid reading event->prog > twice which could result in a NULL pointer dereference if the > pointer becomes NULL between the two reads. > > Reported-by: [email protected] > Closes: https://syzkaller.appspot.com/bug?extid=651d2774bd1d8395595f > Fixes: f11f10bfa1ca ("perf/bpf: Call BPF handler directly, not through overflow machinery") > Signed-off-by: Deepanshu Kartikey <[email protected]> > Reported-by: [email protected] > Signed-off-by: Deepanshu Kartikey <[email protected]> The trailer block contains duplicate tags: both Reported-by: and Signed-off-by: appear twice. Also, the second Reported-by: is placed after the first Signed-off-by:, which breaks the conventional trailer ordering (Reported-by/Closes/Fixes should come before Signed-off-by). Should the duplicates be collapsed to one of each, in proper trailer order? --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31550171807