From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E881326F46F; Wed, 25 Feb 2026 01:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771984034; cv=none; b=GfFwCOvStRz+QzMHzn3Z5yk+Xjpc5UOAOWNEkhwVv2IyfIYvcE1dggZKDy6jF8OC5sPbvUGZaGyM04Gy+PHV5SQhjIB5Vwg6kUh5WELxyx/26s6nCI0uJoxTpnp7pyowLvljl5qMsVw8kEIWIJW3ozu7fxmNeF2u6kwZR8lWmDM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771984034; c=relaxed/simple; bh=06s5Xt0CIRQWyDplGp/RqcJFIGCsrkYrYz5Li5ap8Jg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UrPaukFKHcfUaV/BNX2hfszys+xLJ7lpW2CPg2MVJszrQK0SgVTno0tCp4/L7Lsvt9Hfy51bVi1IKcqOmvlTzqySzCZUpkgrh/jZ+bu60wuf7/IZUNfQYOK7K1fjot2UZW3LLQM7yB/TYH19j6kmZuiAXkPjp041NIH7dpLcDso= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LV+xroU3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LV+xroU3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4DE0C116D0; Wed, 25 Feb 2026 01:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1771984033; bh=06s5Xt0CIRQWyDplGp/RqcJFIGCsrkYrYz5Li5ap8Jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LV+xroU3Da0bswnkOoUy+1LTILy5nykjMNEbEn14y9fNgw/+vcsRRcC6TRxcS6vgJ /gudn9L9MtdaUpeBWrM1xGsfnZPvhL/NoMZSVMGtTJXDzloxjSSpmaWOWsfmnE7F5k Am1d8I8N+5qdgHdeSnxvQbWrZ+X+XhYfwlRjt2jE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhiyu Zhang , OGAWA Hirofumi , Al Viro , Christian Brauner , Jan Kara , Andrew Morton , Sasha Levin Subject: [PATCH 6.18 277/641] fat: avoid parent link count underflow in rmdir Date: Tue, 24 Feb 2026 17:20:03 -0800 Message-ID: <20260225012355.500158732@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260225012348.915798704@linuxfoundation.org> References: <20260225012348.915798704@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhiyu Zhang [ Upstream commit 8cafcb881364af5ef3a8b9fed4db254054033d8a ] Corrupted FAT images can leave a directory inode with an incorrect i_nlink (e.g. 2 even though subdirectories exist). rmdir then unconditionally calls drop_nlink(dir) and can drive i_nlink to 0, triggering the WARN_ON in drop_nlink(). Add a sanity check in vfat_rmdir() and msdos_rmdir(): only drop the parent link count when it is at least 3, otherwise report a filesystem error. Link: https://lkml.kernel.org/r/20260101111148.1437-1-zhiyuzhang999@gmail.com Fixes: 9a53c3a783c2 ("[PATCH] r/o bind mounts: unlink: monitor i_nlink") Signed-off-by: Zhiyu Zhang Reported-by: Zhiyu Zhang Closes: https://lore.kernel.org/linux-fsdevel/aVN06OKsKxZe6-Kv@casper.infradead.org/T/#t Tested-by: Zhiyu Zhang Acked-by: OGAWA Hirofumi Cc: Al Viro Cc: Christian Brauner Cc: Jan Kara Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- fs/fat/namei_msdos.c | 7 ++++++- fs/fat/namei_vfat.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index 0b920ee40a7f9..262ec1b790b56 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -325,7 +325,12 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry) err = fat_remove_entries(dir, &sinfo); /* and releases bh */ if (err) goto out; - drop_nlink(dir); + if (dir->i_nlink >= 3) + drop_nlink(dir); + else { + fat_fs_error(sb, "parent dir link count too low (%u)", + dir->i_nlink); + } clear_nlink(inode); fat_truncate_time(inode, NULL, S_CTIME); diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 5dbc4cbb8fce3..47ff083cfc7e6 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -803,7 +803,12 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry) err = fat_remove_entries(dir, &sinfo); /* and releases bh */ if (err) goto out; - drop_nlink(dir); + if (dir->i_nlink >= 3) + drop_nlink(dir); + else { + fat_fs_error(sb, "parent dir link count too low (%u)", + dir->i_nlink); + } clear_nlink(inode); fat_truncate_time(inode, NULL, S_ATIME|S_MTIME); -- 2.51.0