WARNING in nilfs_rmdir
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: bf9aa14fc523 Merge tag 'timers-core-2024-11-18' of git://g.. git tree: upstream console+strace: https://syzkaller.appspot.com/x/log.txt?x=1093c6c0580000 kernel config: https://syzkaller.appspot.com/x/.config?x=ccd6152c3e2378ce dashboard link: https://syzkaller.appspot.com/bug?extid=9260555647a5132edd48 compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1497e930580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15f0bae8580000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/f7f38a2c24fc/disk-bf9aa14f.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/9fe13f1c9a0f/vmlinux-bf9aa14f.xz
kernel image: https://storage.googleapis.com/syzbot-assets/04d354ff9f6b/bzImage-bf9aa14f.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/1605c6d5cd44/mount_0.gz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
NILFS (loop0): deleting nonexistent file (ino=11), 0
------------[ cut here ]------------ WARNING: CPU: 1 PID: 5833 at fs/inode.c:407 drop_nlink+0xc4/0x110 fs/inode.c:407 Modules linked in: CPU: 1 UID: 0 PID: 5833 Comm: syz-executor181 Not tainted 6.12.0-syzkaller-01782-gbf9aa14fc523 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/30/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 07 df e5 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 6d f4 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc90003e97c70 EFLAGS: 00010293 RAX: ffffffff8215f523 RBX: 1ffff1100ef7b1cc RCX: ffff888030afbc00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff8215f4a3 R09: 1ffff1100fb87cee R10: dffffc0000000000 R11: ffffed100fb87cef R12: ffff888077bd8e60 R13: 1ffff1100ef7b030 R14: ffff888077bd8e18 R15: dffffc0000000000 FS: 0000555584ff0480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000000045bdd0 CR3: 0000000074070000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 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 RIP: 0033:0x7febf80a8507 Code: 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 b8 54 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffc733beac8 EFLAGS: 00000207 ORIG_RAX: 0000000000000054 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007febf80a8507 RDX: 0000000000008790 RSI: 0000000000000000 RDI: 00007ffc733bfc70 RBP: 0000000000000065 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000001000 R11: 0000000000000207 R12: 00007ffc733bfc70 R13: 0000555585001840 R14: 431bde82d7b634db R15: 00007ffc733c1df0 </TASK>
---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
#syz test: https://github.com/ea1davis/linux nilfs/syz_0163
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 89e182ea nilfs2: Preventing dirty inode git tree: https://github.com/ea1davis/linux nilfs/syz_0163 console output: https://syzkaller.appspot.com/x/log.txt?x=1035840f980000 kernel config: https://syzkaller.appspot.com/x/.config?x=35f1fa828fe386c2 dashboard link: https://syzkaller.appspot.com/bug?extid=9260555647a5132edd48 compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
Note: no patches were applied.
Note: testing is done by a robot and is best-effort only.
#syz test: https://github.com/ea1davis/linux nilfs/syz_0163_v2
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue: lost connection to test machine
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
lost connection to test machine
Tested on:
commit: 7a22f39b nilfs2: replace drop with clear for nlink git tree: https://github.com/ea1davis/linux nilfs/syz_0163_v2 console output: https://syzkaller.appspot.com/x/log.txt?x=1629a330580000 kernel config: https://syzkaller.appspot.com/x/.config?x=35f1fa828fe386c2 dashboard link: https://syzkaller.appspot.com/bug?extid=9260555647a5132edd48 compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
Note: no patches were applied.
#syz test: https://github.com/ea1davis/linux nilfs/syz_0163_v3
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 22aa0501 nilfs2: drop the inode which has been removed git tree: https://github.com/ea1davis/linux nilfs/syz_0163_v3 console output: https://syzkaller.appspot.com/x/log.txt?x=13a68020580000 kernel config: https://syzkaller.appspot.com/x/.config?x=35f1fa828fe386c2 dashboard link: https://syzkaller.appspot.com/bug?extid=9260555647a5132edd48 compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
Note: no patches were applied.
Note: testing is done by a robot and is best-effort only.
PATCH 1/1 nilfs2: drop the inode which has been removed
In reply to syzbotsyzbot reported a WARNING in nilfs_rmdir. [1]
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_size and i_nlink in nilfs_iget(), if they are both 0, it means that this inode has been removed, 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 Modules linked in: CPU: 1 UID: 0 PID: 5824 Comm: syz-executor223 Not tainted 6.12.0-syzkaller-12113-gbcc8eda6d349 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 57 0b e6 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 9d 4c 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc900037f7c70 EFLAGS: 00010293 RAX: ffffffff822124a3 RBX: 1ffff1100e7ae034 RCX: ffff88807cf53c00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff82212423 R09: 1ffff1100f8ba8ee R10: dffffc0000000000 R11: ffffed100f8ba8ef R12: ffff888073d701a0 R13: 1ffff1100e79f5c4 R14: ffff888073d70158 R15: dffffc0000000000 FS: 0000555558d1e480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555558d37878 CR3: 000000007d920000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 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
--- fs/nilfs2/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/nilfs2/inode.c +8 -1
@@ -544,8 +544,15 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_size && !inode->i_nlink) { +make_bad_inode (inode); +iput (inode); +return ERR_PTR (-EIO ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) {
Signature · 1 line
2.47.0
Ryusuke Konishi
maintainerRe: [PATCH] nilfs2: drop the inode which has been removed
Quoted 69 lines · Edward Adam Davis
syzbot reported a WARNING in
nilfs_rmdir. [1]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_sizeandi_nlinkinnilfs_iget(), if they are both 0, it means that this inode has been removed, 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 Modules linked in: CPU: 1 UID: 0 PID: 5824 Comm: syz-executor223 Not tainted 6.12.0-syzkaller-12113-gbcc8eda6d349 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 57 0b e6 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 9d 4c 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc900037f7c70 EFLAGS: 00010293 RAX: ffffffff822124a3 RBX: 1ffff1100e7ae034 RCX: ffff88807cf53c00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff82212423 R09: 1ffff1100f8ba8ee R10: dffffc0000000000 R11: ffffed100f8ba8ef R12: ffff888073d701a0 R13: 1ffff1100e79f5c4 R14: ffff888073d70158 R15: dffffc0000000000 FS: 0000555558d1e480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555558d37878 CR3: 000000007d920000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 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/0x7fReported-and-tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- fs/nilfs2/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)fs/nilfs2/inode.c +8
-2@@ -544,8 +544,15 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_size && !inode->i_nlink) { +make_bad_inode (inode); +iput (inode); +return ERR_PTR (-EIO ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) { --
Quoted 1 line
2.47.0
Thank you Edward.
This fix seems good except for the i_size check, but I think we need to look into what's going on a bit more.
I was unable to work for a while due to machine trouble, so I'd like to know if you have made any progress on your investigation.
First, is this caused by a corrupted filesystem image? Or is it that the directories or files with the same inode number were generated during the namespace operations (due to a timing issue or something), and could this problem occur even if the original filesystem image is normal?
When I mounted the mount_0 image as read-only, the filesystem looked normal without such inode duplication.
At least, nilfs_read_inode_common(), which reads inodes from block devices, is implemented to return an error with -ESTALE if i_nlink ==
0. So it seems that nilfs_iget() picked up this inode with i_nlilnk == 0 because it hit an inode being deleted in the inode cache. Why is that happening?
Also, why do you put the i_size check as an AND condition? i_size is independent of i_nlink and the inode lifecycles. If i_size is also broken, this check will not work properly.
If something is not working and you have included it as a workaround, I would like to know about it.
Thanks,
Ryusuke Konishi
Re: [PATCH] nilfs2: drop the inode which has been removed
Quoted 75 lines · Ryusuke Konishi
Quoted 68 lines
syzbot reported a WARNING in
nilfs_rmdir. [1]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_sizeandi_nlinkinnilfs_iget(), if they are both 0, it means that this inode has been removed, 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 Modules linked in: CPU: 1 UID: 0 PID: 5824 Comm: syz-executor223 Not tainted 6.12.0-syzkaller-12113-gbcc8eda6d349 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 57 0b e6 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 9d 4c 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc900037f7c70 EFLAGS: 00010293 RAX: ffffffff822124a3 RBX: 1ffff1100e7ae034 RCX: ffff88807cf53c00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff82212423 R09: 1ffff1100f8ba8ee R10: dffffc0000000000 R11: ffffed100f8ba8ef R12: ffff888073d701a0 R13: 1ffff1100e79f5c4 R14: ffff888073d70158 R15: dffffc0000000000 FS: 0000555558d1e480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555558d37878 CR3: 000000007d920000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 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/0x7fReported-and-tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- fs/nilfs2/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)fs/nilfs2/inode.c +8
-2@@ -544,8 +544,15 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_size && !inode->i_nlink) { +make_bad_inode (inode); +iput (inode); +return ERR_PTR (-EIO ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) { --Quoted 1 line
2.47.0
Thank you Edward.
This fix seems good except for the
i_sizecheck, but I think we need to look into what's going on a bit more.
Quoted 8 lines
I was unable to work for a while due to machine trouble, so I'd like to know if you have made any progress on your investigation.
First, is this caused by a corrupted filesystem image? Or is it that the directories or files with the same inode number were generated during the namespace operations (due to a timing issue or something), and could this problem occur even if the original filesystem image is normal?
According to the log when I reproduced the problem, I analyzed that the problem occurred like this:
CPU0 CPU1
==== ====
nilfs_mkdir // file0
nilfs_new_inode // ino is 11
mount // mount file0
umount // .nilfs, ino is 11
nilfs_rmdir // ino is 11, i_size = 0, i_nlink = 0
umount // file0, ino is 11
nilfs_rmdir // ino 11, i_size = 0, i_nlink = 0, trigger warning
Quoted 9 lines
When I mounted the
mount_0image as read-only, the filesystem looked normal without such inode duplication.At least,
nilfs_read_inode_common(), which reads inodes from block devices, is implemented to return an error with-ESTALEifi_nlink==
0. So it seems thatnilfs_iget()picked up this inode withi_nlilnk== 0 because it hit an inode being deleted in the inode cache. Why is that happening?
Are you talking about the following call trace?
If so, then because the value of inode->i_state is I_DIRTY (set in nilfs_mkdir) it will not enter __nilfs_read_inode().
nilfs_iget()->
__nilfs_read_inode()->
nilfs_read_inode_common()
Quoted 2 lines
Also, why do you put the
i_sizecheck as an AND condition?
i_size will set to 0 in nilfs_rmdir(), so check it too.
Quoted 4 lines
i_sizeis independent ofi_nlinkand the inode lifecycles. Ifi_sizeis also broken, this check will not work properly.
If something is not working and you have included it as a workaround, I would like to know about it.
BR,
Edward
Ryusuke Konishi
maintainerRe: [PATCH] nilfs2: drop the inode which has been removed
Quoted 88 lines · Edward Adam Davis
Quoted 75 lines · Ryusuke Konishi
Quoted 68 lines
syzbot reported a WARNING in
nilfs_rmdir. [1]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_sizeandi_nlinkinnilfs_iget(), if they are both 0, it means that this inode has been removed, 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 Modules linked in: CPU: 1 UID: 0 PID: 5824 Comm: syz-executor223 Not tainted 6.12.0-syzkaller-12113-gbcc8eda6d349 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 57 0b e6 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 9d 4c 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc900037f7c70 EFLAGS: 00010293 RAX: ffffffff822124a3 RBX: 1ffff1100e7ae034 RCX: ffff88807cf53c00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff82212423 R09: 1ffff1100f8ba8ee R10: dffffc0000000000 R11: ffffed100f8ba8ef R12: ffff888073d701a0 R13: 1ffff1100e79f5c4 R14: ffff888073d70158 R15: dffffc0000000000 FS: 0000555558d1e480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555558d37878 CR3: 000000007d920000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 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/0x7fReported-and-tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- fs/nilfs2/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)fs/nilfs2/inode.c +8
-2@@ -544,8 +544,15 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_size && !inode->i_nlink) { +make_bad_inode (inode); +iput (inode); +return ERR_PTR (-EIO ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) { --Quoted 1 line
2.47.0
Thank you Edward.
This fix seems good except for the
i_sizecheck, but I think we need to look into what's going on a bit more.Quoted 8 lines
I was unable to work for a while due to machine trouble, so I'd like to know if you have made any progress on your investigation.
First, is this caused by a corrupted filesystem image? Or is it that the directories or files with the same inode number were generated during the namespace operations (due to a timing issue or something), and could this problem occur even if the original filesystem image is normal?
According to the log when I reproduced the problem, I analyzed that the problem occurred like this:
Quoted 10 lines
CPU0 CPU1
==== ====
nilfs_mkdir// file0
nilfs_new_inode// ino is 11
mount // mount file0
umount // .nilfs, ino is 11
nilfs_rmdir// ino is 11,i_size= 0,i_nlink= 0
umount // file0, ino is 11
nilfs_rmdir// ino 11,i_size= 0,i_nlink= 0, trigger warning
Thank you for explaining the situation. I understand what's going on.
In the end, going back to my question, this is caused by file system corruption. 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.
After considering the issue, I came to the conclusion that although there is an approach that strengthens checks for bitmap inconsistencies and inode type inconsistencies to detect errors in advance, these approaches are difficult to fundamentally solve.
This is caused by a corrupted inode bitmap, but checking is difficult in the first place when there are multiple directories with the same inode number in the name space.
Therefore, the appropriate solution is to either check for i_nlink underflow during rmdir, or to detect i_nlink == 0 in the call path of nilfs_lookup() --> nilfs_iget(), and I think the latter approach is better, as you have chosen.
Quoted 9 lines
Quoted 9 lines
When I mounted the
mount_0image as read-only, the filesystem looked normal without such inode duplication.At least,
nilfs_read_inode_common(), which reads inodes from block devices, is implemented to return an error with-ESTALEifi_nlink==
0. So it seems thatnilfs_iget()picked up this inode withi_nlilnk== 0 because it hit an inode being deleted in the inode cache. Why is that happening?
Quoted 7 lines
Are you talking about the following call trace?
If so, then because the value ofinode->i_stateisI_DIRTY(set innilfs_mkdir) it will not enter__nilfs_read_inode().nilfs_iget()->
__nilfs_read_inode()->
nilfs_read_inode_common()
Yes, in this case __nifls_read_inode() is not called. As mentioned above, the conclusion is that i_nlink abnormalities can occur in other FS corruption patterns such as inode bitmap corruption and directory inconsistency.
Quoted 7 lines
Quoted 2 lines
Also, why do you put the
i_sizecheck as an AND condition?
i_sizewill set to 0 innilfs_rmdir(), so check it too.Quoted 4 lines
i_sizeis independent ofi_nlinkand the inode lifecycles. Ifi_sizeis also broken, this check will not work properly.
If something is not working and you have included it as a workaround, I would like to know about it.
To fix the problem, please modify the patch as follows:
(1) In nilfs_iget(), if the inode without I_NEW obtained by nilfs_iget_locked() has i_nlink == 0, call iput() and return ERR_PTR(-ESTALE). Do not call make_bad_inode(). Also do not check for i_size == 0 (it is not a good idea to check this to identify the case of rmdir).
(2) In nilfs_lookup(), if the return value of nilfs_iget() is ERR_PTR(-ESTALE), output a message with nilfs_error() indicating that file system corruption has been detected , and returns ERR_PTR(-EIO). Please refer to ext2_lookup() for the concrete implementation.
The reason for not calling make_bad_inode() is to prevent interference from the side when i_nlink is set to 0 and nilfs_evict() is trying to delete the inode. The VFS layer guarantees that inode acquisition and evict are mutually exclusive, but it is possible to grab it before evict(), and the result of interference in that case is unpredictable. Instead, as mentioned above, I think it is safer to call nilfs_error() at the nilfs_lookup() level, where namespace operations are involved.
Also, could you please explain in the commit log that inode duplication has occurred due to file system corruption (in this case, inode bitmap corruption), and that when inode duplication occurs due to file system inconsistencies like this, a link count underflow can occur during an rmdir operation, so that a link count check is necessary at runtime?
Thank you in advance.
Ryusuke Konishi
PATCH v2 1/1 nilfs2: prevent use of deleted inode
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.
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 Modules linked in: CPU: 1 UID: 0 PID: 5824 Comm: syz-executor223 Not tainted 6.12.0-syzkaller-12113-gbcc8eda6d349 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 57 0b e6 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 9d 4c 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc900037f7c70 EFLAGS: 00010293 RAX: ffffffff822124a3 RBX: 1ffff1100e7ae034 RCX: ffff88807cf53c00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff82212423 R09: 1ffff1100f8ba8ee R10: dffffc0000000000 R11: ffffed100f8ba8ef R12: ffff888073d701a0 R13: 1ffff1100e79f5c4 R14: ffff888073d70158 R15: dffffc0000000000 FS: 0000555558d1e480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555558d37878 CR3: 000000007d920000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 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
---
V1 -> V2: Adjust the patch as suggested by Ryusuke Konishi
fs/nilfs2/inode.c | 8 +++++++- fs/nilfs2/namei.c | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
fs/nilfs2/inode.c +7 -1
@@ -544,8 +544,14 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_nlink) { +iput (inode); +return ERR_PTR (-ESTALE ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) {
fs/nilfs2/namei.c +6 -0
@@ -67,6 +67,12 @@ nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) inode =NULL ; }else { inode =nilfs_iget (dir->i_sb,NILFS_I (dir)->i_root, ino); +if (inode ==ERR_PTR (-ESTALE )) { +nilfs_error (dir->i_sb, __func__, +"deleted inode referenced: %lu" , + (unsigned long ) ino); +return ERR_PTR (-EIO ); + } }return d_splice_alias (inode, dentry);
Signature · 1 line
2.47.0
Ryusuke Konishi
maintainerRe: [PATCH V2] nilfs2: prevent use of deleted inode
Quoted 32 lines · Edward Adam Davis
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_mkdirfor "file0", causing an inode duplication during execution.
And this causes an underflow ofi_nlinkin rmdir operations.Avoid to this issue, check
i_nlinkinnilfs_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 Modules linked in: CPU: 1 UID: 0 PID: 5824 Comm: syz-executor223 Not tainted 6.12.0-syzkaller-12113-gbcc8eda6d349 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 57 0b e6 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 9d 4c 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc900037f7c70 EFLAGS: 00010293 RAX: ffffffff822124a3 RBX: 1ffff1100e7ae034 RCX: ffff88807cf53c00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff82212423 R09: 1ffff1100f8ba8ee R10: dffffc0000000000 R11: ffffed100f8ba8ef R12: ffff888073d701a0 R13: 1ffff1100e79f5c4 R14: ffff888073d70158 R15: dffffc0000000000 FS: 0000555558d1e480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555558d37878 CR3: 000000007d920000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> nilfs_rmdir+0x1b0/0x250 fs/nilfs2/namei.c:342
Quoted 9 lines
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
I'll make a few comments.
Quoted 1 line
Reported-and-tested-by [email protected]
First please separate "Reported-and-tested-by" into two tags. Although it is still seen occasionally, it causes warnings for the checkpatch script. (It has already been explicitly deprecated in some subtrees, because it just complicates automatic tag extraction.)
Quoted 34 lines
Signed-off-by Edward Adam Davis <[email protected]>---
V1 -> V2: Adjust the patch as suggested by Ryusuke Konishifs/nilfs2/inode.c | 8 +++++++- fs/nilfs2/namei.c | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)fs/nilfs2/inode.c +7
-1@@ -544,8 +544,14 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_nlink) { +iput (inode); +return ERR_PTR (-ESTALE ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) {fs/nilfs2/namei.c +0
-0
fs/nilfs2/namei.c nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) · line 74
Quoted 8 lines
fs/nilfs2/namei.c +4
-0@@ -67,6 +67,12 @@ nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) inode =NULL ; }else { inode =nilfs_iget (dir->i_sb,NILFS_I (dir)->i_root, ino); +if (inode ==ERR_PTR (-ESTALE )) { +nilfs_error (dir->i_sb, __func__, +"deleted inode referenced: %lu" , + (unsigned long ) ino);
Unlink ext2_error(), nilfs_error() does not require __func__, to be passed as an argument.nilfs_error() is a wrapper macro for the actual error output function __nilfs_error(), which hides __func__ there.
(I should have mentioned the difference, sorry.)
Another comment: "ino" is of type "ino_t", which is of type "unsigned long", so the typecast to "unsigned long" for the argument "ino" is not necessary.
I don't know why the ext2 implementation does it, but even if this patch is backported to stable trees, this typecast is not necessary.
Thanks,
Ryusuke Konishi
Quoted 8 lines
fs/nilfs2/namei.c +2
-0+return ERR_PTR (-EIO ); + } }return d_splice_alias(inode, dentry);--
2.47.0
PATCH v3 1/1 nilfs2: prevent use of deleted inode
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 Modules linked in: CPU: 1 UID: 0 PID: 5824 Comm: syz-executor223 Not tainted 6.12.0-syzkaller-12113-gbcc8eda6d349 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 57 0b e6 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 9d 4c 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc900037f7c70 EFLAGS: 00010293 RAX: ffffffff822124a3 RBX: 1ffff1100e7ae034 RCX: ffff88807cf53c00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff82212423 R09: 1ffff1100f8ba8ee R10: dffffc0000000000 R11: ffffed100f8ba8ef R12: ffff888073d701a0 R13: 1ffff1100e79f5c4 R14: ffff888073d70158 R15: dffffc0000000000 FS: 0000555558d1e480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555558d37878 CR3: 000000007d920000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 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
---
V1 -> V2: Adjust the patch as suggested by Ryusuke Konishi
V2 -> V3: Modify the input parameters of nilfs_error and split Reported-and-tested_by
fs/nilfs2/inode.c | 8 +++++++- fs/nilfs2/namei.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-)
fs/nilfs2/inode.c +7 -1
@@ -544,8 +544,14 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_nlink) { +iput (inode); +return ERR_PTR (-ESTALE ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) {
fs/nilfs2/namei.c +5 -0
@@ -67,6 +67,11 @@ nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) inode =NULL ; }else { inode =nilfs_iget (dir->i_sb,NILFS_I (dir)->i_root, ino); +if (inode ==ERR_PTR (-ESTALE )) { +nilfs_error (dir->i_sb, +"deleted inode referenced: %lu" , ino); +return ERR_PTR (-EIO ); + } }return d_splice_alias (inode, dentry);
Signature · 1 line
2.47.0
Ryusuke Konishi
maintainerRe: [PATCH V3] nilfs2: prevent use of deleted inode
Quoted 48 lines · Edward Adam Davis
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_mkdirfor "file0", causing an inode duplication during execution.
And this causes an underflow ofi_nlinkin 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_nlinkinnilfs_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 Modules linked in: CPU: 1 UID: 0 PID: 5824 Comm: syz-executor223 Not tainted 6.12.0-syzkaller-12113-gbcc8eda6d349 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:drop_nlink+0xc4/0x110 fs/inode.c:407 Code: bb 70 07 00 00 be 08 00 00 00 e8 57 0b e6 ff f0 48 ff 83 70 07 00 00 5b 41 5c 41 5e 41 5f 5d c3 cc cc cc cc e8 9d 4c 7e ff 90 <0f> 0b 90 eb 83 44 89 e1 80 e1 07 80 c1 03 38 c1 0f 8c 5c ff ff ff RSP: 0018:ffffc900037f7c70 EFLAGS: 00010293 RAX: ffffffff822124a3 RBX: 1ffff1100e7ae034 RCX: ffff88807cf53c00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: ffffffff82212423 R09: 1ffff1100f8ba8ee R10: dffffc0000000000 R11: ffffed100f8ba8ef R12: ffff888073d701a0 R13: 1ffff1100e79f5c4 R14: ffff888073d70158 R15: dffffc0000000000 FS: 0000555558d1e480(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000555558d37878 CR3: 000000007d920000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 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/0x7fReported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>
Quoted 7 lines
---
V1 -> V2: Adjust the patch as suggested by Ryusuke Konishi
V2 -> V3: Modify the input parameters ofnilfs_errorand split Reported-and-tested_byfs/nilfs2/inode.c | 8 +++++++- fs/nilfs2/namei.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-)
Thank you for your help. I'll adopt this and send it upstream after running tests that include more than just the reproducer.
Thanks,
Ryusuke Konishi
Quoted 40 lines
fs/nilfs2/inode.c +7
-1@@ -544,8 +544,14 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_nlink) { +iput (inode); +return ERR_PTR (-ESTALE ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) {fs/nilfs2/namei.c +5
-1@@ -67,6 +67,11 @@ nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) inode =NULL ; }else { inode =nilfs_iget (dir->i_sb,NILFS_I (dir)->i_root, ino); +if (inode ==ERR_PTR (-ESTALE )) { +nilfs_error (dir->i_sb, +"deleted inode referenced: %lu" , ino); +return ERR_PTR (-EIO ); + } }return d_splice_alias (inode, dentry); --2.47.0
#syz test: https://github.com/ea1davis/linux nilfs/syz_0163_v4
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 9731d37c nilfs2: prevent use of deleted inode git tree: https://github.com/ea1davis/linux nilfs/syz_0163_v4 console output: https://syzkaller.appspot.com/x/log.txt?x=10b0f330580000 kernel config: https://syzkaller.appspot.com/x/.config?x=35f1fa828fe386c2 dashboard link: https://syzkaller.appspot.com/bug?extid=9260555647a5132edd48 compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
Note: no patches were applied.
Note: testing is done by a robot and is best-effort only.
Ryusuke Konishi
maintainerPATCH 1/1 nilfs2: prevent use of deleted inode
In reply to syzbotFrom: Edward Adam Davis <[email protected]>
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
---
Hi Andrew, please apply this as a bug fix.
This prevents the link count underflow that can occur when deleting directories in an inconsistent file system, which was recently reported by syzbot.
Thanks,
Ryusuke Konishi
fs/nilfs2/inode.c | 8 +++++++- fs/nilfs2/namei.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-)
fs/nilfs2/inode.c +7 -1
@@ -544,8 +544,14 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root, inode =nilfs_iget_locked (sb, root, ino);if (unlikely (!inode))return ERR_PTR (-ENOMEM ); -if (!(inode->i_state &I_NEW )) + +if (!(inode->i_state &I_NEW )) { +if (!inode->i_nlink) { +iput (inode); +return ERR_PTR (-ESTALE ); + }return inode; + } err =__nilfs_read_inode (sb, root, ino, inode);if (unlikely (err)) {
fs/nilfs2/namei.c +5 -0
@@ -67,6 +67,11 @@ nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) inode =NULL ; }else { inode =nilfs_iget (dir->i_sb,NILFS_I (dir)->i_root, ino); +if (inode ==ERR_PTR (-ESTALE )) { +nilfs_error (dir->i_sb, +"deleted inode referenced: %lu" , ino); +return ERR_PTR (-EIO ); + } }return d_splice_alias (inode, dentry);
Signature · 1 line
2.43.0