mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qing Wang <wangqing7171@gmail.com>
To: akpm@linux-foundation.org
Cc: Liam.Howlett@oracle.com, brauner@kernel.org, bsegall@google.com,
	david@kernel.org, dietmar.eggemann@arm.com, jack@suse.cz,
	joel.granados@kernel.org, juri.lelli@redhat.com,
	keescook@chomium.org, linux-kernel@vger.kernel.org,
	lorenzo.stoakes@oracle.com, mingo@redhat.com, mjguzik@gmail.com,
	oleg@redhat.com, peterz@infradead.org, rostedt@goodmis.org,
	rppt@kernel.org,
	syzbot+e0378d4f4fe57aa2bdd0@syzkaller.appspotmail.com,
	vbabka@suse.cz, vincent.guittot@linaro.org,
	wangqing7171@gmail.com
Subject: Re: [PATCH] fork/pid: Fix use-after-free in __task_pid_nr_ns
Date: Tue,  6 Jan 2026 15:07:22 +0800	[thread overview]
Message-ID: <20260106070723.2313045-1-wangqing7171@gmail.com> (raw)
In-Reply-To: <20260105144641.5dcce6cdeac8514580d3cd14@linux-foundation.org>

> It might be helpful to have a comment here telling readers how
> task->signal can be zero.
> 
> Also, what in here prevents task->signal from being zeroed after we've
> tested it and before we dereference it?

Thank you for your feedback. Regarding the "test-and-use" race condition
you raised, I’ve thought about it extensively but haven’t found a
better solution on the access side.

However, after re-examining the issue, I guess the root cause lies in
the copy_process() flow itself, and we may not need complex handling at
the access site:

1. The signal_struct is not fully managed by reference counting: In
the normal (successful) path of copy_process(), the signal structure is
indeed reference-counted, and its lifetime should be at least longer than
the task’s. However, in the failure/cleanup path, signal is explicitly
freed via free_signal_struct(), which prematurely ends its lifetime. At
the same time, other subsystems (e.g., perf) might still hold references
and attempt to access it—even if such access may be questionable.

2. A newly created task should not be visible to other CPUs during
creation: The perf subsystem copies the parent’s events
to the child during copy_process(). Later, when the parent closes or
manipulates its own perf event, it may traverse child events and access
child_ctx->task->signal. This means that a child process that has not
yet been fully created can be referenced by other CPUs.

Based on this analysis, I propose two possible fixes—either one should
resolve the issue:

1. Remove the explicit free_signal() in the cleanup path, and
fully managed by reference counting for signal lifetime. Currently
put_signal_struct() is only used in __put_task_struct(), so the lifetime
of signal is longer than or equal to task.

2. Defer perf_event_init_task() until after copy_signal() succeeds,
ensuring that if copy_process() failed perf events will be cleaned
up before the signal. This guarantees that no perf event can access
the signal.

I believe either approach would eliminate the issue. Could you please
review whether this analysis and the proposed solutions are correct? Any
guidance would be greatly appreciated.

  reply	other threads:[~2026-01-06  7:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05  4:36 Qing Wang
2026-01-05 22:46 ` Andrew Morton
2026-01-06  7:07   ` Qing Wang [this message]
2026-01-06  9:04 ` Oleg Nesterov
2026-01-06 10:06   ` Qing Wang
2026-01-06 10:26   ` Qing Wang
2026-01-06 10:58     ` Oleg Nesterov
2026-01-06 10:58   ` Qing Wang
2026-01-06 11:19     ` Oleg Nesterov
2026-01-07  2:43       ` Qing Wang
2026-01-06 12:50   ` Oleg Nesterov
2026-01-07  9:40     ` Qing Wang
2026-01-07 14:54       ` Oleg Nesterov
2026-01-07  9:43     ` Oleg Nesterov
     [not found] <20260105045609.1764387-1-wangqing7171@gmail.com>
2026-01-07 20:39 ` Kees Cook
2026-01-08  2:15   ` Qing Wang
2026-01-08  3:44   ` Qing Wang

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=20260106070723.2313045-1-wangqing7171@gmail.com \
    --to=wangqing7171@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=bsegall@google.com \
    --cc=david@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=jack@suse.cz \
    --cc=joel.granados@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=keescook@chomium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mingo@redhat.com \
    --cc=mjguzik@gmail.com \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=syzbot+e0378d4f4fe57aa2bdd0@syzkaller.appspotmail.com \
    --cc=vbabka@suse.cz \
    --cc=vincent.guittot@linaro.org \
    /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

all inboxes | Powered by JetHome®