All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shung-Hsi Yu <shung-hsi.yu@suse.com>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	 Mykyta Yatsenko <yatsenko@meta.com>
Cc: Paul Chaignon <paul.chaignon@gmail.com>,
	 Ihor Solodrai <ihor.solodrai@linux.dev>,
	bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
	 daniel@iogearbox.net, kafai@meta.com, kernel-team@meta.com,
	eddyz87@gmail.com,  memxor@gmail.com
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Reject scalar store into kptr slot
Date: Tue, 2 Jun 2026 12:38:34 +0800	[thread overview]
Message-ID: <ah5czWWfKhE-9L33@u94a> (raw)
In-Reply-To: <aeFglj36jC4DyiIC@mail.gmail.com>

Cc Ihor since BPF CI should be able to remove map_kptr from deny list
once this is fixed.

On Fri, Apr 17, 2026 at 12:20:06AM +0200, Paul Chaignon wrote:
> On Thu, Apr 16, 2026 at 11:08:08AM -0700, Mykyta Yatsenko wrote:
...
> > +SEC("?tc")
> > +__failure __msg("invalid kptr access, R")
> > +int reject_scalar_store_to_kptr(struct __sk_buff *ctx)
> > +{
> > +	struct map_value *v;
> > +	int key = 0;
> > +
> > +	v = bpf_map_lookup_elem(&array_map, &key);
> > +	if (!v)
> > +		return 0;
> > +
> > +	*(volatile u64 *)&v->unref_ptr = 0xBADC0DE;
> > +	return 0;
> > +}
> > +
...

With test_progs-cpuv4 the error was slightly different due to the use of
BPF_ST instead of BPF_STX, and thus this test will fail due to
mismatched error message:

  run_subtest:PASS:obj_open_mem 0 nsec
  libbpf: prog 'reject_scalar_store_to_kptr': BPF program load failed: -EACCES
  libbpf: prog 'reject_scalar_store_to_kptr': failed to load: -EACCES
  libbpf: failed to load object 'map_kptr_fail'
  run_subtest:PASS:unexpected_load_success 0 nsec
  validate_msgs:FAIL:934 expect_msg
  VERIFIER LOG:
  =============
  0: R1=ctx() R10=fp0
  ; int key = 0; @ map_kptr_fail.c:393
  0: (62) *(u32 *)(r10 -4) = 0          ; R10=fp0 fp-8=0000????
  1: (bf) r2 = r10                      ; R2=fp0 R10=fp0
  2: (07) r2 += -4                      ; R2=fp-4
  ; v = bpf_map_lookup_elem(&array_map, &key); @ map_kptr_fail.c:395
  3: (18) r1 = 0xffff8ddd0bb76c00       ; R1=map_ptr(map=array_map,ks=4,vs=32)
  5: (85) call bpf_map_lookup_elem#1    ; R0=map_value(map=array_map,ks=4,vs=32)
  ; if (!v) @ map_kptr_fail.c:396
  6: (15) if r0 == 0x0 goto pc+1        ; R0=map_value(map=array_map,ks=4,vs=32)
  ; *(volatile u64 *)&v->unref_ptr = 0xBADC0DE; @ map_kptr_fail.c:399
  7: (7a) *(u64 *)(r0 +8) = 195936478
  BPF_ST imm must be 0 when storing to kptr at off=8
  processed 7 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
  =============
  EXPECTED   SUBSTR: 'invalid kptr access, R'
  #214/20  map_kptr/reject_scalar_store_to_kptr:FAIL

Note: currently BPF CI does not test map_kptr due to it being in the
denylist.

  reply	other threads:[~2026-06-02  4:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16 18:08 [PATCH bpf-next 0/2] bpf: Fix NULL deref when storing scalar into kptr slot Mykyta Yatsenko
2026-04-16 18:08 ` [PATCH bpf-next 1/2] bpf: Fix NULL deref in map_kptr_match_type for scalar regs Mykyta Yatsenko
2026-04-16 22:16   ` Paul Chaignon
2026-04-16 18:08 ` [PATCH bpf-next 2/2] selftests/bpf: Reject scalar store into kptr slot Mykyta Yatsenko
2026-04-16 22:20   ` Paul Chaignon
2026-06-02  4:38     ` Shung-Hsi Yu [this message]
2026-04-16 22:30 ` [PATCH bpf-next 0/2] bpf: Fix NULL deref when storing scalar " patchwork-bot+netdevbpf

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=ah5czWWfKhE-9L33@u94a \
    --to=shung-hsi.yu@suse.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=kafai@meta.com \
    --cc=kernel-team@meta.com \
    --cc=memxor@gmail.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=paul.chaignon@gmail.com \
    --cc=yatsenko@meta.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.