================================================================== BUG: KASAN: use-after-free in string_nocheck lib/vsprintf.c:644 [inline] BUG: KASAN: use-after-free in string+0x218/0x2b0 lib/vsprintf.c:726 Read of size 1 at addr ffff888029068d80 by task udevd/17790 CPU: 0 PID: 17790 Comm: udevd Not tainted 6.2.0-rc7-syzkaller-00135-g38c1e0c65865 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/21/2023 Call Trace: __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:306 [inline] print_report+0x163/0x4f0 mm/kasan/report.c:417 kasan_report+0x13a/0x170 mm/kasan/report.c:517 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:2422 uevent_show+0x19a/0x310 drivers/base/core.c:2493 dev_attr_show+0x54/0xc0 drivers/base/core.c:2196 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:2183 [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:0x7f8e90f258fe 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:00007ffe6ebe3038 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 RAX: ffffffffffffffda RBX: 000055b3b0c1e7c0 RCX: 00007f8e90f258fe RDX: 0000000000001000 RSI: 000055b3b0c5bb40 RDI: 0000000000000008 RBP: 00007f8e90ff2380 R08: 0000000000000008 R09: 00007f8e90ff5a60 R10: 0000000000000080 R11: 0000000000000246 R12: 000055b3b0c1e7c0 R13: 0000000000000d68 R14: 00007f8e90ff1780 R15: 0000000000000d68 Allocated by task 18080: kasan_save_stack mm/kasan/common.c:45 [inline] kasan_set_track+0x4f/0x80 mm/kasan/common.c:52 ____kasan_kmalloc mm/kasan/common.c:371 [inline] __kasan_kmalloc+0x9b/0xb0 mm/kasan/common.c:380 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 18080: kasan_save_stack mm/kasan/common.c:45 [inline] kasan_set_track+0x4f/0x80 mm/kasan/common.c:52 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:518 ____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: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:320 task_work_run+0x24a/0x300 kernel/task_work.c:179 exit_task_work include/linux/task_work.h:38 [inline] do_exit+0x605/0x2210 kernel/exit.c:867 do_group_exit+0x206/0x2c0 kernel/exit.c:1012 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 The buggy address belongs to the object at ffff888029068d80 which belongs to the cache kmalloc-32 of size 32 The buggy address is located 0 bytes inside of 32-byte region [ffff888029068d80, ffff888029068da0) The buggy address belongs to the physical page: page:ffffea0000a41a00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x29068 flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff) raw: 00fff00000000200 ffff888012441500 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 0x112c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_HARDWALL), pid 5106, tgid 5106 (syz-executor.4), ts 912608319531, free_ts 912514849051 prep_new_page mm/page_alloc.c:2531 [inline] get_page_from_freelist+0x3449/0x35c0 mm/page_alloc.c:4283 __alloc_pages+0x291/0x7e0 mm/page_alloc.c:5549 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/0x2a0 mm/slub.c:3491 __do_kmalloc_node mm/slab_common.c:967 [inline] __kmalloc+0xa2/0x1a0 mm/slab_common.c:981 kmalloc include/linux/slab.h:584 [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_path_number_perm+0x210/0x840 security/tomoyo/file.c:723 security_file_ioctl+0x71/0xa0 security/security.c:1624 __do_sys_ioctl fs/ioctl.c:864 [inline] __se_sys_ioctl+0x47/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 page last free stack trace: reset_page_owner include/linux/page_owner.h:24 [inline] free_pages_prepare mm/page_alloc.c:1446 [inline] free_pcp_prepare mm/page_alloc.c:1496 [inline] free_unref_page_prepare+0xf3a/0x1040 mm/page_alloc.c:3369 free_unref_page_list+0x6b1/0x950 mm/page_alloc.c:3510 release_pages+0x219e/0x2470 mm/swap.c:1076 tlb_batch_pages_flush mm/mmu_gather.c:97 [inline] tlb_flush_mmu_free mm/mmu_gather.c:292 [inline] tlb_flush_mmu+0x100/0x210 mm/mmu_gather.c:299 tlb_finish_mmu+0xd4/0x1f0 mm/mmu_gather.c:391 exit_mmap+0x2c6/0x970 mm/mmap.c:3100 __mmput+0x115/0x3c0 kernel/fork.c:1207 exit_mm+0x227/0x310 kernel/exit.c:563 do_exit+0x588/0x2210 kernel/exit.c:854 do_group_exit+0x206/0x2c0 kernel/exit.c:1012 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 Memory state around the buggy address: ffff888029068c80: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ffff888029068d00: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc >ffff888029068d80: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ^ ffff888029068e00: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ffff888029068e80: 00 00 00 fc fc fc fc fc 00 00 00 00 fc fc fc fc ==================================================================