From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v1 1/2] bpf: Reject non-scalar bpf_loop iteration counts
Date: Sat, 05 Sep 2026 01:57:01 +0000 [thread overview]
Message-ID: <20260905015702.5ED241F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260905014735.1452988-2-memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing negative bounds checks for enum array indices in memcg BPF kfuncs (bpf_mem_cgroup_memory_events and bpf_mem_cgroup_vm_events).
--
commit 3f8d69cede626ae022617ccb30f54b8f41f90edd
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Reject non-scalar bpf_loop iteration counts
This commit fixes a verifier warning and subsequent panic triggered when
pointer values are passed to the bpf_loop() nr_loops argument. It
introduces ARG_SCALAR to ensure generic helper argument validation
rejects pointers before loop inlining and precision processing.
Link: https://lore.kernel.org/bpf/6a9ad24c.b5d4176b.238c3e.0001.GAE@google.com/
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 3a7eb2185c354..591dfab3e706c 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -894,6 +894,7 @@ enum bpf_arg_type {
>
> ARG_PTR_TO_CTX, /* pointer to context */
> ARG_ANYTHING, /* any (initialized) argument is ok */
> + ARG_SCALAR, /* scalar argument */
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the addition
of ARG_SCALAR and how the verifier handles scalar arguments, a pre-existing
missing bounds check was noticed in the memory cgroup kfuncs.
Could negative enum values passed by untrusted BPF programs cause an
out-of-bounds read in the memcg BPF kfuncs?
Looking at 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]);
And similarly in mm/bpf_memcontrol.c:bpf_mem_cgroup_vm_events(), which
exposes validation logic from mm/memcontrol.c:memcg_vm_event_item_valid():
if (idx >= NR_VM_EVENT_ITEMS)
return false;
return !BAD_STAT_IDX(memcg_events_index(idx));
Because the BPF verifier enforces scalar types but does not validate enum
ranges, a BPF program can pass a negative integer as the event parameter.
The bounds checks use signed comparisons without a lower bound (< 0) check,
so negative values will bypass the validation (e.g., -1 >= 4 evaluates to
false).
Can this lead to an out-of-bounds array access on kernel memory when the
negative value is used as an index into memcg->memory_events?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260905014735.1452988-1-memxor@gmail.com?part=1
next prev parent reply other threads:[~2026-09-05 1:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 1:47 [PATCH bpf v1 0/2] Fix bpf_loop syzbot report Kumar Kartikeya Dwivedi
2026-09-05 1:47 ` [PATCH bpf v1 1/2] bpf: Reject non-scalar bpf_loop iteration counts Kumar Kartikeya Dwivedi
2026-09-05 1:57 ` sashiko-bot [this message]
2026-09-05 5:56 ` Kumar Kartikeya Dwivedi
2026-09-06 3:46 ` Eduard Zingerman
2026-09-05 1:47 ` [PATCH bpf v1 2/2] selftests/bpf: Test pointer bpf_loop iteration count rejection Kumar Kartikeya Dwivedi
2026-09-06 3:45 ` Eduard Zingerman
2026-09-06 4:10 ` [PATCH bpf v1 0/2] Fix bpf_loop syzbot report 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=20260905015702.5ED241F00A3D@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.