Re: [PATCH bpf-next v5 08/14] bpf: Report Register Type Safety errors

Eduard Zingerman <[email protected]>
Newsgroups org.kernel.vger.bpf
Message-ID <[email protected]>
On Sat, 2026-08-15 at 07:34 +0000, [email protected] wrote:
> > diff --git a/kernel/bpf/diagnostics.c b/kernel/bpf/diagnostics.c
> 
> [ ... ]
> 
> > +static int diag_stack_argno(u8 slot)
> > +{
> > +	return MAX_BPF_FUNC_REG_ARGS + slot + 1;
> > +}
> > +
> > +static void diag_format_stack_arg(char *buf, size_t size, u8 slot, const char *arg_name)
> > +{
> > +	int argno = diag_stack_argno(slot);
> > +	const char *ordinal = diag_arg_ordinal(argno);
> > +
> > +	if (ordinal && arg_name)
> > +		scnprintf(buf, size, "outgoing stack argument %u (%s argument, %s)", slot + 1,
> > +			  ordinal, arg_name);
> 
> [ ... ]
> 
> > +static const char *diag_mod_target_desc(struct bpf_verifier_env *env,
> > +					const struct bpf_diag_mod_target *target)
> > +{
> > +	switch (target->kind) {
> > +	case BPF_DIAG_MOD_TARGET_REG:
> > +		return bpf_diag_fmt(env, "R%u", target->regno);
> > +	case BPF_DIAG_MOD_TARGET_STACK_ARG:
> > +		return bpf_diag_fmt(env, "stack arg%d", diag_stack_argno(target->stack_arg));
>                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Does this numbering match the rest of the diagnostic output?
> 
> diag_stack_argno() returns MAX_BPF_FUNC_REG_ARGS + slot + 1, which for
> slot 0 gives 6 (the absolute argument ordinal). But diag_format_stack_arg()
> uses slot + 1 to label the same slot, and the pre-existing verbose() message
> in check_outgoing_stack_args() also uses spi + 1.

This is legit, I think we need to use verifier.c:reg_arg_name() here.

...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.