BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	bot+bpf-ci@kernel.org,
	 Anton Protopopov <a.s.protopopov@gmail.com>
Cc: emil@etsalapatis.com, bpf@vger.kernel.org, andrii@kernel.org,
	ast@kernel.org, 	daniel@iogearbox.net, john.fastabend@gmail.com,
	memxor@gmail.com, 	yonghong.song@linux.dev,
	martin.lau@kernel.org, clm@meta.com, 	ihor.solodrai@linux.dev
Subject: Re: [PATCH v4 2/5] bpf/verifier: do not limit maximum direct offset into arena map
Date: Tue, 16 Dec 2025 10:48:40 -0800	[thread overview]
Message-ID: <18ef13a0b9588cefacc58434bb6a097b92c7d6a7.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzazeSaj5MgF01uDMOdiMDSA=YVU=kvzSDKB_Hx7NOARtw@mail.gmail.com>

On Tue, 2025-12-16 at 10:38 -0800, Andrii Nakryiko wrote:
> On Tue, Dec 16, 2025 at 10:02 AM <bot+bpf-ci@kernel.org> wrote:
> > 
> > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > > index a31c032b2dd6..d6b8a77fbe3b 100644
> > > --- a/kernel/bpf/verifier.c
> > > +++ b/kernel/bpf/verifier.c
> > > @@ -21132,11 +21132,6 @@ static int resolve_pseudo_ldimm64(struct bpf_verifier_env *env)
> > >               } else {
> > >                       u32 off = insn[1].imm;
> > > 
> > > -                     if (off >= BPF_MAX_VAR_OFF) {
> > > -                             verbose(env, "direct value offset of %u is not allowed\n", off);
> > > -                             return -EINVAL;
> > > -                     }
> > > -
> > >                       if (!map->ops->map_direct_value_addr) {
> > >                               verbose(env, "no direct value access support for this map type\n");
> > >                               return -EINVAL;
> > 
> > The map_direct_value_addr() implementations for array and arena maps
> > return only the base address, and then resolve_pseudo_ldimm64() adds the
> > offset at line 21148:
> > 
> >     aux->map_off = off;
> >     addr += off;
> > 
> > However, insn_array_map_direct_value_addr() (kernel/bpf/bpf_insn_array.c)
> > has a different implementation pattern:
> > 
> >     static int insn_array_map_direct_value_addr(const struct bpf_map *map,
> >                                                  u64 *imm, u32 off)
> >     {
> >         struct bpf_insn_array *insn_array = cast_insn_array(map);
> > 
> >         if ((off % sizeof(long)) != 0 ||
> >             (off / sizeof(long)) >= map->max_entries)
> >             return -EINVAL;
> > 
> >         /* from BPF's point of view, this map is a jump table */
> >         *imm = (unsigned long)insn_array->ips + off;
> > 
> >         return 0;
> >     }
> > 
> > Notice that insn_array adds the offset to the base address inside the
> > function (line: *imm = (unsigned long)insn_array->ips + off). When
> > resolve_pseudo_ldimm64() then adds the offset again at line 21148, the
> > result is:
> > 
> >     addr = (insn_array->ips + off) + off = insn_array->ips + 2*off
> > 
> > Can this cause insn_array maps to access incorrect array elements? For
> > example, if a program requests offset 32 (which passes the bounds check
> > since 32/8 = 4 < max_entries), the actual offset becomes 64, potentially
> > accessing insn_array->ips[8] when max_entries is only 10.
> 
> That's a question to Anton (cc'ed), not really related to this patch.
> Anton, please check and send a fix, if necessary.

Seem to be a valid concern.
We don't have tests for BPF_PSEUDO_MAP_VALUE used in combination with
instruction maps.

[...]

  reply	other threads:[~2025-12-16 18:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-16 17:33 [PATCH v4 0/5] libbpf: move arena variables out of the zero page Emil Tsalapatis
2025-12-16 17:33 ` [PATCH v4 1/5] selftests/bpf: explicitly account for globals in verifier_arena_large Emil Tsalapatis
2025-12-16 17:33 ` [PATCH v4 2/5] bpf/verifier: do not limit maximum direct offset into arena map Emil Tsalapatis
2025-12-16 18:02   ` bot+bpf-ci
2025-12-16 18:38     ` Andrii Nakryiko
2025-12-16 18:48       ` Eduard Zingerman [this message]
2025-12-16 23:32         ` Anton Protopopov
2025-12-16 17:33 ` [PATCH v4 3/5] libbpf: turn relo_core->sym_off unsigned Emil Tsalapatis
2025-12-16 17:33 ` [PATCH v4 4/5] libbpf: move arena globals to the end of the arena Emil Tsalapatis
2025-12-16 17:33 ` [PATCH v4 5/5] selftests/bpf: add tests for the arena offset of globals Emil Tsalapatis
2025-12-16 19:00 ` [PATCH v4 0/5] libbpf: move arena variables out of the zero page 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=18ef13a0b9588cefacc58434bb6a097b92c7d6a7.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=a.s.protopopov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=yonghong.song@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