]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf,fork: wipe ->bpf_storage before bailouts that access it
authorJann Horn <jannh@google.com>
Fri, 26 Jun 2026 15:52:52 +0000 (17:52 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 29 Jun 2026 22:08:23 +0000 (15:08 -0700)
commit9b51a6155d14389876916726430da30eabb1d4ed
tree9df35d6866ce873eeeb5669d4e0febd48303d48b
parent26490a375cb9be9bac96b5171610fd85ca6c2305
bpf,fork: wipe ->bpf_storage before bailouts that access it

Currently, copy_process() can bail out to free_task() before p->bpf_storage
has been initialized, with this call graph (shown here for the
!CONFIG_MEMCG case):

copy_process
  dup_task_struct
    arch_dup_task_struct
      [copies the entire task_struct, including ->bpf_storage member]
  [RLIMIT_NPROC check fails]
  delayed_free_task
    free_task
      bpf_task_storage_free
        rcu_dereference(task->bpf_storage)
        bpf_local_storage_destroy

In this case, the nascent task's ->bpf_storage member that
bpf_local_storage_destroy() operates on is a plain copy of the parent's
->bpf_storage pointer, not a real initialized pointer.
This leads to badness (kernel hangs, UAF).

This is reachable as long as the process calling fork() has been inserted
into a task storage map.

Cc: stable@kernel.org
Fixes: a10787e6d58c ("bpf: Enable task local storage for tracing programs")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
kernel/fork.c