From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) (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 8A7CD204C29 for ; Thu, 9 Jan 2025 07:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.178.238 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736408402; cv=none; b=MKqIm5LTVAo6WVqAvUNuvG40xkdrRnJQwYOJnsqX/NXO5emoCGzMld4UROY9J6iDN+UDm5E2GbZr5/rqOx2/9CDWc9MR4FotsSiemhHxX2rq+MDR0jUSy4UKfaE0ZZQXLZcKBNwlL96TkTC1KfbPegrrUTRfMpbIlaukYhCUQhA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736408402; c=relaxed/simple; bh=QZkBsV5yUAmqoGhbQd9/47oxhcex3nrtDCYQYA8KqiU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cGE2IUGAZgUZrv2lZPJThkaiOvaQdqZQkUqRaA/tf6C6mDNlUgVtJwzi/Ol9JiXaECsDL2lgs2XPN4fOHN9HVpiKztwhbEf1vDP2oCto0MhoopyK5kt18Mt/rxhEUxqtZfvZVyLRYYUIyyZInbLrVX0s2bRxIZjBnynEmjyzqh0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com; spf=pass smtp.mailfrom=windriver.com; arc=none smtp.client-ip=205.220.178.238 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=windriver.com Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5096dnKq031899; Thu, 9 Jan 2025 07:39:54 GMT Received: from ala-exchng01.corp.ad.wrs.com (ala-exchng01.wrs.com [147.11.82.252]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 441fv3sfm4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 09 Jan 2025 07:39:54 +0000 (GMT) Received: from ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) by ala-exchng01.corp.ad.wrs.com (147.11.82.252) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.43; Wed, 8 Jan 2025 23:39:53 -0800 Received: from pek-lpd-ccm6.wrs.com (147.11.136.210) by ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) with Microsoft SMTP Server id 15.1.2507.43 via Frontend Transport; Wed, 8 Jan 2025 23:39:51 -0800 From: Lizhi Xu To: CC: , , , , Subject: Re: [PATCH] bfs: put a inode if link count is 0 Date: Thu, 9 Jan 2025 15:39:50 +0800 Message-ID: <20250109073950.2142484-1-lizhi.xu@windriver.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250109073228.GR1977892@ZenIV> References: <20250109073228.GR1977892@ZenIV> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: 6EMuOTZLElyxlipw6rL9drSx0Y3pnakE X-Authority-Analysis: v=2.4 cv=NIUv+16g c=1 sm=1 tr=0 ts=677f7d4a cx=c_pps a=/ZJR302f846pc/tyiSlYyQ==:117 a=/ZJR302f846pc/tyiSlYyQ==:17 a=VdSt8ZQiCzkA:10 a=7FwhLeI6WjRnNbgii6EA:9 X-Proofpoint-ORIG-GUID: 6EMuOTZLElyxlipw6rL9drSx0Y3pnakE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-09_03,2025-01-09_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 mlxscore=0 clxscore=1015 malwarescore=0 mlxlogscore=947 phishscore=0 adultscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.21.0-2411120000 definitions=main-2501090062 On Thu, 9 Jan 2025 07:32:28 +0000, Al Viro wrote: > > On Thu, 9 Jan 2025 06:22:16 +0000, Al Viro wrote: > > > > The reproducer performs the rename operation on the file twice in succession > > > > and changes the file to the same file name. After the first rename operation, > > > > the number of links in the inode is set to 0. In the second execution, the > > > > same inode is used, resulting in a 0 value warning for i_nlink. > > > > > > > > To avoid this issue, put the target inode before exiting the bfs_rename. > > > > > > This is completely insane - you get an extra drop of in-core inode > > > refcount, which *will* end up with dangling pointer and memory corruption. > > > Besides, there is a perfectly legitimate case when you open a file and > > > rename something on top of it. It MUST remain open and alive until the > > > last in-core reference to inode goes away, which must not happen before > > > close(). > > In the reproducer, changes the file to the same file, the same file name is > > "file0", file0 uses mknod to create its inode and sets the i_nlink value to 1. > > There is no operation to open file0 in the reproducer. Is this situation also > > as you said? > > I'm not sure I understand your sentence, to be honest. > > Your patch is 100% wrong - you must *not*, under any circumstances, have > ->rename() drop references to in-core struct inode instances. It's *always* > wrong; the reference to new_inode in new_dentry->d_inode remains there (as > it ought to) and its contribution to new_inode refcount remains unchanged. > It has nothing to do with ->i_nlink; you are decrementing ->i_count, which > controls the lifetime of in-core struct inode instance. As soon as that > reaches zero, struct inode instance will be freed. And destructor of > new_dentry *will* call iput() on its ->d_inode, so you'll end up with > attempt to decrement refcount of already freed memory object. > > Again, that has nothing to do with ->i_nlink. I'm not familiar with > bfs layout, so I can't tell what's going on with the corrupted image syzbot > are messing with just by visual examination. Is there, by any chance, > a preexisting file0 in the root of that bfs image? Does mknod() succeed > there? Because if it doesn't and what you have is a buggered image with > 'file0' being there having zero link count, yes, renaming over it would > trigger warnings about detected corrupted filesystem - we are trying to > remove a link (on disk) to something that claims (on disk) to have 0 links > at the time of that operation; something is clearly wrong and deserves > a warning. > > Again, that iput() in there is basically introducing random memory > corruption; it might make the warning go away, but it's not a fix. I also have deep doubts about using iput in rename. Thanks for your analysis. Lizhi