All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amery Hung" <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 22/22] bpf: Check helper and kfunc arguments in one path
Date: Sat, 05 Sep 2026 22:33:47 +0000	[thread overview]
Message-ID: <20260905223348.85D551F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260905220117.922028-23-ameryhung@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Out-of-bounds reads on `meta->fn->arg_type` and `meta->fn->arg_btf_id` for kfuncs with more than 5 arguments, allowing bypass of eBPF verifier safety checks.
--

commit a1895fafaa5219b7b972d20a932c550f7862cec8
Author: Amery Hung <ameryhung@gmail.com>

bpf: Check helper and kfunc arguments in one path

This commit unifies the argument checking logic for BPF helpers and kfuncs
by introducing check_func_args(). It moves kfunc-specific argument handling
into the shared check_func_arg() path to avoid duplicating the argument
iteration and switch logic.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 6c5d7e544f844..54656fb31bbe7 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -8808,6 +8840,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
>  			  struct bpf_call_arg_meta *meta,
>  			  int insn_idx)
>  {
> +	const struct btf_param *btf_arg = meta->btf ? &btf_params(meta->func_proto)[arg] : NULL;
>  	const struct bpf_func_proto *fn = meta->fn;
>  	struct bpf_func_state *caller = cur_func(env);
>  	struct bpf_reg_state *regs = cur_regs(env);
>  	argno_t argno = argno_from_arg(arg + 1);
>  	struct bpf_reg_state *reg = get_func_arg_reg(caller, regs, arg);
>  	enum bpf_arg_type arg_type = fn->arg_type[arg];

[Severity: Critical]
Can this read out of bounds when processing kfuncs with more than 5
arguments? The fn->arg_type array is sized for MAX_BPF_FUNC_ARGS (5), but
kfuncs can have more arguments. For stack arguments (arg >= 5), this appears
to read past the end of the array.

[ ... ]
> @@ -8935,6 +8980,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
>  	case ARG_PTR_TO_BTF_ID_SOCK_COMMON:
>  	{
>  		const u32 *arg_btf_id = fn->arg_btf_id[arg];

[Severity: Critical]
Does this also read out of bounds for kfuncs with more than 5 arguments?
Similar to arg_type, the arg_btf_id array in struct bpf_func_proto is limited
to MAX_BPF_FUNC_ARGS. If a garbage pointer is dereferenced here, could it
crash the verifier?

[ ... ]
> @@ -9056,6 +9389,37 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
>  	return err;
>  }
>  
> +static int check_func_args(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,
> +			   int insn_idx)
> +{
> +	struct bpf_func_state *caller = cur_func(env);
> +	const struct btf_param *args = NULL;
> +	u32 arg, nargs = MAX_BPF_FUNC_REG_ARGS;
> +	int err;
> +
> +	if (meta->btf) {
> +		args = btf_params(meta->func_proto);
> +		nargs = btf_type_vlen(meta->func_proto);
> +	}
> +
> +	if (nargs > MAX_BPF_FUNC_REG_ARGS) {
> +		err = check_outgoing_stack_args(env, caller, nargs, meta->func_name,
> +						meta->btf, args);
> +		if (err)
> +			return err;
> +	}
> +
> +	for (arg = 0; arg < nargs; arg++) {
> +		if (meta->fn->arg_type[arg] == ARG_UNUSED)
> +			break;

[Severity: Critical]
Could this loop early-exit and bypass verifier checks for stack arguments?

Since nargs can exceed 5 for kfuncs, the out-of-bounds read on
meta->fn->arg_type[arg] might evaluate to ARG_UNUSED (0). If this happens,
the loop breaks and skips the safety checks for all remaining stack
arguments, potentially allowing unverified memory access.

> +		err = check_func_arg(env, arg, meta, insn_idx);
> +		if (err)
> +			return err;
> +	}
> +
> +	return 0;
> +}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260905220117.922028-1-ameryhung@gmail.com?part=22

  reply	other threads:[~2026-09-05 22:33 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-05 22:00 [PATCH bpf-next v1 00/22] bpf: Unify helper and kfunc argument checks Amery Hung
2026-09-05 22:00 ` [PATCH bpf-next v1 01/22] bpf: Pass call metadata through shared " Amery Hung
2026-09-05 22:00 ` [PATCH bpf-next v1 02/22] bpf: Address check_func_arg() arguments by argno Amery Hung
2026-09-05 22:44   ` bot+bpf-ci
2026-09-09 17:37     ` Amery Hung
2026-09-05 22:00 ` [PATCH bpf-next v1 03/22] bpf: Only compare func_id against BPF_FUNC_* for helper calls Amery Hung
2026-09-05 22:00 ` [PATCH bpf-next v1 04/22] bpf: Only compare func_id against kfunc BTF IDs for kfunc calls Amery Hung
2026-09-05 22:44   ` bot+bpf-ci
2026-09-09 17:47     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 05/22] bpf: Rename ambiguous function argument types Amery Hung
2026-09-05 23:08   ` bot+bpf-ci
2026-09-09 17:54     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 06/22] bpf: Unify kfunc argument kinds with enum bpf_arg_type Amery Hung
2026-09-05 23:08   ` bot+bpf-ci
2026-09-09 18:04     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 07/22] bpf: Align helper and kfunc ARG_PTR_TO_PROG_AUX handling Amery Hung
2026-09-05 23:08   ` bot+bpf-ci
2026-09-09 18:23     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 08/22] bpf: Classify kfunc arguments the verifier ignores Amery Hung
2026-09-05 22:44   ` bot+bpf-ci
2026-09-09 18:27     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 09/22] bpf: Set OBJ_RELEASE when generating kfunc argument types Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 10/22] bpf: Set MEM_UNINIT and dynptr subtypes when generating kfunc arg types Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 11/22] bpf: Set MEM_RCU when generating kfunc argument types Amery Hung
2026-09-05 22:44   ` bot+bpf-ci
2026-09-09 18:41     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 12/22] bpf: Resolve BTF ID of ARG_PTR_TO_BTF_ID in kfunc bpf_func_proto Amery Hung
2026-09-05 23:08   ` bot+bpf-ci
2026-09-09 20:42     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 13/22] bpf: Resolve ARG_PTR_TO_MEM | MEM_FIXED_SIZE size " Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 14/22] bpf: Consolidate runtime argument type resolution Amery Hung
2026-09-10 21:52   ` Alexei Starovoitov
2026-09-11 21:01     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 15/22] bpf: Consolidate nullable argument validation Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 16/22] bpf: Drop redundant BTF pointer helper write rejection Amery Hung
2026-09-05 23:08   ` bot+bpf-ci
2026-09-09 20:48     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 17/22] bpf: Consolidate helper and kfunc PTR_TO_BTF_ID argument matching Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 18/22] bpf: Admit kfunc argument registers through check_reg_type() Amery Hung
2026-09-05 23:23   ` bot+bpf-ci
2026-09-10 16:18     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 19/22] selftests/bpf: Test kfunc packet memory direct writes Amery Hung
2026-09-05 22:44   ` bot+bpf-ci
2026-09-11 20:46     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 20/22] bpf: Consolidate function call pkt_access validation Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 21/22] bpf: Consolidate release argument validation Amery Hung
2026-09-05 23:08   ` bot+bpf-ci
2026-09-11 20:47     ` Amery Hung
2026-09-05 22:01 ` [PATCH bpf-next v1 22/22] bpf: Check helper and kfunc arguments in one path Amery Hung
2026-09-05 22:33   ` sashiko-bot [this message]
2026-09-11 20:59     ` Amery Hung
2026-09-10 21:53   ` Alexei Starovoitov
2026-09-11 20:55     ` Amery Hung
2026-09-12  3:20 ` [PATCH bpf-next v1 00/22] bpf: Unify helper and kfunc argument checks patchwork-bot+netdevbpf

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=20260905223348.85D551F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ameryhung@gmail.com \
    --cc=bpf@vger.kernel.org \
    --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.