* [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers
@ 2026-12-05 13:11 Chris Mason
2026-12-05 13:11 ` [PATCH v2 1/8] tsacct: don't dereference a stale group_leader Chris Mason
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:11 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: Felix Kuehling, amd-gfx, akpm, peterz, mingo, kees, viro, jack,
tj, hannes, mkoutny, bsingharora, eddyz87, memxor, yonghong.song,
martin.lau, song, jolsa, emil, ihor.solodrai, sched-ext, cgroups,
linux-fsdevel, linux-mm, mason
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/8] tsacct: don't dereference a stale group_leader
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
@ 2026-12-05 13:11 ` Chris Mason
2026-12-05 13:12 ` [PATCH v2 2/8] exec, cgroup, prlimit: prepare for group_leader resets Chris Mason
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:11 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: akpm, peterz, mingo, kees, viro, jack, tj, hannes, mkoutny,
bsingharora, eddyz87, memxor, yonghong.song, martin.lau, song,
jolsa, emil, ihor.solodrai, sched-ext, cgroups, linux-fsdevel,
linux-mm, mason
bacct_add_tsk() hits a use-after-free if a group leader is freed during a
TASKSTATS_CMD_GET for one of its threads.
fill_stats_for_pid() only holds a reference on tsk, but bacct_add_tsk()
also dereferences tsk->group_leader, without RCU or a pid_alive() check:
bacct_add_tsk(tsk) process exits
================== =============
leader = tsk->group_leader
release_task(tsk)
release_task(leader)
/* freed after a grace period */
leader->start_time
/* use-after-free */
The fix used here is to check pid_alive() under RCU before dereferencing
group_leader.
Fixes: 0e0af57e0e91 ("taskstats: version 12 with thread group and exe info")
Signed-off-by: Chris Mason <mason@kernel.org>
---
kernel/tsacct.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index 48320684c7c01..d8e941674fb13 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -30,8 +30,10 @@ void bacct_add_tsk(struct user_namespace *user_ns,
/* calculate task elapsed time in nsec */
now_ns = ktime_get_ns();
- /* store whole group time first */
- delta = now_ns - tsk->group_leader->start_time;
+ /* store whole group time first, or tsk's own if it's been released */
+ rcu_read_lock();
+ delta = now_ns - (pid_alive(tsk) ? tsk->group_leader : tsk)->start_time;
+ rcu_read_unlock();
/* Convert to micro seconds */
do_div(delta, NSEC_PER_USEC);
stats->ac_tgetime = delta;
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/8] exec, cgroup, prlimit: prepare for group_leader resets
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
2026-12-05 13:11 ` [PATCH v2 1/8] tsacct: don't dereference a stale group_leader Chris Mason
@ 2026-12-05 13:12 ` Chris Mason
2026-12-05 13:12 ` [PATCH v2 3/8] exit: reset a released task's parent and leader Chris Mason
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:12 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: akpm, peterz, mingo, kees, viro, jack, tj, hannes, mkoutny,
bsingharora, eddyz87, memxor, yonghong.song, martin.lau, song,
jolsa, emil, ihor.solodrai, sched-ext, cgroups, linux-fsdevel,
linux-mm, mason
This is a prep patch that allows us to reset group_leader in
release_task().
exec and cgroup migration walk the threads with next_thread(t), which
wraps from the last thread to t->group_leader. If t is released meanwhile,
that would be t itself, and the walk would never end. So use
for_each_thread() there.
do_prlimit() reads tsk->group_leader for task_lock(), and again for
task_unlock(). So let prlimit64() hold tasklist_lock unless tsk is current.
Signed-off-by: Chris Mason <mason@kernel.org>
---
fs/exec.c | 4 ++--
include/linux/sched/signal.h | 4 ++--
kernel/cgroup/cgroup.c | 24 ++++++++++++------------
kernel/sys.c | 4 ++--
4 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index 8d2b14e1d455c..b3b80a47fb657 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1621,10 +1621,10 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
* from another sub-thread until de_thread() succeeds, this
* state is protected by cred_guard_mutex we hold.
*/
- n_fs = 1;
+ n_fs = 0;
read_seqlock_excl(&p->fs->seq);
rcu_read_lock();
- for_other_threads(p, t) {
+ for_each_thread(p, t) {
if (t->fs == p->fs)
n_fs++;
}
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 0adb51ab15428..cf73f4dd6946a 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -663,8 +663,8 @@ extern void flush_itimer_signals(void);
extern bool current_is_single_threaded(void);
/*
- * Without tasklist/siglock it is only rcu-safe if g can't exit/exec,
- * otherwise next_thread(t) will never reach g after list_del_rcu(g).
+ * Needs tasklist/siglock, otherwise next_thread(t) may never reach g
+ * after t or g has been released. Use for_each_thread() under RCU.
*/
#define while_each_thread(g, t) \
while ((t = next_thread(t)) != g)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index b3657e72db99e..640af2d4551d1 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -3075,12 +3075,12 @@ int cgroup_migrate(struct task_struct *leader, bool threadgroup,
* spin_lock_irq() implies RCU critical section here.
*/
spin_lock_irq(&css_set_lock);
- task = leader;
- do {
- cgroup_migrate_add_task(task, mgctx);
- if (!threadgroup)
- break;
- } while_each_thread(leader, task);
+ if (threadgroup) {
+ for_each_thread(leader, task)
+ cgroup_migrate_add_task(task, mgctx);
+ } else {
+ cgroup_migrate_add_task(leader, mgctx);
+ }
spin_unlock_irq(&css_set_lock);
return cgroup_migrate_execute(mgctx);
@@ -3103,12 +3103,12 @@ int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
/* look up all src csets */
spin_lock_irq(&css_set_lock);
- task = leader;
- do {
- cgroup_migrate_add_src(task_css_set(task), dst_cgrp, &mgctx);
- if (!threadgroup)
- break;
- } while_each_thread(leader, task);
+ if (threadgroup) {
+ for_each_thread(leader, task)
+ cgroup_migrate_add_src(task_css_set(task), dst_cgrp, &mgctx);
+ } else {
+ cgroup_migrate_add_src(task_css_set(leader), dst_cgrp, &mgctx);
+ }
spin_unlock_irq(&css_set_lock);
/* prepare dst csets and commit */
diff --git a/kernel/sys.c b/kernel/sys.c
index 755bfa5ccd92c..9cb8eac08b7d2 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1764,10 +1764,10 @@ SYSCALL_DEFINE4(prlimit64, pid_t, pid, unsigned int, resource,
get_task_struct(tsk);
rcu_read_unlock();
- need_tasklist = !same_thread_group(tsk, current);
+ need_tasklist = tsk != current;
if (need_tasklist) {
/*
- * Ensure we can't race with group exit or de_thread(),
+ * Ensure we can't race with release_task() or de_thread(),
* so tsk->group_leader can't be freed or changed until
* read_unlock(tasklist_lock) below.
*/
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/8] exit: reset a released task's parent and leader
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
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 ` Chris Mason
2026-12-05 13:12 ` [PATCH v2 4/8] fork: don't leave stale parent pointers in a new task Chris Mason
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:12 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: akpm, peterz, mingo, kees, viro, jack, tj, hannes, mkoutny,
bsingharora, eddyz87, memxor, yonghong.song, martin.lau, song,
jolsa, emil, ihor.solodrai, sched-ext, cgroups, linux-fsdevel,
linux-mm, mason
release_task() causes a use-after-free in BPF programs if a released task
outlives its parent or group leader.
real_parent, parent and group_leader are never updated after
release_task(), but BPF programs can dereference them without a
pid_alive() check:
release_task(p)
release_task(p->group_leader) /* freed after a grace period */
BPF program with a reference on p:
p->group_leader->pid /* use-after-free */
The fix used here is to let release_task() reset the parents to init_task
and group_leader to the task itself.
A lockless walk up the parents can now end early, at a task that is being
released. A BPF LSM program that denies something to all descendants of a
process can then miss one, and Yama can wrongly refuse a ptrace attach.
Signed-off-by: Chris Mason <mason@kernel.org>
---
include/linux/sched/task.h | 11 +++++++++++
kernel/exit.c | 1 +
2 files changed, 12 insertions(+)
diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index 90ed5bc3c7afe..b30a66748af2c 100644
--- a/include/linux/sched/task.h
+++ b/include/linux/sched/task.h
@@ -80,6 +80,17 @@ extern void fork_init(void);
extern void release_task(struct task_struct * p);
+/*
+ * Nobody updates these pointers if @p isn't in the process tree, but BPF
+ * programs can still follow them. So don't leave any that can go stale.
+ */
+static inline void reset_parent_and_leader(struct task_struct *p)
+{
+ RCU_INIT_POINTER(p->real_parent, &init_task);
+ RCU_INIT_POINTER(p->parent, &init_task);
+ WRITE_ONCE(p->group_leader, p);
+}
+
extern int copy_thread(struct task_struct *, const struct kernel_clone_args *);
extern void flush_thread(void);
diff --git a/kernel/exit.c b/kernel/exit.c
index d5e7bc2af804a..8a5985821e17d 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -288,6 +288,7 @@ void release_task(struct task_struct *p)
leader->exit_state = EXIT_DEAD;
}
+ reset_parent_and_leader(p);
write_unlock_irq(&tasklist_lock);
proc_flush_pid(thread_pid);
put_pid(thread_pid);
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/8] fork: don't leave stale parent pointers in a new task
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
` (2 preceding siblings ...)
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 ` Chris Mason
2026-12-05 13:12 ` [PATCH v2 5/8] bpf: Don't start a thread walk at a released task Chris Mason
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:12 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: akpm, peterz, mingo, kees, viro, jack, tj, hannes, mkoutny,
bsingharora, eddyz87, memxor, yonghong.song, martin.lau, song,
jolsa, emil, ihor.solodrai, sched-ext, cgroups, linux-fsdevel,
linux-mm, mason
copy_process() causes a use-after-free in BPF programs if the forking
task's parent is freed during the fork.
forget_original_parent() doesn't find a new task until copy_process() has
added it to the process tree. But BPF programs can dereference its
real_parent before that, in the task_alloc LSM hook and in sched_ext's
ops.init_task():
copy_process() parent exits
============== ============
p = dup_task_struct(current, node)
/* copies real_parent */
forget_original_parent()
/* doesn't find p */
release_task(parent)
/* freed after a grace period */
security_task_alloc(p)
BPF program:
p->real_parent->pid
/* use-after-free */
If the fork fails, the same can happen in ops.exit_task(), and later in a
BPF program attached to free_task(), when the forking task can be gone too.
pid_alive(p) catches none of this, as thread_pid is copied too.
The idle threads from fork_idle() never get into the process tree, but BPF
programs see them in sched_switch. Their real_parent is init's first
thread, which is freed if another thread of init calls execve().
The fix used here is to use the forking task as the parent during the
fork, and init_task if the new task never gets into the process tree.
Signed-off-by: Chris Mason <mason@kernel.org>
---
include/linux/pid.h | 1 +
kernel/fork.c | 17 +++++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/include/linux/pid.h b/include/linux/pid.h
index 185bf0cde2d14..26eee52fb1e30 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -319,6 +319,7 @@ static inline pid_t task_tgid_nr(struct task_struct *tsk)
* @p: Task structure to be checked.
*
* Test if a process is not yet dead (at most zombie state)
+ * and no longer being forked.
* If pid_alive fails, then pointers within the task structure
* can be stale and must not be dereferenced.
*
diff --git a/kernel/fork.c b/kernel/fork.c
index d55a7d21a8fb2..c99d7147f1f1d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -928,6 +928,14 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
if (err)
goto free_tsk;
+ /*
+ * pid_alive() has to fail until copy_process() links the task. @orig is
+ * a safe parent until then, as it can't exit during its own fork.
+ */
+ tsk->thread_pid = NULL;
+ RCU_INIT_POINTER(tsk->real_parent, orig);
+ RCU_INIT_POINTER(tsk->parent, orig);
+
err = alloc_thread_stack_node(tsk, node);
if (err)
goto free_tsk;
@@ -2480,14 +2488,12 @@ __latent_entropy struct task_struct *copy_process(
/* CLONE_PARENT re-uses the old parent */
if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
- p->real_parent = current->real_parent;
p->parent_exec_id = current->parent_exec_id;
if (clone_flags & CLONE_THREAD)
p->exit_signal = -1;
else
p->exit_signal = current->group_leader->exit_signal;
} else {
- p->real_parent = current;
p->parent_exec_id = current->self_exec_id;
p->exit_signal = args->exit_signal;
}
@@ -2520,6 +2526,10 @@ __latent_entropy struct task_struct *copy_process(
/* No more failure paths after this point. */
+ /* Not earlier, as nobody updates it if the fork fails. */
+ if (clone_flags & (CLONE_PARENT | CLONE_THREAD))
+ p->real_parent = current->real_parent;
+
/*
* One for the user space visible state that goes away when reaped.
* One for the scheduler.
@@ -2678,6 +2688,8 @@ __latent_entropy struct task_struct *copy_process(
* can access it concurrently anymore, but prevent later access.
*/
p->mm = NULL;
+ /* current can exit before p is freed. */
+ reset_parent_and_leader(p);
WRITE_ONCE(p->__state, TASK_DEAD);
exit_task_stack_account(p);
put_task_stack(p);
@@ -2718,6 +2730,7 @@ struct task_struct * __init fork_idle(int cpu)
task = copy_process(&init_struct_pid, 0, cpu_to_node(cpu), &args);
if (!IS_ERR(task)) {
+ reset_parent_and_leader(task);
init_idle_pids(task);
init_idle(task, cpu);
}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/8] bpf: Don't start a thread walk at a released task
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
` (3 preceding siblings ...)
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 ` Chris Mason
2026-12-05 13:12 ` [PATCH v2 6/8] drm/amdkfd: fix crashes if a debugged process exits Chris Mason
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:12 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: akpm, peterz, mingo, kees, viro, jack, tj, hannes, mkoutny,
bsingharora, eddyz87, memxor, yonghong.song, martin.lau, song,
jolsa, emil, ihor.solodrai, sched-ext, cgroups, linux-fsdevel,
linux-mm, mason
bpf_iter_task_next() can hit a use-after-free if a
BPF_TASK_ITER_PROC_THREADS walk starts at a released task.
bpf_iter_task_new() doesn't check if the task is on the thread list. If it
isn't, thread_node.next can point to a freed thread:
release_task(A)
list_del_rcu(&A->thread_node) /* A still points to B */
release_task(B) /* freed after a grace period */
bpf_iter_task_new(A)
bpf_iter_task_next() /* returns A */
bpf_iter_task_next()
__next_thread(B) /* use-after-free */
The fix used here is to refuse the walk if pid_alive() fails.
Fixes: c68a78ffe2cb ("bpf: Introduce task open coded iterator kfuncs")
Signed-off-by: Chris Mason <mason@kernel.org>
---
kernel/bpf/task_iter.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index 2ee7b3b3c10be..a5f0849500715 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -1145,6 +1145,9 @@ __bpf_kfunc int bpf_iter_task_new(struct bpf_iter_task *it,
case BPF_TASK_ITER_PROC_THREADS:
if (!task__nullable)
return -EINVAL;
+ /* ->thread_node of a released task is stale, see next_tid() */
+ if (!pid_alive(task__nullable))
+ return -ESRCH;
break;
default:
return -EINVAL;
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 6/8] drm/amdkfd: fix crashes if a debugged process exits
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
` (4 preceding siblings ...)
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 ` 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
7 siblings, 0 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:12 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: Felix Kuehling, amd-gfx, akpm, peterz, mingo, kees, viro, jack,
tj, hannes, mkoutny, bsingharora, eddyz87, memxor, yonghong.song,
martin.lau, song, jolsa, emil, ihor.solodrai, sched-ext, cgroups,
linux-fsdevel, linux-mm, mason
kfd_create_process() hits a NULL dereference or a use-after-free if a
process exits during a KFD_IOC_DBG_TRAP_ENABLE for it.
It takes a reference on thread->mm, but it and create_process() read the
pointer again:
kfd_create_process(thread) thread exits
========================== ============
mmget_not_zero(thread->mm)
exit_mm()
/* thread->mm = NULL */
mmput(thread->mm)
/* NULL dereference */
create_process() takes a reference on the group leader without RCU or a
pid_alive() check:
create_process(thread) process exits
====================== =============
leader = thread->group_leader
release_task(leader)
/* freed after a grace period */
get_task_struct(leader)
/* use-after-free */
The fix used here is to remember the mm, and to take the leader's reference
under RCU if the thread is still alive.
Fixes: 0ab2d7532b05 ("drm/amdkfd: prepare per-process debug enable and disable")
Signed-off-by: Chris Mason <mason@kernel.org>
---
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 ++-
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 33 +++++++++++++++---------
3 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 3984b2c3bf45d..a46a4e498ac51 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -3363,7 +3363,7 @@ static int kfd_ioctl_create_process(struct file *filep, struct kfd_process *p, v
return -EINVAL;
}
- process = create_process(current, false);
+ process = create_process(current, current->mm, false);
if (IS_ERR(process)) {
mutex_unlock(&kfd_processes_mutex);
return PTR_ERR(process);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 70d67f9d8cd75..e70d47ec8617d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1113,7 +1113,8 @@ struct amdkfd_ioctl_desc {
};
bool kfd_dev_is_large_bar(struct kfd_node *dev);
-struct kfd_process *create_process(const struct task_struct *thread, bool primary);
+struct kfd_process *create_process(const struct task_struct *thread,
+ struct mm_struct *mm, bool primary);
int kfd_process_create_wq(void);
void kfd_process_destroy_wq(void);
void kfd_cleanup_processes(void);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index 336c66d9c5a73..458637a81f66c 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -66,8 +66,6 @@ static struct workqueue_struct *kfd_process_wq;
*/
static struct workqueue_struct *kfd_restore_wq;
-static struct kfd_process *find_process(const struct task_struct *thread,
- bool ref);
static void kfd_process_ref_release(struct kref *ref);
static void evict_process_worker(struct work_struct *work);
@@ -966,9 +964,11 @@ static void kfd_process_free_id(struct kfd_process *process)
struct kfd_process *kfd_create_process(struct task_struct *thread)
{
struct kfd_process *process;
+ struct mm_struct *mm;
int ret;
- if (!(thread->mm && mmget_not_zero(thread->mm)))
+ mm = get_task_mm(thread);
+ if (!mm)
return ERR_PTR(-EINVAL);
/* If the process just called exec(3), it is possible that the
@@ -999,13 +999,13 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
}
/* A prior open of /dev/kfd could have already created the process.
- * find_process will increase process kref in this case
+ * kfd_lookup_process_by_mm will increase process kref in this case
*/
- process = find_process(thread, true);
+ process = kfd_lookup_process_by_mm(mm);
if (process) {
pr_debug("Process already found\n");
} else {
- process = create_process(thread, true);
+ process = create_process(thread, mm, true);
if (IS_ERR(process))
goto out;
@@ -1025,7 +1025,7 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
}
out:
mutex_unlock(&kfd_processes_mutex);
- mmput(thread->mm);
+ mmput(mm);
return process;
}
@@ -1680,7 +1680,8 @@ void kfd_process_set_trap_debug_flag(struct qcm_process_device *qpd,
* On return the kfd_process is fully operational and will be freed when the
* mm is released
*/
-struct kfd_process *create_process(const struct task_struct *thread, bool primary)
+struct kfd_process *create_process(const struct task_struct *thread,
+ struct mm_struct *mm, bool primary)
{
struct kfd_process *process;
struct mmu_notifier *mn;
@@ -1692,13 +1693,20 @@ struct kfd_process *create_process(const struct task_struct *thread, bool primar
kref_init(&process->ref);
mutex_init(&process->mutex);
- process->mm = thread->mm;
- process->lead_thread = thread->group_leader;
+ process->mm = mm;
/*
* Take the reference on the lead thread before the process can be
* released through kfd_process_wq_release(), which drops it again.
+ * A process that's being debugged can exit meanwhile.
*/
- get_task_struct(process->lead_thread);
+ rcu_read_lock();
+ if (pid_alive(thread))
+ process->lead_thread = get_task_struct(thread->group_leader);
+ rcu_read_unlock();
+ if (!process->lead_thread) {
+ err = -ESRCH;
+ goto err_lead_thread;
+ }
process->n_pdds = 0;
process->queues_paused = false;
@@ -1816,8 +1824,9 @@ struct kfd_process *create_process(const struct task_struct *thread, bool primar
err_process_pqm_init:
kfd_event_free_process(process);
err_event_init:
- mutex_destroy(&process->mutex);
put_task_struct(process->lead_thread);
+err_lead_thread:
+ mutex_destroy(&process->mutex);
kfree(process);
err_alloc_process:
return ERR_PTR(err);
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC PATCH v2 7/8] signal: add task_group_leader()
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
` (5 preceding siblings ...)
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 ` Chris Mason
2026-12-05 13:13 ` [RFC PATCH v2 8/8] signal: move group_leader into signal_struct Chris Mason
7 siblings, 0 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:13 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: akpm, peterz, mingo, kees, viro, jack, tj, hannes, mkoutny,
bsingharora, eddyz87, memxor, yonghong.song, martin.lau, song,
jolsa, emil, ihor.solodrai, sched-ext, cgroups, linux-fsdevel,
linux-mm, mason
This is a prep patch that allows us to move group_leader into
signal_struct. As Oleg Nesterov suggested, it adds a helper to read the
field, which warns if another process's leader is read without RCU or
tasklist_lock.
cgroup, cpuset, Yama and current_is_single_threaded() now use
thread_group_leader() or same_thread_group() instead of comparing with the
leader.
Signed-off-by: Chris Mason <mason@kernel.org>
---
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 | 4 ++--
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +-
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 | 10 +++++-----
include/linux/cgroup.h | 2 +-
include/linux/sched/signal.h | 21 ++++++++++++++++++---
kernel/acct.c | 2 +-
kernel/bpf/task_iter.c | 4 ++--
kernel/cgroup/cgroup.c | 2 +-
kernel/cgroup/cpuset.c | 4 ++--
kernel/debug/kdb/kdb_main.c | 2 +-
kernel/exit.c | 4 ++--
kernel/fork.c | 10 +++++-----
kernel/signal.c | 6 +++---
kernel/sys.c | 20 ++++++++++----------
kernel/tsacct.c | 2 +-
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 ++++------
35 files changed, 105 insertions(+), 81 deletions(-)
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 80a7f41cf3ad9..edbb18810d720 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -243,7 +243,7 @@ static void fpu_lock_guest_permissions(void)
return;
spin_lock_irq(¤t->sighand->siglock);
- fpuperm = &x86_task_fpu(current->group_leader)->guest_perm;
+ fpuperm = &x86_task_fpu(task_group_leader(current))->guest_perm;
perm = fpuperm->__state_perm;
/* First fpstate allocation locks down permissions. */
@@ -636,7 +636,7 @@ void fpstate_reset(struct fpu *fpu)
static inline void fpu_inherit_perms(struct fpu *dst_fpu)
{
if (fpu_state_size_dynamic()) {
- struct fpu *src_fpu = x86_task_fpu(current->group_leader);
+ struct fpu *src_fpu = x86_task_fpu(task_group_leader(current));
spin_lock_irq(¤t->sighand->siglock);
/* Fork also inherits the permissions of the parent */
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index da303714379cd..4c805e09225c7 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1689,7 +1689,7 @@ static int fpstate_realloc(u64 xfeatures, unsigned int ksize,
static int validate_sigaltstack(unsigned int usize)
{
- struct task_struct *thread, *leader = current->group_leader;
+ struct task_struct *thread, *leader = task_group_leader(current);
unsigned long framesize = get_sigframe_size();
lockdep_assert_held(¤t->sighand->siglock);
@@ -1713,7 +1713,7 @@ static int __xstate_request_perm(u64 permitted, u64 requested, bool guest)
* AVX512.
*/
bool compacted = cpu_feature_enabled(X86_FEATURE_XCOMPACTED);
- struct fpu *fpu = x86_task_fpu(current->group_leader);
+ struct fpu *fpu = x86_task_fpu(task_group_leader(current));
struct fpu_state_perm *perm;
unsigned int ksize, usize;
u64 mask;
@@ -1820,7 +1820,7 @@ int __xfd_enable_feature(u64 xfd_err, struct fpu_guest *guest_fpu)
return -EPERM;
}
- fpu = x86_task_fpu(current->group_leader);
+ fpu = x86_task_fpu(task_group_leader(current));
perm = guest_fpu ? &fpu->guest_perm : &fpu->perm;
ksize = perm->__state_size;
usize = perm->__user_state_size;
diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h
index 1ea762e930866..676f4db6caf63 100644
--- a/arch/x86/kernel/fpu/xstate.h
+++ b/arch/x86/kernel/fpu/xstate.h
@@ -2,6 +2,8 @@
#ifndef __X86_KERNEL_FPU_XSTATE_H
#define __X86_KERNEL_FPU_XSTATE_H
+#include <linux/sched/signal.h>
+
#include <asm/cpufeature.h>
#include <asm/fpu/xstate.h>
#include <asm/fpu/xcr.h>
@@ -23,7 +25,7 @@ static inline void xstate_init_xcomp_bv(struct xregs_state *xsave, u64 mask)
static inline u64 xstate_get_group_perm(bool guest)
{
- struct fpu *fpu = x86_task_fpu(current->group_leader);
+ struct fpu *fpu = x86_task_fpu(task_group_leader(current));
struct fpu_state_perm *perm;
/* Pairs with WRITE_ONCE() in xstate_request_perm() */
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 2404233336ab6..4fdc5b9af9916 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -423,14 +423,14 @@ bool sigaltstack_size_valid(size_t ss_size)
if (!fpu_state_size_dynamic() && !strict_sigaltstack_size)
return true;
- fsize += x86_task_fpu(current->group_leader)->perm.__user_state_size;
+ fsize += x86_task_fpu(task_group_leader(current))->perm.__user_state_size;
if (likely(ss_size > fsize))
return true;
if (strict_sigaltstack_size)
return ss_size > fsize;
- mask = x86_task_fpu(current->group_leader)->perm.__state_perm;
+ mask = x86_task_fpu(task_group_leader(current))->perm.__state_perm;
if (mask & XFEATURE_MASK_USER_DYNAMIC)
return ss_size > fsize;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 326abc9b7f690..ea872eed0fcfd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1362,7 +1362,7 @@ int amdgpu_ttm_tt_set_userptr(struct ttm_buffer_object *bo,
if (gtt->usertask)
put_task_struct(gtt->usertask);
- gtt->usertask = current->group_leader;
+ gtt->usertask = task_group_leader(current);
get_task_struct(gtt->usertask);
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 45f0f6aca754c..e9d64fc337d91 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2595,7 +2595,7 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
get_task_comm(vm->task_info->task.comm, current);
vm->task_info->tgid = current->tgid;
- get_task_comm(vm->task_info->process_name, current->group_leader);
+ get_task_comm(vm->task_info->process_name, task_group_leader(current));
}
/**
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index a46a4e498ac51..cab536027ec16 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -3670,7 +3670,7 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
ptrace_attached = true;
rcu_read_unlock();
- if (process->lead_thread != current->group_leader
+ if (process->lead_thread != task_group_leader(current)
&& !ptrace_attached) {
dev_dbg(kfd_device, "Using KFD FD in wrong process\n");
retcode = -EBADF;
@@ -3794,7 +3794,7 @@ static int kfd_mmap(struct file *filep, struct vm_area_struct *vma)
if (!process)
return -ESRCH;
- if (process->lead_thread != current->group_leader)
+ if (process->lead_thread != task_group_leader(current))
return -EBADF;
mmap_offset = vma->vm_pgoff << PAGE_SHIFT;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index 458637a81f66c..1a72d9a206038 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -1701,7 +1701,7 @@ struct kfd_process *create_process(const struct task_struct *thread,
*/
rcu_read_lock();
if (pid_alive(thread))
- process->lead_thread = get_task_struct(thread->group_leader);
+ process->lead_thread = get_task_struct(task_group_leader(thread));
rcu_read_unlock();
if (!process->lead_thread) {
err = -ESRCH;
diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c
index 518f24549b9de..219f94540068c 100644
--- a/drivers/gpu/drm/panfrost/panfrost_gem.c
+++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
@@ -48,7 +48,7 @@ static void panfrost_gem_debugfs_bo_add(struct panfrost_device *pfdev,
struct panfrost_gem_object *bo)
{
bo->debugfs.creator.tgid = current->tgid;
- get_task_comm(bo->debugfs.creator.process_name, current->group_leader);
+ get_task_comm(bo->debugfs.creator.process_name, task_group_leader(current));
mutex_lock(&pfdev->debugfs.gems_lock);
list_add_tail(&bo->debugfs.node, &pfdev->debugfs.gems_list);
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 22b57ab6f9291..df3119b5fb39b 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -54,7 +54,7 @@ static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo)
struct panthor_device, base);
bo->debugfs.creator.tgid = current->tgid;
- get_task_comm(bo->debugfs.creator.process_name, current->group_leader);
+ get_task_comm(bo->debugfs.creator.process_name, task_group_leader(current));
mutex_lock(&ptdev->gems.lock);
list_add_tail(&bo->debugfs.node, &ptdev->gems.node);
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index a343c5180e01e..0fd46bf8a6531 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -647,12 +647,12 @@ struct panthor_group {
size_t kbo_sizes;
} fdinfo;
- /** @task_info: Info of current->group_leader that created the group. */
+ /** @task_info: Info of the process that created the group. */
struct {
- /** @task_info.pid: pid of current->group_leader */
+ /** @task_info.pid: pid of its thread group leader */
pid_t pid;
- /** @task_info.comm: comm of current->group_leader */
+ /** @task_info.comm: comm of its thread group leader */
char comm[TASK_COMM_LEN];
} task_info;
@@ -3592,7 +3592,7 @@ group_create_queue(struct panthor_group *group,
static void group_init_task_info(struct panthor_group *group)
{
- struct task_struct *task = current->group_leader;
+ struct task_struct *task = task_group_leader(current);
group->task_info.pid = task->pid;
get_task_comm(group->task_info.comm, task);
diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
index 03e68b4102d50..7e6227803226a 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -24,6 +24,7 @@
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/completion.h>
+#include <linux/sched/signal.h>
#include <drm/drm_print.h>
#include <drm/gpu_scheduler.h>
@@ -130,7 +131,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
INIT_LIST_HEAD(&entity->list);
entity->guilty = guilty;
- entity->last_user = current->group_leader;
+ entity->last_user = task_group_leader(current);
entity->num_sched_list = num_sched_list;
entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
RB_CLEAR_NODE(&entity->rb_tree_node);
@@ -374,8 +375,8 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)
}
/* For a killed process disallow further enqueueing of jobs. */
- last_user = cmpxchg(&entity->last_user, current->group_leader, NULL);
- if (last_user == current->group_leader &&
+ last_user = cmpxchg(&entity->last_user, task_group_leader(current), NULL);
+ if (last_user == task_group_leader(current) &&
(current->flags & PF_EXITING) && (current->exit_code == SIGKILL))
drm_sched_entity_kill(entity);
@@ -632,7 +633,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
trace_drm_sched_job_add_dep(sched_job, entry);
}
atomic_inc(entity->rq->sched->score);
- WRITE_ONCE(entity->last_user, current->group_leader);
+ WRITE_ONCE(entity->last_user, task_group_leader(current));
/*
* After the sched_job is pushed into the entity queue, it may be
diff --git a/drivers/iommu/iommufd/ioas.c b/drivers/iommu/iommufd/ioas.c
index 8fb5271a95060..8a163ddb7ed24 100644
--- a/drivers/iommu/iommufd/ioas.c
+++ b/drivers/iommu/iommufd/ioas.c
@@ -497,7 +497,7 @@ static int charge_current(unsigned long *npinned)
{
struct iopt_pages tmp = {
.source_mm = current->mm,
- .source_task = current->group_leader,
+ .source_task = task_group_leader(current),
.source_user = current_user(),
};
unsigned int account_mode;
@@ -538,7 +538,7 @@ static void change_mm(struct iopt_pages *pages)
mmgrab(pages->source_mm);
mmdrop(old_mm);
- pages->source_task = current->group_leader;
+ pages->source_task = task_group_leader(current);
get_task_struct(pages->source_task);
put_task_struct(old_task);
diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
index fcdbde007a9ab..ff1b8cd85a22b 100644
--- a/drivers/iommu/iommufd/pages.c
+++ b/drivers/iommu/iommufd/pages.c
@@ -1401,8 +1401,8 @@ static struct iopt_pages *iopt_alloc_pages(unsigned long start_byte,
pages->account_mode = IOPT_PAGES_ACCOUNT_NONE;
else
pages->account_mode = IOPT_PAGES_ACCOUNT_USER;
- pages->source_task = current->group_leader;
- get_task_struct(current->group_leader);
+ pages->source_task = task_group_leader(current);
+ get_task_struct(task_group_leader(current));
pages->source_user = get_uid(current_user());
return pages;
}
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index f7addfbe1aab4..83929ff28c0d7 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1651,7 +1651,7 @@ static bool vfio_iommu_iova_dma_valid(struct vfio_iommu *iommu,
static int vfio_change_dma_owner(struct vfio_dma *dma)
{
- struct task_struct *task = current->group_leader;
+ struct task_struct *task = task_group_leader(current);
struct mm_struct *mm = current->mm;
long npage = dma->locked_vm;
bool lock_cap;
@@ -1776,8 +1776,8 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
* the same task, to make debugging easier. VM locked pages requires
* an mm_struct, so grab the mm in case the task dies.
*/
- get_task_struct(current->group_leader);
- dma->task = current->group_leader;
+ get_task_struct(task_group_leader(current));
+ dma->task = task_group_leader(current);
dma->lock_cap = capable(CAP_IPC_LOCK);
dma->mm = current->mm;
mmgrab(dma->mm);
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index bf7f8f47548d3..5e96c9a7bfa6f 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1895,7 +1895,7 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
/*
* Fill in the two process-wide notes.
*/
- fill_psinfo(psinfo, dump_task->group_leader, dump_task->mm);
+ fill_psinfo(psinfo, task_group_leader(dump_task), dump_task->mm);
info->size += notesize(&info->psinfo);
fill_siginfo_note(&info->signote, &info->csigdata, cprm->siginfo);
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index d3872169f55e5..e4e43b1a5e738 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -1542,7 +1542,7 @@ static bool elf_fdpic_core_dump(struct coredump_params *cprm)
* with info from their /proc.
*/
- fill_psinfo(psinfo, current->group_leader, current->mm);
+ fill_psinfo(psinfo, task_group_leader(current), current->mm);
fill_note(&psinfo_note, PRPSINFO, sizeof(*psinfo), psinfo);
thread_status_size += notesize(&psinfo_note);
diff --git a/fs/exec.c b/fs/exec.c
index b3b80a47fb657..3bae1a6dc62c3 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -269,9 +269,9 @@ static int bprm_mm_init(struct linux_binprm *bprm)
bprm->user_ns = get_user_ns(current_user_ns());
/* Save current stack limit for all calculations made during exec. */
- task_lock(current->group_leader);
+ task_lock(task_group_leader(current));
bprm->rlim_stack = current->signal->rlim[RLIMIT_STACK];
- task_unlock(current->group_leader);
+ task_unlock(task_group_leader(current));
#ifndef CONFIG_MMU
bprm->p = PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *);
@@ -963,7 +963,7 @@ static int de_thread(struct task_struct *tsk)
* and to assume its PID:
*/
if (!thread_group_leader(tsk)) {
- struct task_struct *leader = tsk->group_leader;
+ struct task_struct *leader = task_group_leader(tsk);
for (;;) {
cgroup_threadgroup_change_begin(tsk);
@@ -1402,9 +1402,9 @@ EXPORT_SYMBOL(setup_new_exec);
void finalize_exec(struct linux_binprm *bprm)
{
/* Store any stack rlimit changes before starting thread. */
- task_lock(current->group_leader);
+ task_lock(task_group_leader(current));
current->signal->rlim[RLIMIT_STACK] = bprm->rlim_stack;
- task_unlock(current->group_leader);
+ task_unlock(task_group_leader(current));
}
EXPORT_SYMBOL(finalize_exec);
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 2afb4cb2bb4fa..0a1a5b09d0d50 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -377,7 +377,7 @@ void css_task_iter_end(struct css_task_iter *it);
for ((leader) = cgroup_taskset_first((tset), &(dst_css)); \
(leader); \
(leader) = cgroup_taskset_next((tset), &(dst_css))) \
- if ((leader) != (leader)->group_leader) \
+ if (!thread_group_leader(leader)) \
; \
else
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index cf73f4dd6946a..802e264c323d3 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -211,8 +211,8 @@ struct signal_struct {
* because there is no reader checking a limit that actually needs
* to get both rlim_cur and rlim_max atomically, and either one
* alone is a single word that can safely be read normally.
- * getrlimit/setrlimit use task_lock(current->group_leader) to
- * protect this instead of the siglock, because they really
+ * getrlimit/setrlimit use task_lock(task_group_leader(current))
+ * to protect this instead of the siglock, because they really
* have no need to disable irqs.
*/
struct rlimit rlim[RLIM_NLIMITS];
@@ -745,6 +745,21 @@ static inline bool thread_group_leader(struct task_struct *p)
return p->exit_signal >= 0;
}
+/*
+ * Another process's leader can exit, or be replaced by exec, at any time. So
+ * hold RCU or tasklist_lock while you use it, and check pid_alive(@p) before
+ * you take a reference on it.
+ */
+static inline struct task_struct *task_group_leader(const struct task_struct *p)
+{
+ RCU_LOCKDEP_WARN(p->signal != current->signal &&
+ !rcu_read_lock_any_held() &&
+ !lockdep_tasklist_lock_is_held(),
+ "another process's leader needs RCU or tasklist_lock");
+
+ return READ_ONCE(p->group_leader);
+}
+
static inline
bool same_thread_group(struct task_struct *p1, struct task_struct *p2)
{
@@ -764,7 +779,7 @@ static inline struct task_struct *__next_thread(struct task_struct *p)
static inline struct task_struct *next_thread(struct task_struct *p)
{
- return __next_thread(p) ?: p->group_leader;
+ return __next_thread(p) ?: task_group_leader(p);
}
static inline int thread_group_empty(struct task_struct *p)
diff --git a/kernel/acct.c b/kernel/acct.c
index c440d43479ca5..710ae0e65555a 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -459,7 +459,7 @@ static void fill_ac(struct bsd_acct_struct *acct)
/* calculate run_time in nsec*/
run_time = ktime_get_ns();
- run_time -= current->group_leader->start_time;
+ run_time -= task_group_leader(current)->start_time;
/* convert nsec -> AHZ */
elapsed = nsec_to_AHZ(run_time);
#if ACCT_VERSION == 3
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index a5f0849500715..b17c5f9a50d4e 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -79,7 +79,7 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm
if (!next_tid)
goto retry;
- if (skip_if_dup_files && task->files == task->group_leader->files)
+ if (skip_if_dup_files && task->files == task_group_leader(task)->files)
goto retry;
*tid = common->pid_visiting = next_tid;
@@ -126,7 +126,7 @@ static struct task_struct *task_seq_get_next(struct bpf_iter_seq_task_common *co
++*tid;
goto retry;
} else if (skip_if_dup_files && !thread_group_leader(task) &&
- task->files == task->group_leader->files) {
+ task->files == task_group_leader(task)->files) {
put_task_struct(task);
task = NULL;
++*tid;
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 640af2d4551d1..61f88297de431 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -3146,7 +3146,7 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup,
}
if (threadgroup)
- tsk = tsk->group_leader;
+ tsk = task_group_leader(tsk);
/*
* kthreads may acquire PF_NO_SETAFFINITY during initialization.
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index db32d330cfbc2..fbb0c1e27b348 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -3252,7 +3252,7 @@ static int cpuset_can_attach(struct cgroup_taskset *tset)
goto out_unlock;
/* Update attach_ctx.old_cs to the latest group leader */
- if (task == task->group_leader)
+ if (thread_group_leader(task))
attach_ctx.old_cs = task_cs(task);
if (setsched_check) {
@@ -3343,7 +3343,7 @@ static void cpuset_attach_task(struct cpuset *cs, struct task_struct *task)
cpuset_change_task_nodemask(task, &attach_ctx.nodemask_to);
cpuset1_update_task_spread_flags(cs, task);
- if ((task != task->group_leader) || !attach_ctx.mems_updated)
+ if (!thread_group_leader(task) || !attach_ctx.mems_updated)
return;
/*
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 40c332d2179d8..31c592761eb56 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -2351,7 +2351,7 @@ static int kdb_kill(int argc, const char **argv)
kdb_printf("The specified process isn't found.\n");
return 0;
}
- p = p->group_leader;
+ p = task_group_leader(p);
kdb_send_sig(p, sig);
return 0;
}
diff --git a/kernel/exit.c b/kernel/exit.c
index 8a5985821e17d..5046360b8a6a4 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -272,7 +272,7 @@ void release_task(struct task_struct *p)
* group leader's parent process. (if it wants notification.)
*/
zap_leader = 0;
- leader = p->group_leader;
+ leader = task_group_leader(p);
if (leader != p && thread_group_empty(leader)
&& leader->exit_state == EXIT_ZOMBIE) {
/* for pidfs_exit() and do_notify_parent() */
@@ -750,7 +750,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
forget_original_parent(tsk, &dead);
if (group_dead)
- kill_orphaned_pgrp(tsk->group_leader, NULL);
+ kill_orphaned_pgrp(task_group_leader(tsk), NULL);
tsk->exit_state = EXIT_ZOMBIE;
diff --git a/kernel/fork.c b/kernel/fork.c
index c99d7147f1f1d..ff0e367b2a81d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1795,9 +1795,9 @@ static int copy_signal(u64 clone_flags, struct task_struct *tsk)
hrtimer_setup(&sig->real_timer, it_real_fn, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
#endif
- task_lock(current->group_leader);
+ task_lock(task_group_leader(current));
memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim);
- task_unlock(current->group_leader);
+ task_unlock(task_group_leader(current));
posix_cpu_timers_init_group(sig);
@@ -2492,7 +2492,7 @@ __latent_entropy struct task_struct *copy_process(
if (clone_flags & CLONE_THREAD)
p->exit_signal = -1;
else
- p->exit_signal = current->group_leader->exit_signal;
+ p->exit_signal = task_group_leader(current)->exit_signal;
} else {
p->parent_exec_id = current->self_exec_id;
p->exit_signal = args->exit_signal;
@@ -3135,7 +3135,7 @@ void walk_process_tree(struct task_struct *top, proc_visitor visitor, void *data
int res;
read_lock(&tasklist_lock);
- leader = top = top->group_leader;
+ leader = top = task_group_leader(top);
down:
for_each_thread(leader, parent) {
list_for_each_entry(child, &parent->children, sibling) {
@@ -3154,7 +3154,7 @@ void walk_process_tree(struct task_struct *top, proc_visitor visitor, void *data
if (leader != top) {
child = leader;
parent = child->real_parent;
- leader = parent->group_leader;
+ leader = task_group_leader(parent);
goto up;
}
out:
diff --git a/kernel/signal.c b/kernel/signal.c
index dd770e68faee0..f5e77076ca2a8 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2366,7 +2366,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk,
if (for_ptracer) {
parent = tsk->parent;
} else {
- tsk = tsk->group_leader;
+ tsk = task_group_leader(tsk);
parent = tsk->real_parent;
}
@@ -2929,8 +2929,8 @@ bool get_signal(struct ksignal *ksig)
read_lock(&tasklist_lock);
do_notify_parent_cldstop(current, false, why);
- if (ptrace_reparented(current->group_leader))
- do_notify_parent_cldstop(current->group_leader,
+ if (ptrace_reparented(task_group_leader(current)))
+ do_notify_parent_cldstop(task_group_leader(current),
true, why);
read_unlock(&tasklist_lock);
diff --git a/kernel/sys.c b/kernel/sys.c
index 9cb8eac08b7d2..bfa0a7b5420e7 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1117,7 +1117,7 @@ COMPAT_SYSCALL_DEFINE1(times, struct compat_tms __user *, tbuf)
SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)
{
struct task_struct *p;
- struct task_struct *group_leader = current->group_leader;
+ struct task_struct *group_leader = task_group_leader(current);
struct pid *pids[PIDTYPE_MAX] = { 0 };
struct pid *pgrp;
int err;
@@ -1259,7 +1259,7 @@ SYSCALL_DEFINE1(getsid, pid_t, pid)
static void set_special_pids(struct pid **pids, struct pid *pid)
{
- struct task_struct *curr = current->group_leader;
+ struct task_struct *curr = task_group_leader(current);
if (task_session(curr) != pid)
change_pid(pids, curr, PIDTYPE_SID, pid);
@@ -1270,7 +1270,7 @@ static void set_special_pids(struct pid **pids, struct pid *pid)
int ksys_setsid(void)
{
- struct task_struct *group_leader = current->group_leader;
+ struct task_struct *group_leader = task_group_leader(current);
struct pid *sid = task_pid(group_leader);
struct pid *pids[PIDTYPE_MAX] = { 0 };
pid_t session = pid_vnr(sid);
@@ -1520,7 +1520,7 @@ static int do_prlimit(struct task_struct *tsk, unsigned int resource,
/* Holding a refcount on tsk protects tsk->signal from disappearing. */
rlim = tsk->signal->rlim + resource;
- task_lock(tsk->group_leader);
+ task_lock(task_group_leader(tsk));
if (new_rlim) {
/*
* Keep the capable check against init_user_ns until cgroups can
@@ -1538,7 +1538,7 @@ static int do_prlimit(struct task_struct *tsk, unsigned int resource,
if (new_rlim)
*rlim = *new_rlim;
}
- task_unlock(tsk->group_leader);
+ task_unlock(task_group_leader(tsk));
/*
* RLIMIT_CPU handling. Arm the posix CPU timer if the limit is not
@@ -1557,7 +1557,7 @@ static int do_prlimit(struct task_struct *tsk, unsigned int resource,
* cannot update_rlimit_cpu on it, then the entire process is
* exiting and we do not need to update at all.
*/
- update_rlimit_cpu(tsk->group_leader, new_rlim->rlim_cur);
+ update_rlimit_cpu(task_group_leader(tsk), new_rlim->rlim_cur);
}
return retval;
@@ -1636,9 +1636,9 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
return -EINVAL;
resource = array_index_nospec(resource, RLIM_NLIMITS);
- task_lock(current->group_leader);
+ task_lock(task_group_leader(current));
x = current->signal->rlim[resource];
- task_unlock(current->group_leader);
+ task_unlock(task_group_leader(current));
if (x.rlim_cur > 0x7FFFFFFF)
x.rlim_cur = 0x7FFFFFFF;
if (x.rlim_max > 0x7FFFFFFF)
@@ -1656,9 +1656,9 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
return -EINVAL;
resource = array_index_nospec(resource, RLIM_NLIMITS);
- task_lock(current->group_leader);
+ task_lock(task_group_leader(current));
r = current->signal->rlim[resource];
- task_unlock(current->group_leader);
+ task_unlock(task_group_leader(current));
if (r.rlim_cur > 0x7FFFFFFF)
r.rlim_cur = 0x7FFFFFFF;
if (r.rlim_max > 0x7FFFFFFF)
diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index d8e941674fb13..7fb6d9fff3b60 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -32,7 +32,7 @@ void bacct_add_tsk(struct user_namespace *user_ns,
now_ns = ktime_get_ns();
/* store whole group time first, or tsk's own if it's been released */
rcu_read_lock();
- delta = now_ns - (pid_alive(tsk) ? tsk->group_leader : tsk)->start_time;
+ delta = now_ns - (pid_alive(tsk) ? task_group_leader(tsk) : tsk)->start_time;
rcu_read_unlock();
/* Convert to micro seconds */
do_div(delta, NSEC_PER_USEC);
diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
index 8c98b20bfc414..efe9b6b35c55c 100644
--- a/lib/is_single_threaded.c
+++ b/lib/is_single_threaded.c
@@ -30,7 +30,7 @@ bool current_is_single_threaded(void)
for_each_process(p) {
if (unlikely(p->flags & PF_KTHREAD))
continue;
- if (unlikely(p == task->group_leader))
+ if (unlikely(same_thread_group(p, task)))
continue;
for_each_thread(p, t) {
diff --git a/rust/helpers/task.c b/rust/helpers/task.c
index b46b1433a67e8..e62daa6067038 100644
--- a/rust/helpers/task.c
+++ b/rust/helpers/task.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/kernel.h>
+#include <linux/sched/signal.h>
#include <linux/sched/task.h>
__rust_helper void rust_helper_might_resched(void)
@@ -23,6 +24,12 @@ __rust_helper void rust_helper_put_task_struct(struct task_struct *t)
put_task_struct(t);
}
+__rust_helper struct task_struct *
+rust_helper_task_group_leader(const struct task_struct *p)
+{
+ return task_group_leader(p);
+}
+
__rust_helper kuid_t rust_helper_task_uid(struct task_struct *task)
{
return task_uid(task);
diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
index 3336df493decc..b83971543d5c9 100644
--- a/rust/kernel/task.rs
+++ b/rust/kernel/task.rs
@@ -334,14 +334,15 @@ pub fn active_pid_ns(&self) -> Option<&PidNamespace> {
}
/// Returns the group leader of the current task.
+ #[inline]
pub fn group_leader(&self) -> &Task {
// SAFETY: The group leader of a task never changes while the task is running, and `self`
// is the current task, which is guaranteed running.
- let ptr = unsafe { (*self.as_ptr()).group_leader };
+ let ptr = unsafe { bindings::task_group_leader(self.as_ptr()) };
- // SAFETY: `current->group_leader` stays valid for at least the duration in which `current`
- // is running, and the signature of this function ensures that the returned `&Task` can
- // only be used while `current` is still valid, thus still running.
+ // SAFETY: The group leader stays valid for at least the duration in which `current` is
+ // running, and the signature of this function ensures that the returned `&Task` can only be
+ // used while `current` is still valid, thus still running.
unsafe { &*ptr.cast() }
}
}
diff --git a/security/apparmor/resource.c b/security/apparmor/resource.c
index 64212b39ba4bb..76892a1e66bd5 100644
--- a/security/apparmor/resource.c
+++ b/security/apparmor/resource.c
@@ -199,7 +199,7 @@ void __aa_transition_rlimits(struct aa_label *old_l, struct aa_label *new_l)
if (j == RLIMIT_CPU &&
rlim->rlim_cur != RLIM_INFINITY &&
IS_ENABLED(CONFIG_POSIX_TIMERS))
- (void) update_rlimit_cpu(current->group_leader,
+ (void) update_rlimit_cpu(task_group_leader(current),
rlim->rlim_cur);
}
}
diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
index cef3776cf3b2d..c71588e237213 100644
--- a/security/yama/yama_lsm.c
+++ b/security/yama/yama_lsm.c
@@ -232,7 +232,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
* leader checking is handled later when walking the ancestry
* at the time of PTRACE_ATTACH check.
*/
- myself = current->group_leader;
+ myself = task_group_leader(current);
if (arg2 == 0) {
yama_ptracer_del(NULL, myself);
@@ -274,12 +274,10 @@ static int task_is_descendant(struct task_struct *parent,
return 0;
rcu_read_lock();
- if (!thread_group_leader(parent))
- parent = rcu_dereference(parent->group_leader);
while (walker->pid > 0) {
if (!thread_group_leader(walker))
- walker = rcu_dereference(walker->group_leader);
- if (walker == parent) {
+ walker = task_group_leader(walker);
+ if (same_thread_group(walker, parent)) {
rc = 1;
break;
}
@@ -319,7 +317,7 @@ static int ptracer_exception_found(struct task_struct *tracer,
/* Look for a PR_SET_PTRACER relationship. */
if (!thread_group_leader(tracee))
- tracee = rcu_dereference(tracee->group_leader);
+ tracee = task_group_leader(tracee);
list_for_each_entry_rcu(relation, &ptracer_relations, node) {
if (relation->invalid)
continue;
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC PATCH v2 8/8] signal: move group_leader into signal_struct
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
` (6 preceding siblings ...)
2026-12-05 13:13 ` [RFC PATCH v2 7/8] signal: add task_group_leader() Chris Mason
@ 2026-12-05 13:13 ` Chris Mason
7 siblings, 0 replies; 9+ messages in thread
From: Chris Mason @ 2026-12-05 13:13 UTC (permalink / raw)
To: brauner, oleg, ast, daniel, andrii, bpf, linux-kernel
Cc: akpm, peterz, mingo, kees, viro, jack, tj, hannes, mkoutny,
bsingharora, eddyz87, memxor, yonghong.song, martin.lau, song,
jolsa, emil, ihor.solodrai, sched-ext, cgroups, linux-fsdevel,
linux-mm, mason
release_task() makes a thread look like its own group leader to BPF
programs.
All threads of a process have the same leader, but each task_struct has its
own pointer to it. The leader can be freed while somebody still holds the
thread, so release_task() has to reset the thread's pointer.
The fix used here is to share one pointer in signal_struct, as Oleg
Nesterov suggested, and to point it at init_task when the leader's last
reference is dropped. A task now keeps its signal_struct until it's freed.
BPF programs that read task->group_leader no longer load. They have to read
task->signal->group_leader instead.
Signed-off-by: Chris Mason <mason@kernel.org>
---
Documentation/bpf/kfuncs.rst | 2 +-
fs/exec.c | 3 +-
include/linux/sched.h | 1 -
include/linux/sched/signal.h | 7 +-
include/linux/sched/task.h | 36 +---------
init/init_task.c | 3 +-
kernel/bpf/task_iter.c | 9 ++-
kernel/bpf/verifier.c | 5 ++
kernel/exit.c | 2 +-
kernel/fork.c | 70 +++++++++++++------
kernel/sys.c | 6 +-
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 +-
16 files changed, 132 insertions(+), 96 deletions(-)
diff --git a/Documentation/bpf/kfuncs.rst b/Documentation/bpf/kfuncs.rst
index 31389dd5c9f6d..2f038d680f0b2 100644
--- a/Documentation/bpf/kfuncs.rst
+++ b/Documentation/bpf/kfuncs.rst
@@ -95,7 +95,7 @@ or
const cpumask_t *cpus_ptr;
struct css_set __rcu *cgroups;
struct task_struct __rcu *real_parent;
- struct task_struct *group_leader;
+ struct signal_struct *signal;
};
In other words, you must:
diff --git a/fs/exec.c b/fs/exec.c
index 3bae1a6dc62c3..883b98da1b21f 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1015,8 +1015,7 @@ static int de_thread(struct task_struct *tsk)
list_replace_rcu(&leader->tasks, &tsk->tasks);
list_replace_init(&leader->sibling, &tsk->sibling);
- tsk->group_leader = tsk;
- leader->group_leader = tsk;
+ WRITE_ONCE(sig->group_leader, tsk);
tsk->exit_signal = SIGCHLD;
leader->exit_signal = -1;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e4f6323d78555..0254da6ae6199 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1104,7 +1104,6 @@ struct task_struct {
*/
struct list_head children;
struct list_head sibling;
- struct task_struct *group_leader;
/*
* 'ptraced' is the list of tasks this task is using ptrace() on.
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 802e264c323d3..c99459531c0c4 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -99,6 +99,9 @@ struct signal_struct {
int quick_threads;
struct list_head thread_head;
+ /* See task_group_leader(). It's init_task once the leader is gone. */
+ struct task_struct *group_leader;
+
wait_queue_head_t wait_chldexit; /* for wait4() */
/* current thread group signal load-balancing target: */
@@ -664,7 +667,7 @@ extern bool current_is_single_threaded(void);
/*
* Needs tasklist/siglock, otherwise next_thread(t) may never reach g
- * after t or g has been released. Use for_each_thread() under RCU.
+ * after g has been released. Use for_each_thread() under RCU.
*/
#define while_each_thread(g, t) \
while ((t = next_thread(t)) != g)
@@ -757,7 +760,7 @@ static inline struct task_struct *task_group_leader(const struct task_struct *p)
!lockdep_tasklist_lock_is_held(),
"another process's leader needs RCU or tasklist_lock");
- return READ_ONCE(p->group_leader);
+ return READ_ONCE(p->signal->group_leader);
}
static inline
diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index b30a66748af2c..c581ed2e4b311 100644
--- a/include/linux/sched/task.h
+++ b/include/linux/sched/task.h
@@ -84,11 +84,10 @@ extern void release_task(struct task_struct * p);
* Nobody updates these pointers if @p isn't in the process tree, but BPF
* programs can still follow them. So don't leave any that can go stale.
*/
-static inline void reset_parent_and_leader(struct task_struct *p)
+static inline void reset_parents(struct task_struct *p)
{
RCU_INIT_POINTER(p->real_parent, &init_task);
RCU_INIT_POINTER(p->parent, &init_task);
- WRITE_ONCE(p->group_leader, p);
}
extern int copy_thread(struct task_struct *, const struct kernel_clone_args *);
@@ -134,40 +133,11 @@ static inline struct task_struct *tryget_task_struct(struct task_struct *t)
}
extern void __put_task_struct(struct task_struct *t);
-extern void __put_task_struct_rcu_cb(struct rcu_head *rhp);
static inline void put_task_struct(struct task_struct *t)
{
- if (!refcount_dec_and_test(&t->usage))
- return;
-
- /*
- * Under PREEMPT_RT, we can't call __put_task_struct
- * in atomic context because it will indirectly
- * acquire sleeping locks. The same is true if the
- * current process has a mutex enqueued (blocked on
- * a PI chain).
- *
- * In !RT, it is always safe to call __put_task_struct().
- * Though, in order to simplify the code, resort to the
- * deferred call too.
- *
- * call_rcu() will schedule __put_task_struct_rcu_cb()
- * to be called in process context.
- *
- * __put_task_struct() is called when
- * refcount_dec_and_test(&t->usage) succeeds.
- *
- * This means that it can't "conflict" with
- * put_task_struct_rcu_user() which abuses ->rcu the same
- * way; rcu_users has a reference so task->usage can't be
- * zero after rcu_users 1 -> 0 transition.
- *
- * delayed_free_task() also uses ->rcu, but it is only called
- * when it fails to fork a process. Therefore, there is no
- * way it can conflict with __put_task_struct().
- */
- call_rcu(&t->rcu, __put_task_struct_rcu_cb);
+ if (refcount_dec_and_test(&t->usage))
+ __put_task_struct(t);
}
DEFINE_FREE(put_task, struct task_struct *, if (_T) put_task_struct(_T))
diff --git a/init/init_task.c b/init/init_task.c
index ce7c2b07d855d..03b86a4fb5efc 100644
--- a/init/init_task.c
+++ b/init/init_task.c
@@ -20,8 +20,10 @@
#include <linux/uaccess.h>
static struct signal_struct init_signals = {
+ .sigcnt = REFCOUNT_INIT(1),
.nr_threads = 1,
.thread_head = LIST_HEAD_INIT(init_task.thread_node),
+ .group_leader = &init_task,
.wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit),
.shared_pending = {
.list = LIST_HEAD_INIT(init_signals.shared_pending.list),
@@ -158,7 +160,6 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = {
.parent = &init_task,
.children = LIST_HEAD_INIT(init_task.children),
.sibling = LIST_HEAD_INIT(init_task.sibling),
- .group_leader = &init_task,
RCU_POINTER_INITIALIZER(real_cred, &init_cred),
.cred = &init_cred,
.comm = INIT_TASK_COMM,
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index b17c5f9a50d4e..f4e15517ad35d 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -904,7 +904,13 @@ __bpf_kfunc int bpf_iter_task_vma_new(struct bpf_iter_task_vma *it,
if (!kit->data)
return -ENOMEM;
- kit->data->task = get_task_struct(task);
+ /* Programs can still reach a group leader whose refcount is zero. */
+ kit->data->task = tryget_task_struct(task);
+ if (!kit->data->task) {
+ err = -ENOENT;
+ goto err_free_iter;
+ }
+
/*
* Safely read task->mm and acquire an mm reference.
*
@@ -935,6 +941,7 @@ __bpf_kfunc int bpf_iter_task_vma_new(struct bpf_iter_task_vma *it,
err_cleanup_iter:
put_task_struct(kit->data->task);
+err_free_iter:
bpf_mem_free(&bpf_global_ma, kit->data);
/* NULL kit->data signals failed bpf_iter_task_vma initialization */
kit->data = NULL;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 85fec1f389277..5f7f7f35b3c68 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -6521,6 +6521,10 @@ BTF_TYPE_SAFE_RCU(struct task_struct) {
const cpumask_t *cpus_ptr;
struct css_set __rcu *cgroups;
struct task_struct __rcu *real_parent;
+ struct signal_struct *signal;
+};
+
+BTF_TYPE_SAFE_RCU(struct signal_struct) {
struct task_struct *group_leader;
};
@@ -6618,6 +6622,7 @@ static bool type_is_rcu(struct bpf_verifier_env *env,
const char *field_name, u32 btf_id)
{
BTF_TYPE_EMIT(BTF_TYPE_SAFE_RCU(struct task_struct));
+ BTF_TYPE_EMIT(BTF_TYPE_SAFE_RCU(struct signal_struct));
BTF_TYPE_EMIT(BTF_TYPE_SAFE_RCU(struct cgroup));
BTF_TYPE_EMIT(BTF_TYPE_SAFE_RCU(struct css_set));
BTF_TYPE_EMIT(BTF_TYPE_SAFE_RCU(struct cgroup_subsys_state));
diff --git a/kernel/exit.c b/kernel/exit.c
index 5046360b8a6a4..b8328d87d406c 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -288,7 +288,7 @@ void release_task(struct task_struct *p)
leader->exit_state = EXIT_DEAD;
}
- reset_parent_and_leader(p);
+ reset_parents(p);
write_unlock_irq(&tasklist_lock);
proc_flush_pid(thread_pid);
put_pid(thread_pid);
diff --git a/kernel/fork.c b/kernel/fork.c
index ff0e367b2a81d..f5e01ab4ff3a1 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -530,6 +530,8 @@ void put_task_stack(struct task_struct *tsk)
}
#endif
+static void put_signal_struct(struct signal_struct *sig);
+
void free_task(struct task_struct *tsk)
{
#ifdef CONFIG_SECCOMP
@@ -559,6 +561,8 @@ void free_task(struct task_struct *tsk)
free_kthread_struct(tsk);
bpf_task_storage_free(tsk);
put_task_exec_state(rcu_access_pointer(tsk->exec_state));
+ /* Not earlier, as BPF programs can follow ->signal until here. */
+ put_signal_struct(tsk->signal);
free_task_struct(tsk);
}
EXPORT_SYMBOL(free_task);
@@ -773,14 +777,16 @@ static inline void free_signal_struct(struct signal_struct *sig)
kmem_cache_free(signal_cachep, sig);
}
-static inline void put_signal_struct(struct signal_struct *sig)
+static void put_signal_struct(struct signal_struct *sig)
{
if (refcount_dec_and_test(&sig->sigcnt))
free_signal_struct(sig);
}
-void __put_task_struct(struct task_struct *tsk)
+static void __put_task_struct_rcu_cb(struct rcu_head *rhp)
{
+ struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
+
WARN_ON(!tsk->exit_state);
WARN_ON(refcount_read(&tsk->usage));
WARN_ON(tsk == current);
@@ -792,19 +798,44 @@ void __put_task_struct(struct task_struct *tsk)
security_task_free(tsk);
exit_creds(tsk);
delayacct_tsk_free(tsk);
- put_signal_struct(tsk->signal);
sched_core_free(tsk);
free_task(tsk);
}
-EXPORT_SYMBOL_GPL(__put_task_struct);
-void __put_task_struct_rcu_cb(struct rcu_head *rhp)
+/* The last reference to @tsk is gone. */
+void __put_task_struct(struct task_struct *tsk)
{
- struct task_struct *task = container_of(rhp, struct task_struct, rcu);
+ struct signal_struct *sig = tsk->signal;
+
+ /*
+ * Somebody can still hold another thread of the group, and follow the
+ * pointer under RCU. So reset it a grace period before the leader is
+ * freed. It can't be NULL, as BPF programs don't check for that.
+ */
+ if (READ_ONCE(sig->group_leader) == tsk)
+ WRITE_ONCE(sig->group_leader, &init_task);
- __put_task_struct(task);
+ /*
+ * Under PREEMPT_RT, the task can't be freed in atomic
+ * context because that will indirectly acquire sleeping
+ * locks. The same is true if the current process has a
+ * mutex enqueued (blocked on a PI chain).
+ *
+ * call_rcu() will schedule __put_task_struct_rcu_cb()
+ * to be called in process context.
+ *
+ * This can't "conflict" with put_task_struct_rcu_user()
+ * which abuses ->rcu the same way; rcu_users has a
+ * reference so task->usage can't be zero after rcu_users
+ * 1 -> 0 transition.
+ *
+ * delayed_free_task() also uses ->rcu, but it is only called
+ * when it fails to fork a process. Therefore, there is no
+ * way it can conflict with this.
+ */
+ call_rcu(&tsk->rcu, __put_task_struct_rcu_cb);
}
-EXPORT_SYMBOL_GPL(__put_task_struct_rcu_cb);
+EXPORT_SYMBOL_GPL(__put_task_struct);
void __init __weak arch_task_cache_init(void) { }
@@ -964,6 +995,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
#endif
RCU_INIT_POINTER(tsk->exec_state, NULL);
+ /* free_task() drops it, even if the fork fails. */
+ refcount_inc(&tsk->signal->sigcnt);
setup_thread_stack(tsk, orig);
clear_user_return_notifier(tsk);
@@ -1769,10 +1802,12 @@ static int copy_signal(u64 clone_flags, struct task_struct *tsk)
return 0;
sig = kmem_cache_zalloc(signal_cachep, GFP_KERNEL);
- tsk->signal = sig;
if (!sig)
return -ENOMEM;
+ sig->group_leader = tsk;
+ put_signal_struct(tsk->signal);
+ tsk->signal = sig;
sig->nr_threads = 1;
sig->quick_threads = 1;
atomic_set(&sig->live, 1);
@@ -2335,7 +2370,7 @@ __latent_entropy struct task_struct *copy_process(
goto bad_fork_cleanup_sighand;
retval = copy_mm(clone_flags, p);
if (retval)
- goto bad_fork_cleanup_signal;
+ goto bad_fork_cleanup_sighand;
retval = user_events_fork(p, clone_flags);
if (retval)
goto bad_fork_cleanup_mm;
@@ -2412,13 +2447,10 @@ __latent_entropy struct task_struct *copy_process(
/* ok, now we should be set up.. */
p->pid = pid_nr(pid);
- if (clone_flags & CLONE_THREAD) {
- p->group_leader = current->group_leader;
+ if (clone_flags & CLONE_THREAD)
p->tgid = current->tgid;
- } else {
- p->group_leader = p;
+ else
p->tgid = p->pid;
- }
p->nr_dirtied = 0;
p->nr_dirtied_pause = 128 >> (PAGE_SHIFT - 10);
@@ -2583,7 +2615,6 @@ __latent_entropy struct task_struct *copy_process(
current->signal->nr_threads++;
current->signal->quick_threads++;
atomic_inc(¤t->signal->live);
- refcount_inc(¤t->signal->sigcnt);
task_join_group_stop(p);
list_add_tail_rcu(&p->thread_node,
&p->signal->thread_head);
@@ -2651,9 +2682,6 @@ __latent_entropy struct task_struct *copy_process(
mm_clear_owner(mm, p);
mmput(mm);
}
-bad_fork_cleanup_signal:
- if (!(clone_flags & CLONE_THREAD))
- free_signal_struct(p->signal);
bad_fork_cleanup_sighand:
__cleanup_sighand(p->sighand);
bad_fork_cleanup_fs:
@@ -2689,7 +2717,7 @@ __latent_entropy struct task_struct *copy_process(
*/
p->mm = NULL;
/* current can exit before p is freed. */
- reset_parent_and_leader(p);
+ reset_parents(p);
WRITE_ONCE(p->__state, TASK_DEAD);
exit_task_stack_account(p);
put_task_stack(p);
@@ -2730,7 +2758,7 @@ struct task_struct * __init fork_idle(int cpu)
task = copy_process(&init_struct_pid, 0, cpu_to_node(cpu), &args);
if (!IS_ERR(task)) {
- reset_parent_and_leader(task);
+ reset_parents(task);
init_idle_pids(task);
init_idle(task, cpu);
}
diff --git a/kernel/sys.c b/kernel/sys.c
index bfa0a7b5420e7..15919d7a20498 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1764,11 +1764,11 @@ SYSCALL_DEFINE4(prlimit64, pid_t, pid, unsigned int, resource,
get_task_struct(tsk);
rcu_read_unlock();
- need_tasklist = tsk != current;
+ need_tasklist = !same_thread_group(tsk, current);
if (need_tasklist) {
/*
- * Ensure we can't race with release_task() or de_thread(),
- * so tsk->group_leader can't be freed or changed until
+ * Ensure we can't race with group exit or de_thread(),
+ * so tsk's group leader can't be freed or changed until
* read_unlock(tasklist_lock) below.
*/
read_lock(&tasklist_lock);
diff --git a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c
index 948dde25034ef..97aabb93cc6fe 100644
--- a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c
+++ b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c
@@ -28,6 +28,19 @@ enum bpf_link_type___local {
BPF_LINK_TYPE_PERF_EVENT___local = 7,
};
+/* group_leader is in signal_struct, and was in task_struct before. */
+struct signal_struct___local {
+ struct task_struct *group_leader;
+} __attribute__((preserve_access_index));
+
+struct task_struct___local {
+ struct signal_struct___local *signal;
+} __attribute__((preserve_access_index));
+
+struct task_struct___old {
+ struct task_struct *group_leader;
+} __attribute__((preserve_access_index));
+
extern const void bpf_link_fops __ksym;
extern const void bpf_link_fops_poll __ksym __weak;
extern const void bpf_map_fops __ksym;
@@ -63,6 +76,16 @@ static __u64 get_bpf_cookie(struct bpf_link *link)
return BPF_CORE_READ(event, bpf_cookie);
}
+static __always_inline struct task_struct *get_group_leader(void *task)
+{
+ struct task_struct___local *new = task;
+ struct task_struct___old *old = task;
+
+ if (bpf_core_field_exists(old->group_leader))
+ return BPF_CORE_READ(old, group_leader);
+ return BPF_CORE_READ(new, signal, group_leader);
+}
+
SEC("iter/task_file")
int iter(struct bpf_iter__task_file *ctx)
{
@@ -115,7 +138,7 @@ int iter(struct bpf_iter__task_file *ctx)
}
bpf_probe_read_kernel_str(&e.comm, sizeof(e.comm),
- task->group_leader->comm);
+ get_group_leader(task)->comm);
bpf_seq_write(ctx->meta->seq, &e, sizeof(e));
return 0;
diff --git a/tools/testing/selftests/bpf/progs/rcu_read_lock.c b/tools/testing/selftests/bpf/progs/rcu_read_lock.c
index cdb255addbc30..e17b287b6c60c 100644
--- a/tools/testing/selftests/bpf/progs/rcu_read_lock.c
+++ b/tools/testing/selftests/bpf/progs/rcu_read_lock.c
@@ -335,8 +335,8 @@ int task_trusted_non_rcuptr(void *ctx)
task = bpf_get_current_task_btf();
bpf_rcu_read_lock();
- /* the pointer group_leader is explicitly marked as trusted */
- group_leader = task->real_parent->group_leader;
+ /* the pointers signal and group_leader are explicitly marked as trusted */
+ group_leader = task->real_parent->signal->group_leader;
(void)bpf_task_storage_get(&map_a, group_leader, 0, 0);
bpf_rcu_read_unlock();
return 0;
diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_success.c b/tools/testing/selftests/bpf/progs/task_kfunc_success.c
index 6545b124dee14..7d14f0aac13a1 100644
--- a/tools/testing/selftests/bpf/progs/task_kfunc_success.c
+++ b/tools/testing/selftests/bpf/progs/task_kfunc_success.c
@@ -356,8 +356,8 @@ int BPF_PROG(task_kfunc_acquire_trusted_walked, struct task_struct *task, u64 cl
{
struct task_struct *acquired;
- /* task->group_leader is listed as a trusted, non-NULL field of task struct. */
- acquired = bpf_task_acquire(task->group_leader);
+ /* signal and group_leader are listed as trusted, non-NULL fields. */
+ acquired = bpf_task_acquire(task->signal->group_leader);
if (acquired)
bpf_task_release(acquired);
else
diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c b/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c
index ee4a601dcb066..118cc4f7208b1 100644
--- a/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c
+++ b/tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c
@@ -24,11 +24,15 @@ struct core_reloc_kernel_output {
bool local_task_struct_matches;
};
+struct signal_struct {
+ struct task_struct *group_leader;
+};
+
struct task_struct {
int pid;
int tgid;
char comm[16];
- struct task_struct *group_leader;
+ struct signal_struct *signal;
};
struct mm_struct___wrong {
@@ -54,13 +58,17 @@ int test_core_kernel(void *ctx)
struct core_reloc_kernel_output *out = (void *)&data.out;
uint64_t pid_tgid = bpf_get_current_pid_tgid();
int32_t real_tgid = (int32_t)pid_tgid;
+ struct task_struct *leader;
+ struct signal_struct *sig;
int pid, tgid;
if (data.my_pid_tgid != pid_tgid)
return 0;
if (CORE_READ(&pid, &task->pid) ||
- CORE_READ(&tgid, &task->tgid))
+ CORE_READ(&tgid, &task->tgid) ||
+ CORE_READ(&sig, &task->signal) ||
+ CORE_READ(&leader, &sig->group_leader))
return 1;
/* validate pid + tgid matches */
@@ -70,42 +78,35 @@ int test_core_kernel(void *ctx)
out->valid[1] = BPF_CORE_READ(task,
tgid) == real_tgid;
out->valid[2] = BPF_CORE_READ(task,
- group_leader,
- tgid) == real_tgid;
+ signal, group_leader) == leader;
out->valid[3] = BPF_CORE_READ(task,
- group_leader, group_leader,
+ signal, group_leader,
tgid) == real_tgid;
out->valid[4] = BPF_CORE_READ(task,
- group_leader, group_leader, group_leader,
- tgid) == real_tgid;
+ signal, group_leader, signal, group_leader) == leader;
out->valid[5] = BPF_CORE_READ(task,
- group_leader, group_leader, group_leader,
- group_leader,
+ signal, group_leader, signal, group_leader,
tgid) == real_tgid;
out->valid[6] = BPF_CORE_READ(task,
- group_leader, group_leader, group_leader,
- group_leader, group_leader,
- tgid) == real_tgid;
+ signal, group_leader, signal, group_leader,
+ signal, group_leader) == leader;
out->valid[7] = BPF_CORE_READ(task,
- group_leader, group_leader, group_leader,
- group_leader, group_leader, group_leader,
+ signal, group_leader, signal, group_leader,
+ signal, group_leader,
tgid) == real_tgid;
out->valid[8] = BPF_CORE_READ(task,
- group_leader, group_leader, group_leader,
- group_leader, group_leader, group_leader,
- group_leader,
- tgid) == real_tgid;
+ signal, group_leader, signal, group_leader,
+ signal, group_leader, signal, group_leader) == leader;
out->valid[9] = BPF_CORE_READ(task,
- group_leader, group_leader, group_leader,
- group_leader, group_leader, group_leader,
- group_leader, group_leader,
+ signal, group_leader, signal, group_leader,
+ signal, group_leader, signal, group_leader,
tgid) == real_tgid;
/* test BPF_CORE_READ_STR_INTO() returns correct code and contents */
out->comm_len = BPF_CORE_READ_STR_INTO(
&out->comm, task,
- group_leader, group_leader, group_leader, group_leader,
- group_leader, group_leader, group_leader, group_leader,
+ signal, group_leader, signal, group_leader,
+ signal, group_leader, signal, group_leader,
comm);
out->local_task_struct_matches = bpf_core_type_matches(struct task_struct___local);
diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/btf_typecast_accepted.tc b/tools/testing/selftests/ftrace/test.d/dynevent/btf_typecast_accepted.tc
index dd5552727054c..7c8483ab7df23 100644
--- a/tools/testing/selftests/ftrace/test.d/dynevent/btf_typecast_accepted.tc
+++ b/tools/testing/selftests/ftrace/test.d/dynevent/btf_typecast_accepted.tc
@@ -39,7 +39,7 @@ if [ "$FPROBES" ] ; then
# 6. Test $current variable support on fprobe
echo 'f:fpevent6 vfs_read pid=$current->pid' >> dynamic_events
echo 'f:fpevent7 vfs_read pid=(task_struct)$current->pid' >> dynamic_events
- echo 'f:fpevent8 vfs_read pid=(task_struct,group_leader)$current->pid' >> dynamic_events
+ echo 'f:fpevent8 vfs_read pid=(task_struct,real_parent)$current->pid' >> dynamic_events
# Test this_cpu_read and this_cpu_ptr on fprobe
echo 'f:fpevent9 sample_timer_cb name=(foo_timer_data,timer)t->name:string count=this_cpu_read((foo_timer_data,timer)t->counter)' >> dynamic_events
@@ -60,7 +60,7 @@ if [ "$KPROBES" ] ; then
# 12. Test $current variable support on kprobe
echo 'p:kpevent6 vfs_read pid=$current->pid' >> dynamic_events
echo 'p:kpevent7 vfs_read pid=(task_struct)$current->pid' >> dynamic_events
- echo 'p:kpevent8 vfs_read pid=(task_struct,group_leader)$current->pid' >> dynamic_events
+ echo 'p:kpevent8 vfs_read pid=(task_struct,real_parent)$current->pid' >> dynamic_events
# Test this_cpu_read and this_cpu_ptr on kprobe
echo 'p:kpevent9 sample_timer_cb name=(foo_timer_data,timer)t->name:string count=this_cpu_read((foo_timer_data,timer)t->counter)' >> dynamic_events
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-05 13:13 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox