From: sashiko-bot@kernel.org
To: "Dawei Feng" <dawei.feng@seu.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 1/2] bpf: cgroup: fix sysctl new value replacement
Date: Tue, 26 May 2026 14:03:28 +0000 [thread overview]
Message-ID: <20260526140329.187C01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260526131035.1312864-2-dawei.feng@seu.edu.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Calling kfree() on the sysctl buffer can cause a kernel panic because the buffer is originally allocated with kvzalloc() and may be backed by vmalloc().
- [High] The BPF-provided sysctl replacement buffer is not explicitly NUL-terminated, which violates the VFS sysctl contract and risks out-of-bounds reads in downstream proc handlers.
--
commit 87d6f30bc7d66708176be678dd7992a7d205d7b2
Author: Dawei Feng <dawei.feng@seu.edu.cn>
bpf: cgroup: fix sysctl new value replacement
This commit changes the success check from ret == 1 to !ret in
__cgroup_bpf_run_filter_sysctl(). This allows cgroup/sysctl BPF programs to
correctly replace the pending sysctl buffer after bpf_prog_run_array_cg()
returns 0 on success.
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index 876f6a81a9b61..8715a014c21d9 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -1935,7 +1935,7 @@ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
>
> kfree(ctx.cur_val);
>
> - if (ret == 1 && ctx.new_updated) {
> + if (!ret && ctx.new_updated) {
> kfree(*buf);
[Severity: Critical]
This is a pre-existing issue, but by activating this code path, could this
kfree() trigger a kernel panic?
Looking at proc_sys_call_handler(), the original sysctl write buffer is
allocated using kvzalloc(), which means it might be backed by vmalloc()
for larger allocations. If kfree() is called on a vmalloc address, it would
cause an invalid virtual-to-physical translation.
I noticed this is fixed in a later commit (bpf: cgroup: Use kvfree instead
of kfree in __cgroup_bpf_run_filter_sysctl), but should this patch be
self-contained to avoid exposing this bug?
> *buf = ctx.new_val;
[Severity: High]
This isn't a bug introduced by this patch, but now that this buffer
replacement path is reachable, does this violate the VFS sysctl contract
for null-termination?
The VFS sysctl contract guarantees that the write buffer passed to proc
handlers is a null-terminated string. Since ctx.new_val is allocated with
kmalloc_track_caller() which does not zero-initialize memory, and the
helper copies the buffer without explicitly appending a null byte, the
memory past the new length could contain uninitialized garbage.
Could this lead to out-of-bounds reads when downstream handlers pass this
buffer to string-parsing functions like kstrtoint()?
> *pcount = ctx.new_len;
> } else {
> kfree(ctx.new_val);
> }
>
> return ret;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260526131035.1312864-1-dawei.feng@seu.edu.cn?part=1
next prev parent reply other threads:[~2026-05-26 14:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 13:10 [PATCH 0/2] bpf: cgroup: fix sysctl new-value handling in __cgroup_bpf_run_filter_sysctl Dawei Feng
2026-05-26 13:10 ` [PATCH 1/2] bpf: cgroup: fix sysctl new value replacement Dawei Feng
2026-05-26 13:55 ` bot+bpf-ci
2026-05-26 14:03 ` sashiko-bot [this message]
2026-05-26 22:16 ` Emil Tsalapatis
2026-05-27 14:51 ` Dawei Feng
2026-05-26 13:10 ` [PATCH 2/2] bpf: cgroup: Use kvfree instead of kfree in __cgroup_bpf_run_filter_sysctl Dawei Feng
2026-05-26 22:24 ` Emil Tsalapatis
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=20260526140329.187C01F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dawei.feng@seu.edu.cn \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox