From nobody Sun Feb 8 21:20:42 2026 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 7CEE5645 for ; Fri, 17 Jan 2025 01:46:29 +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=1737078391; cv=none; b=MD5CYuXsaIcEHdgibzwWh804VsBeW0gP1hNlhwDClPfvo//Ki/9wuJvvAaK8nlQpBlMqyjXsDnWJewFnessRoUp2xf1ipIXpq4AhBKsxq8VeyiZaz0bKfjubsIwS1LH0O10HP1CWpLuNsZ63eYqk7qmai0/7zsOZVUey8x+I+vQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737078391; c=relaxed/simple; bh=Qu8E4nM5D2xljwGtiOSuBw/VF5aRNoLkrlTjiNlrT1w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q+xercE+zETMQ6cep18yPCLf20QSOlZgt0NubyEJymPiRVBQEjBBG9yDztjh/MU/Xqd8srz2oKQVZGrfCClxY3KFOJO+kjL6VM277THsxn/vRZmRxEr6n6+oyII9DCcL2AffhOgc5d1DIvioo6JLwW+gjUDDFit/8epw9fd6vIg= 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 50H0t6dR007482; Fri, 17 Jan 2025 01:46:24 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 443dv16cqw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 17 Jan 2025 01:46:24 +0000 (GMT) Received: from ala-exchng01.corp.ad.wrs.com (147.11.82.252) 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; Thu, 16 Jan 2025 17:46:23 -0800 Received: from pek-lpd-ccm6.wrs.com (147.11.136.210) by ala-exchng01.corp.ad.wrs.com (147.11.82.252) with Microsoft SMTP Server id 15.1.2507.43 via Frontend Transport; Thu, 16 Jan 2025 17:46:21 -0800 From: Lizhi Xu To: CC: , , , , Subject: [PATCH V2] bfs: prevent rename a target of link count is 0 Date: Fri, 17 Jan 2025 09:46:20 +0800 Message-ID: <20250117014620.2100111-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: quoted-printable X-Proofpoint-GUID: F3IGNemLq4d74xbqTlt4sILpWkCdRXOJ X-Authority-Analysis: v=2.4 cv=N5zTF39B c=1 sm=1 tr=0 ts=6789b670 cx=c_pps a=/ZJR302f846pc/tyiSlYyQ==:117 a=/ZJR302f846pc/tyiSlYyQ==:17 a=VdSt8ZQiCzkA:10 a=edf1wS77AAAA:8 a=hSkVLCK3AAAA:8 a=t7CeM3EgAAAA:8 a=kzhpyt5GazuMIt-plYoA:9 a=DcSpbTIhAlouE1Uv7lRv:22 a=cQPPKAXgyycSBL8etih5:22 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-ORIG-GUID: F3IGNemLq4d74xbqTlt4sILpWkCdRXOJ 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-16_11,2025-01-16_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=586 clxscore=1015 suspectscore=0 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 impostorscore=0 malwarescore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.21.0-2411120000 definitions=main-2501170011 Content-Type: text/plain; charset="utf-8" syzbot reported a warning in drop_nlink. [1] 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 operati= on, 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, if the number of hard links to the target is 0 then quit renaming. [1] WARNING: CPU: 0 PID: 5819 at fs/inode.c:407 drop_nlink+0xc4/0x110 fs/inode.= c:407 Modules linked in: CPU: 0 UID: 0 PID: 5819 Comm: syz-executor232 Not tainted 6.13.0-rc5-syzkal= ler-00161-g63676eefb7a0 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Goo= gle 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 37 3b e7 ff f0 48 ff 83 70 07 00 00 = 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 8d 5b 83 ff 90 <0f> 0b 90 eb 83 4= 4 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc90003c6f950 EFLAGS: 00010293 RAX: ffffffff821c1843 RBX: 1ffff1100e5181f8 RCX: ffff8880351d9e00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff821c17c3 R09: 1ffffffff2030ad6 R10: dffffc0000000000 R11: fffffbfff2030ad7 R12: ffff8880728c0fc0 R13: dffffc0000000000 R14: ffff8880728c0f78 R15: dffffc0000000000 FS: 0000555562096380(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000558ecae7b0d8 CR3: 0000000012a66000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: inode_dec_link_count include/linux/fs.h:2521 [inline] bfs_rename+0x44e/0x530 fs/bfs/dir.c:247 vfs_rename+0xbdb/0xf00 fs/namei.c:5067 do_renameat2+0xd94/0x13f0 fs/namei.c:5224 __do_sys_rename fs/namei.c:5271 [inline] __se_sys_rename fs/namei.c:5269 [inline] __x64_sys_rename+0x82/0x90 fs/namei.c:5269 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83 Reported-by: syzbot+80e60df48923e1b7691d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D80e60df48923e1b7691d Signed-off-by: Lizhi Xu --- V1 -> V2: if the number of hard links to the target is 0 then quit renaming fs/bfs/dir.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c index c375e22c4c0c..c78272a5bc60 100644 --- a/fs/bfs/dir.c +++ b/fs/bfs/dir.c @@ -227,6 +227,12 @@ static int bfs_rename(struct mnt_idmap *idmap, struct = inode *old_dir, =20 error =3D -EPERM; new_inode =3D d_inode(new_dentry); + if (new_inode) { + if (new_inode->i_nlink < 1) { + error =3D -EUCLEAN; + goto end_rename; + } + } new_bh =3D bfs_find_entry(new_dir, &new_dentry->d_name, &new_de); =20 if (new_bh && !new_inode) { --=20 2.43.0