android_kernel_xiaomi_sm8350/fs/nilfs2
Edward Adam Davis 55e4baa0d3 nilfs2: prevent use of deleted inode
commit 901ce9705fbb9f330ff1f19600e5daf9770b0175 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>
2025-01-09 13:23:29 +01:00
..
alloc.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 11:40:52 +02:00
alloc.h nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 11:40:52 +02:00
bmap.c nilfs2: fix infinite loop in nilfs_mdt_get_block() 2023-05-17 11:35:54 +02:00
bmap.h
btnode.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-12-14 19:44:19 +01:00
btnode.h
btree.c nilfs2: fix potential oob read in nilfs_btree_check_delete() 2024-11-08 16:20:31 +01:00
btree.h
cpfile.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
cpfile.h
dat.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 11:40:52 +02:00
dat.h
dir.c nilfs2: fix potential out-of-bounds memory access in nilfs_find_entry() 2024-12-14 19:44:49 +01:00
direct.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
direct.h
export.h
file.c nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() 2024-02-23 08:25:12 +01:00
gcinode.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-12-14 19:44:19 +01:00
ifile.c nilfs2: fix incorrect inode allocation from reserved inodes 2024-07-18 11:40:52 +02:00
ifile.h
inode.c nilfs2: prevent use of deleted inode 2025-01-09 13:23:29 +01:00
ioctl.c nilfs2: fix out-of-range warning 2024-06-16 13:28:32 +02:00
Kconfig
Makefile
mdt.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-12-14 19:44:19 +01:00
mdt.h
namei.c nilfs2: prevent use of deleted inode 2025-01-09 13:23:29 +01:00
nilfs.h nilfs2: propagate directory read errors from nilfs_find_entry() 2024-11-08 16:20:49 +01:00
page.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-12-14 19:44:19 +01:00
page.h
recovery.c nilfs2: fix missing cleanup on rollforward recovery error 2024-09-12 11:03:51 +02:00
segbuf.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
segbuf.h
segment.c nilfs2: fix state management in error path of log writing function 2024-09-12 11:03:51 +02:00
segment.h
sufile.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
sufile.h
super.c nilfs2: use a more common logging style 2024-04-13 12:51:27 +02:00
sysfs.c nilfs2: protect references to superblock parameters exposed in sysfs 2024-09-12 11:03:56 +02:00
sysfs.h
the_nilfs.c nilfs2: fix inode number range checks 2024-07-18 11:40:51 +02:00
the_nilfs.h nilfs2: fix inode number range checks 2024-07-18 11:40:51 +02:00