BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP
Date: Fri, 09 Oct 2026 03:03:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-164740@kernel.org> (raw)
In-Reply-To: <20261009024925.3169077-2-memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: PROBE_MEM oops during RCU grace period due to early kallsyms removal
--

commit 9e4e375ce4c3205ad3741d292c6701b8a1d5a5c3
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

x86/mm: Resolve BPF exception fixups for user address faults under SMAP

This commit allows the x86 page fault handler to resolve BPF PROBE_MEM
exception table entries for user address faults when SMAP is enabled, avoiding
an immediate oops. It paves the way for dropping the JIT-emitted address
range checks.

> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index aa88370ce7394..2060e5f35d77a 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c

[ ... ]

> @@ -1262,6 +1263,16 @@ void do_user_addr_fault(struct pt_regs *regs,
>  	if (unlikely(cpu_feature_enabled(X86_FEATURE_SMAP) &&
>  		     !(error_code & X86_PF_USER) &&
>  		     !(regs->flags & X86_EFLAGS_AC))) {
> +		/*
> +		 * JITed BPF programs dereference untrusted pointers with loads
> +		 * that carry an exception table entry (PROBE_MEM). SMAP makes
> +		 * sure such a load cannot read user memory, so resolve the
> +		 * fault through the exception table, as for an unmapped kernel
> +		 * address, instead of oopsing.
> +		 */
> +		if (is_bpf_text_address(regs->ip) &&
> +		    fixup_exception(regs, X86_TRAP_PF, error_code, address))
> +			return;

[Severity: High]
Does this introduce a race condition during BPF program destruction?

If a BPF program with PROBE_MEM loads has its reference count drop to zero,
__bpf_prog_put_noref() synchronously removes it from the global bpf_tree via
bpf_prog_kallsyms_del_all() before waiting for the RCU grace period:

kernel/bpf/syscall.c:__bpf_prog_put_noref() {
    ...
    bpf_prog_kallsyms_del_all(prog);
    ...
    if (deferred) {
        ...
        call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu);
    ...
}

If a CPU is still executing this program inside an RCU read-side critical
section and hits a PROBE_MEM fault, could the page fault handler fail to find
the actively executing program?

The handler calls is_bpf_text_address() and then fixup_exception(), which
eventually searches for the program using bpf_prog_ksym_find():

kernel/bpf/core.c:search_bpf_extables() {
    rcu_read_lock();
    prog = bpf_prog_ksym_find(addr);
    if (!prog)
        goto out;
    ...
}

Because the program was already cleared from bpf_tree, is_bpf_text_address()
and fixup_exception() will fail to resolve the exception, causing the kernel to
incorrectly fall through to page_fault_oops() instead.

>  		/*
>  		 * No extable entry here.  This was a kernel access to an
>  		 * invalid pointer.  get_kernel_nofault() will not get here.
>  		 */
>  		page_fault_oops(regs, error_code, address);
>  		return;
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261009024925.3169077-1-memxor@gmail.com?part=1

  reply	other threads:[~2026-10-09  3:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09  2:49 [PATCH bpf-next v1 0/3] bpf, x86: Drop the PROBE_MEM address range check under SMAP Kumar Kartikeya Dwivedi
2026-10-09  2:49 ` [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults " Kumar Kartikeya Dwivedi
2026-10-09  3:03   ` sashiko-bot [this message]
2026-10-09  4:13   ` Borislav Petkov
2026-10-09 15:23     ` Kumar Kartikeya Dwivedi
2026-10-09  2:49 ` [PATCH bpf-next v1 2/3] bpf, x86: Skip the PROBE_MEM address range check " Kumar Kartikeya Dwivedi
2026-10-09  3:42   ` bot+bpf-ci
2026-10-09  2:49 ` [PATCH bpf-next v1 3/3] selftests/bpf: Test PROBE_MEM loads from invalid addresses Kumar Kartikeya Dwivedi
2026-10-09  2:56   ` sashiko-bot

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=sashiko-outbox-164740@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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