================================================================== BUG: KASAN: use-after-free in string_nocheck lib/vsprintf.c:643 [inline] BUG: KASAN: use-after-free in string+0x39c/0x3d0 lib/vsprintf.c:725 Read of size 1 at addr ffff8880739ba780 by task udevd/2972 CPU: 1 PID: 2972 Comm: udevd Not tainted 6.0.0-rc7-syzkaller-00068-g49c13ed0316d #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/26/2022 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:317 [inline] print_report.cold+0x2ba/0x6e9 mm/kasan/report.c:433 kasan_report+0xb1/0x1e0 mm/kasan/report.c:495 string_nocheck lib/vsprintf.c:643 [inline] string+0x39c/0x3d0 lib/vsprintf.c:725 vsnprintf+0x71b/0x14f0 lib/vsprintf.c:2782 add_uevent_var+0x15d/0x380 lib/kobject_uevent.c:665 dev_uevent+0x18d/0x770 drivers/base/core.c:2421 uevent_show+0x1b8/0x380 drivers/base/core.c:2492 dev_attr_show+0x4b/0x90 drivers/base/core.c:2195 sysfs_kf_seq_show+0x219/0x3d0 fs/sysfs/file.c:59 kernfs_seq_show+0x169/0x1e0 fs/kernfs/file.c:217 seq_read_iter+0x4f5/0x1280 fs/seq_file.c:230 kernfs_fop_read_iter+0x523/0x710 fs/kernfs/file.c:299 call_read_iter include/linux/fs.h:2181 [inline] new_sync_read fs/read_write.c:389 [inline] vfs_read+0x67d/0x930 fs/read_write.c:470 ksys_read+0x127/0x250 fs/read_write.c:607 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7f3e1f7258fe 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:00007ffd8d2fbeb8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 RAX: ffffffffffffffda RBX: 00005562de564480 RCX: 00007f3e1f7258fe RDX: 0000000000001000 RSI: 00005562de58ff10 RDI: 000000000000000c RBP: 00007f3e1f7f2380 R08: 000000000000000c R09: 00007f3e1f7f5a60 R10: 0000000000000004 R11: 0000000000000246 R12: 00005562de564480 R13: 0000000000000d68 R14: 00007f3e1f7f1780 R15: 0000000000000d68 Allocated by task 11650: kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38 kasan_set_track mm/kasan/common.c:45 [inline] set_alloc_info mm/kasan/common.c:437 [inline] ____kasan_kmalloc mm/kasan/common.c:516 [inline] ____kasan_kmalloc mm/kasan/common.c:475 [inline] __kasan_kmalloc+0xa6/0xd0 mm/kasan/common.c:525 kasan_kmalloc include/linux/kasan.h:234 [inline] kmem_cache_alloc_trace+0x25a/0x460 mm/slab.c:3559 kmalloc include/linux/slab.h:600 [inline] raw_ioctl_init+0x152/0x820 drivers/usb/gadget/legacy/raw_gadget.c:460 raw_ioctl+0x8ef/0x2740 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 fs/ioctl.c:856 [inline] __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd Freed by task 11650: kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38 kasan_set_track+0x21/0x30 mm/kasan/common.c:45 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370 ____kasan_slab_free mm/kasan/common.c:367 [inline] ____kasan_slab_free+0x13d/0x1a0 mm/kasan/common.c:329 kasan_slab_free include/linux/kasan.h:200 [inline] __cache_free mm/slab.c:3418 [inline] kfree+0x173/0x390 mm/slab.c:3786 dev_free+0x9a/0x700 drivers/usb/gadget/legacy/raw_gadget.c:210 kref_put include/linux/kref.h:65 [inline] raw_release+0x219/0x290 drivers/usb/gadget/legacy/raw_gadget.c:424 __fput+0x277/0x9d0 fs/file_table.c:320 task_work_run+0xdd/0x1a0 kernel/task_work.c:177 exit_task_work include/linux/task_work.h:38 [inline] do_exit+0xad5/0x29b0 kernel/exit.c:795 do_group_exit+0xd2/0x2f0 kernel/exit.c:925 get_signal+0x238c/0x2610 kernel/signal.c:2857 arch_do_signal_or_restart+0x82/0x2300 arch/x86/kernel/signal.c:869 exit_to_user_mode_loop kernel/entry/common.c:166 [inline] exit_to_user_mode_prepare+0x15f/0x250 kernel/entry/common.c:201 __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline] syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294 do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86 entry_SYSCALL_64_after_hwframe+0x63/0xcd The buggy address belongs to the object at ffff8880739ba780 which belongs to the cache kmalloc-32 of size 32 The buggy address is located 0 bytes inside of 32-byte region [ffff8880739ba780, ffff8880739ba7a0) The buggy address belongs to the physical page: page:ffffea0001ce6e80 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff8880739bafc1 pfn:0x739ba flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff) raw: 00fff00000000200 ffffea0001edb348 ffffea0000865208 ffff888011840100 raw: ffff8880739bafc1 ffff8880739ba000 000000010000003f 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 0x342220(__GFP_HIGH|__GFP_ATOMIC|__GFP_NOWARN|__GFP_COMP|__GFP_HARDWALL|__GFP_THISNODE), pid 3838, tgid 3838 (syz-executor.1), ts 356062603283, free_ts 355708343242 prep_new_page mm/page_alloc.c:2532 [inline] get_page_from_freelist+0x109b/0x2ce0 mm/page_alloc.c:4283 __alloc_pages+0x1c7/0x510 mm/page_alloc.c:5549 __alloc_pages_node include/linux/gfp.h:243 [inline] kmem_getpages mm/slab.c:1363 [inline] cache_grow_begin+0x75/0x360 mm/slab.c:2569 cache_alloc_refill+0x27f/0x380 mm/slab.c:2942 ____cache_alloc mm/slab.c:3018 [inline] ____cache_alloc mm/slab.c:3001 [inline] __do_cache_alloc mm/slab.c:3246 [inline] slab_alloc mm/slab.c:3287 [inline] __do_kmalloc mm/slab.c:3684 [inline] __kmalloc_track_caller+0x39e/0x4a0 mm/slab.c:3701 kmemdup+0x23/0x50 mm/util.c:129 kmemdup include/linux/fortify-string.h:456 [inline] sidtab_sid2str_get+0x17c/0x650 security/selinux/ss/sidtab.c:615 sidtab_entry_to_string+0x33/0x110 security/selinux/ss/services.c:1285 security_sid_to_context_core+0x344/0x590 security/selinux/ss/services.c:1378 selinux_inode_init_security+0x4c8/0x6b0 security/selinux/hooks.c:2906 security_inode_init_security+0x14b/0x370 security/security.c:1106 __ext4_new_inode+0x3a37/0x5690 fs/ext4/ialloc.c:1325 ext4_symlink+0x5a8/0xa00 fs/ext4/namei.c:3356 vfs_symlink fs/namei.c:4378 [inline] vfs_symlink+0x365/0x5b0 fs/namei.c:4363 do_symlinkat+0x261/0x2e0 fs/namei.c:4407 __do_sys_symlinkat fs/namei.c:4424 [inline] __se_sys_symlinkat fs/namei.c:4421 [inline] __x64_sys_symlinkat+0x93/0xc0 fs/namei.c:4421 page last free stack trace: reset_page_owner include/linux/page_owner.h:24 [inline] free_pages_prepare mm/page_alloc.c:1449 [inline] free_pcp_prepare+0x5e4/0xd20 mm/page_alloc.c:1499 free_unref_page_prepare mm/page_alloc.c:3380 [inline] free_unref_page_list+0x16f/0xb90 mm/page_alloc.c:3522 release_pages+0xbd3/0x1400 mm/swap.c:1012 tlb_batch_pages_flush+0xa8/0x1a0 mm/mmu_gather.c:58 tlb_flush_mmu_free mm/mmu_gather.c:255 [inline] tlb_flush_mmu mm/mmu_gather.c:262 [inline] tlb_finish_mmu+0x147/0x7e0 mm/mmu_gather.c:353 exit_mmap+0x1d2/0x490 mm/mmap.c:3118 __mmput+0x122/0x4b0 kernel/fork.c:1187 mmput+0x56/0x60 kernel/fork.c:1208 exit_mm kernel/exit.c:510 [inline] do_exit+0x9e2/0x29b0 kernel/exit.c:782 do_group_exit+0xd2/0x2f0 kernel/exit.c:925 get_signal+0x238c/0x2610 kernel/signal.c:2857 arch_do_signal_or_restart+0x82/0x2300 arch/x86/kernel/signal.c:869 exit_to_user_mode_loop kernel/entry/common.c:166 [inline] exit_to_user_mode_prepare+0x15f/0x250 kernel/entry/common.c:201 __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline] syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294 do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86 entry_SYSCALL_64_after_hwframe+0x63/0xcd Memory state around the buggy address: ffff8880739ba680: 00 00 00 00 fc fc fc fc 00 00 00 fc fc fc fc fc ffff8880739ba700: 00 00 fc fc fc fc fc fc 00 00 00 fc fc fc fc fc >ffff8880739ba780: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc ^ ffff8880739ba800: 00 00 00 00 fc fc fc fc 00 00 00 fc fc fc fc fc ffff8880739ba880: 00 00 00 fc fc fc fc fc 00 00 fc fc fc fc fc fc ==================================================================