linux-nilfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [syzbot] [nilfs?] kernel BUG in nilfs_btnode_create_block (2)
@ 2024-06-15 16:32 syzbot
  2024-06-15 23:36 ` Ryusuke Konishi
  2024-07-25  5:20 ` [PATCH] nilfs2: handle inconsistent state in nilfs_btnode_create_block() Ryusuke Konishi
  0 siblings, 2 replies; 3+ messages in thread
From: syzbot @ 2024-06-15 16:32 UTC (permalink / raw)
  To: konishi.ryusuke, linux-kernel, linux-nilfs, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    83a7eefedc9b Linux 6.10-rc3
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=13ab3d96980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=c79815c08cc14227
dashboard link: https://syzkaller.appspot.com/bug?extid=89cc4f2324ed37988b60
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/b45273014a8f/disk-83a7eefe.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/94cd5708292e/vmlinux-83a7eefe.xz
kernel image: https://storage.googleapis.com/syzbot-assets/a89698812e8b/bzImage-83a7eefe.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+89cc4f2324ed37988b60@syzkaller.appspotmail.com

------------[ cut here ]------------
kernel BUG at fs/nilfs2/btnode.c:59!
Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN PTI
CPU: 1 PID: 7600 Comm: segctord Not tainted 6.10.0-rc3-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/02/2024
RIP: 0010:nilfs_btnode_create_block+0x3dc/0x400 fs/nilfs2/btnode.c:59
Code: 8e 48 89 da e8 85 25 73 01 e9 a7 fd ff ff e8 cb d2 28 fe eb 0c e8 c4 d2 28 fe eb 05 e8 bd d2 28 fe 4c 89 ef e8 35 00 00 00 90 <0f> 0b e8 ad d2 28 fe 4c 89 f7 48 c7 c6 40 f2 06 8c e8 8e c0 6f fe
RSP: 0000:ffffc90004f1f270 EFLAGS: 00010202
RAX: ffffffff821b2801 RBX: 0000000000000010 RCX: ffffffff821b2819
RDX: 0000000000000001 RSI: 0000000000000004 RDI: ffff88807746f5d0
RBP: 0000000000001cc3 R08: ffff88807746f5d3 R09: 1ffff1100ee8deba
R10: dffffc0000000000 R11: ffffed100ee8debb R12: dffffc0000000000
R13: ffff88807746f570 R14: 1ffff1100ee8deae R15: ffff88805e399490
FS:  0000000000000000(0000) GS:ffff8880b9500000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fdd25186000 CR3: 000000007a728000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 nilfs_btnode_prepare_change_key+0x26d/0x300 fs/nilfs2/btnode.c:219
 nilfs_btree_prepare_update_v+0x397/0x450 fs/nilfs2/btree.c:1942
 nilfs_btree_prepare_propagate_v fs/nilfs2/btree.c:2001 [inline]
 nilfs_btree_propagate_v fs/nilfs2/btree.c:2054 [inline]
 nilfs_btree_propagate+0x3bf/0xdf0 fs/nilfs2/btree.c:2111
 nilfs_bmap_propagate+0x75/0x120 fs/nilfs2/bmap.c:345
 nilfs_segctor_apply_buffers+0x184/0x340 fs/nilfs2/segment.c:1006
 nilfs_segctor_scan_file+0x810/0xa50 fs/nilfs2/segment.c:1066
 nilfs_segctor_collect_blocks fs/nilfs2/segment.c:1164 [inline]
 nilfs_segctor_collect fs/nilfs2/segment.c:1492 [inline]
 nilfs_segctor_do_construct+0x1c43/0x6b50 fs/nilfs2/segment.c:2040
 nilfs_segctor_construct+0x181/0x6b0 fs/nilfs2/segment.c:2408
 nilfs_segctor_thread_construct fs/nilfs2/segment.c:2516 [inline]
 nilfs_segctor_thread+0x55c/0x11b0 fs/nilfs2/segment.c:2601
 kthread+0x2f0/0x390 kernel/kthread.c:389
 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:nilfs_btnode_create_block+0x3dc/0x400 fs/nilfs2/btnode.c:59
Code: 8e 48 89 da e8 85 25 73 01 e9


---
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 syzkaller@googlegroups.com.

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 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [syzbot] [nilfs?] kernel BUG in nilfs_btnode_create_block (2)
  2024-06-15 16:32 [syzbot] [nilfs?] kernel BUG in nilfs_btnode_create_block (2) syzbot
@ 2024-06-15 23:36 ` Ryusuke Konishi
  2024-07-25  5:20 ` [PATCH] nilfs2: handle inconsistent state in nilfs_btnode_create_block() Ryusuke Konishi
  1 sibling, 0 replies; 3+ messages in thread
From: Ryusuke Konishi @ 2024-06-15 23:36 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, linux-nilfs, syzkaller-bugs

On Sun, Jun 16, 2024 at 1:32 AM syzbot  wrote:
>
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit:    83a7eefedc9b Linux 6.10-rc3
> git tree:       upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=13ab3d96980000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=c79815c08cc14227
> dashboard link: https://syzkaller.appspot.com/bug?extid=89cc4f2324ed37988b60
> compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
>
> Unfortunately, I don't have any reproducer for this issue yet.
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/b45273014a8f/disk-83a7eefe.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/94cd5708292e/vmlinux-83a7eefe.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/a89698812e8b/bzImage-83a7eefe.xz
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+89cc4f2324ed37988b60@syzkaller.appspotmail.com
>
> ------------[ cut here ]------------
> kernel BUG at fs/nilfs2/btnode.c:59!
> Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN PTI
> CPU: 1 PID: 7600 Comm: segctord Not tainted 6.10.0-rc3-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/02/2024
> RIP: 0010:nilfs_btnode_create_block+0x3dc/0x400 fs/nilfs2/btnode.c:59
> Code: 8e 48 89 da e8 85 25 73 01 e9 a7 fd ff ff e8 cb d2 28 fe eb 0c e8 c4 d2 28 fe eb 05 e8 bd d2 28 fe 4c 89 ef e8 35 00 00 00 90 <0f> 0b e8 ad d2 28 fe 4c 89 f7 48 c7 c6 40 f2 06 8c e8 8e c0 6f fe
> RSP: 0000:ffffc90004f1f270 EFLAGS: 00010202
> RAX: ffffffff821b2801 RBX: 0000000000000010 RCX: ffffffff821b2819
> RDX: 0000000000000001 RSI: 0000000000000004 RDI: ffff88807746f5d0
> RBP: 0000000000001cc3 R08: ffff88807746f5d3 R09: 1ffff1100ee8deba
> R10: dffffc0000000000 R11: ffffed100ee8debb R12: dffffc0000000000
> R13: ffff88807746f570 R14: 1ffff1100ee8deae R15: ffff88805e399490
> FS:  0000000000000000(0000) GS:ffff8880b9500000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007fdd25186000 CR3: 000000007a728000 CR4: 00000000003506f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
>  <TASK>
>  nilfs_btnode_prepare_change_key+0x26d/0x300 fs/nilfs2/btnode.c:219
>  nilfs_btree_prepare_update_v+0x397/0x450 fs/nilfs2/btree.c:1942
>  nilfs_btree_prepare_propagate_v fs/nilfs2/btree.c:2001 [inline]
>  nilfs_btree_propagate_v fs/nilfs2/btree.c:2054 [inline]
>  nilfs_btree_propagate+0x3bf/0xdf0 fs/nilfs2/btree.c:2111
>  nilfs_bmap_propagate+0x75/0x120 fs/nilfs2/bmap.c:345
>  nilfs_segctor_apply_buffers+0x184/0x340 fs/nilfs2/segment.c:1006
>  nilfs_segctor_scan_file+0x810/0xa50 fs/nilfs2/segment.c:1066
>  nilfs_segctor_collect_blocks fs/nilfs2/segment.c:1164 [inline]
>  nilfs_segctor_collect fs/nilfs2/segment.c:1492 [inline]
>  nilfs_segctor_do_construct+0x1c43/0x6b50 fs/nilfs2/segment.c:2040
>  nilfs_segctor_construct+0x181/0x6b0 fs/nilfs2/segment.c:2408
>  nilfs_segctor_thread_construct fs/nilfs2/segment.c:2516 [inline]
>  nilfs_segctor_thread+0x55c/0x11b0 fs/nilfs2/segment.c:2601
>  kthread+0x2f0/0x390 kernel/kthread.c:389
>  ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
>  ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
>  </TASK>
> Modules linked in:
> ---[ end trace 0000000000000000 ]---
> RIP: 0010:nilfs_btnode_create_block+0x3dc/0x400 fs/nilfs2/btnode.c:59
> Code: 8e 48 89 da e8 85 25 73 01 e9
>
>
> ---
> 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 syzkaller@googlegroups.com.
>
> 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 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

Looking at the call trace, it looks like in
nilfs_btnode_create_block(), the buffer obtained by
nilfs_grab_buffer() is in an unexpected state, triggering a BUG() that
remains there.

If the abnormal state is reproducible when given a corrupted
filesystem image (which I suspect it is), it should be rewritten to
return an appropriate error, or at least handled with WARN_ON() or
WARN_ON_ONCE() if it is caused by some other bug.

Once syzbot finds the reproducer, this will become clearer.

Ryusuke Konishi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] nilfs2: handle inconsistent state in nilfs_btnode_create_block()
  2024-06-15 16:32 [syzbot] [nilfs?] kernel BUG in nilfs_btnode_create_block (2) syzbot
  2024-06-15 23:36 ` Ryusuke Konishi
@ 2024-07-25  5:20 ` Ryusuke Konishi
  1 sibling, 0 replies; 3+ messages in thread
From: Ryusuke Konishi @ 2024-07-25  5:20 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-nilfs, linux-kernel, syzbot, syzkaller-bugs

Syzbot reported that a buffer state inconsistency was detected in
nilfs_btnode_create_block(), triggering a kernel bug.

It is not appropriate to treat this inconsistency as a bug; it can
occur if the argument block address (the buffer index of the newly
created block) is a virtual block number and has been reallocated due
to corruption of the bitmap used to manage its allocation state.

So, modify nilfs_btnode_create_block() and its callers to treat it as
a possible filesystem error, rather than triggering a kernel bug.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+89cc4f2324ed37988b60@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=89cc4f2324ed37988b60
Fixes: a60be987d45d ("nilfs2: B-tree node cache")
Cc: stable@vger.kernel.org
---
Andrew, please apply this as a bug fix.

This fixes one syzbot-reported issue where a kernel bug could be
triggered on corrupted file system images.

Thanks,
Ryusuke Konishi

 fs/nilfs2/btnode.c | 25 ++++++++++++++++++++-----
 fs/nilfs2/btree.c  |  4 ++--
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/fs/nilfs2/btnode.c b/fs/nilfs2/btnode.c
index 0131d83b912d..c034080c334b 100644
--- a/fs/nilfs2/btnode.c
+++ b/fs/nilfs2/btnode.c
@@ -51,12 +51,21 @@ nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr)
 
 	bh = nilfs_grab_buffer(inode, btnc, blocknr, BIT(BH_NILFS_Node));
 	if (unlikely(!bh))
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	if (unlikely(buffer_mapped(bh) || buffer_uptodate(bh) ||
 		     buffer_dirty(bh))) {
-		brelse(bh);
-		BUG();
+		/*
+		 * The block buffer at the specified new address was already
+		 * in use.  This can happen if it is a virtual block number
+		 * and has been reallocated due to corruption of the bitmap
+		 * used to manage its allocation state (if not, the buffer
+		 * clearing of an abandoned b-tree node is missing somewhere).
+		 */
+		nilfs_error(inode->i_sb,
+			    "state inconsistency probably due to duplicate use of b-tree node block address %llu (ino=%lu)",
+			    (unsigned long long)blocknr, inode->i_ino);
+		goto failed;
 	}
 	memset(bh->b_data, 0, i_blocksize(inode));
 	bh->b_bdev = inode->i_sb->s_bdev;
@@ -67,6 +76,12 @@ nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr)
 	folio_unlock(bh->b_folio);
 	folio_put(bh->b_folio);
 	return bh;
+
+failed:
+	folio_unlock(bh->b_folio);
+	folio_put(bh->b_folio);
+	brelse(bh);
+	return ERR_PTR(-EIO);
 }
 
 int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
@@ -217,8 +232,8 @@ int nilfs_btnode_prepare_change_key(struct address_space *btnc,
 	}
 
 	nbh = nilfs_btnode_create_block(btnc, newkey);
-	if (!nbh)
-		return -ENOMEM;
+	if (IS_ERR(nbh))
+		return PTR_ERR(nbh);
 
 	BUG_ON(nbh == obh);
 	ctxt->newbh = nbh;
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index a139970e4804..862bdf23120e 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -63,8 +63,8 @@ static int nilfs_btree_get_new_block(const struct nilfs_bmap *btree,
 	struct buffer_head *bh;
 
 	bh = nilfs_btnode_create_block(btnc, ptr);
-	if (!bh)
-		return -ENOMEM;
+	if (IS_ERR(bh))
+		return PTR_ERR(bh);
 
 	set_buffer_nilfs_volatile(bh);
 	*bhp = bh;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-25  5:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-15 16:32 [syzbot] [nilfs?] kernel BUG in nilfs_btnode_create_block (2) syzbot
2024-06-15 23:36 ` Ryusuke Konishi
2024-07-25  5:20 ` [PATCH] nilfs2: handle inconsistent state in nilfs_btnode_create_block() Ryusuke Konishi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).