linux-stable/kernel
Daniel Borkmann 66da7cee78 bpf: Fix oob access in cgroup local storage
[ Upstream commit abad3d0bad ]

Lonial reported that an out-of-bounds access in cgroup local storage
can be crafted via tail calls. Given two programs each utilizing a
cgroup local storage with a different value size, and one program
doing a tail call into the other. The verifier will validate each of
the indivial programs just fine. However, in the runtime context
the bpf_cg_run_ctx holds an bpf_prog_array_item which contains the
BPF program as well as any cgroup local storage flavor the program
uses. Helpers such as bpf_get_local_storage() pick this up from the
runtime context:

  ctx = container_of(current->bpf_ctx, struct bpf_cg_run_ctx, run_ctx);
  storage = ctx->prog_item->cgroup_storage[stype];

  if (stype == BPF_CGROUP_STORAGE_SHARED)
    ptr = &READ_ONCE(storage->buf)->data[0];
  else
    ptr = this_cpu_ptr(storage->percpu_buf);

For the second program which was called from the originally attached
one, this means bpf_get_local_storage() will pick up the former
program's map, not its own. With mismatching sizes, this can result
in an unintended out-of-bounds access.

To fix this issue, we need to extend bpf_map_owner with an array of
storage_cookie[] to match on i) the exact maps from the original
program if the second program was using bpf_get_local_storage(), or
ii) allow the tail call combination if the second program was not
using any of the cgroup local storage maps.

Fixes: 7d9c342789 ("bpf: Make cgroup storages shared between programs on the same cgroup")
Reported-by: Lonial Con <kongln9170@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20250730234733.530041-4-daniel@iogearbox.net
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-09-09 18:54:11 +02:00
..
bpf bpf: Fix oob access in cgroup local storage 2025-09-09 18:54:11 +02:00
cgroup cgroup/cpuset: Use static_branch_enable_cpuslocked() on cpusets_insane_config_key 2025-08-28 16:26:17 +02:00
configs
debug kdb: Do not assume write() callback available 2025-02-21 13:50:09 +01:00
dma dma/pool: Ensure DMA_DIRECT_REMAP allocations are decrypted 2025-09-04 15:26:30 +02:00
entry
events perf/core: Prevent VMA split of buffer mappings 2025-08-15 12:05:11 +02:00
futex
gcov
irq genirq: Make handle_enforce_irqctx() unconditionally available 2025-02-21 13:48:57 +01:00
kcsan kcsan: test: Initialize dummy variable 2025-08-15 12:04:59 +02:00
livepatch
locking locking/lockdep: Decrease nr_unused_locks if lock unused in zap_class() 2025-04-25 10:43:41 +02:00
module module: Prevent silent truncation of module name in delete_module(2) 2025-08-28 16:26:01 +02:00
power PM: sleep: console: Fix the black screen issue 2025-08-28 16:25:53 +02:00
printk printk: Fix signed integer overflow when defining LOG_BUF_LEN_MAX 2025-02-21 13:49:30 +01:00
rcu rcu: Protect ->defer_qs_iw_pending from data race 2025-08-28 16:25:55 +02:00
sched sched/fair: Bump sd->max_newidle_lb_cost when newidle balance fails 2025-08-28 16:25:56 +02:00
time clocksource: Fix the CPUs' choice in the watchdog per CPU verification 2025-06-27 11:07:31 +01:00
trace ftrace: Fix potential warning in trace_printk_seq during ftrace_dump 2025-09-04 15:26:24 +02:00
.gitignore
acct.c acct: block access to kernel internal filesystems 2025-03-07 16:56:39 +01:00
async.c
audit_fsnotify.c
audit_tree.c
audit_watch.c
audit.c
audit.h
auditfilter.c
auditsc.c
backtracetest.c
bounds.c
capability.c
cfi.c
compat.c
configs.c
context_tracking.c
cpu_pm.c
cpu.c hrtimers: Handle CPU state correctly on hotplug 2025-01-23 17:17:15 +01:00
crash_core.c
crash_dump.c
cred.c
delayacct.c
dma.c
exec_domain.c
exit.c perf: Fix sample vs do_exit() 2025-06-27 11:07:41 +01:00
extable.c
fail_function.c
fork.c mm: drop the assumption that VM_SHARED always implies writable 2025-08-28 16:26:12 +02:00
freezer.c
gen_kheaders.sh
groups.c
hung_task.c
iomem.c
irq_work.c
jump_label.c
kallsyms_internal.h
kallsyms.c
kcmp.c
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt
kcov.c
kexec_core.c
kexec_elf.c kexec: initialize ELF lowest address to ULONG_MAX 2025-04-10 14:33:36 +02:00
kexec_file.c
kexec_internal.h
kexec.c
kheaders.c
kmod.c
kprobes.c
ksysfs.c
kthread.c
latencytop.c
Makefile
module_signature.c
notifier.c
nsproxy.c
numa.c
padata.c padata: do not leak refcount in reorder_work 2025-06-04 14:40:20 +02:00
panic.c
params.c module: ensure that kobject_put() is safe for module type kobjects 2025-05-18 08:21:23 +02:00
pid_namespace.c
pid.c pid: add pidfd_prepare() 2025-06-04 14:40:25 +02:00
profile.c
ptrace.c
range.c
reboot.c
regset.c
relay.c
resource_kunit.c
resource.c
rseq.c rseq: Fix segfault on registration when rseq_cs is non-zero 2025-07-17 18:32:15 +02:00
scftorture.c
scs.c
seccomp.c
signal.c
smp.c
smpboot.c
smpboot.h
softirq.c lockdep: Fix wait context check on softirq for PREEMPT_RT 2025-06-04 14:40:03 +02:00
stackleak.c
stacktrace.c
static_call_inline.c
static_call.c
stop_machine.c
sys_ni.c
sys.c hrtimer: Use and report correct timerslack values for realtime tasks 2025-03-28 21:58:48 +01:00
sysctl-test.c
sysctl.c
task_work.c
taskstats.c
torture.c
tracepoint.c
tsacct.c
ucount.c ucount: fix atomic_long_inc_below() argument type 2025-08-15 12:05:05 +02:00
uid16.c
uid16.h
umh.c
up.c
user_namespace.c
user-return-notifier.c
user.c
usermode_driver.c
utsname_sysctl.c
utsname.c
watch_queue.c watch_queue: fix pipe accounting mismatch 2025-04-10 14:33:30 +02:00
watchdog_hld.c
watchdog.c
workqueue_internal.h
workqueue.c