From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Luo Gengkun <luogengkun@huaweicloud.com>
Cc: stable@vger.kernel.org, Sasha Levin <sashal@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>, Jiri Olsa <jolsa@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Alexei Starovoitov <ast@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, alexander.shishkin@linux.intel.com
Subject: Re: [PATCH stable/linux-6.6.y] perf, bpf: Fix NULL event->orig_overflow_handler dereference
Date: Tue, 24 Nov 2026 09:21:20 +0100 [thread overview]
Message-ID: <2026112402-dictation-juror-2e5d@gregkh> (raw)
In-Reply-To: <20261124084837.2327711-1-luogengkun@huaweicloud.com>
On Tue, Nov 24, 2026 at 08:48:37AM +0000, Luo Gengkun wrote:
> We hit the following problem on x86:
>
> BUG: kernel NULL pointer dereference, address: 0000000000000000
> #PF: supervisor instruction fetch in kernel mode
> #PF: error_code(0x0010) - not-present page
> RIP: 0010:0x0
> Call Trace:
> <IRQ>
> bpf_overflow_handler+0xa4/0x120
> __perf_event_overflow+0x11d/0x2f0
> perf_swevent_hrtimer+0x127/0x140
> __hrtimer_run_queues+0x108/0x250
> hrtimer_interrupt+0xfb/0x230
> sysvec_apic_timer_interrupt+0x69/0x90
> </IRQ>
> <TASK>
> asm_sysvec_apic_timer_interrupt+0x1a/0x20
> __perf_event_set_bpf_prog+0xb7/0x180
> _perf_ioctl+0x1f9/0xb40
> perf_ioctl+0x41/0x70
> __se_sys_ioctl+0x82/0xc0
> do_syscall_64+0x44/0xb0
> entry_SYSCALL_64_after_hwframe+0x78/0xe2
> </TASK>
>
> RIP is 0 with error_code(0x0010) (instruction fetch, not-present), i.e.
> an indirect call through a NULL function pointer.
>
> perf_event_set_bpf_handler() records the handler currently installed on
> the event and replaces it with bpf_overflow_handler():
>
> event->prog = prog;
> event->bpf_cookie = bpf_cookie;
> event->orig_overflow_handler = READ_ONCE(event->overflow_handler);
> WRITE_ONCE(event->overflow_handler, bpf_overflow_handler);
>
> WRITE_ONCE() is a single-copy atomic access, not a compiler barrier, and
> the store to orig_overflow_handler is a plain assignment, so the compiler
> may reorder the two stores. GCC 11.4.0 does; disassembly of
> __perf_event_set_bpf_prog():
>
> mov 0x3d0(%rbp),%rax ; prev = overflow_handler
> mov %rsi,0x3e8(%rbp) ; event->prog = prog
> mov %r13,0x3f0(%rbp) ; event->bpf_cookie = cookie
> movq $bpf_overflow_handler,0x3d0(%rbp) ; publish overflow_handler
> mov %rax,0x3e0(%rbp) ; orig_overflow_handler = prev
>
> Use smp_store_release()/smp_load_acquire() to guarantee both the compiler
> and the memory ordering.
>
> Upstream status:
> Not affected. commit f11f10bfa1ca ("perf/bpf: Call BPF handler directly,
> not through overflow machinery") removed orig_overflow_handler and
> calls bpf_overflow_handler() directly from __perf_event_overflow(), so
> the reordering window no longer exists. That rework was not backported
> to any stable tree.
Please backport that rework instead of doing a one-off patch.
thanks,
greg k-h
prev parent reply other threads:[~2026-11-24 8:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 8:48 [PATCH stable/linux-6.6.y] perf, bpf: Fix NULL event->orig_overflow_handler dereference Luo Gengkun
2026-11-24 8:21 ` Greg Kroah-Hartman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2026112402-dictation-juror-2e5d@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=luogengkun@huaweicloud.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox