linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate
@ 2025-08-04  7:18 syzbot
  2025-08-04 12:18 ` Alan Huang
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: syzbot @ 2025-08-04  7:18 UTC (permalink / raw)
  To: kent.overstreet, linux-bcachefs, linux-kernel, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    352af6a011d5 Merge tag 'rust-6.17' of git://git.kernel.org..
git tree:       upstream
console+strace: https://syzkaller.appspot.com/x/log.txt?x=135d7aa2580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=cae1291240e8962a
dashboard link: https://syzkaller.appspot.com/bug?extid=cd063f869beedf5b9cd7
compiler:       Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14dcc6a2580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=133e02f0580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/a762497d1fce/disk-352af6a0.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/3055e1e47995/vmlinux-352af6a0.xz
kernel image: https://storage.googleapis.com/syzbot-assets/aa300ee98202/bzImage-352af6a0.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/de2a4b00a48a/mount_0.gz

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

bcachefs (loop0): error reading btree root btree=subvolumes level=0: btree_node_read_error, fixing
bcachefs (loop0): invalid bkey in btree_node btree=snapshot_trees level=0: u64s 6 type snapshot_tree POS_MIN len 0 ver 0: subvol 1 root snapshot 4294967295
  bad pos, deleting
bcachefs (loop0): error reading btree root btree=snapshot_trees level=0: btree_node_read_error, fixing
------------[ cut here ]------------
UBSAN: array-index-out-of-bounds in fs/bcachefs/disk_accounting.c:238:2
index 175 is out of range for type 'const unsigned int[9]'
CPU: 0 UID: 0 PID: 5849 Comm: syz-executor427 Tainted: G        W           6.16.0-syzkaller-11322-g352af6a011d5 #0 PREEMPT_{RT,(full)} 
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
 ubsan_epilogue+0xa/0x40 lib/ubsan.c:233
 __ubsan_handle_out_of_bounds+0xe9/0xf0 lib/ubsan.c:455
 bch2_accounting_validate+0x112f/0x1400 fs/bcachefs/disk_accounting.c:238
 bch2_bkey_val_validate+0x202/0x3e0 fs/bcachefs/bkey_methods.c:143
 btree_node_bkey_val_validate fs/bcachefs/btree_io.c:880 [inline]
 bch2_btree_node_read_done+0x4051/0x5550 fs/bcachefs/btree_io.c:1303
 btree_node_read_work+0x40e/0xe60 fs/bcachefs/btree_io.c:1440
 bch2_btree_node_read+0x887/0x2a00 fs/bcachefs/btree_io.c:-1
 __bch2_btree_root_read fs/bcachefs/btree_io.c:1906 [inline]
 bch2_btree_root_read+0x5f0/0x760 fs/bcachefs/btree_io.c:1928
 read_btree_roots+0x2c6/0x840 fs/bcachefs/recovery.c:615
 bch2_fs_recovery+0x261f/0x3a50 fs/bcachefs/recovery.c:1006
 bch2_fs_start+0xaaf/0xda0 fs/bcachefs/super.c:1213
 bch2_fs_get_tree+0xb39/0x1520 fs/bcachefs/fs.c:2488
 vfs_get_tree+0x92/0x2b0 fs/super.c:1815
 do_new_mount+0x2a2/0x9e0 fs/namespace.c:3805
 do_mount fs/namespace.c:4133 [inline]
 __do_sys_mount fs/namespace.c:4344 [inline]
 __se_sys_mount+0x317/0x410 fs/namespace.c:4321
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f5016bf5eaa
Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 5e 04 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 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:00007ffd552f5c58 EFLAGS: 00000282 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007ffd552f5c70 RCX: 00007f5016bf5eaa
RDX: 0000200000001000 RSI: 0000200000000000 RDI: 00007ffd552f5c70
RBP: 0000200000000000 R08: 00007ffd552f5cb0 R09: 000000000000492c
R10: 0000000000000000 R11: 0000000000000282 R12: 0000200000001000
R13: 00007ffd552f5cb0 R14: 0000000000000003 R15: 0000000000000000
 </TASK>
---[ end trace ]---


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

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

* Re: [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate
  2025-08-04  7:18 [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate syzbot
@ 2025-08-04 12:18 ` Alan Huang
  2025-08-04 12:19   ` syzbot
  2025-08-04 12:21 ` Alan Huang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Alan Huang @ 2025-08-04 12:18 UTC (permalink / raw)
  To: syzbot; +Cc: kent.overstreet, linux-bcachefs, linux-kernel, syzkaller-bugs

On Aug 4, 2025, at 15:18, syzbot <syzbot+cd063f869beedf5b9cd7@syzkaller.appspotmail.com> wrote:
> 
> Hello,
> 
> syzbot found the following issue on:
> 
> HEAD commit:    352af6a011d5 Merge tag 'rust-6.17' of git://git.kernel.org..
> git tree:       upstream
> console+strace: https://syzkaller.appspot.com/x/log.txt?x=135d7aa2580000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=cae1291240e8962a
> dashboard link: https://syzkaller.appspot.com/bug?extid=cd063f869beedf5b9cd7
> compiler:       Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14dcc6a2580000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=133e02f0580000
> 
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/a762497d1fce/disk-352af6a0.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/3055e1e47995/vmlinux-352af6a0.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/aa300ee98202/bzImage-352af6a0.xz
> mounted in repro: https://storage.googleapis.com/syzbot-assets/de2a4b00a48a/mount_0.gz
> 
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+cd063f869beedf5b9cd7@syzkaller.appspotmail.com
> 
> bcachefs (loop0): error reading btree root btree=subvolumes level=0: btree_node_read_error, fixing
> bcachefs (loop0): invalid bkey in btree_node btree=snapshot_trees level=0: u64s 6 type snapshot_tree POS_MIN len 0 ver 0: subvol 1 root snapshot 4294967295
>  bad pos, deleting
> bcachefs (loop0): error reading btree root btree=snapshot_trees level=0: btree_node_read_error, fixing
> ------------[ cut here ]------------
> UBSAN: array-index-out-of-bounds in fs/bcachefs/disk_accounting.c:238:2
> index 175 is out of range for type 'const unsigned int[9]'
> CPU: 0 UID: 0 PID: 5849 Comm: syz-executor427 Tainted: G        W           6.16.0-syzkaller-11322-g352af6a011d5 #0 PREEMPT_{RT,(full)} 
> Tainted: [W]=WARN
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
> Call Trace:
> <TASK>
> dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
> ubsan_epilogue+0xa/0x40 lib/ubsan.c:233
> __ubsan_handle_out_of_bounds+0xe9/0xf0 lib/ubsan.c:455
> bch2_accounting_validate+0x112f/0x1400 fs/bcachefs/disk_accounting.c:238
> bch2_bkey_val_validate+0x202/0x3e0 fs/bcachefs/bkey_methods.c:143
> btree_node_bkey_val_validate fs/bcachefs/btree_io.c:880 [inline]
> bch2_btree_node_read_done+0x4051/0x5550 fs/bcachefs/btree_io.c:1303
> btree_node_read_work+0x40e/0xe60 fs/bcachefs/btree_io.c:1440
> bch2_btree_node_read+0x887/0x2a00 fs/bcachefs/btree_io.c:-1
> __bch2_btree_root_read fs/bcachefs/btree_io.c:1906 [inline]
> bch2_btree_root_read+0x5f0/0x760 fs/bcachefs/btree_io.c:1928
> read_btree_roots+0x2c6/0x840 fs/bcachefs/recovery.c:615
> bch2_fs_recovery+0x261f/0x3a50 fs/bcachefs/recovery.c:1006
> bch2_fs_start+0xaaf/0xda0 fs/bcachefs/super.c:1213
> bch2_fs_get_tree+0xb39/0x1520 fs/bcachefs/fs.c:2488
> vfs_get_tree+0x92/0x2b0 fs/super.c:1815
> do_new_mount+0x2a2/0x9e0 fs/namespace.c:3805
> do_mount fs/namespace.c:4133 [inline]
> __do_sys_mount fs/namespace.c:4344 [inline]
> __se_sys_mount+0x317/0x410 fs/namespace.c:4321
> do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
> do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
> entry_SYSCALL_64_after_hwframe+0x77/0x7f
> RIP: 0033:0x7f5016bf5eaa
> Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 5e 04 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 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:00007ffd552f5c58 EFLAGS: 00000282 ORIG_RAX: 00000000000000a5
> RAX: ffffffffffffffda RBX: 00007ffd552f5c70 RCX: 00007f5016bf5eaa
> RDX: 0000200000001000 RSI: 0000200000000000 RDI: 00007ffd552f5c70
> RBP: 0000200000000000 R08: 00007ffd552f5cb0 R09: 000000000000492c
> R10: 0000000000000000 R11: 0000000000000282 R12: 0000200000001000
> R13: 00007ffd552f5cb0 R14: 0000000000000003 R15: 0000000000000000
> </TASK>
> ---[ end trace ]---
> 
> 
> ---
> 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 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:

diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c
index f96530c70262..4f5b290dc8f1 100644
--- a/fs/bcachefs/disk_accounting.c
+++ b/fs/bcachefs/disk_accounting.c
@@ -184,6 +184,11 @@ int bch2_accounting_validate(struct bch_fs *c, struct bkey_s_c k,
        void *end = &acc_k + 1;
        int ret = 0;
 
+       bkey_fsck_err_on(acc_k.type >= BCH_DISK_ACCOUNTING_TYPE_NR,
+                        c, accounting_key_type_invalid,
+                        "invalid accounting type (%u >= %u)",
+                        acc_k.type, BCH_DISK_ACCOUNTING_TYPE_NR);
+
        bkey_fsck_err_on((from.flags & BCH_VALIDATE_commit) &&
                         bversion_zero(k.k->bversion),
                         c, accounting_key_version_0,
diff --git a/fs/bcachefs/sb-errors_format.h b/fs/bcachefs/sb-errors_format.h
index 5317b1bfe2e5..5ba28a684f51 100644
--- a/fs/bcachefs/sb-errors_format.h
+++ b/fs/bcachefs/sb-errors_format.h
@@ -328,6 +328,7 @@ enum bch_fsck_flags {
        x(accounting_key_replicas_devs_unsorted,                280,    FSCK_AUTOFIX)   \
        x(accounting_key_version_0,                             282,    FSCK_AUTOFIX)   \
        x(accounting_key_nr_counters_wrong,                     307,    FSCK_AUTOFIX)   \
+       x(accounting_key_type_invalid,                          325,    FSCK_AUTOFIX)   \
        x(logged_op_but_clean,                                  283,    FSCK_AUTOFIX)   \
        x(compression_opt_not_marked_in_sb,                     295,    FSCK_AUTOFIX)   \
        x(compression_type_not_marked_in_sb,                    296,    FSCK_AUTOFIX)   \
@@ -336,7 +337,7 @@ enum bch_fsck_flags {
        x(dirent_stray_data_after_cf_name,                      305,    0)              \
        x(rebalance_work_incorrectly_set,                       309,    FSCK_AUTOFIX)   \
        x(rebalance_work_incorrectly_unset,                     310,    FSCK_AUTOFIX)   \
-       x(MAX,                                                  325,    0)
+       x(MAX,                                                  326,    0)
 
 enum bch_sb_error_id {
 #define x(t, n, ...) BCH_FSCK_ERR_##t = n,


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

* Re: [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate
  2025-08-04 12:18 ` Alan Huang
@ 2025-08-04 12:19   ` syzbot
  0 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-08-04 12:19 UTC (permalink / raw)
  To: mmpgouride
  Cc: kent.overstreet, linux-bcachefs, linux-kernel, mmpgouride,
	syzkaller-bugs

> On Aug 4, 2025, at 15:18, syzbot <syzbot+cd063f869beedf5b9cd7@syzkaller.appspotmail.com> wrote:
>> 
>> Hello,
>> 
>> syzbot found the following issue on:
>> 
>> HEAD commit:    352af6a011d5 Merge tag 'rust-6.17' of git://git.kernel.org..
>> git tree:       upstream
>> console+strace: https://syzkaller.appspot.com/x/log.txt?x=135d7aa2580000
>> kernel config:  https://syzkaller.appspot.com/x/.config?x=cae1291240e8962a
>> dashboard link: https://syzkaller.appspot.com/bug?extid=cd063f869beedf5b9cd7
>> compiler:       Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
>> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14dcc6a2580000
>> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=133e02f0580000
>> 
>> Downloadable assets:
>> disk image: https://storage.googleapis.com/syzbot-assets/a762497d1fce/disk-352af6a0.raw.xz
>> vmlinux: https://storage.googleapis.com/syzbot-assets/3055e1e47995/vmlinux-352af6a0.xz
>> kernel image: https://storage.googleapis.com/syzbot-assets/aa300ee98202/bzImage-352af6a0.xz
>> mounted in repro: https://storage.googleapis.com/syzbot-assets/de2a4b00a48a/mount_0.gz
>> 
>> IMPORTANT: if you fix the issue, please add the following tag to the commit:
>> Reported-by: syzbot+cd063f869beedf5b9cd7@syzkaller.appspotmail.com
>> 
>> bcachefs (loop0): error reading btree root btree=subvolumes level=0: btree_node_read_error, fixing
>> bcachefs (loop0): invalid bkey in btree_node btree=snapshot_trees level=0: u64s 6 type snapshot_tree POS_MIN len 0 ver 0: subvol 1 root snapshot 4294967295
>>  bad pos, deleting
>> bcachefs (loop0): error reading btree root btree=snapshot_trees level=0: btree_node_read_error, fixing
>> ------------[ cut here ]------------
>> UBSAN: array-index-out-of-bounds in fs/bcachefs/disk_accounting.c:238:2
>> index 175 is out of range for type 'const unsigned int[9]'
>> CPU: 0 UID: 0 PID: 5849 Comm: syz-executor427 Tainted: G        W           6.16.0-syzkaller-11322-g352af6a011d5 #0 PREEMPT_{RT,(full)} 
>> Tainted: [W]=WARN
>> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
>> Call Trace:
>> <TASK>
>> dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
>> ubsan_epilogue+0xa/0x40 lib/ubsan.c:233
>> __ubsan_handle_out_of_bounds+0xe9/0xf0 lib/ubsan.c:455
>> bch2_accounting_validate+0x112f/0x1400 fs/bcachefs/disk_accounting.c:238
>> bch2_bkey_val_validate+0x202/0x3e0 fs/bcachefs/bkey_methods.c:143
>> btree_node_bkey_val_validate fs/bcachefs/btree_io.c:880 [inline]
>> bch2_btree_node_read_done+0x4051/0x5550 fs/bcachefs/btree_io.c:1303
>> btree_node_read_work+0x40e/0xe60 fs/bcachefs/btree_io.c:1440
>> bch2_btree_node_read+0x887/0x2a00 fs/bcachefs/btree_io.c:-1
>> __bch2_btree_root_read fs/bcachefs/btree_io.c:1906 [inline]
>> bch2_btree_root_read+0x5f0/0x760 fs/bcachefs/btree_io.c:1928
>> read_btree_roots+0x2c6/0x840 fs/bcachefs/recovery.c:615
>> bch2_fs_recovery+0x261f/0x3a50 fs/bcachefs/recovery.c:1006
>> bch2_fs_start+0xaaf/0xda0 fs/bcachefs/super.c:1213
>> bch2_fs_get_tree+0xb39/0x1520 fs/bcachefs/fs.c:2488
>> vfs_get_tree+0x92/0x2b0 fs/super.c:1815
>> do_new_mount+0x2a2/0x9e0 fs/namespace.c:3805
>> do_mount fs/namespace.c:4133 [inline]
>> __do_sys_mount fs/namespace.c:4344 [inline]
>> __se_sys_mount+0x317/0x410 fs/namespace.c:4321
>> do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
>> do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
>> entry_SYSCALL_64_after_hwframe+0x77/0x7f
>> RIP: 0033:0x7f5016bf5eaa
>> Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 5e 04 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 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:00007ffd552f5c58 EFLAGS: 00000282 ORIG_RAX: 00000000000000a5
>> RAX: ffffffffffffffda RBX: 00007ffd552f5c70 RCX: 00007f5016bf5eaa
>> RDX: 0000200000001000 RSI: 0000200000000000 RDI: 00007ffd552f5c70
>> RBP: 0000200000000000 R08: 00007ffd552f5cb0 R09: 000000000000492c
>> R10: 0000000000000000 R11: 0000000000000282 R12: 0000200000001000
>> R13: 00007ffd552f5cb0 R14: 0000000000000003 R15: 0000000000000000
>> </TASK>
>> ---[ end trace ]---
>> 
>> 
>> ---
>> 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 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:

want either no args or 2 args (repo, branch), got 4

>
> diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c
> index f96530c70262..4f5b290dc8f1 100644
> --- a/fs/bcachefs/disk_accounting.c
> +++ b/fs/bcachefs/disk_accounting.c
> @@ -184,6 +184,11 @@ int bch2_accounting_validate(struct bch_fs *c, struct bkey_s_c k,
>         void *end = &acc_k + 1;
>         int ret = 0;
>  
> +       bkey_fsck_err_on(acc_k.type >= BCH_DISK_ACCOUNTING_TYPE_NR,
> +                        c, accounting_key_type_invalid,
> +                        "invalid accounting type (%u >= %u)",
> +                        acc_k.type, BCH_DISK_ACCOUNTING_TYPE_NR);
> +
>         bkey_fsck_err_on((from.flags & BCH_VALIDATE_commit) &&
>                          bversion_zero(k.k->bversion),
>                          c, accounting_key_version_0,
> diff --git a/fs/bcachefs/sb-errors_format.h b/fs/bcachefs/sb-errors_format.h
> index 5317b1bfe2e5..5ba28a684f51 100644
> --- a/fs/bcachefs/sb-errors_format.h
> +++ b/fs/bcachefs/sb-errors_format.h
> @@ -328,6 +328,7 @@ enum bch_fsck_flags {
>         x(accounting_key_replicas_devs_unsorted,                280,    FSCK_AUTOFIX)   \
>         x(accounting_key_version_0,                             282,    FSCK_AUTOFIX)   \
>         x(accounting_key_nr_counters_wrong,                     307,    FSCK_AUTOFIX)   \
> +       x(accounting_key_type_invalid,                          325,    FSCK_AUTOFIX)   \
>         x(logged_op_but_clean,                                  283,    FSCK_AUTOFIX)   \
>         x(compression_opt_not_marked_in_sb,                     295,    FSCK_AUTOFIX)   \
>         x(compression_type_not_marked_in_sb,                    296,    FSCK_AUTOFIX)   \
> @@ -336,7 +337,7 @@ enum bch_fsck_flags {
>         x(dirent_stray_data_after_cf_name,                      305,    0)              \
>         x(rebalance_work_incorrectly_set,                       309,    FSCK_AUTOFIX)   \
>         x(rebalance_work_incorrectly_unset,                     310,    FSCK_AUTOFIX)   \
> -       x(MAX,                                                  325,    0)
> +       x(MAX,                                                  326,    0)
>  
>  enum bch_sb_error_id {
>  #define x(t, n, ...) BCH_FSCK_ERR_##t = n,
>

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

* Re: [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate
  2025-08-04  7:18 [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate syzbot
  2025-08-04 12:18 ` Alan Huang
@ 2025-08-04 12:21 ` Alan Huang
  2025-08-04 19:30   ` syzbot
  2025-08-04 17:26 ` syzbot
  2025-08-04 22:56 ` Forwarded: syzbot
  3 siblings, 1 reply; 7+ messages in thread
From: Alan Huang @ 2025-08-04 12:21 UTC (permalink / raw)
  To: syzbot; +Cc: kent.overstreet, linux-bcachefs, linux-kernel, syzkaller-bugs

On Aug 4, 2025, at 15:18, syzbot <syzbot+cd063f869beedf5b9cd7@syzkaller.appspotmail.com> wrote:
> 
> Hello,
> 
> syzbot found the following issue on:
> 
> HEAD commit:    352af6a011d5 Merge tag 'rust-6.17' of git://git.kernel.org..
> git tree:       upstream
> console+strace: https://syzkaller.appspot.com/x/log.txt?x=135d7aa2580000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=cae1291240e8962a
> dashboard link: https://syzkaller.appspot.com/bug?extid=cd063f869beedf5b9cd7
> compiler:       Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14dcc6a2580000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=133e02f0580000
> 
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/a762497d1fce/disk-352af6a0.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/3055e1e47995/vmlinux-352af6a0.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/aa300ee98202/bzImage-352af6a0.xz
> mounted in repro: https://storage.googleapis.com/syzbot-assets/de2a4b00a48a/mount_0.gz
> 
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+cd063f869beedf5b9cd7@syzkaller.appspotmail.com
> 
> bcachefs (loop0): error reading btree root btree=subvolumes level=0: btree_node_read_error, fixing
> bcachefs (loop0): invalid bkey in btree_node btree=snapshot_trees level=0: u64s 6 type snapshot_tree POS_MIN len 0 ver 0: subvol 1 root snapshot 4294967295
>  bad pos, deleting
> bcachefs (loop0): error reading btree root btree=snapshot_trees level=0: btree_node_read_error, fixing
> ------------[ cut here ]------------
> UBSAN: array-index-out-of-bounds in fs/bcachefs/disk_accounting.c:238:2
> index 175 is out of range for type 'const unsigned int[9]'
> CPU: 0 UID: 0 PID: 5849 Comm: syz-executor427 Tainted: G        W           6.16.0-syzkaller-11322-g352af6a011d5 #0 PREEMPT_{RT,(full)} 
> Tainted: [W]=WARN
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
> Call Trace:
> <TASK>
> dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
> ubsan_epilogue+0xa/0x40 lib/ubsan.c:233
> __ubsan_handle_out_of_bounds+0xe9/0xf0 lib/ubsan.c:455
> bch2_accounting_validate+0x112f/0x1400 fs/bcachefs/disk_accounting.c:238
> bch2_bkey_val_validate+0x202/0x3e0 fs/bcachefs/bkey_methods.c:143
> btree_node_bkey_val_validate fs/bcachefs/btree_io.c:880 [inline]
> bch2_btree_node_read_done+0x4051/0x5550 fs/bcachefs/btree_io.c:1303
> btree_node_read_work+0x40e/0xe60 fs/bcachefs/btree_io.c:1440
> bch2_btree_node_read+0x887/0x2a00 fs/bcachefs/btree_io.c:-1
> __bch2_btree_root_read fs/bcachefs/btree_io.c:1906 [inline]
> bch2_btree_root_read+0x5f0/0x760 fs/bcachefs/btree_io.c:1928
> read_btree_roots+0x2c6/0x840 fs/bcachefs/recovery.c:615
> bch2_fs_recovery+0x261f/0x3a50 fs/bcachefs/recovery.c:1006
> bch2_fs_start+0xaaf/0xda0 fs/bcachefs/super.c:1213
> bch2_fs_get_tree+0xb39/0x1520 fs/bcachefs/fs.c:2488
> vfs_get_tree+0x92/0x2b0 fs/super.c:1815
> do_new_mount+0x2a2/0x9e0 fs/namespace.c:3805
> do_mount fs/namespace.c:4133 [inline]
> __do_sys_mount fs/namespace.c:4344 [inline]
> __se_sys_mount+0x317/0x410 fs/namespace.c:4321
> do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
> do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
> entry_SYSCALL_64_after_hwframe+0x77/0x7f
> RIP: 0033:0x7f5016bf5eaa
> Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb a6 e8 5e 04 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 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:00007ffd552f5c58 EFLAGS: 00000282 ORIG_RAX: 00000000000000a5
> RAX: ffffffffffffffda RBX: 00007ffd552f5c70 RCX: 00007f5016bf5eaa
> RDX: 0000200000001000 RSI: 0000200000000000 RDI: 00007ffd552f5c70
> RBP: 0000200000000000 R08: 00007ffd552f5cb0 R09: 000000000000492c
> R10: 0000000000000000 R11: 0000000000000282 R12: 0000200000001000
> R13: 00007ffd552f5cb0 R14: 0000000000000003 R15: 0000000000000000
> </TASK>
> ---[ end trace ]---
> 
> 
> ---
> 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 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

diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c
index f96530c70262..4f5b290dc8f1 100644
--- a/fs/bcachefs/disk_accounting.c
+++ b/fs/bcachefs/disk_accounting.c
@@ -184,6 +184,11 @@ int bch2_accounting_validate(struct bch_fs *c, struct bkey_s_c k,
        void *end = &acc_k + 1;
        int ret = 0;
 
+       bkey_fsck_err_on(acc_k.type >= BCH_DISK_ACCOUNTING_TYPE_NR,
+                        c, accounting_key_type_invalid,
+                        "invalid accounting type (%u >= %u)",
+                        acc_k.type, BCH_DISK_ACCOUNTING_TYPE_NR);
+
        bkey_fsck_err_on((from.flags & BCH_VALIDATE_commit) &&
                         bversion_zero(k.k->bversion),
                         c, accounting_key_version_0,
diff --git a/fs/bcachefs/sb-errors_format.h b/fs/bcachefs/sb-errors_format.h
index 5317b1bfe2e5..5ba28a684f51 100644
--- a/fs/bcachefs/sb-errors_format.h
+++ b/fs/bcachefs/sb-errors_format.h
@@ -328,6 +328,7 @@ enum bch_fsck_flags {
        x(accounting_key_replicas_devs_unsorted,                280,    FSCK_AUTOFIX)   \
        x(accounting_key_version_0,                             282,    FSCK_AUTOFIX)   \
        x(accounting_key_nr_counters_wrong,                     307,    FSCK_AUTOFIX)   \
+       x(accounting_key_type_invalid,                          325,    FSCK_AUTOFIX)   \
        x(logged_op_but_clean,                                  283,    FSCK_AUTOFIX)   \
        x(compression_opt_not_marked_in_sb,                     295,    FSCK_AUTOFIX)   \
        x(compression_type_not_marked_in_sb,                    296,    FSCK_AUTOFIX)   \
@@ -336,7 +337,7 @@ enum bch_fsck_flags {
        x(dirent_stray_data_after_cf_name,                      305,    0)              \
        x(rebalance_work_incorrectly_set,                       309,    FSCK_AUTOFIX)   \
        x(rebalance_work_incorrectly_unset,                     310,    FSCK_AUTOFIX)   \
-       x(MAX,                                                  325,    0)
+       x(MAX,                                                  326,    0)
 
 enum bch_sb_error_id {
 #define x(t, n, ...) BCH_FSCK_ERR_##t = n,


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

* Re: [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate
  2025-08-04  7:18 [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate syzbot
  2025-08-04 12:18 ` Alan Huang
  2025-08-04 12:21 ` Alan Huang
@ 2025-08-04 17:26 ` syzbot
  2025-08-04 22:56 ` Forwarded: syzbot
  3 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-08-04 17:26 UTC (permalink / raw)
  To: bfoster, elver, justinstitt, keescook, kent.overstreet,
	linux-bcachefs, linux-kernel, mmpgouride, syzkaller-bugs

syzbot has bisected this issue to:

commit 557f8c582a9ba8abe6aa0fd734b6f342af106b26
Author: Kees Cook <keescook@chromium.org>
Date:   Thu Jan 18 23:06:05 2024 +0000

    ubsan: Reintroduce signed overflow sanitizer

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=161982f0580000
start commit:   352af6a011d5 Merge tag 'rust-6.17' of git://git.kernel.org..
git tree:       upstream
final oops:     https://syzkaller.appspot.com/x/report.txt?x=151982f0580000
console output: https://syzkaller.appspot.com/x/log.txt?x=111982f0580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=cae1291240e8962a
dashboard link: https://syzkaller.appspot.com/bug?extid=cd063f869beedf5b9cd7
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14dcc6a2580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=133e02f0580000

Reported-by: syzbot+cd063f869beedf5b9cd7@syzkaller.appspotmail.com
Fixes: 557f8c582a9b ("ubsan: Reintroduce signed overflow sanitizer")

For information about bisection process see: https://goo.gl/tpsmEJ#bisection

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

* Re: [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate
  2025-08-04 12:21 ` Alan Huang
@ 2025-08-04 19:30   ` syzbot
  0 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-08-04 19:30 UTC (permalink / raw)
  To: kent.overstreet, linux-bcachefs, linux-kernel, mmpgouride,
	syzkaller-bugs

Hello,

syzbot tried to test the proposed patch but the build/boot failed:

failed to apply patch:
checking file fs/bcachefs/disk_accounting.c
checking file fs/bcachefs/sb-errors_format.h
Hunk #1 succeeded at 323 (offset -5 lines).
Hunk #2 FAILED at 337.
1 out of 2 hunks FAILED



Tested on:

commit:         35a813e0 Merge tag 'printk-for-6.17' of git://git.kern..
git tree:       upstream
kernel config:  https://syzkaller.appspot.com/x/.config?x=cae1291240e8962a
dashboard link: https://syzkaller.appspot.com/bug?extid=cd063f869beedf5b9cd7
compiler:       
patch:          https://syzkaller.appspot.com/x/patch.diff?x=135082f0580000


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

* Forwarded:
  2025-08-04  7:18 [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate syzbot
                   ` (2 preceding siblings ...)
  2025-08-04 17:26 ` syzbot
@ 2025-08-04 22:56 ` syzbot
  3 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2025-08-04 22:56 UTC (permalink / raw)
  To: linux-kernel, syzkaller-bugs

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: 
Author: kent.overstreet@linux.dev

#syz fix:  bcachefs: Ignore accounting key type larger than BCH_DISK_ACCOUNTING_TYPE_NR

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

end of thread, other threads:[~2025-08-04 22:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04  7:18 [syzbot] [bcachefs?] UBSAN: array-index-out-of-bounds in bch2_accounting_validate syzbot
2025-08-04 12:18 ` Alan Huang
2025-08-04 12:19   ` syzbot
2025-08-04 12:21 ` Alan Huang
2025-08-04 19:30   ` syzbot
2025-08-04 17:26 ` syzbot
2025-08-04 22:56 ` Forwarded: syzbot

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