================================================================== BUG: KASAN: double-free in dev_free drivers/usb/gadget/legacy/raw_gadget.c:225 [inline] BUG: KASAN: double-free in kref_put+0x4ab/0x7c0 include/linux/kref.h:65 Free of addr ffff888072410200 by task syz.1.2348/12826 CPU: 0 UID: 0 PID: 12826 Comm: syz.1.2348 Not tainted 6.12.0-rc1-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 Call Trace: __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:377 [inline] print_report+0x169/0x550 mm/kasan/report.c:488 kasan_report_invalid_free+0x11a/0x140 mm/kasan/report.c:563 check_slab_allocation+0xc6/0x110 kasan_slab_pre_free include/linux/kasan.h:195 [inline] slab_free_hook mm/slub.c:2288 [inline] slab_free mm/slub.c:4580 [inline] kfree+0x151/0x440 mm/slub.c:4728 dev_free drivers/usb/gadget/legacy/raw_gadget.c:225 [inline] kref_put+0x4ab/0x7c0 include/linux/kref.h:65 raw_release+0x135/0x1e0 drivers/usb/gadget/legacy/raw_gadget.c:473 __fput+0x23f/0x880 fs/file_table.c:431 task_work_run+0x24f/0x310 kernel/task_work.c:228 exit_task_work include/linux/task_work.h:40 [inline] do_exit+0xa2f/0x28e0 kernel/exit.c:939 do_group_exit+0x207/0x2c0 kernel/exit.c:1088 get_signal+0x16a3/0x1740 kernel/signal.c:2917 arch_do_signal_or_restart+0x96/0x860 arch/x86/kernel/signal.c:337 exit_to_user_mode_loop kernel/entry/common.c:111 [inline] exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline] __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline] syscall_exit_to_user_mode+0xc9/0x370 kernel/entry/common.c:218 __do_fast_syscall_32+0xc4/0x110 arch/x86/entry/common.c:389 do_fast_syscall_32+0x34/0x80 arch/x86/entry/common.c:411 entry_SYSENTER_compat_after_hwframe+0x84/0x8e RIP: 0023:0xf748d579 Code: Unable to access opcode bytes at 0xf748d54f. RSP: 002b:00000000f5776530 EFLAGS: 00000206 ORIG_RAX: 0000000000000006 RAX: 0000000000000000 RBX: 0000000000000003 RCX: 00000000f5776b40 RDX: 0000000000000000 RSI: 00000000f747bff4 RDI: 0000000000000000 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 Allocated by task 12843: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x3f/0x80 mm/kasan/common.c:68 poison_kmalloc_redzone mm/kasan/common.c:377 [inline] __kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:394 kasan_kmalloc include/linux/kasan.h:257 [inline] __do_kmalloc_node mm/slub.c:4265 [inline] __kmalloc_node_track_caller_noprof+0x225/0x440 mm/slub.c:4284 memdup_user+0x2b/0xc0 mm/util.c:226 raw_ioctl_ep_enable drivers/usb/gadget/legacy/raw_gadget.c:847 [inline] raw_ioctl+0xd0c/0x3cd0 drivers/usb/gadget/legacy/raw_gadget.c:1318 __do_compat_sys_ioctl fs/ioctl.c:1007 [inline] __se_compat_sys_ioctl+0x510/0xc90 fs/ioctl.c:950 do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline] __do_fast_syscall_32+0xb4/0x110 arch/x86/entry/common.c:386 do_fast_syscall_32+0x34/0x80 arch/x86/entry/common.c:411 entry_SYSENTER_compat_after_hwframe+0x84/0x8e Freed by task 12826: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x3f/0x80 mm/kasan/common.c:68 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:579 poison_slab_object mm/kasan/common.c:247 [inline] __kasan_slab_free+0x59/0x70 mm/kasan/common.c:264 kasan_slab_free include/linux/kasan.h:230 [inline] slab_free_hook mm/slub.c:2343 [inline] slab_free mm/slub.c:4580 [inline] kfree+0x1a0/0x440 mm/slub.c:4728 dev_free drivers/usb/gadget/legacy/raw_gadget.c:225 [inline] kref_put+0x4ab/0x7c0 include/linux/kref.h:65 raw_release+0x135/0x1e0 drivers/usb/gadget/legacy/raw_gadget.c:473 __fput+0x23f/0x880 fs/file_table.c:431 __do_sys_close fs/open.c:1565 [inline] __se_sys_close fs/open.c:1550 [inline] __ia32_sys_close+0x7f/0x110 fs/open.c:1550 do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline] __do_fast_syscall_32+0xb4/0x110 arch/x86/entry/common.c:386 do_fast_syscall_32+0x34/0x80 arch/x86/entry/common.c:411 entry_SYSENTER_compat_after_hwframe+0x84/0x8e The buggy address belongs to the object at ffff888072410200 which belongs to the cache kmalloc-16 of size 16 The buggy address is located 0 bytes inside of 16-byte region [ffff888072410200, ffff888072410210) The buggy address belongs to the physical page: page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x72410 flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff) page_type: f5(slab) raw: 00fff00000000000 ffff88801ac41640 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000800080 00000001f5000000 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 0x252800(GFP_NOWAIT|__GFP_NORETRY|__GFP_COMP|__GFP_THISNODE), pid 11347, tgid 11347 (syz-executor), ts 564101421992, free_ts 564100998848 set_page_owner include/linux/page_owner.h:32 [inline] post_alloc_hook+0x1f3/0x230 mm/page_alloc.c:1537 prep_new_page mm/page_alloc.c:1545 [inline] get_page_from_freelist+0x3045/0x3190 mm/page_alloc.c:3457 __alloc_pages_noprof+0x256/0x6c0 mm/page_alloc.c:4733 __alloc_pages_node_noprof include/linux/gfp.h:269 [inline] alloc_slab_page+0x59/0x120 mm/slub.c:2415 allocate_slab+0x5a/0x2f0 mm/slub.c:2579 new_slab mm/slub.c:2632 [inline] ___slab_alloc+0xcd1/0x14b0 mm/slub.c:3819 __slab_alloc+0x58/0xa0 mm/slub.c:3909 __slab_alloc_node mm/slub.c:3962 [inline] slab_alloc_node mm/slub.c:4123 [inline] __do_kmalloc_node mm/slub.c:4264 [inline] __kmalloc_node_noprof+0x286/0x440 mm/slub.c:4271 __kvmalloc_node_noprof+0x72/0x190 mm/util.c:658 xt_jumpstack_alloc net/netfilter/x_tables.c:1355 [inline] xt_replace_table+0x1a2/0x780 net/netfilter/x_tables.c:1394 __do_replace+0x1ae/0xa40 net/ipv4/netfilter/ip_tables.c:1064 compat_do_replace net/ipv4/netfilter/ip_tables.c:1529 [inline] do_ipt_set_ctl+0xd1f/0x1250 net/ipv4/netfilter/ip_tables.c:1632 nf_setsockopt+0x295/0x2c0 net/netfilter/nf_sockopt.c:101 do_sock_setsockopt+0x3af/0x720 net/socket.c:2329 __sys_setsockopt+0x1a2/0x250 net/socket.c:2352 __do_compat_sys_socketcall net/compat.c:491 [inline] __se_compat_sys_socketcall+0x85a/0x1430 net/compat.c:423 page last free pid 11347 tgid 11347 stack trace: reset_page_owner include/linux/page_owner.h:25 [inline] free_pages_prepare mm/page_alloc.c:1108 [inline] free_unref_page+0xcfb/0xf20 mm/page_alloc.c:2638 vfree+0x186/0x2e0 mm/vmalloc.c:3361 compat_copy_entries_to_user+0x550/0x620 net/ipv4/netfilter/ip_tables.c:1574 compat_get_entries net/ipv4/netfilter/ip_tables.c:1604 [inline] do_ipt_get_ctl+0xe4d/0x1810 net/ipv4/netfilter/ip_tables.c:1665 nf_getsockopt+0x299/0x2c0 net/netfilter/nf_sockopt.c:116 ip_getsockopt+0x222/0x2e0 net/ipv4/ip_sockglue.c:1777 tcp_getsockopt+0x163/0x1c0 net/ipv4/tcp.c:4670 do_sock_getsockopt+0x3c4/0x7e0 net/socket.c:2391 __sys_getsockopt+0x267/0x330 net/socket.c:2420 __do_compat_sys_socketcall net/compat.c:494 [inline] __se_compat_sys_socketcall+0x349/0x1430 net/compat.c:423 do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline] __do_fast_syscall_32+0xb4/0x110 arch/x86/entry/common.c:386 do_fast_syscall_32+0x34/0x80 arch/x86/entry/common.c:411 entry_SYSENTER_compat_after_hwframe+0x84/0x8e Memory state around the buggy address: ffff888072410100: 00 00 fc fc 00 07 fc fc 00 00 fc fc 00 01 fc fc ffff888072410180: 00 00 fc fc fa fb fc fc 00 00 fc fc 00 00 fc fc >ffff888072410200: fa fb fc fc fa fb fc fc 00 00 fc fc 00 07 fc fc ^ ffff888072410280: 00 00 fc fc 00 06 fc fc 00 01 fc fc 00 06 fc fc ffff888072410300: 00 06 fc fc 00 06 fc fc fa fb fc fc 00 01 fc fc ==================================================================