From: "Chris Mason" <mason@kernel.org>
To: brauner@kernel.org, oleg@redhat.com, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: "Felix Kuehling" <Felix.Kuehling@amd.com>,
amd-gfx@lists.freedesktop.org, akpm@linux-foundation.org,
peterz@infradead.org, mingo@redhat.com, kees@kernel.org,
viro@zeniv.linux.org.uk, jack@suse.cz, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com, bsingharora@gmail.com,
eddyz87@gmail.com, memxor@gmail.com, yonghong.song@linux.dev,
martin.lau@linux.dev, song@kernel.org, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev,
sched-ext@lists.linux.dev, cgroups@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
mason@kernel.org
Subject: [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers
Date: Sat, 05 Dec 2026 08:11:02 -0500 [thread overview]
Message-ID: <20261204233428.14861-1-mason@kernel.org> (raw)
Hi everyone,
This is v2 of the AI generated fixes for stale pointers in task_struct.
The kernel only updates real_parent, parent and group_leader while a task is in
the process tree. BPF programs can find it before that, during the fork, and
after that, once it's been released. These pointers can lead to freed memory
then.
In v1, a released thread held a reference on its group leader, which I didn't
love. v2 takes no references. Instead, a task outside of the process tree only
points at tasks that can't go away: the forking task during the fork, and
init_task or itself after release_task().
- Patch 1: taskstats has the same bug without BPF, as Alexei spotted. It checks
pid_alive() now.
- Patch 2: a prep patch for patch 3.
- Patch 3: release_task() resets the pointers.
- Patch 4: the same for tasks that are still being forked, and for idle tasks.
- Patch 5: the BPF thread iterator doesn't start outside of the process tree.
- Patch 6: amdkfd can use a freed group leader too, without any BPF.
- Patches 7 and 8: an optional RFC for Oleg's idea to move group_leader into
signal_struct. BPF programs then see the right leader of a released thread,
but have to read it from the new place.
Patch 7/8 aren't required for my series but I had the bots look at Oleg's
suggestion.
The downside of patches 1-5 is that BPF programs see PID 0 as the parent of a
released task. Without patch 8, they also see a released thread as its own
leader.
AI generated tests reproduce the BPF bugs with KASAN on v7.4-rc5, and none of
them shows up with patches 1-5. Patch 6 isn't tested on hardware.
Changes since v1:
- Patches 1, 2 and 6-8: new.
- Patch 3: no reference on the leader any more, because it leaked (sashiko,
bpf-ci).
- Patch 4: pid_alive() now fails during a fork (Oleg), so patch 5 also catches
tasks that are still being forked (bpf-ci). The pointers are reset after a
failed fork too (sashiko). New changelog (Oleg).
- Patches 3 and 4: no Fixes: lines, because BPF programs could hit these bugs
before the commits that v1 named.
- The title doesn't blame BPF any more (Alexei).
v1: https://lore.kernel.org/all/20261203200612.26376-1-mason@kernel.org/
This is on top of v7.4-rc5.
Chris Mason (8):
tsacct: don't dereference a stale group_leader
exec, cgroup, prlimit: prepare for group_leader resets
exit: reset a released task's parent and leader
fork: don't leave stale parent pointers in a new task
bpf: Don't start a thread walk at a released task
drm/amdkfd: fix crashes if a debugged process exits
signal: add task_group_leader()
signal: move group_leader into signal_struct
Documentation/bpf/kfuncs.rst | 2 +-
arch/x86/kernel/fpu/core.c | 4 +-
arch/x86/kernel/fpu/xstate.c | 6 +-
arch/x86/kernel/fpu/xstate.h | 4 +-
arch/x86/kernel/signal.c | 4 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 +-
drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 33 ++++---
drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +-
drivers/gpu/drm/panthor/panthor_gem.c | 2 +-
drivers/gpu/drm/panthor/panthor_sched.c | 8 +-
drivers/gpu/drm/scheduler/sched_entity.c | 9 +-
drivers/iommu/iommufd/ioas.c | 4 +-
drivers/iommu/iommufd/pages.c | 4 +-
drivers/vfio/vfio_iommu_type1.c | 6 +-
fs/binfmt_elf.c | 2 +-
fs/binfmt_elf_fdpic.c | 2 +-
fs/exec.c | 17 ++--
include/linux/cgroup.h | 2 +-
include/linux/pid.h | 1 +
include/linux/sched.h | 1 -
include/linux/sched/signal.h | 28 +++++-
include/linux/sched/task.h | 43 +++------
init/init_task.c | 3 +-
kernel/acct.c | 2 +-
kernel/bpf/task_iter.c | 16 +++-
kernel/bpf/verifier.c | 5 +
kernel/cgroup/cgroup.c | 26 +++---
kernel/cgroup/cpuset.c | 4 +-
kernel/debug/kdb/kdb_main.c | 2 +-
kernel/exit.c | 5 +-
kernel/fork.c | 93 +++++++++++++------
kernel/signal.c | 6 +-
kernel/sys.c | 22 ++---
kernel/tsacct.c | 6 +-
lib/is_single_threaded.c | 2 +-
rust/helpers/task.c | 7 ++
rust/kernel/task.rs | 9 +-
security/apparmor/resource.c | 2 +-
security/yama/yama_lsm.c | 10 +-
tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 25 ++++-
.../selftests/bpf/progs/rcu_read_lock.c | 4 +-
.../selftests/bpf/progs/task_kfunc_success.c | 4 +-
.../bpf/progs/test_core_reloc_kernel.c | 47 +++++-----
.../test.d/dynevent/btf_typecast_accepted.tc | 4 +-
47 files changed, 301 insertions(+), 200 deletions(-)
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
next reply other threads:[~2026-12-05 13:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 13:11 Chris Mason [this message]
2026-12-05 13:11 ` [PATCH v2 1/8] tsacct: don't dereference a stale group_leader Chris Mason
2026-12-05 13:12 ` [PATCH v2 2/8] exec, cgroup, prlimit: prepare for group_leader resets Chris Mason
2026-12-05 13:12 ` [PATCH v2 3/8] exit: reset a released task's parent and leader Chris Mason
2026-12-05 13:12 ` [PATCH v2 4/8] fork: don't leave stale parent pointers in a new task Chris Mason
2026-12-05 13:12 ` [PATCH v2 5/8] bpf: Don't start a thread walk at a released task Chris Mason
2026-12-05 13:12 ` [PATCH v2 6/8] drm/amdkfd: fix crashes if a debugged process exits Chris Mason
2026-12-05 13:13 ` [RFC PATCH v2 7/8] signal: add task_group_leader() Chris Mason
2026-12-05 13:13 ` [RFC PATCH v2 8/8] signal: move group_leader into signal_struct Chris Mason
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=20261204233428.14861-1-mason@kernel.org \
--to=mason@kernel.org \
--cc=Felix.Kuehling@amd.com \
--cc=akpm@linux-foundation.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=bsingharora@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hannes@cmpxchg.org \
--cc=ihor.solodrai@linux.dev \
--cc=jack@suse.cz \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=sched-ext@lists.linux.dev \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yonghong.song@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