]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
cgroup/rstat: validate cpu before css_rstat_cpu() access
authorQing Ming <a0yami@mailbox.org>
Sat, 16 May 2026 07:08:49 +0000 (15:08 +0800)
committerTejun Heo <tj@kernel.org>
Mon, 18 May 2026 19:31:52 +0000 (09:31 -1000)
commit8817005efbdfdf5d4e4814cb5dc52b53d12917d7
tree0be542a0dde49a8b72477bcbded6f032be25add6
parent345f40166694e60db6d5cf02233814bb27ac5dec
cgroup/rstat: validate cpu before css_rstat_cpu() access

css_rstat_updated() is exposed as a BPF kfunc and accepts a
caller-provided cpu argument. The function uses cpu for per-cpu rstat
lookups without checking whether it refers to a valid possible CPU.

A BPF iter/cgroup program with CAP_BPF and CAP_PERFMON can pass an
invalid cpu value. On an unfixed UBSCAN_BOUNDS test kernel, cpu ==
0x7fffffff triggers:

  UBSAN: array-index-out-of-bounds in kernel/cgroup/rstat.c:31:9
  index 2147483647 is out of range for type 'long unsigned int [64]'
  Call Trace:
    css_rstat_updated
    bpf_iter_run_prog
    cgroup_iter_seq_show
    bpf_seq_read

Add cpu validation to the BPF-facing css_rstat_updated() kfunc and
move the common implementation to __css_rstat_updated() for in-kernel
callers.

Fixes: a319185be9f5 ("cgroup: bpf: enable bpf programs to integrate with rstat")
Signed-off-by: Qing Ming <a0yami@mailbox.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
block/blk-cgroup.c
include/linux/cgroup.h
kernel/cgroup/rstat.c
mm/memcontrol.c