nilfs2: fix incorrect inode allocation from reserved inodes
authorRyusuke Konishi <konishi.ryusuke@gmail.com>
Sun, 23 Jun 2024 05:11:35 +0000 (14:11 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 3 Jul 2024 19:29:25 +0000 (12:29 -0700)
commit93aef9eda1cea9e84ab2453fcceb8addad0e46f1
tree9b8e14b48c8682532bba708815e960154c14c63d
parentbb76c6c274683c8570ad788f79d4b875bde0e458
nilfs2: fix incorrect inode allocation from reserved inodes

If the bitmap block that manages the inode allocation status is corrupted,
nilfs_ifile_create_inode() may allocate a new inode from the reserved
inode area where it should not be allocated.

Previous fix commit d325dc6eb763 ("nilfs2: fix use-after-free bug of
struct nilfs_root"), fixed the problem that reserved inodes with inode
numbers less than NILFS_USER_INO (=11) were incorrectly reallocated due to
bitmap corruption, but since the start number of non-reserved inodes is
read from the super block and may change, in which case inode allocation
may occur from the extended reserved inode area.

If that happens, access to that inode will cause an IO error, causing the
file system to degrade to an error state.

Fix this potential issue by adding a wraparound option to the common
metadata object allocation routine and by modifying
nilfs_ifile_create_inode() to disable the option so that it only allocates
inodes with inode numbers greater than or equal to the inode number read
in "nilfs->ns_first_ino", regardless of the bitmap status of reserved
inodes.

Link: https://lkml.kernel.org/r/20240623051135.4180-4-konishi.ryusuke@gmail.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: Hillf Danton <hdanton@sina.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/nilfs2/alloc.c
fs/nilfs2/alloc.h
fs/nilfs2/dat.c
fs/nilfs2/ifile.c