From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.7 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796233951; b=AvbzDiTxWrqh17UNGDzrAyrieOstVfDOwGlGanuWbpeoQl1NpZxqfEA8CgzcjcoxjqWh tyfM6yCZGWEGFVAZfKGmH5S4ibYvnp1FU9Ne99u5kxKarh90ZX0fVRshUiljBOQydCuP2 2jECVQ28dpqwbRf+FtnxeYNr9KY0UJx2SJn1Vmuwsfm8pDfDJsPReFIzBDcHT041Tpmmi Vwq1Ah+7mP5Ju30ZVbXwoPaXcoQnOchk32U+viIEgJgiLtQQitGIqUh4OSZ6yDmuqhfET qY9go2wPseeoJG1hcilvQtnT4XXoQI5/BUfpF2ns/8h2DMZV3x2uECeeUBaI/Qll5tA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796233951; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=2AuuiYEK3zl29YToIIOqWYj64GGMX53LA7BzILtnKXo=; b=GJUhOHvaICuCJDMPhw1SeHHvjjWw9uZliiwolCZUjRo88PWoSXkLkg22lmkWjr8DYckE tr+R1UfiztQi25kKHbWl2IQBHkd3o3nvpl944NodMts3fcYI+IZbDPQpCnkeF9sOrikB/ oMOlKCdgV8pbsjVuGRONxkGwoGDpXdOADumEQJ1CulB88eZrmn8QlNmVn40+yM3hz8Yq3 mNOPsx+cvGdGG2AE7yHcxO7G+2Frjw1GfBJ60gtzR3daShmtFeErk/p5Hwep27drxb5lf vIsV1lf6sreoA2GBHiJAaIzDw8NMeDsFmUcJIfIm4ZMpzqjpQOtGR+QCGxyCgpRiM+w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zXqkWDPv; arc=none smtp.remote-ip=74.125.229.7 Received: from mail-dy2-f7.google.com (mail-dy2-f7.google.com [74.125.229.7]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D71BD606A322 for ; Wed, 2 Dec 2026 17:52:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D71BD606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zXqkWDPv Received: by mail-dy2-f7.google.com with SMTP id 5a478bee46e88-386e226acaaso2069763eec.0 for ; Wed, 02 Dec 2026 09:52:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796233950; x=1796838750; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=2AuuiYEK3zl29YToIIOqWYj64GGMX53LA7BzILtnKXo=; b=zXqkWDPvbN3V31NAdik4Kk7iR5R7o7QZHATLhr6vq5Alu81TQl+GArp78woePhU3u5 Ook9bptjIfY4qeKpv1FFbZVUb1Jm4+0qQEQIPQLjQUKNDd4F4EgUqHuexLssfqbPc4vl GqBaVl9yLAbfvoefGaXWDjRu+dETAamCUp1gwMxmFBffF/RrOhsHDFn17j4jOVkBJSlo YwZa7tndE0iAjvIeJz5l7MjAZvZZNBRc6aXxO6HCktl2Gi6+jscTZ9F1Z/doz4yxgZPy WjllwrCYxdUKgU3JSFjmsX0NQBl59YSDeXeMFMv4FNsh/05NEUFmqmYjSABggZUoTHeY cH9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796233950; x=1796838750; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2AuuiYEK3zl29YToIIOqWYj64GGMX53LA7BzILtnKXo=; b=zXYQQJp/lSSmPBPzzRR+ffJiITD0v7aEA/ebZjJ3K4vpBDFQhb68Zg2n7KLJUWfxab /KSHe10Nxj6bdLcFhUDm9UtKUjRltf2AVuK6aGSdvuEcFbTPTEkxZqqeqrAmstwnqigV KzuH3pXfbeoYiRk1w2pX5f4I8/lAuPyxhqonQP3Vq3ZQLw9vm7tsRB7GxijiTcar6bgJ Qg5ZTZud0XQvZoxnFNxIw6/IdMKOawsT58zw8uXePNg7/1DfzOO9SOvFdVWjvQqZWkL7 ZnrjX6AHM3jz1IMb8Kf3z0H76TTy0NT8rCL5ezS5zWaaAQOsi3nVh+jI06sEY2AmMoXU u/0w== X-Forwarded-Encrypted: i=1; AL+hErHRsxnDhgKwvuROVhGu/7YffUetqbyQDvvYjg3BAKqW8sn0Oy+PFHUpqyn3Gke+1R10FJ/4vHULkcFqbnY=@vger.kernel.org X-Gm-Message-State: APuU4Z9fnXyvlh9dXcxTapMlTYNVfb8Dqhq8DN6SPydQ9Rg3Ad+jng0Y Bqd/2YtxUChbbS5+K2hah1ULtTfv771NPyB8pQdq9LU0aU/BCnj6AbHL X-Gm-Gg: AZFdTZf1Oowvb0tgDGDA1vfYt9Fj2LuxN9FHlU18A9L3pqXyEjt1aUp3CjrQPFaD52G a+XtieL5yGClH6Pu082m3KXDSJV8cb6W6cCil/67gTU8KiSgnLI3F52rL6xePaXiYN+9H8+z97F y/5CFWZ/i6bHotFVcpWfMc9CIr8YkCj032sWEAjUxftAMITxn8BSMYLEoztgc8bN2CZCOhXoe2O bJLBf7lQlhLtxOp+/wyap8Iz6wFnQosdWd3Zgf4kQsPEImsZ9+Trl+M3NyZj8iYUw/I+G3+p+vy xY9k/3h1MADS3jvLMsK+U4aO85Dh+qi1koDTpIr6TIFBHXUe3I7alCbpSQYt8Mr1pon9HoO8piu HJkuCRzxQ9mLH29zUwbT/WS7n3YrKPknCOX2gEjx97N1Tewc7HyDicBGNZ/MPNI6NnVtHIVYjny 0QCExqV8r3w2e/iyCWcfk7YMdiJsVTl0dkAjCP82dbeaeV4SJtzjkVnTT9xFt5SiMTdzVP9QPiB Ot3eHk1IKGl6cNmm3FVmWd3MhGPGDXrufXryGoq52jnh6rjVaSFnpXvcjSBXhV5slJYTqWk9rE5 VU4ug9PAMpIrjO2fRdHgyzv0eU8daq9wvwBUy9NtFYmfvjMQMNF+aMC0 X-Received: by 2002:a05:7300:ce93:b0:36c:a44c:1763 with SMTP id 5a478bee46e88-386bbfa6402mr26355416eec.32.1796233949786; Wed, 02 Dec 2026 09:52:29 -0800 (PST) Received: from jiayi-vm-sprl-server17.local ([155.69.195.24]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38567cafec4sm132811616eec.26.2026.12.02.09.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 09:52:29 -0800 (PST) From: Jiayi Zhang To: Christian Brauner , Andrew Morton Cc: Oleg Nesterov , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+d608d486bd3b7062bafc@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: [PATCH] proc: use pid_has_task() in proc_inode_is_dead() Date: Wed, 2 Dec 2026 17:52:10 +0000 Message-ID: <20261202175210.4123870-1-zhangjiayi1014@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit proc_inode_is_dead() tests whether the pid still has a task by reading pid->tasks[PIDTYPE_PID].first with a plain load. The list is changed with RCU list operations when the task is released, so the read races with detach_pid() when a /proc/ dentry is put while the task is released. KCSAN reports: BUG: KCSAN: data-race in detach_pid / pid_delete_dentry write (marked) to 0xffff888101d47270 of 8 bytes by task 6239 on cpu 0: __hlist_del include/linux/list.h:1045 [inline] hlist_del_rcu include/linux/rculist.h:599 [inline] __change_pid kernel/pid.c:413 [inline] detach_pid+0xb1/0x1a0 kernel/pid.c:426 __unhash_process kernel/exit.c:141 [inline] __exit_signal kernel/exit.c:206 [inline] release_task+0x67e/0xba0 kernel/exit.c:267 read to 0xffff888101d47270 of 8 bytes by task 7384 on cpu 1: proc_inode_is_dead fs/proc/base.c:2067 [inline] pid_delete_dentry+0x30/0x50 fs/proc/base.c:2076 retain_dentry fs/dcache.c:913 [inline] finish_dput+0xd8/0x1d0 fs/dcache.c:1033 dput+0x43/0x50 fs/dcache.c:1073 proc_invalidate_siblings_dcache+0x1e6/0x2c0 fs/proc/inode.c:143 The race does not cause a functional problem. If the reader still sees the task, pid_delete_dentry() keeps the dentry, and pid_revalidate() or proc_flush_pid() drops it later. proc_task_readdir() uses the same helper and can at worst list an empty directory once, as noted in commit d855a4b79f49 ("proc: don't (ab)use ->group_leader in proc_task_readdir() paths"). Use pid_has_task(), the helper other lockless callers use for this check. It tests the list with hlist_empty(), which reads the head with READ_ONCE(). Fixes: 13b41b09491e ("[PATCH] proc: Use struct pid not struct task_ref") Reported-by: syzbot+d608d486bd3b7062bafc@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=d608d486bd3b7062bafc Signed-off-by: Jiayi Zhang --- The syzbot report is still in moderation and has not been sent to the lists; the Closes: link shows it. Tested in QEMU with a test program that forks short-lived children while other threads stat, open and read /proc/ of those children (KCSAN report filter set to these functions): without the patch 2 of 5 instances reported the race within 10 minutes; with the patch none of 10 instances did (two of them stopped earlier with an RCU stall from the load, which also happened without the patch). The kernel was fe6ff8d5d675; fs/proc/base.c there is the same as on master. AI tools assisted with the analysis, the code and the changelog. fs/proc/base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 7685660..c40b47a 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2064,7 +2064,7 @@ out: static inline bool proc_inode_is_dead(struct inode *inode) { - return !proc_pid(inode)->tasks[PIDTYPE_PID].first; + return !pid_has_task(proc_pid(inode), PIDTYPE_PID); } int pid_delete_dentry(const struct dentry *dentry) -- 2.53.0