linux/fs/fat
Zhiyu Zhang 9894c79fd9 fat: avoid parent link count underflow in rmdir
[ Upstream commit 8cafcb8813 ]

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: 9a53c3a783 ("[PATCH] r/o bind mounts: unlink: monitor i_nlink")
Signed-off-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
Reported-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
Closes: https://lore.kernel.org/linux-fsdevel/aVN06OKsKxZe6-Kv@casper.infradead.org/T/#t
Tested-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-03-04 07:19:35 -05:00
..
.kunitconfig fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
cache.c fat: new inline functions to determine the FAT variant (32, 16 or 12) 2019-01-04 13:13:47 -08:00
dir.c treewide: Remove uninitialized_var() usage 2020-07-16 12:35:15 -07:00
fat.h fs: make helpers idmap mount aware 2021-01-24 14:27:20 +01:00
fat_test.c fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
fatent.c fat: add ratelimit to fat*_ent_bread() 2022-06-09 10:22:42 +02:00
file.c idmapped-mounts-v5.12 2021-02-23 13:39:45 -08:00
inode.c mm: require ->set_page_dirty to be explicitly wired up 2021-06-29 10:53:48 -07:00
Kconfig fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
Makefile fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
misc.c fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
namei_msdos.c fat: avoid parent link count underflow in rmdir 2026-03-04 07:19:35 -05:00
namei_vfat.c fat: avoid parent link count underflow in rmdir 2026-03-04 07:19:35 -05:00
nfs.c fat: fix uninitialized field in nostale filehandles 2024-04-10 16:18:35 +02:00