================================================================== 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 ffff88801d29d440 by task udevd/2996 CPU: 0 PID: 2996 Comm: udevd Not tainted 6.1.0-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xd1/0x138 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:284 [inline] print_report+0x15e/0x461 mm/kasan/report.c:395 kasan_report+0xbf/0x1f0 mm/kasan/report.c:495 string_nocheck lib/vsprintf.c:643 [inline] string+0x39c/0x3d0 lib/vsprintf.c:725 vsnprintf+0xa11/0x16b0 lib/vsprintf.c:2800 add_uevent_var+0x161/0x390 lib/kobject_uevent.c:665 dev_uevent+0x191/0x780 drivers/base/core.c:2421 uevent_show+0x1bc/0x380 drivers/base/core.c:2492 dev_attr_show+0x4f/0x90 drivers/base/core.c:2195 sysfs_kf_seq_show+0x21d/0x3d0 fs/sysfs/file.c:59 seq_read_iter+0x4f9/0x1280 fs/seq_file.c:230 kernfs_fop_read_iter+0x546/0x7a0 fs/kernfs/file.c:275 call_read_iter include/linux/fs.h:2193 [inline] new_sync_read fs/read_write.c:389 [inline] vfs_read+0x681/0x930 fs/read_write.c:470 ksys_read+0x12b/0x250 fs/read_write.c:613 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7f67833258fe 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:00007ffd70518638 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 RAX: ffffffffffffffda RBX: 000055c2c5910730 RCX: 00007f67833258fe RDX: 0000000000001000 RSI: 000055c2c5b5c200 RDI: 000000000000000c RBP: 00007f67833f2380 R08: 000000000000000c R09: 00007f67833f5a60 R10: 0000000000000063 R11: 0000000000000246 R12: 000055c2c5910730 R13: 0000000000000d68 R14: 00007f67833f1780 R15: 0000000000000d68 Allocated by task 18272: kasan_save_stack+0x22/0x40 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 ____kasan_kmalloc mm/kasan/common.c:371 [inline] ____kasan_kmalloc mm/kasan/common.c:330 [inline] __kasan_kmalloc+0xa3/0xb0 mm/kasan/common.c:380 kmalloc include/linux/slab.h:553 [inline] raw_ioctl_init+0x152/0x820 drivers/usb/gadget/legacy/raw_gadget.c:460 raw_ioctl+0xbf5/0x27d0 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+0x197/0x210 fs/ioctl.c:856 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd Freed by task 18266: kasan_save_stack+0x22/0x40 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:511 ____kasan_slab_free mm/kasan/common.c:236 [inline] ____kasan_slab_free+0x13b/0x1a0 mm/kasan/common.c:200 kasan_slab_free include/linux/kasan.h:177 [inline] __cache_free mm/slab.c:3389 [inline] __do_kmem_cache_free mm/slab.c:3585 [inline] __kmem_cache_free+0xcd/0x3b0 mm/slab.c:3592 dev_free+0x9a/0x700 drivers/usb/gadget/legacy/raw_gadget.c:210 kref_put include/linux/kref.h:65 [inline] raw_release+0x21d/0x290 drivers/usb/gadget/legacy/raw_gadget.c:424 __fput+0x27c/0xa90 fs/file_table.c:320 task_work_run+0x16f/0x270 kernel/task_work.c:179 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline] exit_to_user_mode_loop kernel/entry/common.c:171 [inline] exit_to_user_mode_prepare+0x23c/0x250 kernel/entry/common.c:203 __syscall_exit_to_user_mode_work kernel/entry/common.c:285 [inline] syscall_exit_to_user_mode+0x1d/0x50 kernel/entry/common.c:296 do_syscall_64+0x46/0xb0 arch/x86/entry/common.c:86 entry_SYSCALL_64_after_hwframe+0x63/0xcd The buggy address belongs to the object at ffff88801d29d440 which belongs to the cache kmalloc-32 of size 32 The buggy address is located 0 bytes inside of 32-byte region [ffff88801d29d440, ffff88801d29d460) The buggy address belongs to the physical page: page:ffffea000074a740 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88801d29dfc1 pfn:0x1d29d flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff) raw: 00fff00000000200 ffffea0000865408 ffffea0000a139c8 ffff888012040100 raw: ffff88801d29dfc1 ffff88801d29d000 000000010000003b 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 0x3420c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_COMP|__GFP_HARDWALL|__GFP_THISNODE), pid 3695, tgid 3695 (syz-executor.5), ts 699872111150, free_ts 699871980176 prep_new_page mm/page_alloc.c:2539 [inline] get_page_from_freelist+0x10b5/0x2d50 mm/page_alloc.c:4291 __alloc_pages+0x1cb/0x5b0 mm/page_alloc.c:5558 __alloc_pages_node include/linux/gfp.h:237 [inline] kmem_getpages mm/slab.c:1363 [inline] cache_grow_begin+0x94/0x390 mm/slab.c:2570 cache_alloc_refill+0x27f/0x380 mm/slab.c:2943 ____cache_alloc mm/slab.c:3019 [inline] ____cache_alloc mm/slab.c:3002 [inline] __do_cache_alloc mm/slab.c:3202 [inline] slab_alloc_node mm/slab.c:3250 [inline] __kmem_cache_alloc_node+0x44a/0x510 mm/slab.c:3549 __do_kmalloc_node mm/slab_common.c:954 [inline] __kmalloc_node+0x4d/0xd0 mm/slab_common.c:962 kmalloc_node include/linux/slab.h:579 [inline] __vmalloc_area_node mm/vmalloc.c:3029 [inline] __vmalloc_node_range+0xa11/0x13c0 mm/vmalloc.c:3213 __vmalloc_node mm/vmalloc.c:3278 [inline] vzalloc+0x6b/0x80 mm/vmalloc.c:3351 xt_counters_alloc+0x50/0x70 net/netfilter/x_tables.c:1379 __do_replace+0x9a/0x8e0 net/ipv4/netfilter/ip_tables.c:1049 do_replace net/ipv4/netfilter/ip_tables.c:1140 [inline] do_ipt_set_ctl+0x89d/0xb10 net/ipv4/netfilter/ip_tables.c:1630 nf_setsockopt+0x87/0xe0 net/netfilter/nf_sockopt.c:101 ip_setsockopt+0xf2/0x110 net/ipv4/ip_sockglue.c:1444 tcp_setsockopt+0x9f/0x100 net/ipv4/tcp.c:3800 __sys_setsockopt+0x2da/0x6a0 net/socket.c:2252 __do_sys_setsockopt net/socket.c:2263 [inline] __se_sys_setsockopt net/socket.c:2260 [inline] __x64_sys_setsockopt+0xbe/0x160 net/socket.c:2260 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+0x65c/0xd90 mm/page_alloc.c:1509 free_unref_page_prepare mm/page_alloc.c:3387 [inline] free_unref_page+0x1d/0x4d0 mm/page_alloc.c:3483 __vunmap+0x85d/0xd30 mm/vmalloc.c:2713 __vfree+0x3c/0xd0 mm/vmalloc.c:2761 vfree+0x5e/0x90 mm/vmalloc.c:2792 copy_entries_to_user net/ipv4/netfilter/ip_tables.c:868 [inline] get_entries net/ipv4/netfilter/ip_tables.c:1024 [inline] do_ipt_get_ctl+0x802/0x9e0 net/ipv4/netfilter/ip_tables.c:1663 nf_getsockopt+0x76/0xd0 net/netfilter/nf_sockopt.c:116 ip_getsockopt+0x189/0x1e0 net/ipv4/ip_sockglue.c:1796 tcp_getsockopt+0x99/0x100 net/ipv4/tcp.c:4401 __sys_getsockopt+0x21a/0x6a0 net/socket.c:2296 __do_sys_getsockopt net/socket.c:2311 [inline] __se_sys_getsockopt net/socket.c:2308 [inline] __x64_sys_getsockopt+0xbe/0x160 net/socket.c:2308 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd Memory state around the buggy address: ffff88801d29d300: 00 00 00 00 fc fc fc fc 00 00 00 00 fc fc fc fc ffff88801d29d380: fb fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc >ffff88801d29d400: 00 00 00 00 fc fc fc fc fa fb fb fb fc fc fc fc ^ ffff88801d29d480: 00 fc fc fc fc fc fc fc fa fb fb fb fc fc fc fc ffff88801d29d500: 00 fc fc fc fc fc fc fc 05 fc fc fc fc fc fc fc ==================================================================