BPF List
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Chris Mason <mason@kernel.org>
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, 4 Dec 2026 16:27:58 +0100	[thread overview]
Message-ID: <axLb_tZ5NJfIFrkb@redhat.com> (raw)
In-Reply-To: <20261203200612.26376-2-mason@kernel.org>

On 12/03, Chris Mason wrote:
>
> copy_process() lets BPF hit a use-after-free through the new task's
> ->real_parent if the forking task's parent is reaped during the fork.
>
> The verifier lets BPF programs follow ->real_parent and ->parent under
> RCU, but forget_original_parent() only updates linked tasks. The new task
> isn't linked until the end of copy_process(), and the task_alloc LSM hook
> and sched_ext's ops.init_task() and ops.exit_task() see it before that.
> dup_task_struct() just copies both pointers, without taking a reference:
>
>     B, child of A                    A and its parent
>     =============                    ================
>     copy_process()
>       dup_task_struct()
>         p->real_parent = A
>                                      exit_notify()
>                                        forget_original_parent()
>                                          B->real_parent = reaper
>                                      release_task(A)
>                                        put_task_struct_rcu_user()
>                                      delayed_put_task_struct()
>       security_task_alloc(p)
>         bpf: p->real_parent->pid

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?

With the change in dup_task_struct(), why is it correct to pretend that
p->real_parent == B ?

> The idle tasks have the same problem. Init forks the ones for the
> secondary CPUs, so their ->real_parent is init's thread group leader.
> They are never linked, so nothing updates the pointer. If another thread
> of init calls execve(), de_thread() releases the old leader, but
> sched_show_task() and BPF programs at sched_switch can still follow
> ->real_parent to it.

Yes... perhaps fork_idle() should use CLONE_PARENT... but your change
looks fine.

> The fix used here is to point both pointers at the forking task until the
> fork can no longer fail,

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?

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?

Oleg.


  parent reply	other threads:[~2026-12-04 15: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 [this message]
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=axLb_tZ5NJfIFrkb@redhat.com \
    --to=oleg@redhat.com \
    --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=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mingo@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox