linux-stable/fs/nilfs2
Edward Adam Davis ef942d2336 nilfs2: prevent use of deleted inode
commit 901ce9705f upstream.

syzbot reported a WARNING in nilfs_rmdir. [1]

Because the inode bitmap is corrupted, an inode with an inode number that
should exist as a ".nilfs" file was reassigned by nilfs_mkdir for "file0",
causing an inode duplication during execution.  And this causes an
underflow of i_nlink in rmdir operations.

The inode is used twice by the same task to unmount and remove directories
".nilfs" and "file0", it trigger warning in nilfs_rmdir.

Avoid to this issue, check i_nlink in nilfs_iget(), if it is 0, it means
that this inode has been deleted, and iput is executed to reclaim it.

[1]
WARNING: CPU: 1 PID: 5824 at fs/inode.c:407 drop_nlink+0xc4/0x110 fs/inode.c:407
...
Call Trace:
 <TASK>
 nilfs_rmdir+0x1b0/0x250 fs/nilfs2/namei.c:342
 vfs_rmdir+0x3a3/0x510 fs/namei.c:4394
 do_rmdir+0x3b5/0x580 fs/namei.c:4453
 __do_sys_rmdir fs/namei.c:4472 [inline]
 __se_sys_rmdir fs/namei.c:4470 [inline]
 __x64_sys_rmdir+0x47/0x50 fs/namei.c:4470
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Link: https://lkml.kernel.org/r/20241209065759.6781-1-konishi.ryusuke@gmail.com
Fixes: d25006523d ("nilfs2: pathname operations")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+9260555647a5132edd48@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9260555647a5132edd48
Tested-by: syzbot+9260555647a5132edd48@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-12-27 13:53:01 +01:00
..
alloc.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-11 12:47:19 +02:00
alloc.h nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-11 12:47:19 +02:00
bmap.c nilfs2: fix infinite loop in nilfs_mdt_get_block() 2023-05-11 23:03:39 +09:00
bmap.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
btnode.c nilfs2: fix buffer head leaks in calls to truncate_inode_pages() 2024-12-27 13:53:00 +01:00
btnode.h fs/nilfs2: Use the enum req_op and blk_opf_t types 2022-07-14 12:14:33 -06:00
btree.c nilfs2: fix potential oob read in nilfs_btree_check_delete() 2024-10-17 15:21:00 +02:00
btree.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
cpfile.c nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
cpfile.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
dat.c nilfs2: prevent WARNING in nilfs_dat_commit_end() 2024-08-29 17:30:16 +02:00
dat.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
dir.c nilfs2: fix potential out-of-bounds memory access in nilfs_find_entry() 2024-12-14 19:54:34 +01:00
direct.c nilfs2: initialize "struct nilfs_binfo_dat"->bi_pad field 2024-08-29 17:30:17 +02:00
direct.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
export.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
file.c nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() 2024-02-23 09:12:44 +01:00
gcinode.c nilfs2: fix buffer head leaks in calls to truncate_inode_pages() 2024-12-27 13:53:00 +01:00
ifile.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-11 12:47:19 +02:00
ifile.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
inode.c nilfs2: prevent use of deleted inode 2024-12-27 13:53:01 +01:00
ioctl.c nilfs2: fix out-of-range warning 2024-06-12 11:03:04 +02:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mdt.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-11-22 15:37:31 +01:00
mdt.h nilfs2: fix lockdep warnings during disk space reclamation 2022-04-01 11:46:09 -07:00
namei.c nilfs2: prevent use of deleted inode 2024-12-27 13:53:01 +01:00
nilfs.h nilfs2: fix buffer head leaks in calls to truncate_inode_pages() 2024-12-27 13:53:00 +01:00
page.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-11-22 15:37:31 +01:00
page.h nilfs2: get rid of nilfs_mapping_init() 2022-04-01 11:46:09 -07:00
recovery.c nilfs2: fix missing cleanup on rollforward recovery error 2024-09-12 11:10:18 +02:00
segbuf.c nilfs2: fix buffer corruption due to concurrent device reads 2023-06-28 11:12:22 +02:00
segbuf.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
segment.c nilfs2: fix state management in error path of log writing function 2024-09-12 11:10:19 +02:00
segment.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
sufile.c nilfs2: prevent WARNING in nilfs_sufile_set_segment_usage() 2023-12-13 18:39:19 +01:00
sufile.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
super.c nilfs2: fix buffer corruption due to concurrent device reads 2023-06-28 11:12:22 +02:00
sysfs.c nilfs2: protect references to superblock parameters exposed in sysfs 2024-09-12 11:10:18 +02:00
sysfs.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
the_nilfs.c nilfs2: fix inode number range checks 2024-07-11 12:47:13 +02:00
the_nilfs.h nilfs2: fix inode number range checks 2024-07-11 12:47:13 +02:00