================================================================== BUG: KASAN: use-after-free in __snd_rawmidi_transmit_peek sound/core/rawmidi.c:1286 [inline] BUG: KASAN: use-after-free in snd_rawmidi_transmit+0x39a/0x410 sound/core/rawmidi.c:1411 Read of size 1 at addr ffff88807e79c04f by task syz-executor/3569 CPU: 1 PID: 3569 Comm: syz-executor Not tainted 5.15.166-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1e3/0x2d0 lib/dump_stack.c:106 print_address_description+0x63/0x3b0 mm/kasan/report.c:248 __kasan_report mm/kasan/report.c:434 [inline] kasan_report+0x16b/0x1c0 mm/kasan/report.c:451 __snd_rawmidi_transmit_peek sound/core/rawmidi.c:1286 [inline] snd_rawmidi_transmit+0x39a/0x410 sound/core/rawmidi.c:1411 snd_usbmidi_standard_output+0x1eb/0xf20 sound/usb/midi.c:650 snd_usbmidi_do_output+0x206/0x520 sound/usb/midi.c:311 snd_usbmidi_error_timer+0x2a3/0x580 sound/usb/midi.c:362 call_timer_fn+0x16d/0x560 kernel/time/timer.c:1451 expire_timers kernel/time/timer.c:1496 [inline] __run_timers+0x67c/0x890 kernel/time/timer.c:1767 run_timer_softirq+0x63/0xf0 kernel/time/timer.c:1780 handle_softirqs+0x3a7/0x930 kernel/softirq.c:558 __do_softirq kernel/softirq.c:592 [inline] invoke_softirq kernel/softirq.c:432 [inline] __irq_exit_rcu+0x157/0x240 kernel/softirq.c:641 irq_exit_rcu+0x5/0x20 kernel/softirq.c:653 sysvec_apic_timer_interrupt+0x91/0xb0 arch/x86/kernel/apic/apic.c:1096 asm_sysvec_apic_timer_interrupt+0x16/0x20 arch/x86/include/asm/idtentry.h:638 RIP: 0010:__raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:161 [inline] RIP: 0010:_raw_spin_unlock_irqrestore+0xd4/0x130 kernel/locking/spinlock.c:194 Code: 9c 8f 44 24 20 42 80 3c 23 00 74 08 4c 89 f7 e8 92 6e 8c f7 f6 44 24 21 02 75 4e 41 f7 c7 00 02 00 00 74 01 fb bf 01 00 00 00 77 b8 19 f7 65 8b 05 58 bb c4 75 85 c0 74 3f 48 c7 04 24 0e 36 RSP: 0018:ffffc90002db74a0 EFLAGS: 00000206 RAX: 330024c32e45f600 RBX: 1ffff920005b6e98 RCX: ffffffff96867f03 RDX: dffffc0000000000 RSI: ffffffff8a8b2a20 RDI: 0000000000000001 RBP: ffffc90002db7530 R08: ffffffff8186dac0 R09: ffffed100c00760b R10: 0000000000000000 R11: dffffc0000000001 R12: dffffc0000000000 R13: 1ffff920005b6e94 R14: ffffc90002db74c0 R15: 0000000000000246 spin_unlock_irqrestore include/linux/spinlock.h:418 [inline] unlock_page_lruvec_irqrestore include/linux/memcontrol.h:1538 [inline] release_pages+0x1b89/0x1f40 mm/swap.c:960 __pagevec_release+0x80/0xf0 mm/swap.c:983 pagevec_release include/linux/pagevec.h:81 [inline] shmem_undo_range+0x67a/0x1b50 mm/shmem.c:964 shmem_truncate_range mm/shmem.c:1063 [inline] shmem_evict_inode+0x21b/0xa00 mm/shmem.c:1145 evict+0x529/0x930 fs/inode.c:622 __dentry_kill+0x436/0x650 fs/dcache.c:586 dentry_kill+0xbb/0x290 dput+0xd8/0x1a0 fs/dcache.c:893 __fput+0x636/0x8e0 fs/file_table.c:288 task_work_run+0x129/0x1a0 kernel/task_work.c:188 exit_task_work include/linux/task_work.h:33 [inline] do_exit+0x6a3/0x2480 kernel/exit.c:874 do_group_exit+0x144/0x310 kernel/exit.c:996 __do_sys_exit_group kernel/exit.c:1007 [inline] __se_sys_exit_group kernel/exit.c:1005 [inline] __x64_sys_exit_group+0x3b/0x40 kernel/exit.c:1005 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x66/0xd0 RIP: 0033:0x7f30e98a9ef9 Code: Unable to access opcode bytes at RIP 0x7f30e98a9ecf. RSP: 002b:00007ffd9521ca78 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 RAX: ffffffffffffffda RBX: 00007f30e991bf56 RCX: 00007f30e98a9ef9 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000001 RBP: 0000000000000010 R08: 00007ffd9521a816 R09: 00007ffd9521dd30 R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffd9521dd30 R13: 00007f30e991bee4 R14: 000055556d2f44a8 R15: 00007ffd9521edf0 Allocated by task 5755: kasan_save_stack mm/kasan/common.c:38 [inline] kasan_set_track mm/kasan/common.c:46 [inline] set_alloc_info mm/kasan/common.c:434 [inline] ____kasan_kmalloc+0xba/0xf0 mm/kasan/common.c:513 kasan_kmalloc include/linux/kasan.h:264 [inline] __kmalloc_node+0x199/0x390 mm/slub.c:4455 kmalloc_node include/linux/slab.h:614 [inline] kvmalloc_node+0x80/0x140 mm/util.c:619 kvmalloc include/linux/mm.h:805 [inline] kvzalloc include/linux/mm.h:813 [inline] snd_rawmidi_runtime_create sound/core/rawmidi.c:162 [inline] open_substream+0x2a4/0x6d0 sound/core/rawmidi.c:306 rawmidi_open_priv+0xc2/0x680 sound/core/rawmidi.c:357 snd_rawmidi_kernel_open+0x1b3/0x240 sound/core/rawmidi.c:392 midisynth_use+0xe7/0x2a0 sound/core/seq/seq_midi.c:221 subscribe_port sound/core/seq/seq_ports.c:412 [inline] check_and_subscribe_port+0x604/0xab0 sound/core/seq/seq_ports.c:495 snd_seq_port_connect+0x284/0x480 sound/core/seq/seq_ports.c:581 snd_seq_ioctl_subscribe_port+0x31a/0x780 sound/core/seq/seq_clientmgr.c:1490 snd_seq_oss_midi_open+0x425/0x9c0 sound/core/seq/oss/seq_oss_midi.c:365 snd_seq_oss_synth_setup_midi+0x114/0x500 sound/core/seq/oss/seq_oss_synth.c:269 snd_seq_oss_open+0x942/0x1010 sound/core/seq/oss/seq_oss_init.c:261 odev_open+0x5f/0x90 sound/core/seq/oss/seq_oss.c:128 chrdev_open+0x54a/0x630 fs/char_dev.c:414 do_dentry_open+0x807/0xfb0 fs/open.c:826 do_open fs/namei.c:3608 [inline] path_openat+0x2705/0x2f20 fs/namei.c:3742 do_filp_open+0x21c/0x460 fs/namei.c:3769 do_sys_openat2+0x13b/0x4f0 fs/open.c:1253 do_sys_open fs/open.c:1269 [inline] __do_sys_openat fs/open.c:1285 [inline] __se_sys_openat fs/open.c:1280 [inline] __x64_sys_openat+0x243/0x290 fs/open.c:1280 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x66/0xd0 Freed by task 5755: kasan_save_stack mm/kasan/common.c:38 [inline] kasan_set_track+0x4b/0x80 mm/kasan/common.c:46 kasan_set_free_info+0x1f/0x40 mm/kasan/generic.c:360 ____kasan_slab_free+0xd8/0x120 mm/kasan/common.c:366 kasan_slab_free include/linux/kasan.h:230 [inline] slab_free_hook mm/slub.c:1705 [inline] slab_free_freelist_hook+0xdd/0x160 mm/slub.c:1731 slab_free mm/slub.c:3499 [inline] kfree+0xf1/0x270 mm/slub.c:4559 snd_rawmidi_runtime_free sound/core/rawmidi.c:176 [inline] close_substream+0x390/0x600 sound/core/rawmidi.c:528 rawmidi_release_priv+0xf1/0x180 sound/core/rawmidi.c:547 snd_rawmidi_kernel_release+0x42/0xa0 sound/core/rawmidi.c:564 unsubscribe_port sound/core/seq/seq_ports.c:437 [inline] __delete_and_unsubscribe_port+0x2c5/0x470 sound/core/seq/seq_ports.c:537 snd_seq_port_disconnect+0x4ab/0x5d0 sound/core/seq/seq_ports.c:616 snd_seq_ioctl_unsubscribe_port+0x31a/0x780 sound/core/seq/seq_clientmgr.c:1535 snd_seq_oss_midi_close+0x348/0x760 sound/core/seq/oss/seq_oss_midi.c:413 snd_seq_oss_synth_cleanup+0x16b/0x580 sound/core/seq/oss/seq_oss_synth.c:307 snd_seq_oss_release+0xf2/0x300 sound/core/seq/oss/seq_oss_init.c:415 odev_release+0x52/0x70 sound/core/seq/oss/seq_oss.c:144 __fput+0x3fe/0x8e0 fs/file_table.c:280 task_work_run+0x129/0x1a0 kernel/task_work.c:188 tracehook_notify_resume include/linux/tracehook.h:189 [inline] exit_to_user_mode_loop+0x106/0x130 kernel/entry/common.c:181 exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:214 __syscall_exit_to_user_mode_work kernel/entry/common.c:296 [inline] syscall_exit_to_user_mode+0x5d/0x240 kernel/entry/common.c:307 do_syscall_64+0x47/0xb0 arch/x86/entry/common.c:86 entry_SYSCALL_64_after_hwframe+0x66/0xd0 The buggy address belongs to the object at ffff88807e79c000 which belongs to the cache kmalloc-4k of size 4096 The buggy address is located 79 bytes inside of 4096-byte region [ffff88807e79c000, ffff88807e79d000) The buggy address belongs to the page: page:ffffea0001f9e600 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7e798 head:ffffea0001f9e600 order:3 compound_mapcount:0 compound_pincount:0 flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff) raw: 00fff00000010200 0000000000000000 dead000000000122 ffff888017042140 raw: 0000000000000000 0000000000040004 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected page_owner tracks the page as allocated page last allocated via order 3, migratetype Unmovable, gfp_mask 0x1d20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 5755, ts 236564008863, free_ts 236354680713 prep_new_page mm/page_alloc.c:2426 [inline] get_page_from_freelist+0x322a/0x33c0 mm/page_alloc.c:4159 __alloc_pages+0x272/0x700 mm/page_alloc.c:5423 alloc_slab_page mm/slub.c:1775 [inline] allocate_slab mm/slub.c:1912 [inline] new_slab+0xbb/0x4b0 mm/slub.c:1975 ___slab_alloc+0x6f6/0xe10 mm/slub.c:3008 __slab_alloc mm/slub.c:3095 [inline] slab_alloc_node mm/slub.c:3186 [inline] __kmalloc_node+0x1fa/0x390 mm/slub.c:4451 kmalloc_node include/linux/slab.h:614 [inline] kvmalloc_node+0x80/0x140 mm/util.c:619 kvmalloc include/linux/mm.h:805 [inline] kvzalloc include/linux/mm.h:813 [inline] snd_rawmidi_runtime_create sound/core/rawmidi.c:162 [inline] open_substream+0x2a4/0x6d0 sound/core/rawmidi.c:306 rawmidi_open_priv+0xc2/0x680 sound/core/rawmidi.c:357 snd_rawmidi_kernel_open+0x1b3/0x240 sound/core/rawmidi.c:392 midisynth_use+0xe7/0x2a0 sound/core/seq/seq_midi.c:221 subscribe_port sound/core/seq/seq_ports.c:412 [inline] check_and_subscribe_port+0x604/0xab0 sound/core/seq/seq_ports.c:495 snd_seq_port_connect+0x284/0x480 sound/core/seq/seq_ports.c:581 snd_seq_ioctl_subscribe_port+0x31a/0x780 sound/core/seq/seq_clientmgr.c:1490 snd_seq_oss_midi_open+0x425/0x9c0 sound/core/seq/oss/seq_oss_midi.c:365 snd_seq_oss_synth_setup_midi+0x114/0x500 sound/core/seq/oss/seq_oss_synth.c:269 snd_seq_oss_open+0x942/0x1010 sound/core/seq/oss/seq_oss_init.c:261 page last free stack trace: reset_page_owner include/linux/page_owner.h:24 [inline] free_pages_prepare mm/page_alloc.c:1340 [inline] free_pcp_prepare mm/page_alloc.c:1391 [inline] free_unref_page_prepare+0xc34/0xcf0 mm/page_alloc.c:3317 free_unref_page+0x95/0x2d0 mm/page_alloc.c:3396 __vunmap+0x8d4/0xa20 mm/vmalloc.c:2621 btf_free kernel/bpf/btf.c:1513 [inline] btf_parse kernel/bpf/btf.c:4390 [inline] btf_new_fd+0x57e/0x920 kernel/bpf/btf.c:5920 __sys_bpf+0x486/0x670 kernel/bpf/syscall.c:4696 __do_sys_bpf kernel/bpf/syscall.c:4755 [inline] __se_sys_bpf kernel/bpf/syscall.c:4753 [inline] __x64_sys_bpf+0x78/0x90 kernel/bpf/syscall.c:4753 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x66/0xd0 Memory state around the buggy address: ffff88807e79bf00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff88807e79bf80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff88807e79c000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88807e79c080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88807e79c100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== ---------------- Code disassembly (best guess): 0: 9c pushf 1: 8f 44 24 20 pop 0x20(%rsp) 5: 42 80 3c 23 00 cmpb $0x0,(%rbx,%r12,1) a: 74 08 je 0x14 c: 4c 89 f7 mov %r14,%rdi f: e8 92 6e 8c f7 call 0xf78c6ea6 14: f6 44 24 21 02 testb $0x2,0x21(%rsp) 19: 75 4e jne 0x69 1b: 41 f7 c7 00 02 00 00 test $0x200,%r15d 22: 74 01 je 0x25 24: fb sti 25: bf 01 00 00 00 mov $0x1,%edi * 2a: e8 77 b8 19 f7 call 0xf719b8a6 <-- trapping instruction 2f: 65 8b 05 58 bb c4 75 mov %gs:0x75c4bb58(%rip),%eax # 0x75c4bb8e 36: 85 c0 test %eax,%eax 38: 74 3f je 0x79 3a: 48 rex.W 3b: c7 .byte 0xc7 3c: 04 24 add $0x24,%al 3e: 0e (bad) 3f: 36 ss