lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <haktyvoigwi2hz7f5j4m3go3trljy4u2cqis3wl7cl5iuhb4d7@nql73373o3ru>
Date: Tue, 1 Oct 2024 18:07:52 -0600
From: Daniel Xu <dxu@...uu.xyz>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Shuah Khan <shuah@...nel.org>, Daniel Borkmann <daniel@...earbox.net>, 
	Alexei Starovoitov <ast@...nel.org>, Eddy Z <eddyz87@...il.com>, Andrii Nakryiko <andrii@...nel.org>, 
	John Fastabend <john.fastabend@...il.com>, Martin KaFai Lau <martin.lau@...ux.dev>, 
	Song Liu <song@...nel.org>, Yonghong Song <yonghong.song@...ux.dev>, 
	KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>, 
	Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>, Mykola Lysenko <mykolal@...com>, 
	bpf <bpf@...r.kernel.org>, LKML <linux-kernel@...r.kernel.org>, 
	"open list:KERNEL SELFTEST FRAMEWORK" <linux-kselftest@...r.kernel.org>, Kernel Team <kernel-team@...a.com>
Subject: Re: [PATCH bpf-next v3 1/2] bpf: verifier: Support eliding map
 lookup nullness

On Wed, Sep 25, 2024 at 10:24:01AM GMT, Alexei Starovoitov wrote:
> On Tue, Sep 24, 2024 at 12:40 PM Daniel Xu <dxu@...uu.xyz> wrote:
> >
> > +
> > +/* Returns constant key value if possible, else -1 */
> > +static long get_constant_map_key(struct bpf_verifier_env *env,
> > +                                struct bpf_reg_state *key)
> > +{
> > +       struct bpf_func_state *state = func(env, key);
> > +       struct bpf_reg_state *reg;
> > +       int stack_off;
> > +       int slot;
> > +       int spi;
> > +
> > +       if (key->type != PTR_TO_STACK)
> > +               return -1;
> > +       if (!tnum_is_const(key->var_off))
> > +               return -1;
> > +
> > +       stack_off = key->off + key->var_off.value;
> > +       slot = -stack_off - 1;
> > +       if (slot < 0)
> > +               /* Stack grew upwards */
> 
> The comment is misleading.
> The verifier is supposed to catch this.
> It's just this helper was called before the stack bounds
> were checked?

Yeah. Stack bounds checked in check_stack_access_within_bounds() as part
of helper call argument checks.


> Maybe the call can be done later?

Maybe? The argument checking starts clobbering state so it'll probably
be not very simple to pull information out after args are checked.

I think the logic will probably be much easier to follow with current
approach. But maybe I'm missing a simpler idea.

> 
> > +               return -1;
> > +       else if (slot >= state->allocated_stack)
> > +               /* Stack uninitialized */
> > +               return -1;
> > +
> > +       spi = slot / BPF_REG_SIZE;
> > +       reg = &state->stack[spi].spilled_ptr;
> > +       if (!tnum_is_const(reg->var_off))
> > +               /* Stack value not statically known */
> > +               return -1;
> > +
> > +       return reg->var_off.value;
> > +}
> 
> Looks like the code is more subtle than it looks.
> 
> I think it's better to guard it all with CAP_BPF.

Ack.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ