From: sashiko-bot@kernel.org
To: listout@listout.xyz, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2] selftests/bpf: Add tests for memcg kfuncs
Date: Tue, 13 Oct 2026 15:23:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-169989@kernel.org> (raw)
In-Reply-To: <20261013151621.1526699-1-listout@listout.xyz>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: Missing negative bounds check in bpf_mem_cgroup_*_events() allows OOB read
--
commit a4794021755b1042b63dca630dda69e60c099827
Author: Brahmajit Das <bdas@suse.de>
selftests/bpf: Add tests for memcg kfuncs
This patch adds new selftest coverage for various memcg kfuncs,
including bpf_mem_cgroup_usage(), bpf_mem_cgroup_memory_events(),
and bpf_proactive_reclaim(). It validates their behavior against
a test cgroup from syscall programs.
Link: https://lore.kernel.org/bpf/20261013143853.1379307-1-listout@listout.xyz/
> diff --git a/tools/testing/selftests/bpf/progs/memcg_kfuncs.c b/tools/testing/selftests/bpf/progs/memcg_kfuncs.c
> new file mode 100644
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/memcg_kfuncs.c
[ ... ]
> @@ -0,0 +1,106 @@
[ ... ]
> +SEC("syscall")
> +int memcg_query(void *ctx)
> +{
[ ... ]
> + /* Out-of-range indices must be rejected with (unsigned long)-1. */
> + bad_memory_event = bpf_mem_cgroup_memory_events(memcg,
> + bpf_core_enum_value(enum memcg_memory_event, MEMCG_NR_MEMORY_EVENTS));
> + bad_vm_event = bpf_mem_cgroup_vm_events(memcg,
> + bpf_core_enum_value(enum vm_event_item, NR_VM_EVENT_ITEMS));
> + bad_page_state = bpf_mem_cgroup_page_state(memcg, -1);
> + /* Negative indices must not bypass the bounds checks. */
> + neg_memory_event = bpf_mem_cgroup_memory_events(memcg, -1);
> + neg_vm_event = bpf_mem_cgroup_vm_events(memcg, -1);
[Severity: High]
Can this test sequence inadvertently trigger an out-of-bounds read regression
in the kernel?
The BPF verifier does not enforce bounds for enum arguments, so a negative
value of -1 is passed directly to the kernel kfunc. Looking at
bpf_mem_cgroup_memory_events() in mm/bpf_memcontrol.c:
if (unlikely(event >= MEMCG_NR_MEMORY_EVENTS))
return (unsigned long)-1;
return atomic_long_read(&memcg->memory_events[event]);
Because event is a signed enum, the bounds check uses a signed comparison.
Passing -1 evaluates as less than MEMCG_NR_MEMORY_EVENTS, bypassing the check,
and proceeds to access the memory_events array with a negative index.
A similar pattern appears to exist for bpf_mem_cgroup_vm_events() which routes
through memcg_vm_event_item_valid() in mm/memcontrol.c and performs a signed
comparison against NR_VM_EVENT_ITEMS.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151621.1526699-1-listout@listout.xyz?part=1
next prev parent reply other threads:[~2026-10-13 15:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 15:16 [PATCH bpf-next v2] selftests/bpf: Add tests for memcg kfuncs listout
2026-10-13 15:23 ` sashiko-bot [this message]
2026-10-13 15:53 ` bot+bpf-ci
2026-10-13 16:59 ` Brahmajit Das
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=sashiko-outbox-169989@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=listout@listout.xyz \
--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.