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 850D53CC7F1 for ; Sat, 18 Jul 2026 15:58:39 +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=1784390333; cv=none; b=kXBm2KLRfN/v+tKyUguooDltuvvgbS9U2jojO19BQIGGykwpN3fGQGuimq8/5+naFaSA36LHh5G+FSABgIWLFdax1eIgQcHpKETJ3TV+LUgpMVsUS7OWVh4ztGAv1O+LK0qzK2rs16NqbdtOZw36qRAoNaiSjo8y23igdUbHlC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784390333; c=relaxed/simple; bh=PvN2HLQhAaLXlpOHHhZweNIus4j78PSrfxzg2sCiE4k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oM9XmjO6LNZ6Dm3vOAC1G7X5mu80upnA30cVl9Vz09kXAtkY+Se3jHck1Ld8J8/cIfWpKFVL7zxuaghVnT23pdLDvhpnzomSQmQLTCaAvc2OTOIuSLEwhx5ZqwmbsJR4JmUwjXgL2POPrE2IqenlSH1XNGS9B44zdLR1q6t6rIY= 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=NQetS+WL; 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="NQetS+WL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784390313; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RcAQ6taD/yyIt8Pb998GX64Zj0fY5Baff1M2jYSbUn8=; b=NQetS+WL/HSUEVxjYGBJUlFGYEo4TejVmXffwopFJVqF7HYHpU3Nfj9OH5RKvwn1vF8BfG U5YFHT86RfQjsbQzyISs7a+6v3TC+g9ZuXchIV6nxWGP8ljZYniWWzCZeuNyGxGy72fVpL mYaaApc3Th/QekgKY2xKZ109g3M0OMU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-FdS8r3tpNqSKldJhCvw1Yw-1; Sat, 18 Jul 2026 11:58:28 -0400 X-MC-Unique: FdS8r3tpNqSKldJhCvw1Yw-1 X-Mimecast-MFC-AGG-ID: FdS8r3tpNqSKldJhCvw1Yw_1784390306 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 85C6C195D031; Sat, 18 Jul 2026 15:58:25 +0000 (UTC) Received: from fedora (unknown [10.44.49.164]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 95F3A300418A; Sat, 18 Jul 2026 15:58:20 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 18 Jul 2026 17:58:25 +0200 (CEST) Date: Sat, 18 Jul 2026 17:58:19 +0200 From: Oleg Nesterov To: Mateusz Guzik Cc: "Cen Zhang (Microsoft)" , brauner@kernel.org, akpm@linux-foundation.org, jack@suse.cz, avagin@gmail.com, ptikhomirov@virtuozzo.com, include@grrlz.net, linux-kernel@vger.kernel.org, AutonomousCodeSecurity@microsoft.com, tgopinath@linux.microsoft.com, kys@microsoft.com, stable@vger.kernel.org Subject: Re: [PATCH v2 2/2] pid: fix cad_pid use-after-free race Message-ID: References: <20260718032000.9184-1-blbllhy@gmail.com> <20260718032000.9184-2-blbllhy@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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 On 07/18, Mateusz Guzik wrote: > > On Sat, Jul 18, 2026 at 3:20 PM Oleg Nesterov wrote: > > > > On 07/17, Cen Zhang (Microsoft) wrote: > > > > > > int kill_cad_pid(int sig, int priv) > > > { > > > - return kill_pid(cad_pid, sig, priv); > > > + struct pid *pid; > > > + int ret; > > > + > > > + rcu_read_lock(); > > > + pid = get_pid(rcu_dereference(cad_pid)); > > > + rcu_read_unlock(); > > > + > > > + ret = kill_pid(pid, sig, priv); > > > + put_pid(pid); > > > > Hmm. Why do we need get/put_pid() ? I think that > > > > rcu_read_lock(); > > ret = kill_pid(rcu_dereference(cad_pid), sig, priv); > > rcu_read_unlock(); > > > > return ret; > > > > should work just fine? > > > > I suggested taking the ref as a future-proofing measure to *not* > impose any requirements on kill_pid. > > Admittedly when responding to v1 I blindly assumed pid is always > rcu-freed, my bad. > > Given the arcane nature of the proc file at hand and 0 performance > concerns, I think the easiest way out is to give it a spinlock to > protect access to cad_pid as opposed to trying to play any rcu and > lockless games. Just in case, I am fine either way. I'd personaly prefer to play rcu games in this case, but I won't insist. I've sent my comment only because get_pid + put_pid + kill_pid() outside of rcu_read_lock() look really confusing to me. As for requirements on kill_pid... See for example kill_pid_info(). kill_pid/kill_pid_info/etc are all rcu safe wrt "struct pid *pid" arg. Oleg.