All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 11/16] bpf: Report Call Type Safety argument errors
Date: Wed, 12 Aug 2026 23:58:59 +0000	[thread overview]
Message-ID: <20260812235900.789091F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260812233326.3575958-12-memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Uninitialized variable `ref_id` used in `check_kfunc_args` for non-pointer release kfunc arguments.
- [Low] Incorrect diagnostic message for kfunc fixed-size memory arguments failing bounds checks.
--

--- Patch [11]: [PATCH bpf-next v4 11/16] bpf: Report Call Type Safety argument errors ---
commit ea19a04c0e142c86cd13b8e8524d76e024167249
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

bpf: Report Call Type Safety argument errors

Augment selected helper and kfunc argument-contract failures with Call Type
Safety reports. Keep the existing terse verifier messages and add reason,
source context, causal register or stack-argument history, and targeted
suggestions.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 24ae3cb38f6d8..7e28f4d9f5c4d 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -12361,29 +12437,43 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_call_arg_me
>  
>  		t = btf_type_skip_modifiers(btf, args[i].type, NULL);
>  
> -		if (btf_type_is_ptr(t) && (bpf_register_is_null(reg) || type_may_be_null(reg->type)) &&
> +		if (btf_type_is_ptr(t)) {
> +			ref_t = btf_type_skip_modifiers(btf, t->type, &ref_id);
> +			ref_tname = btf_name_by_offset(btf, ref_t->name_off);
> +		}
> +
> +		if (btf_type_is_ptr(t) &&
> +		    (bpf_register_is_null(reg) || type_may_be_null(reg->type)) &&
>  		    !type_may_be_null(kf_arg_type)) {

[ ... ]

>  		}
>  
>  		if (regno == meta->release_regno && !is_kfunc_arg_dynptr(meta->btf, &args[i]) &&
>  		    !reg_is_referenced(env, reg) && !bpf_register_is_null(reg)) {
> +			const char *expected_type;
> +
> +			expected_type = diag_btf_type_name(env, btf, ref_id);

[Severity: Medium]
Could this result in using an uninitialized ref_id? If a module registers a
kfunc with KF_RELEASE that takes a non-pointer argument, btf_type_is_ptr(t)
would be false, skipping the initialization of ref_id.

Then, on the release argument mismatch path here, diag_btf_type_name() would
read uninitialized stack memory from ref_id, which might lead to out-of-bounds
reads in btf_type_by_id() or leak stack contents into the verifier log.

[ ... ]

> @@ -12706,8 +12863,17 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_call_arg_me
>  					return -EINVAL;
>  				}
>  				ret = check_mem_reg(env, reg, argno, type_size, BPF_READ | BPF_WRITE, meta);
> -				if (ret < 0)
> +				if (ret < 0) {
> +					const char *expected_type;
> +
> +					expected_type = diag_btf_type_name(env, btf, ref_id);
> +					diag_call_arg_fmt(env, insn_idx, argno, func_name,
> +							  "Pass stack, map, context, or other verifier-known memory of the expected type and size, not an integer cast to a pointer.",
> +							  "the kfunc expects %u bytes of memory for %s, but it is %s and not verifier-known memory",
> +							  type_size, expected_type,
> +							  bpf_diag_reg_type_plain(env, reg->type));

[Severity: Low]
Does this emit a misleading diagnostic when the bounds check fails? If a kfunc
takes a fixed-size memory argument and the BPF program passes a valid
verifier-known memory pointer (like PTR_TO_STACK) but the buffer is too small,
check_mem_reg() returns an error.

This diagnostic would then unconditionally claim the argument is "not
verifier-known memory" and advise not to pass an "integer cast to a pointer",
which obscures the actual bounds-check issue.

>  					return ret;
> +				}
>  			}
>  			break;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812233326.3575958-1-memxor@gmail.com?part=11

  reply	other threads:[~2026-08-12 23:59 UTC|newest]

Thread overview: 22+ 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-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-12 23:33 ` [PATCH bpf-next v4 03/16] bpf: Add verifier diagnostic event log Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 04/16] bpf: Prune verifier diagnostics when switching paths Kumar Kartikeya Dwivedi
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-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-12 23:33 ` [PATCH bpf-next v4 10/16] bpf: Report Resource Lifetime reference leaks Kumar Kartikeya Dwivedi
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 [this message]
2026-08-12 23:33 ` [PATCH bpf-next v4 12/16] bpf: Report Execution Context Safety errors Kumar Kartikeya Dwivedi
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-12 23:33 ` [PATCH bpf-next v4 16/16] bpf: Gate verifier diagnostics on log level Kumar Kartikeya Dwivedi
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=20260812235900.789091F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=sashiko-reviews@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.