From: sashiko-bot@kernel.org
To: "Amery Hung" <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 05/23] bpf: Clarify unused and scalar function argument types
Date: Fri, 11 Sep 2026 22:19:55 +0000 [thread overview]
Message-ID: <20260911221956.1F62A1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260911220415.1396439-6-ameryhung@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Out-of-bounds array access in memcg kfuncs (`bpf_mem_cgroup_memory_events` and `bpf_mem_cgroup_vm_events`) due to missing negative bounds checks for enum arguments.
--
commit a779fb1811c9555981f50c14118ca53a762cdd76
Author: Amery Hung <ameryhung@gmail.com>
bpf: Clarify unused and scalar function argument types
This commit renames ARG_DONTCARE to ARG_UNUSED to indicate it terminates
argument iteration. It also reuses ARG_SCALAR for integer, enum, and
exception callback arguments to reflect that they require SCALAR_VALUE.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 42d89db5df07b..5d21bee458055 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -9818,7 +9815,7 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
> struct bpf_reg_state *reg = get_func_arg_reg(caller, regs, i);
> struct bpf_subprog_arg_info *arg = &sub->args[i];
>
> - if (arg->arg_type == ARG_ANYTHING) {
> + if (arg->arg_type == ARG_SCALAR) {
> if (reg->type != SCALAR_VALUE) {
> bpf_log(log, "%s is not a scalar\n", reg_arg_name(env, argno));
> return -EINVAL;
[Severity: High]
This is a pre-existing issue, but while reviewing how the verifier treats
enum arguments as SCALAR_VALUE, I noticed that the memcg kfuncs might be
vulnerable to negative enum values.
Because the BPF verifier treats enum arguments as scalars without enforcing
their ranges, a BPF program can pass a negative value (like -1).
In bpf_mem_cgroup_memory_events(), the bounds check uses a signed
comparison:
mm/bpf_memcontrol.c:bpf_mem_cgroup_memory_events() {
if (unlikely(event >= MEMCG_NR_MEMORY_EVENTS))
return (unsigned long)-1;
return atomic_long_read(&memcg->memory_events[event]);
}
If event is negative, does this code overflow the memory_events[] array
and allow an out-of-bounds read?
Similarly, in bpf_mem_cgroup_vm_events(), it relies on
memcg_vm_event_item_valid() for bounds checking:
mm/bpf_memcontrol.c:bpf_mem_cgroup_vm_events() {
if (unlikely(!memcg_vm_event_item_valid(event)))
return (unsigned long)-1;
}
mm/memcontrol.c:memcg_vm_event_item_valid() {
if (idx >= NR_VM_EVENT_ITEMS)
return false;
return !BAD_STAT_IDX(memcg_events_index(idx));
}
If idx is negative, will this bypass the >= NR_VM_EVENT_ITEMS check and
cause an out-of-bounds access in memcg_events_index()?
Should these kfuncs be updated to explicitly check for negative values
(e.g., event < 0 || event >= MEMCG_NR_MEMORY_EVENTS)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260911220415.1396439-1-ameryhung@gmail.com?part=5
next prev parent reply other threads:[~2026-09-11 22:19 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 22:03 [PATCH bpf-next v2 00/23] Unify helper and kfunc argument checks Amery Hung
2026-09-11 22:03 ` [PATCH bpf-next v2 01/23] bpf: Pass call metadata through shared " Amery Hung
2026-09-11 22:03 ` [PATCH bpf-next v2 02/23] bpf: Address check_func_arg() arguments by argno Amery Hung
2026-09-11 22:03 ` [PATCH bpf-next v2 03/23] bpf: Only compare func_id against BPF_FUNC_* for helper calls Amery Hung
2026-09-11 22:03 ` [PATCH bpf-next v2 04/23] bpf: Only compare func_id against kfunc BTF IDs for kfunc calls Amery Hung
2026-09-11 22:03 ` [PATCH bpf-next v2 05/23] bpf: Clarify unused and scalar function argument types Amery Hung
2026-09-11 22:19 ` sashiko-bot [this message]
2026-09-11 22:03 ` [PATCH bpf-next v2 06/23] bpf: Unify kfunc argument kinds with enum bpf_arg_type Amery Hung
2026-09-11 22:26 ` sashiko-bot
2026-09-11 22:03 ` [PATCH bpf-next v2 07/23] bpf: Classify kfunc arguments the verifier ignores Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 08/23] bpf: Align helper and kfunc ARG_PTR_TO_PROG_AUX handling Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 09/23] bpf: Set OBJ_RELEASE when generating kfunc argument types Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 10/23] bpf: Set MEM_UNINIT and dynptr subtypes when generating kfunc arg types Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 11/23] bpf: Set MEM_RCU when generating kfunc argument types Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 12/23] bpf: Resolve BTF ID of ARG_PTR_TO_BTF_ID in kfunc bpf_func_proto Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 13/23] bpf: Resolve ARG_PTR_TO_MEM | MEM_FIXED_SIZE size " Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 14/23] bpf: Consolidate runtime argument type resolution Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 15/23] bpf: Consolidate nullable argument validation Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 16/23] bpf: Drop redundant BTF pointer helper write rejection Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 17/23] bpf: Consolidate helper and kfunc PTR_TO_BTF_ID argument matching Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 18/23] bpf: Admit kfunc argument registers through check_reg_type() Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 19/23] bpf: Consolidate function call pkt_access validation Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 20/23] selftests/bpf: Test kfunc packet memory direct writes Amery Hung
2026-09-11 22:36 ` sashiko-bot
2026-09-11 22:04 ` [PATCH bpf-next v2 21/23] bpf: Consolidate release argument validation Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 22/23] selftests/bpf: Test nullable per-CPU kptr identity after exchange Amery Hung
2026-09-11 22:04 ` [PATCH bpf-next v2 23/23] bpf: Check helper and kfunc arguments in one path Amery Hung
2026-09-12 3:20 ` [PATCH bpf-next v2 00/23] 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=20260911221956.1F62A1F00893@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.