BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	kkd@meta.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v4 05/16] bpf: Track verifier register diagnostic events
Date: Thu, 13 Aug 2026 12:44:01 -0700	[thread overview]
Message-ID: <c0a8a71dab13be1009080b4133069c7f55323af1.camel@gmail.com> (raw)
In-Reply-To: <20260812233326.3575958-6-memxor@gmail.com>

On Thu, 2026-08-13 at 01:33 +0200, Kumar Kartikeya Dwivedi wrote:

Claude ensures me that BPF_ATOMIC | BPF_FETCH lacks the mod_end() call
for when the stack memory is modified. Seem to be true.

...

> diff --git a/kernel/bpf/diagnostics.c b/kernel/bpf/diagnostics.c

...

> @@ -30,15 +30,23 @@
>  #define BPF_DIAG_CONTEXT_CNT (1 + BPF_DIAG_CONTEXT * 2)
>  #define BPF_DIAG_SOURCE_LANE_WIDTH 88
>  #define BPF_DIAG_TAB_WIDTH 8
> -#define BPF_DIAG_REG_DESC_LEN 512
> -#define BPF_DIAG_REG_TMP_LEN 192

Churn

...

> @@ -49,6 +57,13 @@ struct bpf_diag_history_event {
>  		struct {
>  			bool cond_true;
>  		} branch;
> +		struct {
> +			struct bpf_diag_mod_target target;
> +			struct bpf_diag_mod_target origin;

Silly question, should we keep the 'src'/'dst' terminology here?
In order to be in line with instruction set.

> +			struct bpf_diag_reg_snapshot old, new;
> +			u8 reason;
> +			bool origin_valid;
> +		} mod;
>  	};
>  };

...

> @@ -375,6 +401,34 @@ static void diag_print_wrapped_prefixed(struct bpf_verifier_env *env, const char
>  	}
>  }
>  
> +static void bpf_diag_format_btf_type(char *buf, size_t size, const struct btf *btf, u32 type_id)
> +{

Nit: single caller, might as well inline.

> +	size_t len;
> +	int ret;
> +
> +	buf[0] = '\0';
> +	ret = btf_type_snprintf_show_name(btf, type_id, buf, size);
> +	if (ret < 0 || !buf[0]) {
> +		scnprintf(buf, size, "BTF type ID %u", type_id);
> +		return;
> +	}
> +
> +	len = strlen(buf);
> +	if (len && buf[len - 1] == '{')
> +		buf[len - 1] = '\0';
> +}
> +
> +const char *bpf_diag_fmt_btf_type(struct bpf_verifier_env *env, const struct btf *btf, u32 type_id)
> +{
> +	char *buf = bpf_diag_fmt_buf(env, BPF_DIAG_FMT_BUF_SIZE);
> +
> +	if (!buf)
> +		return "";
> +
> +	bpf_diag_format_btf_type(buf, BPF_DIAG_FMT_BUF_SIZE, btf, type_id);
> +	return buf;
> +}

...

> +static bool diag_snapshot_eq(const struct bpf_diag_reg_snapshot *old,
> +			     const struct bpf_diag_reg_snapshot *new)
> +{

Nit: memcmp?

> +	return old->type == new->type && old->map_ptr == new->map_ptr && old->btf == new->btf &&
> +	       old->btf_id == new->btf_id && old->var_off.value == new->var_off.value &&
> +	       old->var_off.mask == new->var_off.mask && old->r64.base == new->r64.base &&
> +	       old->r64.size == new->r64.size;
> +}

...

> +static struct bpf_func_state *diag_func_state(struct bpf_verifier_env *env, u32 frameno)
> +{
> +	struct bpf_verifier_state *vstate = env->cur_state;
> +	int frame;
> +
> +	for (frame = 0; frame <= vstate->curframe; frame++) {
> +		if (vstate->frame[frame]->frameno == frameno)
> +			return vstate->frame[frame];
> +	}

Isn't this just `return frameno <= vstate->curframe ? vstate->frame[frameno] : NULL`?

> +	return NULL;
> +}
> +

...

> diff --git a/kernel/bpf/diagnostics.h b/kernel/bpf/diagnostics.h

...

--- 8< --------------------------------------

> +enum bpf_diag_mod_target_kind { ...
> +struct bpf_diag_mod_target { ...
> +static inline struct bpf_diag_mod_target bpf_diag_reg_target(u32 frameno, u8 regno) ...
> +static inline struct bpf_diag_mod_target bpf_diag_stack_arg_target(u32 frameno, u8 slot) ...
> +static inline struct bpf_diag_mod_target bpf_diag_stack_slot_target(u32 frameno, u16 spi) ...
> +static inline struct bpf_diag_mod_target bpf_diag_stack_range_target(u32 frameno, s16 min_off, ...

-------------------------------------- >8 ---

Move this to diagnostics.c? (and drop prefixes).

...

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c

...

> @@ -8902,13 +8936,18 @@ static int check_func_proto(const struct bpf_func_proto *fn, struct bpf_call_arg
>   */
>  static void clear_all_pkt_pointers(struct bpf_verifier_env *env)
>  {
> +	struct bpf_stack_state *stack;
>  	struct bpf_func_state *state;
>  	struct bpf_reg_state *reg;
>  
> -	bpf_for_each_reg_in_vstate(env->cur_state, state, reg, ({
> -		if (reg_is_pkt_pointer_any(reg) || reg_is_dynptr_slice_pkt(reg))
> -			mark_reg_invalid(env, reg);
> -	}));
> +	bpf_for_each_reg_in_vstate_mask(
> +		env->cur_state, state, reg, stack, 1 << STACK_SPILL, ({
> +			if (reg_is_pkt_pointer_any(reg) || reg_is_dynptr_slice_pkt(reg)) {
> +				bpf_diag_record_scrub(env, reg, BPF_DIAG_MOD_PKT_DATA_CHANGE);
> +				mark_reg_invalid(env, reg);
> +			}
> +		}))
> +		;
>  }

Nit: bpf_for_each_reg_in_vstate_mask conversion is not necessary.

  parent reply	other threads:[~2026-08-13 19:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 23:33 [PATCH bpf-next v4 00/16] Redesign Verification Errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 01/16] bpf: Add verifier diagnostics report helpers Kumar Kartikeya Dwivedi
2026-08-12 23:41   ` sashiko-bot
2026-08-13 18:46   ` Eduard Zingerman
2026-08-12 23:33 ` [PATCH bpf-next v4 02/16] bpf: Add source and instruction diagnostic context Kumar Kartikeya Dwivedi
2026-08-13  0:15   ` sashiko-bot
2026-08-13 18:46   ` Eduard Zingerman
2026-08-12 23:33 ` [PATCH bpf-next v4 03/16] bpf: Add verifier diagnostic event log Kumar Kartikeya Dwivedi
2026-08-13 18:45   ` Eduard Zingerman
2026-08-12 23:33 ` [PATCH bpf-next v4 04/16] bpf: Prune verifier diagnostics when switching paths Kumar Kartikeya Dwivedi
2026-08-13 18:34   ` Eduard Zingerman
2026-08-12 23:33 ` [PATCH bpf-next v4 05/16] bpf: Track verifier register diagnostic events Kumar Kartikeya Dwivedi
2026-08-12 23:53   ` sashiko-bot
2026-08-13 19:44   ` Eduard Zingerman [this message]
2026-08-12 23:33 ` [PATCH bpf-next v4 06/16] bpf: Track verifier reference " Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 07/16] bpf: Track verifier context " Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 08/16] bpf: Report Register Type Safety errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 09/16] bpf: Report Memory Safety bounds errors Kumar Kartikeya Dwivedi
2026-08-13 19:52   ` Eduard Zingerman
2026-08-12 23:33 ` [PATCH bpf-next v4 10/16] bpf: Report Resource Lifetime reference leaks Kumar Kartikeya Dwivedi
2026-08-13 19:59   ` Eduard Zingerman
2026-08-12 23:33 ` [PATCH bpf-next v4 11/16] bpf: Report Call Type Safety argument errors Kumar Kartikeya Dwivedi
2026-08-12 23:58   ` sashiko-bot
2026-08-12 23:33 ` [PATCH bpf-next v4 12/16] bpf: Report Execution Context Safety errors Kumar Kartikeya Dwivedi
2026-08-13 20:12   ` Eduard Zingerman
2026-08-12 23:33 ` [PATCH bpf-next v4 13/16] bpf: Report Program Structure CFG errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 14/16] bpf: Report Policy helper and kfunc errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 15/16] bpf: Report Verifier Limit errors Kumar Kartikeya Dwivedi
2026-08-13 20:34   ` Eduard Zingerman
2026-08-12 23:33 ` [PATCH bpf-next v4 16/16] bpf: Gate verifier diagnostics on log level Kumar Kartikeya Dwivedi
2026-08-13 20:38   ` Eduard Zingerman
2026-08-13  1:38 ` [PATCH bpf-next v4 00/16] Redesign Verification Errors 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=c0a8a71dab13be1009080b4133069c7f55323af1.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=emil@etsalapatis.com \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox