linux/fs/fat
Zhiyu Zhang 17866f8a08 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-02-26 14:59:18 -08:00
..
.kunitconfig fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
cache.c mm, slab: remove last vestiges of SLAB_MEM_SPREAD 2024-03-12 20:32:19 -07:00
dir.c vfat: remove unused variable 2025-09-13 17:32:47 -07:00
fat.h fat: Convert to new mount api 2024-07-03 10:48:59 +02:00
fat_test.c fs: fat: add missing MODULE_DESCRIPTION() macros 2024-05-28 12:06:55 +02:00
fatent.c fs: fat: Prevent fsfuzzer from dominating the console 2025-07-09 22:57:55 -07:00
file.c fs: convert simple use of generic_file_*_mmap() to .mmap_prepare() 2025-06-17 13:47:45 +02:00
inode.c vfat: fix missing sb_min_blocksize() return value checks 2025-11-05 14:00:16 +01:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile fat: Add KUnit tests for checksums and timestamps 2021-08-13 13:13:18 -06:00
misc.c fat: fix too many log in fat_chain_add() 2025-08-02 12:01:40 -07:00
namei_msdos.c fat: avoid parent link count underflow in rmdir 2026-02-26 14:59:18 -08:00
namei_vfat.c fat: avoid parent link count underflow in rmdir 2026-02-26 14:59:18 -08:00
nfs.c fat: fix uninitialized field in nostale filehandles 2024-02-22 15:38:55 -08:00