From: sashiko-bot@kernel.org
To: "Chris Mason" <mason@kernel.org>, bpf@vger.kernel.org
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 1/3] fork: make the creator the parent of an unlinked task
Date: Thu, 03 Dec 2026 20:31:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-248634@kernel.org> (raw)
In-Reply-To: <20261203200612.26376-2-mason@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] fork: stale parent and group_leader pointers across
delayed_free_task()
--
commit baa0d889662d0754e858f27233d7dd23f9b6844d
Author: Chris Mason <mason@kernel.org>
fork: make the creator the parent of an unlinked task
This commit points a new task's real_parent and parent at the forking task
in dup_task_struct() until copy_process() reaches the point of no return,
and points idle tasks' parent pointers at init_task.
> diff --git a/kernel/fork.c b/kernel/fork.c
> index d55a7d21a8fb2..3734aaa717130 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -977,6 +977,12 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
> refcount_set(&tsk->rcu_users, 0);
> /* One for the rcu users */
> refcount_set(&tsk->usage, 1);
> + /*
> + * Nobody updates the parents of a task that is on no list, and orig
> + * stays until copy_process() is done.
> + */
> + RCU_INIT_POINTER(tsk->real_parent, orig);
> + RCU_INIT_POINTER(tsk->parent, orig);
> #ifdef CONFIG_BLK_DEV_IO_TRACE
> tsk->btrace_seq = 0;
> #endif
[Severity: Medium]
Can tsk->real_parent and tsk->parent dangle past copy_process() when a fork
fails under CONFIG_MEMCG?
On bad_fork_free, delayed_free_task(p) defers free_task(p) via call_rcu()
when CONFIG_MEMCG is enabled. Once copy_process() returns an error, orig can
exit, be reaped, and be freed before __delayed_free_task() runs on another
CPU:
CPU0 CPU1
copy_process()
dup_task_struct()
p->real_parent = orig
... (fails -> bad_fork_free)
delayed_free_task(p)
call_rcu(&p->rcu, ...)
orig exits and is reaped
delayed_put_task_struct(orig)
free_task(orig)
__delayed_free_task(p)
free_task(p)
fentry/free_task:
bpf_find_vma(p->real_parent, ...)
<-- use-after-free
In an fentry/free_task BPF program, walking tsk->real_parent or tsk->parent
produces a plain PTR_TO_BTF_ID accepted by legacy helpers such as
bpf_find_vma(). bpf_find_vma() directly locks task->alloc_lock without
probe-fault protection, resulting in a slab use-after-free.
bad_fork_free already clears p->mm for this window from commit dab101c9414d
("fork: clear p->mm when copy_process() fails"), and p->group_leader has the
same lifetime issue. Resetting p->real_parent and p->parent to &init_task
and p->group_leader to p before delayed_free_task(p) would close this gap.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203200612.26376-1-mason@kernel.org?part=1
next prev parent reply other threads:[~2026-12-03 20:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 20:06 [PATCH 0/3] fork, exit: fix BPF use-after-frees on task pointers Chris Mason
2026-12-03 20:06 ` [PATCH 1/3] fork: make the creator the parent of an unlinked task Chris Mason
2026-12-03 20:31 ` sashiko-bot [this message]
2026-12-04 15:27 ` Oleg Nesterov
2026-12-04 16:27 ` Chris Mason
2026-12-03 20:06 ` [PATCH 2/3] exit: don't leave stale parent and leader pointers Chris Mason
2026-12-03 20:31 ` sashiko-bot
2026-12-03 20:55 ` bot+bpf-ci
2026-12-03 20:06 ` [PATCH 3/3] bpf: Don't start a thread walk at a released task Chris Mason
2026-12-03 20:42 ` bot+bpf-ci
2026-12-04 2:36 ` [PATCH 0/3] fork, exit: fix BPF use-after-frees on task pointers Alexei Starovoitov
2026-12-04 12:53 ` Oleg Nesterov
2026-12-04 15:36 ` 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=sashiko-outbox-248634@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=mason@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.