BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: memxor@gmail.com, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 3/6] bpf: Reject a store through a fault prone pointer
Date: Sun, 16 Aug 2026 12:54:59 -0700	[thread overview]
Message-ID: <9b30b735a7df1584042a4dbed4d8f2f54cf2f395.camel@gmail.com> (raw)
In-Reply-To: <20260814215301.709827-3-daniel@iogearbox.net>

On Fri, 2026-08-14 at 23:52 +0200, Daniel Borkmann wrote:
> check_ptr_to_btf_access() allows the program to store before the default
> BTF access path gets to reject a non read access. ac65c710cc64 ("bpf:
> Reject writes through untrusted BTF pointers") closed that for a
> PTR_UNTRUSTED pointer, but a bare PTR_TO_BTF_ID may fault on a dereference
> just the same and is let through.
> 
> A BPF_LDX gets the BPF_PROBE_MEM rewrite in bpf_convert_ctx_accesses()
> and a bad address is handled, but a BPF_STX does not and cannot, there
> is no probed store to rewrite. The store is emitted as a plain one without
> an exception table entry and a bad address panics the kernel.
> 
> A bpf_qdisc program can reach this, bpf_qdisc_btf_struct_access() permits a
> write to Qdisc::limit and Qdisc::next_sched is a plain struct Qdisc pointer
> which the walk turns into the compat type:
> 
>   struct Qdisc *next = sch->next_sched;
> 
>   next->limit = 1000;
> 
>   BUG: kernel NULL pointer dereference, address: 0000000000000014
>   RIP: 0010:bpf_prog_c6e14e7f32c8e325_bpf_fifo_enqueue+0x3a/0x12b
>   Code: [...] bf e8 03 00 00 <89> 7e 14 41 8b 7f 14 [...]
>   Kernel panic - not syncing: Fatal exception in interrupt
> 
> Fix by widen the check to bpf_may_fault_on_deref() so that it covers both.
> 
> Fixes: 27ae7997a661 ("bpf: Introduce BPF_PROG_TYPE_STRUCT_OPS")
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
> ---
>  v1 -> v2:
>    - new patch
> 
>  kernel/bpf/verifier.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 2e6992569187..6610e2437047 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -5789,7 +5789,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
>  		return -EACCES;
>  	}
>  
> -	if (atype != BPF_READ && (type_flag(reg->type) & PTR_UNTRUSTED)) {
> +	if (atype != BPF_READ && bpf_may_fault_on_deref(reg->type)) {

The change is correct, but it appears that the if condition could be
simplified as just 'atype != BPF_READ'.
The function is named check_ptr_to_btf_access() and it is only called
when reg->type == PTR_TO_BTF_ID.

>  		verbose(env, "only read is supported\n");
>  		return -EACCES;
>  	}

  parent reply	other threads:[~2026-08-16 19:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 21:52 [PATCH bpf-next v2 1/6] bpf: Keep fault protection when merging pointer types Daniel Borkmann
2026-08-14 21:52 ` [PATCH bpf-next v2 2/6] bpf: Treat a fault prone PTR_TO_MEM as a pointer type mismatch Daniel Borkmann
2026-08-16 19:44   ` Eduard Zingerman
2026-08-14 21:52 ` [PATCH bpf-next v2 3/6] bpf: Reject a store through a fault prone pointer Daniel Borkmann
2026-08-14 22:40   ` bot+bpf-ci
2026-08-14 23:26     ` Daniel Borkmann
2026-08-16 19:54   ` Eduard Zingerman [this message]
2026-08-16 20:02     ` Eduard Zingerman
2026-08-14 21:52 ` [PATCH bpf-next v2 4/6] bpf: Rewrite any fault prone load out of a mem or btf_id pointer Daniel Borkmann
2026-08-16 20:06   ` Eduard Zingerman
2026-08-14 21:52 ` [PATCH bpf-next v2 5/6] selftests/bpf: Add tests for pointer type merge at a shared load Daniel Borkmann
2026-08-14 22:56   ` bot+bpf-ci
2026-08-14 23:35     ` Daniel Borkmann
2026-08-16 22:24   ` Eduard Zingerman
2026-08-16 22:32   ` Eduard Zingerman
2026-08-14 21:53 ` [PATCH bpf-next v2 6/6] selftests/bpf: Add tests for fault prone loads out of RCU pointers Daniel Borkmann
2026-08-14 22:03   ` sashiko-bot
2026-08-14 22:28     ` Daniel Borkmann
2026-08-16 22:24   ` Eduard Zingerman
2026-08-14 22:15 ` [PATCH bpf-next v2 1/6] bpf: Keep fault protection when merging pointer types sashiko-bot
2026-08-14 22:19   ` Daniel Borkmann
2026-08-16 19:42 ` Eduard Zingerman

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=9b30b735a7df1584042a4dbed4d8f2f54cf2f395.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=memxor@gmail.com \
    /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