================================================================== BUG: KASAN: double-free in dev_free+0x446/0x700 drivers/usb/gadget/legacy/raw_gadget.c:225 Free of addr ffff8880295148c0 by task syz.2.1421/10113 CPU: 2 UID: 0 PID: 10113 Comm: syz.2.1421 Not tainted 6.11.0-rc5-syzkaller #0 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:93 [inline] dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119 print_address_description mm/kasan/report.c:377 [inline] print_report+0xc3/0x620 mm/kasan/report.c:488 kasan_report_invalid_free+0xaa/0xd0 mm/kasan/report.c:563 poison_slab_object+0x135/0x160 mm/kasan/common.c:232 __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256 kasan_slab_free include/linux/kasan.h:184 [inline] slab_free_hook mm/slub.c:2252 [inline] slab_free mm/slub.c:4473 [inline] kfree+0x12a/0x3b0 mm/slub.c:4594 dev_free+0x446/0x700 drivers/usb/gadget/legacy/raw_gadget.c:225 kref_put include/linux/kref.h:65 [inline] raw_release+0x16e/0x2c0 drivers/usb/gadget/legacy/raw_gadget.c:473 __fput+0x408/0xbb0 fs/file_table.c:422 task_work_run+0x14e/0x250 kernel/task_work.c:228 get_signal+0x1d3/0x26e0 kernel/signal.c:2689 arch_do_signal_or_restart+0x90/0x7e0 arch/x86/kernel/signal.c:310 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+0x150/0x2a0 kernel/entry/common.c:218 __do_fast_syscall_32+0x80/0x120 arch/x86/entry/common.c:389 do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:411 entry_SYSENTER_compat_after_hwframe+0x84/0x8e RIP: 0023:0xf7f51579 Code: b8 01 10 06 03 74 b4 01 10 07 03 74 b0 01 10 08 03 74 d8 01 00 00 00 00 00 00 00 00 00 00 00 00 00 51 52 55 89 e5 0f 34 cd 80 <5d> 5a 59 c3 90 90 90 90 8d b4 26 00 00 00 00 8d b4 26 00 00 00 00 RSP: 002b:00000000f56d3504 EFLAGS: 00000292 ORIG_RAX: 0000000000000036 RAX: fffffffffffffffc RBX: 0000000000000003 RCX: 0000000080085502 RDX: 00000000f56d4550 RSI: 00000000f73e0ff4 RDI: 0000000000000000 RBP: 00000000f73e0ff4 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 Allocated by task 10113: kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 kasan_save_track+0x14/0x30 mm/kasan/common.c:68 poison_kmalloc_redzone mm/kasan/common.c:370 [inline] __kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:387 kasan_kmalloc include/linux/kasan.h:211 [inline] __do_kmalloc_node mm/slub.c:4158 [inline] __kmalloc_node_track_caller_noprof+0x20f/0x440 mm/slub.c:4177 memdup_user+0x2a/0xd0 mm/util.c:226 raw_ioctl_ep_enable drivers/usb/gadget/legacy/raw_gadget.c:847 [inline] raw_ioctl+0x105d/0x2a50 drivers/usb/gadget/legacy/raw_gadget.c:1318 __do_compat_sys_ioctl+0x2c3/0x330 fs/ioctl.c:1007 do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline] __do_fast_syscall_32+0x73/0x120 arch/x86/entry/common.c:386 do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:411 entry_SYSENTER_compat_after_hwframe+0x84/0x8e Freed by task 10106: kasan_save_stack+0x33/0x60 mm/kasan/common.c:47 kasan_save_track+0x14/0x30 mm/kasan/common.c:68 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579 poison_slab_object+0xf7/0x160 mm/kasan/common.c:240 __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256 kasan_slab_free include/linux/kasan.h:184 [inline] slab_free_hook mm/slub.c:2252 [inline] slab_free mm/slub.c:4473 [inline] kfree+0x12a/0x3b0 mm/slub.c:4594 dev_free+0x446/0x700 drivers/usb/gadget/legacy/raw_gadget.c:225 kref_put include/linux/kref.h:65 [inline] raw_release+0x16e/0x2c0 drivers/usb/gadget/legacy/raw_gadget.c:473 __fput+0x408/0xbb0 fs/file_table.c:422 __fput_sync+0x47/0x50 fs/file_table.c:507 __do_sys_close fs/open.c:1566 [inline] __se_sys_close fs/open.c:1551 [inline] __ia32_sys_close+0x86/0x100 fs/open.c:1551 do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline] __do_fast_syscall_32+0x73/0x120 arch/x86/entry/common.c:386 do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:411 entry_SYSENTER_compat_after_hwframe+0x84/0x8e The buggy address belongs to the object at ffff8880295148c0 which belongs to the cache kmalloc-16 of size 16 The buggy address is located 0 bytes inside of 16-byte region [ffff8880295148c0, ffff8880295148d0) The buggy address belongs to the physical page: page: refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888029514720 pfn:0x29514 flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff) page_type: 0xfdffffff(slab) raw: 00fff00000000000 ffff888015842640 dead000000000100 dead000000000122 raw: ffff888029514720 0000000080800079 00000001fdffffff 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 6795, tgid 6795 (syz-executor), ts 313003746763, free_ts 312991866265 set_page_owner include/linux/page_owner.h:32 [inline] post_alloc_hook+0x2d1/0x350 mm/page_alloc.c:1493 prep_new_page mm/page_alloc.c:1501 [inline] get_page_from_freelist+0x1351/0x2e50 mm/page_alloc.c:3439 __alloc_pages_slowpath mm/page_alloc.c:4228 [inline] __alloc_pages_noprof+0x6ad/0x2460 mm/page_alloc.c:4708 __alloc_pages_node_noprof include/linux/gfp.h:269 [inline] alloc_pages_node_noprof include/linux/gfp.h:296 [inline] alloc_slab_page+0x4e/0xf0 mm/slub.c:2321 allocate_slab mm/slub.c:2484 [inline] new_slab+0x84/0x260 mm/slub.c:2537 ___slab_alloc+0xdac/0x1870 mm/slub.c:3723 __slab_alloc.constprop.0+0x56/0xb0 mm/slub.c:3813 __slab_alloc_node mm/slub.c:3866 [inline] slab_alloc_node mm/slub.c:4025 [inline] __do_kmalloc_node mm/slub.c:4157 [inline] __kmalloc_node_noprof+0x367/0x440 mm/slub.c:4164 __kvmalloc_node_noprof+0x9d/0x1a0 mm/util.c:650 xt_jumpstack_alloc net/netfilter/x_tables.c:1355 [inline] xt_replace_table+0x1c7/0x910 net/netfilter/x_tables.c:1394 __do_replace+0x1d9/0x9c0 net/ipv4/netfilter/arp_tables.c:912 compat_do_replace+0x3ca/0x500 net/ipv4/netfilter/ip_tables.c:1529 do_ip6t_set_ctl+0x686/0xc20 net/ipv6/netfilter/ip6_tables.c:1641 nf_setsockopt+0x8a/0xf0 net/netfilter/nf_sockopt.c:101 ipv6_setsockopt+0x133/0x1a0 net/ipv6/ipv6_sockglue.c:998 tcp_setsockopt+0xa4/0x100 net/ipv4/tcp.c:3768 page last free pid 8982 tgid 8980 stack trace: reset_page_owner include/linux/page_owner.h:25 [inline] free_pages_prepare mm/page_alloc.c:1094 [inline] free_unref_page+0x64a/0xe40 mm/page_alloc.c:2612 __folio_put+0x31c/0x3e0 mm/swap.c:128 folio_put include/linux/mm.h:1486 [inline] free_page_and_swap_cache+0x249/0x2c0 mm/swap_state.c:308 __tlb_remove_table arch/x86/include/asm/tlb.h:34 [inline] __tlb_remove_table_free mm/mmu_gather.c:227 [inline] tlb_remove_table_rcu+0x89/0xe0 mm/mmu_gather.c:282 rcu_do_batch kernel/rcu/tree.c:2569 [inline] rcu_core+0x828/0x16b0 kernel/rcu/tree.c:2843 handle_softirqs+0x216/0x8f0 kernel/softirq.c:554 __do_softirq kernel/softirq.c:588 [inline] invoke_softirq kernel/softirq.c:428 [inline] __irq_exit_rcu kernel/softirq.c:637 [inline] irq_exit_rcu+0xbb/0x120 kernel/softirq.c:649 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1043 [inline] sysvec_apic_timer_interrupt+0x95/0xb0 arch/x86/kernel/apic/apic.c:1043 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:702 Memory state around the buggy address: ffff888029514780: fa fb fc fc 00 00 fc fc fa fb fc fc 00 00 fc fc ffff888029514800: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc >ffff888029514880: fa fb fc fc fa fb fc fc fa fb fc fc 00 00 fc fc ^ ffff888029514900: 00 00 fc fc fa fb fc fc 00 00 fc fc fa fb fc fc ffff888029514980: 00 00 fc fc 00 00 fc fc 00 00 fc fc fa fb fc fc ================================================================== ---------------- Code disassembly (best guess), 2 bytes skipped: 0: 10 06 adc %al,(%rsi) 2: 03 74 b4 01 add 0x1(%rsp,%rsi,4),%esi 6: 10 07 adc %al,(%rdi) 8: 03 74 b0 01 add 0x1(%rax,%rsi,4),%esi c: 10 08 adc %cl,(%rax) e: 03 74 d8 01 add 0x1(%rax,%rbx,8),%esi 1e: 00 51 52 add %dl,0x52(%rcx) 21: 55 push %rbp 22: 89 e5 mov %esp,%ebp 24: 0f 34 sysenter 26: cd 80 int $0x80 * 28: 5d pop %rbp <-- trapping instruction 29: 5a pop %rdx 2a: 59 pop %rcx 2b: c3 ret 2c: 90 nop 2d: 90 nop 2e: 90 nop 2f: 90 nop 30: 8d b4 26 00 00 00 00 lea 0x0(%rsi,%riz,1),%esi 37: 8d b4 26 00 00 00 00 lea 0x0(%rsi,%riz,1),%esi