From: "Chris Mason" <mason@kernel.org>
To: "Oleg Nesterov" <oleg@redhat.com>
Cc: brauner@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
peterz@infradead.org, mingo@redhat.com, kees@kernel.org,
tj@kernel.org, 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
Subject: Re: [PATCH 1/3] fork: make the creator the parent of an unlinked task
Date: Fri, 04 Dec 2026 11:27:37 -0500 [thread overview]
Message-ID: <1796400641.3.26376.2@kernel.org> (raw)
In-Reply-To: <axLb_tZ5NJfIFrkb@redhat.com>
On Fri, 4 Dec 2026 16:27:58 +0100, Oleg Nesterov wrote:
> I know nothing about bpf, could you add more details please ?
>
> OK, B, child of A, does copy_process().
>
> A exits right after dup_task_struct(). p->real_parent points to nowhere.
>
> Who exactly can dererence p->real_parent at this point?
BPF programs...security_task_alloc() and sched_cgroup_fork() call them with
p before it's linked, and they're allowed to read p->real_parent->pid, for
example. The scx_lavd scheduler does this now.
> With the change in dup_task_struct(), why is it correct to pretend that
> p->real_parent == B ?
It's only correct for a plain fork, where B will be the parent anyway? For a
new thread, the parent will be A, and copy_process() sets that at the end.
CLONE_PARENT is the same.
Until then, bpf programs need p->real_parent pointing to a task that can't
be freed. A can exit at any time, but B can't, because it's busy with the fork.
The downside is a window where a bpf program sees B as the parent of a
new thread.
(I don't love any of these fixes, just explaining the crash itself)
[ ... ]
> OK, this change suggests that we have another problem: copy_process() with
> CLONE_PARENT or CLONE_THREAD can fail and drop tasklist_lock after it sets
> p->real_parent = A. A can exit.
>
> Who can derefence ->real_parent of the soon-to-be-freed and not-yet-linked
> task p?
sched_cancel_fork() calls sched_ext's ops.exit_task() after tasklist_lock is
dropped. This patch missed that one, thanks for flagging.
> I am just trying to understand the problem. Perhaps we should change
> dup_task_struct() to nullify p->thread_pid to make pid_alive(p) false?
It looks like that isn't enough on its own. BPF programs follow ->real_parent
without checking pid_alive().
-chris
next prev parent reply other threads:[~2026-12-04 16:28 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
2026-12-04 15:27 ` Oleg Nesterov
2026-12-04 16:27 ` Chris Mason [this message]
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=1796400641.3.26376.2@kernel.org \
--to=mason@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=sched-ext@lists.linux.dev \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--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 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.