]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Restore sysctl new-value from 1 to 0
authorDawei Feng <dawei.feng@seu.edu.cn>
Wed, 3 Jun 2026 10:53:17 +0000 (18:53 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 5 Jun 2026 22:54:35 +0000 (15:54 -0700)
Commit 4e63acdff864 ("bpf: Introduce bpf_sysctl_{get,set}_new_value
helpers") changed the success return value to 0, but failed to update the
corresponding check in __cgroup_bpf_run_filter_sysctl(). Since
bpf_prog_run_array_cg() now returns 0 on success, the legacy ret == 1
condition is never satisfied. As a result, the modified value is ignored,
and bpf_sysctl_set_new_value() fails to replace the write buffer.

Fix this by checking for a return value of 0 instead, so cgroup/sysctl
programs can correctly replace the pending sysctl buffer.

This bug was discovered during a manual code review. Tested via a
cgroup/sysctl BPF reproducer overriding writes to a target sysctl.
Pre-fix, bpf_sysctl_set_new_value("foo") was silently ignored: the write
returned 8192 and the value remained "600". Post-fix, the BPF replacement
buffer properly propagates: the write returns 3 and the value updates to
"foo".

Fixes: f10d05966196 ("bpf: Make BPF_PROG_RUN_ARRAY return -err instead of allow boolean")
Cc: stable@vger.kernel.org
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Signed-off-by: Dawei Feng <dawei.feng@seu.edu.cn>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Acked-by: Xu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/r/20260603105317.944304-4-dawei.feng@seu.edu.cn
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/cgroup.c

index 4bf0ec94e719facf1ff4f2072977118cb6c846d8..35d1f1428ef39e0309aa22cf5e1cef1eaee06747 100644 (file)
@@ -1936,7 +1936,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) {
                kvfree(*buf);
                *buf = ctx.new_val;
                *pcount = ctx.new_len;