lkml.org 
[lkml]   [2024]   [May]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectKASAN: slab-out-of-bounds Read in journal validate key
Hello.
We are Ubisectech Sirius Team, the vulnerability lab of China ValiantSec. Recently, our team has discovered a issue in Linux kernel 6.7. Attached to the email were a PoC file of the issue.

Stack dump:

invalid journal entry, version=1.7: (unknown version) type=btree_keys in superblock: bad format 0, exiting
bcachefs (loop3): Unable to continue, halting
==================================================================
BUG: KASAN: slab-out-of-bounds in journal_validate_key+0xac1/0xb50 fs/bcachefs/journal_io.c:282
Read of size 1 at addr ffff8880590aea28 by task syz-executor.3/31108

CPU: 1 PID: 31108 Comm: syz-executor.3 Not tainted 6.7.0 #2
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:364 [inline]
print_report+0xc1/0x5e0 mm/kasan/report.c:475
kasan_report+0xbe/0xf0 mm/kasan/report.c:588
journal_validate_key+0xac1/0xb50 fs/bcachefs/journal_io.c:282
journal_entry_btree_keys_validate+0x11d/0x1f0 fs/bcachefs/journal_io.c:355
bch2_journal_entry_validate+0xc7/0x130 fs/bcachefs/journal_io.c:752
bch2_sb_clean_validate_late+0x14b/0x1e0 fs/bcachefs/sb-clean.c:32
bch2_read_superblock_clean+0xbb/0x250 fs/bcachefs/sb-clean.c:160
bch2_fs_recovery+0x113/0x52d0 fs/bcachefs/recovery.c:691
bch2_fs_start+0x365/0x5e0 fs/bcachefs/super.c:978
bch2_fs_open+0x1ac9/0x3890 fs/bcachefs/super.c:1968
bch2_mount+0x538/0x13c0 fs/bcachefs/fs.c:1863
legacy_get_tree+0x109/0x220 fs/fs_context.c:662
vfs_get_tree+0x93/0x380 fs/super.c:1771
do_new_mount fs/namespace.c:3337 [inline]
path_mount+0x679/0x1e40 fs/namespace.c:3664
do_mount fs/namespace.c:3677 [inline]
__do_sys_mount fs/namespace.c:3886 [inline]
__se_sys_mount fs/namespace.c:3863 [inline]
__x64_sys_mount+0x287/0x310 fs/namespace.c:3863
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x43/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x6f/0x77
RIP: 0033:0x7f2a55091b3e
Code: 48 c7 c0 ff ff ff ff eb aa e8 be 0d 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 f3 0f 1e fa 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f2a55eeae38 EFLAGS: 00000202 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00000000000119fc RCX: 00007f2a55091b3e
RDX: 0000000020011a00 RSI: 0000000020000040 RDI: 00007f2a55eeae90
RBP: 00007f2a55eeaed0 R08: 00007f2a55eeaed0 R09: 0000000000000001
R10: 0000000000000001 R11: 0000000000000202 R12: 0000000020011a00
R13: 0000000020000040 R14: 00007f2a55eeae90 R15: 0000000020000100
</TASK>

Allocated by task 31108:
kasan_save_stack+0x22/0x50 mm/kasan/common.c:45
kasan_set_track+0x25/0x30 mm/kasan/common.c:52
____kasan_kmalloc mm/kasan/common.c:374 [inline]
____kasan_kmalloc mm/kasan/common.c:333 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:383
kasan_kmalloc include/linux/kasan.h:198 [inline]
__do_kmalloc_node mm/slab_common.c:1007 [inline]
__kmalloc_node_track_caller+0x5e/0xd0 mm/slab_common.c:1027
kmemdup+0x2c/0x60 mm/util.c:131
kmemdup include/linux/fortify-string.h:761 [inline]
bch2_read_superblock_clean+0xa1/0x250 fs/bcachefs/sb-clean.c:153
bch2_fs_recovery+0x113/0x52d0 fs/bcachefs/recovery.c:691
bch2_fs_start+0x365/0x5e0 fs/bcachefs/super.c:978
bch2_fs_open+0x1ac9/0x3890 fs/bcachefs/super.c:1968
bch2_mount+0x538/0x13c0 fs/bcachefs/fs.c:1863
legacy_get_tree+0x109/0x220 fs/fs_context.c:662
vfs_get_tree+0x93/0x380 fs/super.c:1771
do_new_mount fs/namespace.c:3337 [inline]
path_mount+0x679/0x1e40 fs/namespace.c:3664
do_mount fs/namespace.c:3677 [inline]
__do_sys_mount fs/namespace.c:3886 [inline]
__se_sys_mount fs/namespace.c:3863 [inline]
__x64_sys_mount+0x287/0x310 fs/namespace.c:3863
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x43/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x6f/0x77

Last potentially related work creation:
kasan_save_stack+0x22/0x50 mm/kasan/common.c:45
__kasan_record_aux_stack+0xbc/0xd0 mm/kasan/generic.c:492
__call_rcu_common.constprop.0+0x99/0x7a0 kernel/rcu/tree.c:2681
mpls_dev_notify+0x6d6/0x9c0 net/mpls/af_mpls.c:1661
notifier_call_chain+0xba/0x3e0 kernel/notifier.c:93
call_netdevice_notifiers_info+0xbe/0x140 net/core/dev.c:1967
call_netdevice_notifiers_extack net/core/dev.c:2005 [inline]
call_netdevice_notifiers net/core/dev.c:2019 [inline]
unregister_netdevice_many_notify+0x79c/0x18a0 net/core/dev.c:11043
unregister_netdevice_many net/core/dev.c:11099 [inline]
default_device_exit_batch+0x454/0x5c0 net/core/dev.c:11568
ops_exit_list+0x128/0x180 net/core/net_namespace.c:175
cleanup_net+0x4f1/0xb20 net/core/net_namespace.c:614
process_one_work+0x87b/0x15c0 kernel/workqueue.c:2627
process_scheduled_works kernel/workqueue.c:2700 [inline]
worker_thread+0x855/0x1200 kernel/workqueue.c:2781
kthread+0x2cc/0x3b0 kernel/kthread.c:388
ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1b/0x30 arch/x86/entry/entry_64.S:242

The buggy address belongs to the object at ffff8880590aea00
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 0 bytes to the right of
allocated 40-byte region [ffff8880590aea00, ffff8880590aea28)

The buggy address belongs to the physical page:
page:ffffea0001642b80 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x590ae
ksm flags: 0x4fff00000000800(slab|node=1|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 04fff00000000800 ffff888014841640 ffffea00016a7980 dead000000000003
raw: 0000000000000000 0000000080200020 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112cc0(GFP_USER|__GFP_NOWARN|__GFP_NORETRY), pid 10370, tgid 10370 (syz-executor.3), ts 142533203129, free_ts 139112395292
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x2dd/0x350 mm/page_alloc.c:1537
prep_new_page mm/page_alloc.c:1544 [inline]
get_page_from_freelist+0xd38/0x2fa0 mm/page_alloc.c:3312
__alloc_pages+0x21d/0x21f0 mm/page_alloc.c:4568
alloc_pages_mpol+0x245/0x5f0 mm/mempolicy.c:2133
alloc_slab_page mm/slub.c:1870 [inline]
allocate_slab mm/slub.c:2017 [inline]
new_slab+0x28f/0x3d0 mm/slub.c:2070
___slab_alloc+0xac4/0x1480 mm/slub.c:3223
__slab_alloc.constprop.0+0x56/0xb0 mm/slub.c:3322
__slab_alloc_node mm/slub.c:3375 [inline]
slab_alloc_node mm/slub.c:3468 [inline]
__kmem_cache_alloc_node+0x132/0x330 mm/slub.c:3517
kmalloc_node_trace+0x21/0x60 mm/slab_common.c:1111
kmalloc_node include/linux/slab.h:616 [inline]
kzalloc_node include/linux/slab.h:732 [inline]
__get_vm_area_node+0xed/0x400 mm/vmalloc.c:2588
__vmalloc_node_range+0x252/0x1490 mm/vmalloc.c:3280
alloc_thread_stack_node kernel/fork.c:309 [inline]
dup_task_struct kernel/fork.c:1118 [inline]
copy_process+0x1364/0x73f0 kernel/fork.c:2332
kernel_clone+0xeb/0x8d0 kernel/fork.c:2907
__do_sys_clone3+0x1d7/0x250 kernel/fork.c:3208
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x43/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x6f/0x77
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1137 [inline]
free_unref_page_prepare+0x4cd/0xa70 mm/page_alloc.c:2347
free_unref_page+0x33/0x3d0 mm/page_alloc.c:2487
vfree+0x180/0x7b0 mm/vmalloc.c:2842
kvfree+0x32/0x50 mm/util.c:661
kvm_destroy_vm arch/x86/kvm/../../../virt/kvm/kvm_main.c:1341 [inline]
kvm_put_kvm+0x880/0xaf0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:1366
kvm_vm_release+0x43/0x60 arch/x86/kvm/../../../virt/kvm/kvm_main.c:1389
__fput+0x282/0xbc0 fs/file_table.c:394
__fput_sync+0x45/0x50 fs/file_table.c:475
__do_sys_close fs/open.c:1587 [inline]
__se_sys_close fs/open.c:1572 [inline]
__x64_sys_close+0x8b/0x120 fs/open.c:1572
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x43/0x120 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x6f/0x77

Memory state around the buggy address:
ffff8880590ae900: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
ffff8880590ae980: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
>ffff8880590aea00: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
^
ffff8880590aea80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff8880590aeb00: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
==================================================================

Thank you for taking the time to read this email and we look forward to working with you further.








[unhandled content-type:application/octet-stream]
\
 
 \ /
  Last update: 2024-05-09 08:51    [W:0.079 / U:0.648 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site