BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Daniel Xu <dxu@dxuuu.xyz>,
	andrii@kernel.org, ast@kernel.org,  shuah@kernel.org,
	daniel@iogearbox.net
Cc: john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org,
	 yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, 	jolsa@kernel.org, mykolal@fb.com,
	bpf@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v6 4/5] bpf: verifier: Support eliding map lookup nullness
Date: Thu, 02 Jan 2025 18:53:54 -0800	[thread overview]
Message-ID: <478322da282bbdae28027967ff47bfe2504559fe.camel@gmail.com> (raw)
In-Reply-To: <86213ea40c6e6a30bf8ba967da9b9c4c6d77fd0b.1734667691.git.dxu@dxuuu.xyz>

On Thu, 2024-12-19 at 21:09 -0700, Daniel Xu wrote:

lgtm, but please see a note below.

[...]

> +/* Returns constant key value if possible, else negative error */
> +static s64 get_constant_map_key(struct bpf_verifier_env *env,
> +				struct bpf_reg_state *key,
> +				u32 key_size)
> +{
> +	struct bpf_func_state *state = func(env, key);
> +	struct bpf_reg_state *reg;
> +	int slot, spi, off;
> +	int spill_size = 0;
> +	int zero_size = 0;
> +	int stack_off;
> +	int i, err;
> +	u8 *stype;
> +
> +	if (!env->bpf_capable)
> +		return -EOPNOTSUPP;
> +	if (key->type != PTR_TO_STACK)
> +		return -EOPNOTSUPP;
> +	if (!tnum_is_const(key->var_off))
> +		return -EOPNOTSUPP;
> +
> +	stack_off = key->off + key->var_off.value;
> +	slot = -stack_off - 1;
> +	spi = slot / BPF_REG_SIZE;
> +	off = slot % BPF_REG_SIZE;
> +	stype = state->stack[spi].slot_type;
> +
> +	/* First handle precisely tracked STACK_ZERO */
> +	for (i = off; i >= 0 && stype[i] == STACK_ZERO; i--)
> +		zero_size++;
> +	if (zero_size >= key_size)
> +		return 0;
> +
> +	/* Check that stack contains a scalar spill of expected size */
> +	if (!is_spilled_scalar_reg(&state->stack[spi]))
> +		return -EOPNOTSUPP;
> +	for (i = off; i >= 0 && stype[i] == STACK_SPILL; i--)
> +		spill_size++;
> +	if (spill_size != key_size)
> +		return -EOPNOTSUPP;
> +
> +	reg = &state->stack[spi].spilled_ptr;
> +	if (!tnum_is_const(reg->var_off))
> +		/* Stack value not statically known */
> +		return -EOPNOTSUPP;
> +
> +	/* We are relying on a constant value. So mark as precise
> +	 * to prevent pruning on it.
> +	 */
> +	bt_set_frame_slot(&env->bt, env->cur_state->curframe, spi);

I think env->cur_state->curframe is not always correct here.
It should be key->frameno, as key might point a few stack frames up.

> +	err = mark_chain_precision_batch(env);
> +	if (err < 0)
> +		return err;
> +
> +	return reg->var_off.value;
> +}
> +
>  static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
>  			  struct bpf_call_arg_meta *meta,
>  			  const struct bpf_func_proto *fn,

[...]


  reply	other threads:[~2025-01-03  2:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-20  4:09 [PATCH bpf-next v6 0/5] Support eliding map lookup nullness Daniel Xu
2024-12-20  4:09 ` [PATCH bpf-next v6 1/5] bpf: verifier: Add missing newline on verbose() call Daniel Xu
2024-12-20  4:09 ` [PATCH bpf-next v6 2/5] bpf: tcp: Mark bpf_load_hdr_opt() arg2 as read-write Daniel Xu
2024-12-20  4:09 ` [PATCH bpf-next v6 3/5] bpf: verifier: Refactor helper access type tracking Daniel Xu
2024-12-20  4:09 ` [PATCH bpf-next v6 4/5] bpf: verifier: Support eliding map lookup nullness Daniel Xu
2025-01-03  2:53   ` Eduard Zingerman [this message]
2025-01-09 23:30     ` Daniel Xu
2024-12-20  4:09 ` [PATCH bpf-next v6 5/5] bpf: selftests: verifier: Add nullness elision tests Daniel Xu
2025-01-03  3:16   ` 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=478322da282bbdae28027967ff47bfe2504559fe.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dxu@dxuuu.xyz \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --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