[syzbot] [kernel?] KASAN: slab-use-after-free Read in dev_uevent

24 views
Skip to first unread message

syzbot

unread,
Mar 7, 2023, 3:15:50ā€ÆAM3/7/23
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, raf...@kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: f915322fe014 Merge tag 'v6.3-p2' of git://git.kernel.org/p..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1190526cc80000
kernel config: https://syzkaller.appspot.com/x/.config?x=dc0f7cfe5b32efe2
dashboard link: https://syzkaller.appspot.com/bug?extid=5ee79919ffe91d629b96
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/3b5906c911a8/disk-f915322f.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/dba92a9c1a17/vmlinux-f915322f.xz
kernel image: https://storage.googleapis.com/syzbot-assets/e4fca23736a8/bzImage-f915322f.xz

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

==================================================================
BUG: KASAN: slab-use-after-free in string_nocheck lib/vsprintf.c:644 [inline]
BUG: KASAN: slab-use-after-free in string+0x218/0x2b0 lib/vsprintf.c:726
Read of size 1 at addr ffff88807d2fc280 by task udevd/4434

CPU: 1 PID: 4434 Comm: udevd Not tainted 6.2.0-syzkaller-13563-gf915322fe014 #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+0x1e7/0x2d0 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:319 [inline]
print_report+0x163/0x540 mm/kasan/report.c:430
kasan_report+0x176/0x1b0 mm/kasan/report.c:536
string_nocheck lib/vsprintf.c:644 [inline]
string+0x218/0x2b0 lib/vsprintf.c:726
vsnprintf+0x10fc/0x1d80 lib/vsprintf.c:2796
add_uevent_var+0x1c4/0x440 lib/kobject_uevent.c:665
dev_uevent+0x3ec/0x8f0 drivers/base/core.c:2527
uevent_show+0x19a/0x310 drivers/base/core.c:2598
dev_attr_show+0x54/0xc0 drivers/base/core.c:2301
sysfs_kf_seq_show+0x331/0x4b0 fs/sysfs/file.c:59
seq_read_iter+0x43e/0xd10 fs/seq_file.c:230
call_read_iter include/linux/fs.h:1845 [inline]
new_sync_read fs/read_write.c:389 [inline]
vfs_read+0x7e2/0xbe0 fs/read_write.c:470
ksys_read+0x1a0/0x2c0 fs/read_write.c:613
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f0a165258fe
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:00007ffec00b7aa8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 0000561c4316e5c0 RCX: 00007f0a165258fe
RDX: 0000000000001000 RSI: 0000561c43189ba0 RDI: 000000000000000c
RBP: 00007f0a165f2380 R08: 000000000000000c R09: 00007f0a165f5a60
R10: 0000000001000000 R11: 0000000000000246 R12: 0000561c4316e5c0
R13: 0000000000000d68 R14: 00007f0a165f1780 R15: 0000000000000d68
</TASK>

Allocated by task 22572:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4f/0x70 mm/kasan/common.c:52
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:383
kmalloc include/linux/slab.h:580 [inline]
raw_ioctl_init drivers/usb/gadget/legacy/raw_gadget.c:460 [inline]
raw_ioctl+0x1aad/0x3cd0 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+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 22572:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4f/0x70 mm/kasan/common.c:52
kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:521
____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
kasan_slab_free include/linux/kasan.h:162 [inline]
slab_free_hook mm/slub.c:1781 [inline]
slab_free_freelist_hook mm/slub.c:1807 [inline]
slab_free mm/slub.c:3787 [inline]
__kmem_cache_free+0x264/0x3c0 mm/slub.c:3800
dev_free drivers/usb/gadget/legacy/raw_gadget.c:210 [inline]
kref_put+0xb5/0x7c0 include/linux/kref.h:65
raw_release+0x138/0x1e0 drivers/usb/gadget/legacy/raw_gadget.c:424
__fput+0x3b7/0x890 fs/file_table.c:321
task_work_run+0x24a/0x300 kernel/task_work.c:179
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0x68f/0x2290 kernel/exit.c:869
do_group_exit+0x206/0x2c0 kernel/exit.c:1019
get_signal+0x1701/0x17e0 kernel/signal.c:2859
arch_do_signal_or_restart+0x91/0x670 arch/x86/kernel/signal.c:306
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+0x64/0x2e0 kernel/entry/common.c:296
do_syscall_64+0x4d/0xc0 arch/x86/entry/common.c:86
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Last potentially related work creation:
kasan_save_stack+0x3f/0x60 mm/kasan/common.c:45
__kasan_record_aux_stack+0xb0/0xc0 mm/kasan/generic.c:491
kvfree_call_rcu+0x109/0x8d0 kernel/rcu/tree.c:3316
cleanup_net+0x9bb/0xb80 net/core/net_namespace.c:631
process_one_work+0x915/0x13a0 kernel/workqueue.c:2390
worker_thread+0xa63/0x1210 kernel/workqueue.c:2537
kthread+0x270/0x300 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

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

The buggy address belongs to the physical page:
page:ffffea0001f4bf00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7d2fc
ksm flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffff888012441500 ffffea00009c4080 dead000000000003
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 0x12cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY), pid 5113, tgid 5113 (syz-executor.1), ts 244087761826, free_ts 244006526484
prep_new_page mm/page_alloc.c:2552 [inline]
get_page_from_freelist+0x37e0/0x3970 mm/page_alloc.c:4325
__alloc_pages+0x291/0x7f0 mm/page_alloc.c:5591
alloc_slab_page+0x6a/0x160 mm/slub.c:1851
allocate_slab mm/slub.c:1998 [inline]
new_slab+0x84/0x2f0 mm/slub.c:2051
___slab_alloc+0xa85/0x10a0 mm/slub.c:3193
__slab_alloc mm/slub.c:3292 [inline]
__slab_alloc_node mm/slub.c:3345 [inline]
slab_alloc_node mm/slub.c:3442 [inline]
__kmem_cache_alloc_node+0x1b8/0x290 mm/slub.c:3491
kmalloc_trace+0x2a/0x60 mm/slab_common.c:1061
kmalloc include/linux/slab.h:580 [inline]
kzalloc include/linux/slab.h:720 [inline]
vlan_vid_info_alloc net/8021q/vlan_core.c:196 [inline]
__vlan_vid_add net/8021q/vlan_core.c:302 [inline]
vlan_vid_add+0x31c/0x750 net/8021q/vlan_core.c:336
bond_vlan_rx_add_vid+0x14f/0x2e0 drivers/net/bonding/bond_main.c:375
vlan_add_rx_filter_info net/8021q/vlan_core.c:211 [inline]
__vlan_vid_add net/8021q/vlan_core.c:306 [inline]
vlan_vid_add+0x647/0x750 net/8021q/vlan_core.c:336
vlan_device_event+0x1cb3/0x1df0 net/8021q/vlan.c:385
notifier_call_chain kernel/notifier.c:87 [inline]
raw_notifier_call_chain+0xd4/0x170 kernel/notifier.c:455
__dev_notify_flags+0x359/0x650
dev_change_flags+0xf0/0x1a0 net/core/dev.c:8604
do_setlink+0xe93/0x2ae0 net/core/rtnetlink.c:2833
__rtnl_newlink net/core/rtnetlink.c:3623 [inline]
rtnl_newlink+0x172d/0x2010 net/core/rtnetlink.c:3670
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1453 [inline]
free_pcp_prepare mm/page_alloc.c:1503 [inline]
free_unref_page_prepare+0xf0e/0xf70 mm/page_alloc.c:3387
free_unref_page+0x37/0x3f0 mm/page_alloc.c:3482
tlb_batch_list_free mm/mmu_gather.c:113 [inline]
tlb_finish_mmu+0x11f/0x1f0 mm/mmu_gather.c:394
exit_mmap+0x2c9/0x990 mm/mmap.c:3047
__mmput+0x115/0x3c0 kernel/fork.c:1209
exit_mm+0x227/0x310 kernel/exit.c:563
do_exit+0x612/0x2290 kernel/exit.c:856
do_group_exit+0x206/0x2c0 kernel/exit.c:1019
__do_sys_exit_group kernel/exit.c:1030 [inline]
__se_sys_exit_group kernel/exit.c:1028 [inline]
__x64_sys_exit_group+0x3f/0x40 kernel/exit.c:1028
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Memory state around the buggy address:
ffff88807d2fc180: 00 00 00 00 fc fc fc fc 00 00 00 00 fc fc fc fc
ffff88807d2fc200: 00 00 00 00 fc fc fc fc 00 00 00 fc fc fc fc fc
>ffff88807d2fc280: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
^
ffff88807d2fc300: 00 00 00 00 fc fc fc fc 00 00 00 00 fc fc fc fc
ffff88807d2fc380: 00 00 00 00 fc fc fc fc 00 00 00 00 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,
Aug 31, 2023, 10:08:52ā€ÆAM8/31/23
to gre...@linuxfoundation.org, linux-...@vger.kernel.org, raf...@kernel.org, syzkall...@googlegroups.com
syzbot has found a reproducer for the following issue on:

HEAD commit: ef2a0b7cdbc5 Merge tag 'devicetree-header-cleanups-for-6.6..
git tree: upstream
console+strace: https://syzkaller.appspot.com/x/log.txt?x=1636912fa80000
kernel config: https://syzkaller.appspot.com/x/.config?x=70a96c99bb5352a3
dashboard link: https://syzkaller.appspot.com/bug?extid=5ee79919ffe91d629b96
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=1113aa10680000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1738dfffa80000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/207d0a5481f5/disk-ef2a0b7c.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/33a620ea40a4/vmlinux-ef2a0b7c.xz
kernel image: https://storage.googleapis.com/syzbot-assets/93ff8f39ac26/bzImage-ef2a0b7c.xz

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

==================================================================
BUG: KASAN: slab-use-after-free in string_nocheck lib/vsprintf.c:645 [inline]
BUG: KASAN: slab-use-after-free in string+0x218/0x2b0 lib/vsprintf.c:727
Read of size 1 at addr ffff88802c09a487 by task udevd/9531

CPU: 0 PID: 9531 Comm: udevd Not tainted 6.5.0-syzkaller-08262-gef2a0b7cdbc5 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:364 [inline]
print_report+0x163/0x540 mm/kasan/report.c:475
kasan_report+0x175/0x1b0 mm/kasan/report.c:588
string_nocheck lib/vsprintf.c:645 [inline]
string+0x218/0x2b0 lib/vsprintf.c:727
vsnprintf+0x10fc/0x1d80 lib/vsprintf.c:2818
add_uevent_var+0x1c4/0x440 lib/kobject_uevent.c:665
dev_uevent+0x3ec/0x8f0 drivers/base/core.c:2575
uevent_show+0x19a/0x310 drivers/base/core.c:2646
dev_attr_show+0x54/0xc0 drivers/base/core.c:2349
sysfs_kf_seq_show+0x331/0x4b0 fs/sysfs/file.c:59
seq_read_iter+0x43e/0xd10 fs/seq_file.c:230
call_read_iter include/linux/fs.h:1979 [inline]
new_sync_read fs/read_write.c:389 [inline]
vfs_read+0x795/0xb00 fs/read_write.c:470
ksys_read+0x1a0/0x2c0 fs/read_write.c:613
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f49f3b16b6a
Code: 00 3d 00 00 41 00 75 0d 50 48 8d 3d 2d 08 0a 00 e8 ea 7d 01 00 31 c0 e9 07 ff ff ff 64 8b 04 25 18 00 00 00 85 c0 75 1b 0f 05 <48> 3d 00 f0 ff ff 76 6c 48 8b 15 8f a2 0d 00 f7 d8 64 89 02 48 83
RSP: 002b:00007ffcd3fc9478 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 000055dfae9e07a0 RCX: 00007f49f3b16b6a
RDX: 0000000000001000 RSI: 000055dfae9e0980 RDI: 0000000000000008
RBP: 000055dfae9e07a0 R08: 0000000000000008 R09: 0000000000000000
R10: 000000000000010f R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000003fff R14: 00007ffcd3fc9958 R15: 000000000000000a
</TASK>

Allocated by task 12253:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4f/0x70 mm/kasan/common.c:52
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:383
kmalloc include/linux/slab.h:599 [inline]
raw_ioctl_init drivers/usb/gadget/legacy/raw_gadget.c:462 [inline]
raw_ioctl+0x1aad/0x3cd0 drivers/usb/gadget/legacy/raw_gadget.c:1252
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:871 [inline]
__se_sys_ioctl+0xf8/0x170 fs/ioctl.c:857
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 12253:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4f/0x70 mm/kasan/common.c:52
kasan_save_free_info+0x28/0x40 mm/kasan/generic.c:522
____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
kasan_slab_free include/linux/kasan.h:162 [inline]
slab_free_hook mm/slub.c:1800 [inline]
slab_free_freelist_hook mm/slub.c:1826 [inline]
slab_free mm/slub.c:3809 [inline]
__kmem_cache_free+0x25f/0x3b0 mm/slub.c:3822
dev_free drivers/usb/gadget/legacy/raw_gadget.c:210 [inline]
kref_put+0xb5/0x7c0 include/linux/kref.h:65
raw_release+0x138/0x1e0 drivers/usb/gadget/legacy/raw_gadget.c:426
__fput+0x3f8/0x910 fs/file_table.c:384
task_work_run+0x24a/0x300 kernel/task_work.c:179
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0x68f/0x2290 kernel/exit.c:874
do_group_exit+0x206/0x2c0 kernel/exit.c:1024
__do_sys_exit_group kernel/exit.c:1035 [inline]
__se_sys_exit_group kernel/exit.c:1033 [inline]
__x64_sys_exit_group+0x3f/0x40 kernel/exit.c:1033
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff88802c09a480
which belongs to the cache kmalloc-32 of size 32
The buggy address is located 7 bytes inside of
freed 32-byte region [ffff88802c09a480, ffff88802c09a4a0)

The buggy address belongs to the physical page:
page:ffffea0000b02680 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2c09a
ksm flags: 0xfff00000000800(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000800 ffff888012841500 ffffea000057f180 dead000000000003
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 0x12c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY), pid 4463, tgid 4463 (S02klogd), ts 15840613892, free_ts 14931433200
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x1e6/0x210 mm/page_alloc.c:1536
prep_new_page mm/page_alloc.c:1543 [inline]
get_page_from_freelist+0x31ec/0x3370 mm/page_alloc.c:3183
__alloc_pages+0x255/0x670 mm/page_alloc.c:4439
alloc_slab_page+0x6a/0x160 mm/slub.c:1870
allocate_slab mm/slub.c:2017 [inline]
new_slab+0x84/0x2f0 mm/slub.c:2070
___slab_alloc+0xade/0x1100 mm/slub.c:3223
__slab_alloc mm/slub.c:3322 [inline]
__slab_alloc_node mm/slub.c:3375 [inline]
slab_alloc_node mm/slub.c:3468 [inline]
__kmem_cache_alloc_node+0x1af/0x270 mm/slub.c:3517
__do_kmalloc_node mm/slab_common.c:1022 [inline]
__kmalloc+0xa8/0x230 mm/slab_common.c:1036
kmalloc include/linux/slab.h:603 [inline]
kzalloc include/linux/slab.h:720 [inline]
tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
tomoyo_encode+0x26f/0x530 security/tomoyo/realpath.c:80
tomoyo_realpath_from_path+0x598/0x5e0 security/tomoyo/realpath.c:283
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_check_open_permission+0x254/0x4e0 security/tomoyo/file.c:771
security_file_open+0x63/0xa0 security/security.c:2836
do_dentry_open+0x325/0x1430 fs/open.c:916
do_open fs/namei.c:3639 [inline]
path_openat+0x27bb/0x3180 fs/namei.c:3796
do_filp_open+0x234/0x490 fs/namei.c:3823
do_sys_openat2+0x13e/0x1d0 fs/open.c:1422
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1136 [inline]
free_unref_page_prepare+0x8c3/0x9f0 mm/page_alloc.c:2312
free_unref_page+0x37/0x3f0 mm/page_alloc.c:2405
kasan_depopulate_vmalloc_pte+0x74/0x90 mm/kasan/shadow.c:427
apply_to_pte_range mm/memory.c:2585 [inline]
apply_to_pmd_range mm/memory.c:2629 [inline]
apply_to_pud_range mm/memory.c:2665 [inline]
apply_to_p4d_range mm/memory.c:2701 [inline]
__apply_to_page_range+0x8e2/0xdf0 mm/memory.c:2735
kasan_release_vmalloc+0x9a/0xb0 mm/kasan/shadow.c:544
__purge_vmap_area_lazy+0xc0f/0x19c0 mm/vmalloc.c:1770
_vm_unmap_aliases+0x79d/0x840 mm/vmalloc.c:2306
change_page_attr_set_clr+0x2f8/0xf80 arch/x86/mm/pat/set_memory.c:1838
change_page_attr_set arch/x86/mm/pat/set_memory.c:1879 [inline]
set_memory_nx+0xf2/0x130 arch/x86/mm/pat/set_memory.c:2072
free_init_pages arch/x86/mm/init.c:927 [inline]
free_kernel_image_pages arch/x86/mm/init.c:946 [inline]
free_initmem+0x75/0xc0 arch/x86/mm/init.c:973
kernel_init+0x31/0x2a0 init/main.c:1446
ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:145
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304

Memory state around the buggy address:
ffff88802c09a380: 00 00 00 fc fc fc fc fc fa fb fb fb fc fc fc fc
ffff88802c09a400: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
>ffff88802c09a480: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
^
ffff88802c09a500: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
ffff88802c09a580: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
==================================================================


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

Hillf Danton

unread,
Sep 1, 2023, 5:25:15ā€ÆAM9/1/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Thu, 31 Aug 2023 07:08:50 -0700
> HEAD commit: ef2a0b7cdbc5 Merge tag 'devicetree-header-cleanups-for-6.6..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1738dfffa80000

Unregister driver if needed.

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

--- x/drivers/usb/gadget/legacy/raw_gadget.c
+++ y/drivers/usb/gadget/legacy/raw_gadget.c
@@ -402,10 +402,6 @@ static int raw_release(struct inode *ino

spin_lock_irqsave(&dev->lock, flags);
dev->state = STATE_DEV_CLOSED;
- if (!dev->gadget) {
- spin_unlock_irqrestore(&dev->lock, flags);
- goto out_put;
- }
if (dev->gadget_registered)
unregister = true;
dev->gadget_registered = false;
--

syzbot

unread,
Sep 1, 2023, 6:48:27ā€ÆAM9/1/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in dev_uevent

==================================================================
BUG: KASAN: slab-use-after-free in string_nocheck lib/vsprintf.c:645 [inline]
BUG: KASAN: slab-use-after-free in string+0x218/0x2b0 lib/vsprintf.c:727
Read of size 1 at addr ffff8880156b6b80 by task udevd/4483

CPU: 0 PID: 4483 Comm: udevd Not tainted 6.5.0-syzkaller-09276-g99d99825fc07-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:364 [inline]
print_report+0x163/0x540 mm/kasan/report.c:475
kasan_report+0x175/0x1b0 mm/kasan/report.c:588
string_nocheck lib/vsprintf.c:645 [inline]
string+0x218/0x2b0 lib/vsprintf.c:727
vsnprintf+0x10fc/0x1d80 lib/vsprintf.c:2818
add_uevent_var+0x1c4/0x440 lib/kobject_uevent.c:665
dev_uevent+0x3ec/0x8f0 drivers/base/core.c:2575
uevent_show+0x19a/0x310 drivers/base/core.c:2646
dev_attr_show+0x54/0xc0 drivers/base/core.c:2349
sysfs_kf_seq_show+0x331/0x4b0 fs/sysfs/file.c:59
seq_read_iter+0x43e/0xd10 fs/seq_file.c:230
call_read_iter include/linux/fs.h:1979 [inline]
new_sync_read fs/read_write.c:389 [inline]
vfs_read+0x795/0xb00 fs/read_write.c:470
ksys_read+0x1a0/0x2c0 fs/read_write.c:613
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fd11cb16b6a
Code: 00 3d 00 00 41 00 75 0d 50 48 8d 3d 2d 08 0a 00 e8 ea 7d 01 00 31 c0 e9 07 ff ff ff 64 8b 04 25 18 00 00 00 85 c0 75 1b 0f 05 <48> 3d 00 f0 ff ff 76 6c 48 8b 15 8f a2 0d 00 f7 d8 64 89 02 48 83
RSP: 002b:00007ffea04bfe78 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 0000556f408ae0f0 RCX: 00007fd11cb16b6a
RDX: 0000000000001000 RSI: 0000556f408d6790 RDI: 000000000000000c
RBP: 0000556f408ae0f0 R08: 000000000000000c R09: 0000000000000200
R10: 000000000000010f R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000003fff R14: 00007ffea04c0358 R15: 000000000000000a
</TASK>

Allocated by task 14097:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4f/0x70 mm/kasan/common.c:52
____kasan_kmalloc mm/kasan/common.c:374 [inline]
__kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:383
kmalloc include/linux/slab.h:599 [inline]
raw_ioctl_init drivers/usb/gadget/legacy/raw_gadget.c:458 [inline]
raw_ioctl+0x1aad/0x3cd0 drivers/usb/gadget/legacy/raw_gadget.c:1248
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:871 [inline]
__se_sys_ioctl+0xf8/0x170 fs/ioctl.c:857
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 14097:
kasan_save_stack mm/kasan/common.c:45 [inline]
kasan_set_track+0x4f/0x70 mm/kasan/common.c:52
kasan_save_free_info+0x28/0x40 mm/kasan/generic.c:522
____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
kasan_slab_free include/linux/kasan.h:162 [inline]
slab_free_hook mm/slub.c:1800 [inline]
slab_free_freelist_hook mm/slub.c:1826 [inline]
slab_free mm/slub.c:3809 [inline]
__kmem_cache_free+0x25f/0x3b0 mm/slub.c:3822
dev_free drivers/usb/gadget/legacy/raw_gadget.c:210 [inline]
kref_put+0xb5/0x7c0 include/linux/kref.h:65
raw_release+0xfb/0x1a0 drivers/usb/gadget/legacy/raw_gadget.c:422
__fput+0x3f8/0x910 fs/file_table.c:384
task_work_run+0x24a/0x300 kernel/task_work.c:179
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0x68f/0x2290 kernel/exit.c:874
do_group_exit+0x206/0x2c0 kernel/exit.c:1024
__do_sys_exit_group kernel/exit.c:1035 [inline]
__se_sys_exit_group kernel/exit.c:1033 [inline]
__x64_sys_exit_group+0x3f/0x40 kernel/exit.c:1033
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd

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

The buggy address belongs to the physical page:
page:ffffea000055ad80 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x156b6
flags: 0xfff00000000800(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000800 ffff888012841500 dead000000000100 dead000000000122
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 5402, tgid 5402 (syz-executor.5), ts 82260246009, free_ts 82239822109
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x1e6/0x210 mm/page_alloc.c:1536
prep_new_page mm/page_alloc.c:1543 [inline]
get_page_from_freelist+0x31ec/0x3370 mm/page_alloc.c:3183
__alloc_pages+0x255/0x670 mm/page_alloc.c:4439
alloc_slab_page+0x6a/0x160 mm/slub.c:1870
allocate_slab mm/slub.c:2017 [inline]
new_slab+0x84/0x2f0 mm/slub.c:2070
___slab_alloc+0xade/0x1100 mm/slub.c:3223
__slab_alloc mm/slub.c:3322 [inline]
__slab_alloc_node mm/slub.c:3375 [inline]
slab_alloc_node mm/slub.c:3468 [inline]
__kmem_cache_alloc_node+0x1af/0x270 mm/slub.c:3517
kmalloc_trace+0x2a/0xe0 mm/slab_common.c:1114
kmalloc include/linux/slab.h:599 [inline]
kzalloc include/linux/slab.h:720 [inline]
ref_tracker_alloc+0x14b/0x480 lib/ref_tracker.c:203
__netdev_tracker_alloc include/linux/netdevice.h:4056 [inline]
netdev_tracker_alloc include/linux/netdevice.h:4068 [inline]
netdev_get_by_index+0x7a/0xb0 net/core/dev.c:888
fib6_nh_init+0x1da/0x2140 net/ipv6/route.c:3528
ip6_route_info_create+0x95e/0x1220 net/ipv6/route.c:3796
addrconf_f6i_alloc+0x3c2/0x7f0 net/ipv6/route.c:4569
ipv6_add_addr+0x5a5/0x10c0 net/ipv6/addrconf.c:1114
inet6_addr_add+0x55c/0xaf0 net/ipv6/addrconf.c:2997
inet6_rtm_newaddr+0x89e/0xc80 net/ipv6/addrconf.c:4972
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1136 [inline]
free_unref_page_prepare+0x8c3/0x9f0 mm/page_alloc.c:2312
free_unref_page+0x37/0x3f0 mm/page_alloc.c:2405
__slab_free+0x2f6/0x390 mm/slub.c:3715
qlist_free_all+0x22/0x60 mm/kasan/quarantine.c:185
kasan_quarantine_reduce+0x14b/0x160 mm/kasan/quarantine.c:292
__kasan_slab_alloc+0x23/0x70 mm/kasan/common.c:305
kasan_slab_alloc include/linux/kasan.h:186 [inline]
slab_post_alloc_hook+0x6c/0x3b0 mm/slab.h:762
slab_alloc_node mm/slub.c:3478 [inline]
__kmem_cache_alloc_node+0x141/0x270 mm/slub.c:3517
kmalloc_trace+0x2a/0xe0 mm/slab_common.c:1114
kmalloc include/linux/slab.h:599 [inline]
netdevice_queue_work drivers/infiniband/core/roce_gid_mgmt.c:643 [inline]
netdevice_event+0x37d/0x950 drivers/infiniband/core/roce_gid_mgmt.c:802
notifier_call_chain+0x18c/0x3a0 kernel/notifier.c:93
__dev_notify_flags+0x359/0x650
dev_change_flags+0xf0/0x1a0 net/core/dev.c:8674
do_setlink+0xfb2/0x4340 net/core/rtnetlink.c:2880
__rtnl_newlink net/core/rtnetlink.c:3671 [inline]
rtnl_newlink+0x17f6/0x2070 net/core/rtnetlink.c:3718
rtnetlink_rcv_msg+0x82b/0xf50 net/core/rtnetlink.c:6444

Memory state around the buggy address:
ffff8880156b6a80: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
ffff8880156b6b00: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
>ffff8880156b6b80: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
^
ffff8880156b6c00: 00 00 00 00 fc fc fc fc fa fb fb fb fc fc fc fc
ffff8880156b6c80: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
==================================================================


Tested on:

commit: 99d99825 Merge tag 'nfs-for-6.6-1' of git://git.linux-..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=150c6d87a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=b8954a0dbb2cea01
dashboard link: https://syzkaller.appspot.com/bug?extid=5ee79919ffe91d629b96
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=177a8fffa80000

Hillf Danton

unread,
Sep 2, 2023, 4:49:06ā€ÆAM9/2/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Thu, 31 Aug 2023 07:08:50 -0700
> HEAD commit: ef2a0b7cdbc5 Merge tag 'devicetree-header-cleanups-for-6.6..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1738dfffa80000

Unregister driver after unregistering device.
--- o/drivers/usb/gadget/udc/core.c
+++ p/drivers/usb/gadget/udc/core.c
@@ -1534,6 +1534,8 @@ void usb_del_gadget(struct usb_gadget *g
ida_free(&gadget_id_numbers, gadget->id_number);
cancel_work_sync(&udc->vbus_work);
device_unregister(&udc->dev);
+ if (udc->driver && udc->driver->unbind)
+ udc->driver->unbind(gadget);
}
EXPORT_SYMBOL_GPL(usb_del_gadget);

@@ -1646,7 +1648,6 @@ static void gadget_unbind_driver(struct
synchronize_irq(gadget->irq);
mutex_unlock(&udc->connect_lock);

- udc->driver->unbind(gadget);

mutex_lock(&udc->connect_lock);
usb_gadget_udc_stop_locked(udc);
@@ -1654,7 +1655,6 @@ static void gadget_unbind_driver(struct

mutex_lock(&udc_lock);
driver->is_bound = false;
- udc->driver = NULL;
mutex_unlock(&udc_lock);
}

--

syzbot

unread,
Sep 2, 2023, 5:18:32ā€ÆAM9/2/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+5ee799...@syzkaller.appspotmail.com

Tested on:

commit: 0468be89 Merge tag 'iommu-updates-v6.6' of git://git.k..
console output: https://syzkaller.appspot.com/x/log.txt?x=143d4f50680000
kernel config: https://syzkaller.appspot.com/x/.config?x=c33cc29407ed9ff7
dashboard link: https://syzkaller.appspot.com/bug?extid=5ee79919ffe91d629b96
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=13e9be77a80000

Note: testing is done by a robot and is best-effort only.
Reply all
Reply to author
Forward
0 new messages