All of lore.kernel.org
 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 1/6] bpf: Keep fault protection when merging pointer types
Date: Sun, 16 Aug 2026 12:42:07 -0700	[thread overview]
Message-ID: <d73a4991b95cdbdb265f81708c88c04ee253e81b.camel@gmail.com> (raw)
In-Reply-To: <20260814215301.709827-1-daniel@iogearbox.net>

On Fri, 2026-08-14 at 23:52 +0200, Daniel Borkmann wrote:
> When the same BPF_LDX instruction is reached through paths that yield
> different pointer types, save_aux_ptr_type() merges them into a single
> type which is later used by bpf_convert_ctx_accesses() to decide whether
> the load has to be rewritten into a BPF_PROBE_MEM one.
> 
> Before f2362a57aeff ("bpf: allow void* cast using bpf_rdonly_cast()")
> the merge only accepted two PTR_TO_BTF_ID pointers and unconditionally
> fell back to PTR_TO_BTF_ID | PTR_UNTRUSTED, so the merged type was always
> one that gets the BPF_PROBE_MEM rewrite. However, the mentioned commit
> widened the merge to also cover a PTR_TO_MEM base and replaced the
> fallback by a union of the PTR_UNTRUSTED and MEM_RDONLY flags.
> 
> A union of flags though cannot express the property the later rewrite
> is built upon, some examples:
> 
>   - PTR_TO_MEM merged with PTR_TO_BTF_ID | PTR_UNTRUSTED gets
>     PTR_TO_MEM | PTR_UNTRUSTED but only the MEM_RDONLY variant is valid
>   - PTR_TO_MEM merged with a plain PTR_TO_BTF_ID gets PTR_TO_MEM
>     dropping the rewrite the latter type would have gotten
>   - PTR_TO_MEM | MEM_RDONLY merged with a plain PTR_TO_BTF_ID gets
>     PTR_TO_MEM | MEM_RDONLY which is not rewritten either since only
>     its PTR_UNTRUSTED variant is
> 
> In all three cases a program can take the unsafe path at runtime with a
> NULL or otherwise bad pointer and panic the kernel on the faulting load:
> 
>   BUG: kernel NULL pointer dereference, address: 0000000000000038
>   RIP: 0010:bpf_prog_77531a87032eeaf1_mixed_mem_btf_id_type+0x4b/0x65
>   Call Trace:
>    <TASK>
>    bpf_test_run+0x20b/0x460
>    bpf_prog_test_run_skb+0x650/0xbe0
>    __sys_bpf+0xb96/0x3140
>    __x64_sys_bpf+0x2c/0x40
>    do_syscall_64+0xba/0x590
>   Kernel panic - not syncing: Fatal exception in interrupt
> 
> Note that the last two shapes have to be fixed right here, otherwise
> the merged type retains nothing which marks the load as fault prone,
> thus no rule in bpf_convert_ctx_accesses() can recover it. Fix it by
> normalizing the merged type instead.
> 
> Reuse it in is_load_acq_unsafe() to avoid open coding, and trim the
> overly verbose comment which is more of an implementation detail of
> bpf_convert_ctx_accesses() anyway.
> 
> Fixes: f2362a57aeff ("bpf: allow void* cast using bpf_rdonly_cast()")
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
> ---

Acked-by: Eduard Zingerman <eddyz87@gmail.com>

...

      parent reply	other threads:[~2026-08-16 19:42 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
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 [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=d73a4991b95cdbdb265f81708c88c04ee253e81b.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 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.