linux/fs/fat
Zhiyu Zhang 955c5d670b 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:20:05 -05: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 fs: add kernel-doc comments to fat_parse_long() 2024-04-25 21:07:02 -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 fat: add ratelimit to fat*_ent_bread() 2022-04-29 14:38:02 -07:00
file.c fs: pass the request_mask to generic_fillattr 2023-08-09 08:56:36 +02:00
inode.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04: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: convert to new timestamp accessors 2023-10-18 14:08:03 +02:00
namei_msdos.c fat: avoid parent link count underflow in rmdir 2026-03-04 07:20:05 -05:00
namei_vfat.c fat: avoid parent link count underflow in rmdir 2026-03-04 07:20:05 -05:00
nfs.c fat: fix uninitialized field in nostale filehandles 2024-02-22 15:38:55 -08:00