syzbot


KASAN: use-after-free Read in powermate_config_complete (4)

Status: fixed on 2023/12/21 03:45
Subsystems: input
[Documentation on labels]
Reported-by: syzbot+0434ac83f907a1dbdd1e@syzkaller.appspotmail.com
Fix commit: 5c15c60e7be6 Input: powermate - fix use-after-free in powermate_config_complete
First crash: 833d, last: 456d
Cause bisection: introduced by (bisect log) :
commit bdde081d728ab86812947a62bf84a3b4dfeb2635
Author: Kishen Maloor <kishen.maloor@intel.com>
Date: Wed May 4 02:39:00 2022 +0000

  selftests: mptcp: create listeners to receive MPJs

Crash: KASAN: use-after-free Read in powermate_config_complete (log)
Repro: syz .config
  
Fix bisection: fixed by (bisect log) [merge commit]:
commit b1f1382a110bca1ef52234e889246a90f9a0d69b
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Wed Mar 1 00:01:08 2023 +0000

  Merge tag 'docs-6.3-2' of git://git.lwn.net/linux

  
Discussions (14)
Title Replies (including bot) Last reply
[PATCH AUTOSEL 4.14 7/7] Input: powermate - fix use-after-free in powermate_config_complete 1 (1) 2023/10/18 14:16
[PATCH AUTOSEL 4.19 7/7] Input: powermate - fix use-after-free in powermate_config_complete 1 (1) 2023/10/18 14:15
[PATCH AUTOSEL 5.4 7/7] Input: powermate - fix use-after-free in powermate_config_complete 1 (1) 2023/10/18 14:15
[PATCH AUTOSEL 5.10 11/11] Input: powermate - fix use-after-free in powermate_config_complete 1 (1) 2023/10/18 14:14
[PATCH AUTOSEL 5.15 14/14] Input: powermate - fix use-after-free in powermate_config_complete 1 (1) 2023/10/18 14:14
[PATCH AUTOSEL 6.1 19/19] Input: powermate - fix use-after-free in powermate_config_complete 1 (1) 2023/10/18 14:13
[PATCH AUTOSEL 6.5 31/31] Input: powermate - fix use-after-free in powermate_config_complete 1 (1) 2023/10/18 14:11
[PATCH v3] Input: powermate - fix use-after-free in powermate_config_complete 2 (2) 2023/10/14 03:13
[PATCH v2] Input: powermate - fix use-after-free in powermate_config_complete 2 (2) 2023/10/04 14:30
[PATCH] Input: powermate - fix use-after-free in powermate_config_complete 2 (2) 2023/09/20 18:35
Re: [PATCH] Input: powermate - fix use-after-free in powermate_config_complete 1 (1) 2023/09/18 22:10
[syzbot] Monthly input report (Sep 2023) 0 (1) 2023/09/14 09:56
[syzbot] Monthly input report (Jun 2023) 0 (1) 2023/06/06 23:24
[syzbot] KASAN: use-after-free Read in powermate_config_complete (4) 0 (2) 2022/09/17 20:52
Similar bugs (3)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in powermate_config_complete (2) input 91 1059d 1093d 0/28 auto-closed as invalid on 2022/04/13 14:35
upstream KASAN: use-after-free Read in powermate_config_complete usb 1 1402d 1397d 0/28 auto-closed as invalid on 2021/06/05 00:03
upstream KASAN: use-after-free Read in powermate_config_complete (3) input 1 906d 901d 0/28 auto-closed as invalid on 2022/08/14 09:59
Last patch testing requests (1)
Created Duration User Patch Repo Result
2023/05/19 06:04 22m retest repro https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing OK log
Fix bisection attempts (4)
Created Duration User Patch Repo Result
2023/04/09 02:45 5h35m bisect fix upstream OK (1) job log
2023/03/10 02:11 33m bisect fix upstream OK (0) job log log
2023/02/07 15:41 33m bisect fix upstream OK (0) job log log
2022/11/21 20:06 32m bisect fix upstream OK (0) job log log

Sample crash report:
powermate: config urb returned -71
powermate 2-1:0.0: powermate_irq - usb_submit_urb failed with result: -19
powermate: config urb returned -108
==================================================================
BUG: KASAN: use-after-free in __lock_acquire+0x3ee7/0x56d0 kernel/locking/lockdep.c:4923
Read of size 8 at addr ffff8880182f6658 by task swapper/1/0

CPU: 1 PID: 0 Comm: swapper/1 Not tainted 6.0.0-rc5-syzkaller-00094-ga335366bad13 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/26/2022
Call Trace:
 <IRQ>
 __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/0x719 mm/kasan/report.c:433
 kasan_report+0xb1/0x1e0 mm/kasan/report.c:495
 __lock_acquire+0x3ee7/0x56d0 kernel/locking/lockdep.c:4923
 lock_acquire kernel/locking/lockdep.c:5666 [inline]
 lock_acquire+0x1ab/0x570 kernel/locking/lockdep.c:5631
 __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
 _raw_spin_lock_irqsave+0x39/0x50 kernel/locking/spinlock.c:162
 powermate_config_complete+0x79/0xb0 drivers/input/misc/powermate.c:202
 __usb_hcd_giveback_urb+0x2b0/0x5c0 drivers/usb/core/hcd.c:1671
 usb_hcd_giveback_urb+0x380/0x430 drivers/usb/core/hcd.c:1754
 dummy_timer+0x11ff/0x32c0 drivers/usb/gadget/udc/dummy_hcd.c:1988
 call_timer_fn+0x1a0/0x6b0 kernel/time/timer.c:1474
 expire_timers kernel/time/timer.c:1519 [inline]
 __run_timers.part.0+0x674/0xa80 kernel/time/timer.c:1790
 __run_timers kernel/time/timer.c:1768 [inline]
 run_timer_softirq+0xb3/0x1d0 kernel/time/timer.c:1803
 __do_softirq+0x1d3/0x9c6 kernel/softirq.c:571
 invoke_softirq kernel/softirq.c:445 [inline]
 __irq_exit_rcu+0x123/0x180 kernel/softirq.c:650
 irq_exit_rcu+0x5/0x20 kernel/softirq.c:662
 sysvec_apic_timer_interrupt+0x93/0xc0 arch/x86/kernel/apic/apic.c:1106
 </IRQ>
 <TASK>
 asm_sysvec_apic_timer_interrupt+0x16/0x20 arch/x86/include/asm/idtentry.h:649
RIP: 0010:native_save_fl arch/x86/include/asm/irqflags.h:29 [inline]
RIP: 0010:arch_local_save_flags arch/x86/include/asm/irqflags.h:70 [inline]
RIP: 0010:arch_irqs_disabled arch/x86/include/asm/irqflags.h:130 [inline]
RIP: 0010:acpi_safe_halt+0x6f/0xb0 drivers/acpi/processor_idle.c:113
Code: f7 84 db 74 06 5b e9 50 d9 f8 f7 e8 4b d9 f8 f7 e8 76 50 ff f7 66 90 e8 3f d9 f8 f7 0f 00 2d 78 9c d1 00 e8 33 d9 f8 f7 fb f4 <9c> 5b 81 e3 00 02 00 00 fa 31 ff 48 89 de e8 fe d5 f8 f7 48 85 db
RSP: 0018:ffffc90000177d20 EFLAGS: 00000293
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff888011a81d80 RSI: ffffffff89832fed RDI: 0000000000000000
RBP: ffff8880178da064 R08: 0000000000000001 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000001
R13: 0000000000000001 R14: ffff8880178da000 R15: ffff888146e81804
 acpi_idle_do_entry drivers/acpi/processor_idle.c:555 [inline]
 acpi_idle_enter+0x524/0x6a0 drivers/acpi/processor_idle.c:692
 cpuidle_enter_state+0x1ab/0xd30 drivers/cpuidle/cpuidle.c:239
 cpuidle_enter+0x4a/0xa0 drivers/cpuidle/cpuidle.c:356
 call_cpuidle kernel/sched/idle.c:155 [inline]
 cpuidle_idle_call kernel/sched/idle.c:236 [inline]
 do_idle+0x3e8/0x590 kernel/sched/idle.c:303
 cpu_startup_entry+0x14/0x20 kernel/sched/idle.c:400
 start_secondary+0x21d/0x2b0 arch/x86/kernel/smpboot.c:262
 secondary_startup_64_no_verify+0xce/0xdb
 </TASK>

Allocated by task 3702:
 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+0xa9/0xd0 mm/kasan/common.c:525
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 powermate_probe+0x24a/0x12a0 drivers/input/misc/powermate.c:323
 usb_probe_interface+0x30b/0x7f0 drivers/usb/core/driver.c:396
 call_driver_probe drivers/base/dd.c:560 [inline]
 really_probe+0x249/0xb90 drivers/base/dd.c:639
 __driver_probe_device+0x1df/0x4d0 drivers/base/dd.c:778
 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:808
 __device_attach_driver+0x1d0/0x2e0 drivers/base/dd.c:936
 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
 __device_attach+0x1e4/0x530 drivers/base/dd.c:1008
 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
 device_add+0xbd5/0x1e90 drivers/base/core.c:3517
 usb_set_configuration+0x1019/0x1900 drivers/usb/core/message.c:2170
 usb_generic_driver_probe+0xba/0x100 drivers/usb/core/generic.c:238
 usb_probe_device+0xd4/0x2c0 drivers/usb/core/driver.c:293
 call_driver_probe drivers/base/dd.c:560 [inline]
 really_probe+0x249/0xb90 drivers/base/dd.c:639
 __driver_probe_device+0x1df/0x4d0 drivers/base/dd.c:778
 driver_probe_device+0x4c/0x1a0 drivers/base/dd.c:808
 __device_attach_driver+0x1d0/0x2e0 drivers/base/dd.c:936
 bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:427
 __device_attach+0x1e4/0x530 drivers/base/dd.c:1008
 bus_probe_device+0x1e4/0x290 drivers/base/bus.c:487
 device_add+0xbd5/0x1e90 drivers/base/core.c:3517
 usb_new_device.cold+0x685/0x10ad drivers/usb/core/hub.c:2573
 hub_port_connect drivers/usb/core/hub.c:5353 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5497 [inline]
 port_event drivers/usb/core/hub.c:5653 [inline]
 hub_event+0x26c7/0x4610 drivers/usb/core/hub.c:5735
 process_one_work+0x991/0x1610 kernel/workqueue.c:2289
 worker_thread+0x665/0x1080 kernel/workqueue.c:2436
 kthread+0x2e4/0x3a0 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

Freed by task 14:
 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+0x166/0x1c0 mm/kasan/common.c:329
 kasan_slab_free include/linux/kasan.h:200 [inline]
 slab_free_hook mm/slub.c:1754 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1780
 slab_free mm/slub.c:3534 [inline]
 kfree+0xe2/0x580 mm/slub.c:4562
 powermate_disconnect+0x1ce/0x250 drivers/input/misc/powermate.c:432
 usb_unbind_interface+0x1d8/0x8e0 drivers/usb/core/driver.c:458
 device_remove drivers/base/dd.c:550 [inline]
 device_remove+0x11f/0x170 drivers/base/dd.c:542
 __device_release_driver drivers/base/dd.c:1249 [inline]
 device_release_driver_internal+0x4a1/0x700 drivers/base/dd.c:1275
 bus_remove_device+0x2e3/0x590 drivers/base/bus.c:529
 device_del+0x4f3/0xc80 drivers/base/core.c:3704
 usb_disable_device+0x356/0x7a0 drivers/usb/core/message.c:1419
 usb_disconnect.cold+0x259/0x6ed drivers/usb/core/hub.c:2235
 hub_port_connect drivers/usb/core/hub.c:5197 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5497 [inline]
 port_event drivers/usb/core/hub.c:5653 [inline]
 hub_event+0x1f86/0x4610 drivers/usb/core/hub.c:5735
 process_one_work+0x991/0x1610 kernel/workqueue.c:2289
 worker_thread+0x665/0x1080 kernel/workqueue.c:2436
 kthread+0x2e4/0x3a0 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

The buggy address belongs to the object at ffff8880182f6600
 which belongs to the cache kmalloc-256 of size 256
The buggy address is located 88 bytes inside of
 256-byte region [ffff8880182f6600, ffff8880182f6700)

The buggy address belongs to the physical page:
page:ffffea000060bd80 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff8880182f7800 pfn:0x182f6
head:ffffea000060bd80 order:1 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 ffffea0001c73e80 dead000000000006 ffff888011841b40
raw: ffff8880182f7800 000000008010000f 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 1, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 2, tgid 2 (kthreadd), ts 12407975363, free_ts 0
 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:5515
 alloc_pages+0x1a6/0x270 mm/mempolicy.c:2270
 alloc_slab_page mm/slub.c:1824 [inline]
 allocate_slab+0x27e/0x3d0 mm/slub.c:1969
 new_slab mm/slub.c:2029 [inline]
 ___slab_alloc+0x7f1/0xe10 mm/slub.c:3031
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3118
 slab_alloc_node mm/slub.c:3209 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 kmem_cache_alloc_trace+0x323/0x3e0 mm/slub.c:3282
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 set_kthread_struct+0xc5/0x250 kernel/kthread.c:117
 copy_process+0x35c4/0x7090 kernel/fork.c:2184
 kernel_clone+0xe7/0xab0 kernel/fork.c:2674
 kernel_thread+0xb5/0xf0 kernel/fork.c:2727
 create_kthread kernel/kthread.c:399 [inline]
 kthreadd+0x4ea/0x750 kernel/kthread.c:745
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
page_owner free stack trace missing

Memory state around the buggy address:
 ffff8880182f6500: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8880182f6580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880182f6600: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                    ^
 ffff8880182f6680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880182f6700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================
----------------
Code disassembly (best guess):
   0:	f7 84 db 74 06 5b e9 	testl  $0xf7f8d950,-0x16a4f98c(%rbx,%rbx,8)
   7:	50 d9 f8 f7
   b:	e8 4b d9 f8 f7       	callq  0xf7f8d95b
  10:	e8 76 50 ff f7       	callq  0xf7ff508b
  15:	66 90                	xchg   %ax,%ax
  17:	e8 3f d9 f8 f7       	callq  0xf7f8d95b
  1c:	0f 00 2d 78 9c d1 00 	verw   0xd19c78(%rip)        # 0xd19c9b
  23:	e8 33 d9 f8 f7       	callq  0xf7f8d95b
  28:	fb                   	sti
  29:	f4                   	hlt
* 2a:	9c                   	pushfq <-- trapping instruction
  2b:	5b                   	pop    %rbx
  2c:	81 e3 00 02 00 00    	and    $0x200,%ebx
  32:	fa                   	cli
  33:	31 ff                	xor    %edi,%edi
  35:	48 89 de             	mov    %rbx,%rsi
  38:	e8 fe d5 f8 f7       	callq  0xf7f8d63b
  3d:	48 85 db             	test   %rbx,%rbx

Crashes (14):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/09/17 23:00 upstream a335366bad13 dd9a85ff .config console log report syz ci-upstream-kasan-gce KASAN: use-after-free Read in powermate_config_complete
2022/09/17 20:51 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 7eb2bf871454 dd9a85ff .config console log report syz [disk image] [vmlinux] ci2-upstream-usb KASAN: use-after-free Read in powermate_config_complete
2023/01/05 09:09 upstream 512dee0c00ad 1dac8c7a .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce KASAN: use-after-free Read in powermate_config_complete
2022/09/16 20:00 upstream 6879c2d3b960 dd9a85ff .config console log report info [disk image] [vmlinux] ci-upstream-kasan-gce-root KASAN: use-after-free Read in powermate_config_complete
2022/12/11 16:15 upstream 4cee37b3a4e6 67be1ae7 .config console log report info ci-upstream-kasan-gce-386 KASAN: use-after-free Read in powermate_config_complete
2022/10/18 00:29 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing a6afa4199d3d 94744d21 .config console log report info ci2-upstream-usb KASAN: use-after-free Read in powermate_config_complete
2022/10/04 00:08 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 00988f70a076 feb56351 .config console log report info ci2-upstream-usb KASAN: use-after-free Read in powermate_config_complete
2022/09/17 18:21 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 7eb2bf871454 dd9a85ff .config console log report info [disk image] [vmlinux] ci2-upstream-usb KASAN: use-after-free Read in powermate_config_complete
2022/08/30 01:45 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing ffcf9c5700e4 d7593c58 .config console log report info [disk image] [vmlinux] ci2-upstream-usb KASAN: use-after-free Read in powermate_config_complete
2022/08/29 10:05 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing ffcf9c5700e4 07177916 .config console log report info ci2-upstream-usb KASAN: use-after-free Read in powermate_config_complete
2022/08/29 02:22 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing ffcf9c5700e4 07177916 .config console log report info ci2-upstream-usb KASAN: use-after-free Read in powermate_config_complete
2022/08/27 10:13 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing ffcf9c5700e4 07177916 .config console log report info ci2-upstream-usb KASAN: use-after-free Read in powermate_config_complete
2023/09/08 08:02 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 7ba2090ca64e 72324844 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-usb KASAN: slab-use-after-free Read in powermate_config_complete
2023/06/02 09:40 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 243ff7e6a035 a4ae4f42 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-usb KASAN: slab-use-after-free Read in powermate_config_complete
* Struck through repros no longer work on HEAD.