All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: <sashiko-reviews@lists.linux.dev>, <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 2/3] bpf, x86: Skip the PROBE_MEM address range check under SMAP
Date: Sat, 28 Nov 2026 03:16:43 +0100	[thread overview]
Message-ID: <DN6HDX0GXICR.JK53Y1GEJOTT@gmail.com> (raw)
In-Reply-To: <sashiko-outbox-238410@kernel.org>

On Sat Nov 28, 2026 at 2:41 AM CET, sashiko-bot wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] bpf, x86: skipping PROBE_MEM range check breaks
>   flex_array_far_join() test
> --
>
> commit 519a06c0e9f33f01690a25837946e3048111ee57
> Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>
> bpf, x86: Skip the PROBE_MEM address range check under SMAP
>
> This commit omits the x86-64 JIT runtime address range check before
> BPF_PROBE_MEM and BPF_PROBE_MEMSX loads when SMAP is enabled and the
> program was loaded with CAP_BPF, relying on SMAP and the page fault
> handler's exception table lookup instead.
>
>> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
>> index d51ae52fef719..019e5da72136d 100644
>> --- a/arch/x86/net/bpf_jit_comp.c
>> +++ b/arch/x86/net/bpf_jit_comp.c
> [ ... ]
>> @@ -4862,6 +4870,15 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
>>  		addrs[i] = proglen;
>>  	}
>>  	ctx.cleanup_addr = proglen;
>> +	/*
>> +	 * With SMAP enabled, a PROBE_MEM load of a user address faults (#PF, or
>> +	 * #GP with LASS) and the fault handler resolves the exception table
>> +	 * entry of the program, as for an unmapped kernel address. That lookup
>> +	 * only finds programs in the BPF ksym tree, so programs loaded without
>> +	 * CAP_BPF keep the address range check, as do kernels without SMAP.
>> +	 */
>> +	ctx.probe_mem_check = !cpu_feature_enabled(X86_FEATURE_SMAP) ||
>> +			      !bpf_prog_kallsyms_allowed(prog);
>>  skip_init_addrs:
>
> [Severity: Medium]
> Does skipping the range check break the flex_array_far_join() BPF selftest
> on x86-64 systems with SMAP enabled?
>
> tools/testing/selftests/bpf/progs/verifier_btf_array_access.c:flex_array_far_join() {
> 	SEC("tp_btf/exit_mmap")
> 	__success __arch_x86_64
> 	__jited("	leaq	0xa00000(%rbx), %r11")
> 	__naked void flex_array_far_join(void)
> }
>
> That test is loaded with CAP_BPF and matches the "leaq 0xa00000(%rbx), %r11"
> instruction from the PROBE_MEM range check to verify that the load was
> converted to BPF_PROBE_MEM, so its __jited() check fails when
> ctx.probe_mem_check is false.

Yes, this was an oversight on my part. Will fix in v3 respin (after some time).

  reply	other threads:[~2026-11-28  2:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  1:28 [PATCH bpf-next v2 0/3] bpf, x86: Drop the PROBE_MEM address range check under SMAP Kumar Kartikeya Dwivedi
2026-11-28  1:28 ` [PATCH bpf-next v2 1/3] x86/mm: Resolve BPF exception fixups for user address faults " Kumar Kartikeya Dwivedi
2026-11-28  1:46   ` sashiko-bot
2026-11-28  2:16     ` Kumar Kartikeya Dwivedi
2026-11-28  1:28 ` [PATCH bpf-next v2 2/3] bpf, x86: Skip the PROBE_MEM address range check " Kumar Kartikeya Dwivedi
2026-11-28  1:41   ` sashiko-bot
2026-11-28  2:16     ` Kumar Kartikeya Dwivedi [this message]
2026-11-28  1:28 ` [PATCH bpf-next v2 3/3] selftests/bpf: Test PROBE_MEM loads from invalid addresses Kumar Kartikeya Dwivedi

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=DN6HDX0GXICR.JK53Y1GEJOTT@gmail.com \
    --to=memxor@gmail.com \
    --cc=bpf@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.