mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qing Wang <wangqing7171@gmail.com>
To: oleg@redhat.com
Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org,
	brauner@kernel.org, bsegall@google.com, david@kernel.org,
	dietmar.eggemann@arm.com, jack@suse.cz, joel.granados@kernel.org,
	juri.lelli@redhat.com, linux-kernel@vger.kernel.org,
	lorenzo.stoakes@oracle.com, mingo@redhat.com, mjguzik@gmail.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 18:58:32 +0800	[thread overview]
Message-ID: <20260106105832.2779312-1-wangqing7171@gmail.com> (raw)
In-Reply-To: <aVzQEXa6eLhqmul_@redhat.com>

On Tue, 06 Jan 2026 at 17:04, Oleg Nesterov <oleg@redhat.com> wrote:
> At first glance this is racy. Can't task->signal be freed right after
> the check?
> 
> And... Can't we make another fix? If copy_process() fails and does
> free_signal_struct(), the child has not been added to rcu protected
> lists and init_task_pid(child) was not called yet.
> 
> So perhaps something like the patch below can work?
> 
> Oleg.
> ---
> 
> --- x/kernel/events/core.c
> +++ x/kernel/events/core.c
> @@ -1422,16 +1422,17 @@ unclone_ctx(struct perf_event_context *c
>  static u32 perf_event_pid_type(struct perf_event *event, struct task_struct *p,
>  				enum pid_type type)
>  {
> -	u32 nr;
> +	u32 nr = 0;
>  	/*
>  	 * only top level events have the pid namespace they were created in
>  	 */
>  	if (event->parent)
>  		event = event->parent;
>  
> -	nr = __task_pid_nr_ns(p, type, event->ns);
> +	if (pid_alive(p))
> +		nr = __task_pid_nr_ns(p, type, event->ns);
>  	/* avoid -1 if it is idle thread or runs in another ns */
> -	if (!nr && !pid_alive(p))
> +	if (!nr)
>  		nr = -1;
>  	return nr;
>  }

Could we put the checking 'pid_alive(task)' into __task_pid_nr_ns()?
Because there is another similar use case here.

arch/s390/kernel/perf_cpum_sf.c
  619,9: 		pid = __task_pid_nr_ns(tsk, type, event->ns);

---

diff --git a/kernel/pid.c b/kernel/pid.c
index a31771bc89c1..e8826731fa47 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -515,7 +515,7 @@ pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
        rcu_read_lock();
        if (!ns)
                ns = task_active_pid_ns(current);
-       if (ns)
+       if (ns && pid_alive(task))
                nr = pid_nr_ns(rcu_dereference(*task_pid_ptr(task, type)), ns);
        rcu_read_unlock();

  parent reply	other threads:[~2026-01-06 10:58 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
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 [this message]
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=20260106105832.2779312-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=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®