[v6.1] KASAN: use-after-free Read in dev_uevent

5 views
Skip to first unread message

syzbot

unread,
Mar 7, 2023, 2:30:52 PM3/7/23
to syzkaller...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 42616e0f09fb Linux 6.1.15
git tree: linux-6.1.y
console output: https://syzkaller.appspot.com/x/log.txt?x=130a920ac80000
kernel config: https://syzkaller.appspot.com/x/.config?x=690b9ff41783cd73
dashboard link: https://syzkaller.appspot.com/bug?extid=dd213ac7f1cdb8fd8708
compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2

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

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/db869f2ed2bd/disk-42616e0f.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/37951bbe5829/vmlinux-42616e0f.xz
kernel image: https://storage.googleapis.com/syzbot-assets/23aa1a75ce0f/bzImage-42616e0f.xz

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

==================================================================
BUG: KASAN: use-after-free in string_nocheck lib/vsprintf.c:643 [inline]
BUG: KASAN: use-after-free in string+0x218/0x2b0 lib/vsprintf.c:725
Read of size 1 at addr ffff888021364780 by task udevd/2997

CPU: 1 PID: 2997 Comm: udevd Not tainted 6.1.15-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/02/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
print_address_description mm/kasan/report.c:284 [inline]
print_report+0x15f/0x4f0 mm/kasan/report.c:395
kasan_report+0x136/0x160 mm/kasan/report.c:495
string_nocheck lib/vsprintf.c:643 [inline]
string+0x218/0x2b0 lib/vsprintf.c:725
vsnprintf+0x11fc/0x1c70 lib/vsprintf.c:2800
add_uevent_var+0x1c0/0x440 lib/kobject_uevent.c:665
dev_uevent+0x3e8/0x8e0 drivers/base/core.c:2421
uevent_show+0x196/0x300 drivers/base/core.c:2492
dev_attr_show+0x50/0xb0 drivers/base/core.c:2195
sysfs_kf_seq_show+0x32d/0x4b0 fs/sysfs/file.c:59
seq_read_iter+0x43a/0xd10 fs/seq_file.c:230
call_read_iter include/linux/fs.h:2199 [inline]
new_sync_read fs/read_write.c:389 [inline]
vfs_read+0x7de/0xbe0 fs/read_write.c:470
ksys_read+0x19c/0x2c0 fs/read_write.c:613
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f2e627258fe
Code: c0 e9 e6 fe ff ff 50 48 8d 3d 0e c7 09 00 e8 c9 cf 01 00 66 0f 1f 84 00 00 00 00 00 64 8b 04 25 18 00 00 00 85 c0 75 14 0f 05 <48> 3d 00 f0 ff ff 77 5a c3 66 0f 1f 84 00 00 00 00 00 48 83 ec 28
RSP: 002b:00007fff44810a38 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 0000558416ad29a0 RCX: 00007f2e627258fe
RDX: 0000000000001000 RSI: 0000558416b0d5d0 RDI: 000000000000000c
RBP: 00007f2e627f2380 R08: 000000000000000c R09: 00007f2e627f5a60
R10: 0000000000000002 R11: 0000000000000246 R12: 0000558416ad29a0
R13: 0000000000000d68 R14: 00007f2e627f1780 R15: 0000000000000d68
</TASK>

Allocated by task 21558:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0x97/0xb0 mm/kasan/common.c:383
kmalloc include/linux/slab.h:553 [inline]
raw_ioctl_init drivers/usb/gadget/legacy/raw_gadget.c:460 [inline]
raw_ioctl+0x1ab1/0x3bf0 drivers/usb/gadget/legacy/raw_gadget.c:1250
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:870 [inline]
__se_sys_ioctl+0xf1/0x160 fs/ioctl.c:856
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 21547:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
kasan_save_free_info+0x27/0x40 mm/kasan/generic.c:516
____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
kasan_slab_free include/linux/kasan.h:177 [inline]
slab_free_hook mm/slub.c:1724 [inline]
slab_free_freelist_hook mm/slub.c:1750 [inline]
slab_free mm/slub.c:3661 [inline]
__kmem_cache_free+0x25c/0x3c0 mm/slub.c:3674
dev_free drivers/usb/gadget/legacy/raw_gadget.c:210 [inline]
kref_put+0xb5/0x7c0 include/linux/kref.h:65
raw_release+0x134/0x1e0 drivers/usb/gadget/legacy/raw_gadget.c:424
__fput+0x3b7/0x890 fs/file_table.c:320
task_work_run+0x246/0x300 kernel/task_work.c:179
resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
exit_to_user_mode_loop+0xd9/0x100 kernel/entry/common.c:171
exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:203
__syscall_exit_to_user_mode_work kernel/entry/common.c:285 [inline]
syscall_exit_to_user_mode+0x60/0x2c0 kernel/entry/common.c:296
do_syscall_64+0x49/0xb0 arch/x86/entry/common.c:86
entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff888021364780
which belongs to the cache kmalloc-32 of size 32
The buggy address is located 0 bytes inside of
32-byte region [ffff888021364780, ffff8880213647a0)

The buggy address belongs to the physical page:
page:ffffea000084d900 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x21364
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea000078a140 dead000000000004 ffff888012041500
raw: 0000000000000000 0000000000400040 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 3641, tgid 3641 (udevd), ts 104954169643, free_ts 104864374825
prep_new_page mm/page_alloc.c:2539 [inline]
get_page_from_freelist+0x3542/0x36d0 mm/page_alloc.c:4291
__alloc_pages+0x28d/0x7e0 mm/page_alloc.c:5558
__alloc_pages_node include/linux/gfp.h:237 [inline]
alloc_slab_page+0x59/0x150 mm/slub.c:1796
allocate_slab mm/slub.c:1939 [inline]
new_slab+0x84/0x2d0 mm/slub.c:1992
___slab_alloc+0xa71/0x1080 mm/slub.c:3180
__slab_alloc mm/slub.c:3279 [inline]
slab_alloc_node mm/slub.c:3364 [inline]
__kmem_cache_alloc_node+0x19f/0x260 mm/slub.c:3437
__do_kmalloc_node mm/slab_common.c:954 [inline]
__kmalloc_node+0x9e/0x190 mm/slab_common.c:962
kmalloc_array_node include/linux/slab.h:666 [inline]
kcalloc_node include/linux/slab.h:671 [inline]
memcg_alloc_slab_cgroups+0x7d/0x120 mm/memcontrol.c:2885
account_slab mm/slab.h:635 [inline]
allocate_slab mm/slub.c:1957 [inline]
new_slab+0xc0/0x2d0 mm/slub.c:1992
___slab_alloc+0xa71/0x1080 mm/slub.c:3180
__slab_alloc mm/slub.c:3279 [inline]
slab_alloc_node mm/slub.c:3364 [inline]
__kmem_cache_alloc_node+0x19f/0x260 mm/slub.c:3437
__do_kmalloc_node mm/slab_common.c:954 [inline]
__kmalloc_node+0x9e/0x190 mm/slab_common.c:962
kmalloc_node include/linux/slab.h:579 [inline]
kvmalloc_node+0x6e/0x180 mm/util.c:581
kvmalloc include/linux/slab.h:706 [inline]
seq_buf_alloc fs/seq_file.c:38 [inline]
seq_read_iter+0x1fe/0xd10 fs/seq_file.c:210
call_read_iter include/linux/fs.h:2199 [inline]
new_sync_read fs/read_write.c:389 [inline]
vfs_read+0x7de/0xbe0 fs/read_write.c:470
ksys_read+0x19c/0x2c0 fs/read_write.c:613
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1459 [inline]
free_pcp_prepare mm/page_alloc.c:1509 [inline]
free_unref_page_prepare+0xfdc/0x1190 mm/page_alloc.c:3387
free_unref_page_list+0x107/0x890 mm/page_alloc.c:3529
release_pages+0x2836/0x2b40 mm/swap.c:1055
tlb_batch_pages_flush mm/mmu_gather.c:59 [inline]
tlb_flush_mmu_free mm/mmu_gather.c:254 [inline]
tlb_flush_mmu+0xfc/0x210 mm/mmu_gather.c:261
tlb_finish_mmu+0xce/0x1f0 mm/mmu_gather.c:361
exit_mmap+0x2c2/0x950 mm/mmap.c:3100
__mmput+0x115/0x3c0 kernel/fork.c:1188
exit_mm+0x226/0x300 kernel/exit.c:563
do_exit+0x5f4/0x2280 kernel/exit.c:854
do_group_exit+0x202/0x2b0 kernel/exit.c:1012
get_signal+0x16f7/0x17d0 kernel/signal.c:2858
arch_do_signal_or_restart+0xb0/0x1a10 arch/x86/kernel/signal.c:869
exit_to_user_mode_loop+0x6a/0x100 kernel/entry/common.c:168
exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:203
__syscall_exit_to_user_mode_work kernel/entry/common.c:285 [inline]
syscall_exit_to_user_mode+0x60/0x2c0 kernel/entry/common.c:296
do_syscall_64+0x49/0xb0 arch/x86/entry/common.c:86

Memory state around the buggy address:
ffff888021364680: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
ffff888021364700: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
>ffff888021364780: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
^
ffff888021364800: 00 00 00 fc fc fc fc fc fa fb fb fb fc fc fc fc
ffff888021364880: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
==================================================================


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

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

syzbot

unread,
Mar 21, 2023, 9:24:53 AM3/21/23
to syzkaller...@googlegroups.com
syzbot has found a reproducer for the following issue on:

HEAD commit: 7eaef76fbc46 Linux 6.1.20
git tree: linux-6.1.y
console output: https://syzkaller.appspot.com/x/log.txt?x=147274f2c80000
kernel config: https://syzkaller.appspot.com/x/.config?x=28c36fe4d02f8c88
dashboard link: https://syzkaller.appspot.com/bug?extid=dd213ac7f1cdb8fd8708
compiler: Debian clang version 15.0.7, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1340dbd9c80000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17562aa1c80000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/610a00ba4375/disk-7eaef76f.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/57c1310f9a30/vmlinux-7eaef76f.xz
kernel image: https://storage.googleapis.com/syzbot-assets/81999f717d3b/bzImage-7eaef76f.xz

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

==================================================================
BUG: KASAN: use-after-free in string_nocheck lib/vsprintf.c:643 [inline]
BUG: KASAN: use-after-free in string+0x218/0x2b0 lib/vsprintf.c:725
Read of size 1 at addr ffff888021e06e40 by task udevd/2998

CPU: 0 PID: 2998 Comm: udevd Not tainted 6.1.20-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/02/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
print_address_description mm/kasan/report.c:284 [inline]
print_report+0x15f/0x4f0 mm/kasan/report.c:395
kasan_report+0x136/0x160 mm/kasan/report.c:495
string_nocheck lib/vsprintf.c:643 [inline]
string+0x218/0x2b0 lib/vsprintf.c:725
vsnprintf+0x11fc/0x1c70 lib/vsprintf.c:2800
add_uevent_var+0x1c0/0x440 lib/kobject_uevent.c:665
dev_uevent+0x3e8/0x8e0 drivers/base/core.c:2568
uevent_show+0x196/0x300 drivers/base/core.c:2639
dev_attr_show+0x50/0xb0 drivers/base/core.c:2342
sysfs_kf_seq_show+0x32d/0x4b0 fs/sysfs/file.c:59
seq_read_iter+0x43a/0xd10 fs/seq_file.c:230
call_read_iter include/linux/fs.h:2199 [inline]
new_sync_read fs/read_write.c:389 [inline]
vfs_read+0x7de/0xbe0 fs/read_write.c:470
ksys_read+0x19c/0x2c0 fs/read_write.c:613
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fb0023258fe
Code: c0 e9 e6 fe ff ff 50 48 8d 3d 0e c7 09 00 e8 c9 cf 01 00 66 0f 1f 84 00 00 00 00 00 64 8b 04 25 18 00 00 00 85 c0 75 14 0f 05 <48> 3d 00 f0 ff ff 77 5a c3 66 0f 1f 84 00 00 00 00 00 48 83 ec 28
RSP: 002b:00007ffd569dc468 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 000055bd446155d0 RCX: 00007fb0023258fe
RDX: 0000000000001000 RSI: 000055bd44618e80 RDI: 000000000000000c
RBP: 00007fb0023f2380 R08: 000000000000000c R09: 00007fb0023f5a60
R10: 0000000000000800 R11: 0000000000000246 R12: 000055bd446155d0
R13: 0000000000000d68 R14: 00007fb0023f1780 R15: 0000000000000d68
</TASK>

Allocated by task 11172:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0x97/0xb0 mm/kasan/common.c:383
kmalloc include/linux/slab.h:553 [inline]
raw_ioctl_init drivers/usb/gadget/legacy/raw_gadget.c:460 [inline]
raw_ioctl+0x1ab1/0x3bf0 drivers/usb/gadget/legacy/raw_gadget.c:1250
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:870 [inline]
__se_sys_ioctl+0xf1/0x160 fs/ioctl.c:856
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 11172:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
kasan_save_free_info+0x27/0x40 mm/kasan/generic.c:516
____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
kasan_slab_free include/linux/kasan.h:177 [inline]
slab_free_hook mm/slub.c:1724 [inline]
slab_free_freelist_hook mm/slub.c:1750 [inline]
slab_free mm/slub.c:3661 [inline]
__kmem_cache_free+0x25c/0x3c0 mm/slub.c:3674
dev_free drivers/usb/gadget/legacy/raw_gadget.c:210 [inline]
kref_put+0xb5/0x7c0 include/linux/kref.h:65
raw_release+0x134/0x1e0 drivers/usb/gadget/legacy/raw_gadget.c:424
__fput+0x3b7/0x890 fs/file_table.c:320
task_work_run+0x246/0x300 kernel/task_work.c:179
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0x6fb/0x2300 kernel/exit.c:869
do_group_exit+0x202/0x2b0 kernel/exit.c:1019
get_signal+0x16f7/0x17d0 kernel/signal.c:2858
arch_do_signal_or_restart+0xb0/0x1a10 arch/x86/kernel/signal.c:869
exit_to_user_mode_loop+0x6a/0x100 kernel/entry/common.c:168
exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:203
__syscall_exit_to_user_mode_work kernel/entry/common.c:285 [inline]
syscall_exit_to_user_mode+0x60/0x2d0 kernel/entry/common.c:296
do_syscall_64+0x49/0xb0 arch/x86/entry/common.c:86
entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff888021e06e40
which belongs to the cache kmalloc-32 of size 32
The buggy address is located 0 bytes inside of
32-byte region [ffff888021e06e40, ffff888021e06e60)

The buggy address belongs to the physical page:
page:ffffea0000878180 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888021e06ec0 pfn:0x21e06
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea00007a7b88 ffffea0001e7c988 ffff888012441500
raw: ffff888021e06ec0 000000000040003f 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 0x12cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY), pid 1, tgid 1 (swapper/0), ts 8045916958, free_ts 6846917462
prep_new_page mm/page_alloc.c:2539 [inline]
get_page_from_freelist+0x3573/0x3700 mm/page_alloc.c:4291
__alloc_pages+0x28d/0x7e0 mm/page_alloc.c:5558
alloc_page_interleave+0x22/0x1c0 mm/mempolicy.c:2120
alloc_slab_page+0x6a/0x150 mm/slub.c:1794
allocate_slab mm/slub.c:1939 [inline]
new_slab+0x84/0x2d0 mm/slub.c:1992
___slab_alloc+0xa71/0x1080 mm/slub.c:3180
__slab_alloc mm/slub.c:3279 [inline]
slab_alloc_node mm/slub.c:3364 [inline]
__kmem_cache_alloc_node+0x19f/0x260 mm/slub.c:3437
__do_kmalloc_node mm/slab_common.c:954 [inline]
__kmalloc+0x9e/0x1a0 mm/slab_common.c:968
kmalloc include/linux/slab.h:558 [inline]
kzalloc include/linux/slab.h:689 [inline]
rh_call_control drivers/usb/core/hcd.c:514 [inline]
rh_urb_enqueue drivers/usb/core/hcd.c:848 [inline]
usb_hcd_submit_urb+0x8f5/0x1de0 drivers/usb/core/hcd.c:1552
usb_start_wait_urb+0x10f/0x510 drivers/usb/core/message.c:58
usb_internal_control_msg drivers/usb/core/message.c:102 [inline]
usb_control_msg+0x2ad/0x4c0 drivers/usb/core/message.c:153
usb_get_descriptor+0xb3/0x3c0 drivers/usb/core/message.c:793
usb_get_configuration+0x37f/0x4d60 drivers/usb/core/config.c:928
usb_enumerate_device drivers/usb/core/hub.c:2407 [inline]
usb_new_device+0x146/0x18e0 drivers/usb/core/hub.c:2545
register_root_hub+0x271/0x560 drivers/usb/core/hcd.c:1017
usb_add_hcd+0xc4e/0x1250 drivers/usb/core/hcd.c:2991
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1459 [inline]
free_pcp_prepare mm/page_alloc.c:1509 [inline]
free_unref_page_prepare+0xfe1/0x1190 mm/page_alloc.c:3387
free_unref_page+0x98/0x570 mm/page_alloc.c:3483
__vunmap+0x834/0x9a0 mm/vmalloc.c:2713
free_work+0x57/0x80 mm/vmalloc.c:97
process_one_work+0x909/0x1380 kernel/workqueue.c:2289
worker_thread+0xa5f/0x1210 kernel/workqueue.c:2436
kthread+0x268/0x300 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

Memory state around the buggy address:
ffff888021e06d00: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
ffff888021e06d80: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
>ffff888021e06e00: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
^
ffff888021e06e80: fa fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
ffff888021e06f00: 00 00 02 fc fc fc fc fc 00 00 03 fc fc fc fc fc
==================================================================

Reply all
Reply to author
Forward
0 new messages