From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6343F31AA96 for ; Tue, 6 Jan 2026 10:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767697119; cv=none; b=BTktxP95UayRfsc0jESzXal/OYv14uD00ZDDDfwWdvTLLZB3viLjF6waSJr1CMnRd8GVuFfJHZn227wS4U90Sn0CdCVbp8zByuUDXwj/SOJ1j1tfRARppUwYGmgo60w/84L3kCFAC54GKzTuT/2ulgPSwBLbuptLmNY08HmU5+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767697119; c=relaxed/simple; bh=4xr7q5447ijaq42a9RS3FWlwefJoNP62d44eSmuYbEo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SXaZBMGcV8FzOwnWoC/i/9a+kX7ZRv+1coMCv6ah6ou2uTrSOEfWXwFZqdIoEOFANKEisXsrKKLJtXq4ducqrzYaIq7dp76Iu0oGuCFFYou7jQ7T/RsFrpPkvIDvjPitlSRHjaRt8rvMvn8qoK9U7AYBP+IpsSEX86C6IKsEgbw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ATsAYBa2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ATsAYBa2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767697117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UVshW/MmXqy1kUG9HUNoXWmjjV25FxcMbrMvpCyjw0s=; b=ATsAYBa2CaE4EzxGYkjDacEOf2XDu789OtKHiJJCFfDzIbsubVRWxreeNPB4o6lVFpJhVH 1FcCkEfUXI95APjdcJaOpfZvJ3ZahQVIE8qNRWMIYP7qVXsDp2Cpj7NBEmiRMocVup8pmV DLO5Hq4ud+znvjRP7YTaAt8pGAzLuKo= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-376-ZMaTO74zOuecYT_P6px7sA-1; Tue, 06 Jan 2026 05:58:33 -0500 X-MC-Unique: ZMaTO74zOuecYT_P6px7sA-1 X-Mimecast-MFC-AGG-ID: ZMaTO74zOuecYT_P6px7sA_1767697111 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EDDC4180120B; Tue, 6 Jan 2026 10:58:29 +0000 (UTC) Received: from fedora (unknown [10.44.33.62]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 9E6251800367; Tue, 6 Jan 2026 10:58:21 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 6 Jan 2026 11:58:29 +0100 (CET) Date: Tue, 6 Jan 2026 11:58:20 +0100 From: Oleg Nesterov To: Qing Wang 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 Subject: Re: [PATCH] fork/pid: Fix use-after-free in __task_pid_nr_ns Message-ID: References: <20260106102642.2765480-1-wangqing7171@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260106102642.2765480-1-wangqing7171@gmail.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On 01/06, Qing Wang wrote: > > On Tue, 06 Jan 2026 at 17:04, Oleg Nesterov 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; > > } > > Sorry, please ignore my previous reply. I've reconsidered your code, and > using pid_alive() to check the validity of tsk->signal is actually correct. > The pid is assigned after copy_signal(), so if a task has a PID, its > tsk->signal memory is guaranteed to be valid. Yes, if the child wasn't fully created then init_task_pid(child) was not called so pid_alive(p) can't be true. OK, if you agree with this approach, can you make V2? Or do you prefer another approach? The patch above is not 100% correct wrt "avoid -1 ...", but it seems that this can be fixed. Oleg.