From: sashiko-bot@kernel.org
To: "Qiurong Fang" <fangqiurong@kylinos.cn>
Cc: bpf@vger.kernel.org, sched-ext@lists.linux.dev
Subject: Re: [PATCH] sched_ext: Gate cid kfuncs behind the SCX struct_ops check
Date: Wed, 12 Aug 2026 06:24:58 +0000 [thread overview]
Message-ID: <20260812062459.3411E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260812061116.2691443-1-fangqiurong@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing negative bounds checks in memory cgroup kfuncs (`bpf_mem_cgroup_memory_events` and `bpf_mem_cgroup_vm_events`) allow out-of-bounds array access.
--
--- Patch [1]: [PATCH] sched_ext: Gate cid kfuncs behind the SCX struct_ops check ---
commit 44e99221673a68d8565292bb70385d8d0629f96c
Author: fangqiurong <fangqiurong@kylinos.cn>
sched_ext: Gate cid kfuncs behind the SCX struct_ops check
This commit updates scx_kfunc_context_filter() to recognize scx_kfunc_ids_cid.
It ensures that cid kfuncs are properly restricted and cannot be called from
arbitrary struct_ops programs.
[ ... ]
While reviewing this, I noticed a pre-existing issue in the BPF memory
cgroup kfuncs.
In mm/bpf_memcontrol.c:
> __bpf_kfunc unsigned long bpf_mem_cgroup_memory_events(struct mem_cgroup *memcg,
> enum memcg_memory_event event)
> {
> if (unlikely(event >= MEMCG_NR_MEMORY_EVENTS))
> return (unsigned long)-1;
>
> return atomic_long_read(&memcg->memory_events[event]);
> }
[Severity: High]
This is a pre-existing issue, but can a negative enum value bypass this bounds
check?
If a BPF program passes a negative integer for the event argument, the BPF
verifier does not enforce enum ranges, allowing the negative value to reach
the kfunc.
Because the check event >= MEMCG_NR_MEMORY_EVENTS performs a signed comparison,
would it evaluate to false for negative values and lead to an out-of-bounds
read of memcg->memory_events[event]?
In mm/memcontrol.c:
> bool memcg_vm_event_item_valid(enum vm_event_item idx)
> {
> if (idx >= NR_VM_EVENT_ITEMS)
> return false;
>
> return !BAD_STAT_IDX(memcg_events_index(idx));
> }
And in mm/bpf_memcontrol.c:
> __bpf_kfunc unsigned long bpf_mem_cgroup_vm_events(struct mem_cgroup *memcg,
> enum vm_event_item event)
> {
> if (unlikely(!memcg_vm_event_item_valid(event)))
> return (unsigned long)-1;
>
> return memcg_events(memcg, event);
> }
[Severity: High]
This isn't a bug introduced by this patch, but does memcg_vm_event_item_valid()
also miss negative enum values?
Since the bounds check uses a signed comparison, a negative idx evaluates to
false for idx >= NR_VM_EVENT_ITEMS.
When bpf_mem_cgroup_vm_events() passes an unfiltered enum to this helper, could
this result in an out-of-bounds read in memcg_events_index(idx) or
memcg_events()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260812061116.2691443-1-fangqiurong@kylinos.cn?part=1
next prev parent reply other threads:[~2026-08-12 6:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 6:11 [PATCH] sched_ext: Gate cid kfuncs behind the SCX struct_ops check Qiurong Fang
2026-08-12 6:24 ` sashiko-bot [this message]
2026-08-12 19:20 ` Tejun Heo
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=20260812062459.3411E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=fangqiurong@kylinos.cn \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox