syzbot


KASAN: use-after-free Read in device_shutdown

Status: upstream: reported on 2024/09/12 16:07
Reported-by: syzbot+969de4526051212583c5@syzkaller.appspotmail.com
First crash: 30d, last: 24d

Sample crash report:
kvm: exiting hardware virtualization
==================================================================
BUG: KASAN: use-after-free in kobject_put+0x2a0/0x460 lib/kobject.c:757
Read of size 1 at addr ffff88807c6b003c by task init/11521

CPU: 0 PID: 11521 Comm: init Not tainted 5.15.167-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
Call Trace:
 <TASK>
 __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
 kobject_put+0x2a0/0x460 lib/kobject.c:757
 put_device drivers/base/core.c:3523 [inline]
 device_shutdown+0x4da/0x620 drivers/base/core.c:4558
 kernel_shutdown_prepare kernel/reboot.c:266 [inline]
 kernel_power_off+0x4f/0xb0 kernel/reboot.c:291
 __do_sys_reboot kernel/reboot.c:366 [inline]
 __se_sys_reboot+0x4b2/0x540 kernel/reboot.c:312
 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:0x7f2bd5a008b4
Code: f0 ff ff 73 01 c3 48 8b 0d 71 55 0d 00 f7 d8 64 89 01 48 83 c8 ff c3 89 fa be 69 19 12 28 bf ad de e1 fe b8 a9 00 00 00 0f 05 <48> 3d 00 f0 ff ff 76 10 48 8b 15 45 55 0d 00 f7 d8 64 89 02 48 83
RSP: 002b:00007ffd6edeed68 EFLAGS: 00000246 ORIG_RAX: 00000000000000a9
RAX: ffffffffffffffda RBX: 000000000000000c RCX: 00007f2bd5a008b4
RDX: 000000004321fedc RSI: 0000000028121969 RDI: 00000000fee1dead
RBP: 000000004321fedc R08: 0000000000000000 R09: 0000000000000000
R10: 00007ffd6edeed40 R11: 0000000000000246 R12: 00007f2bd5ba74a0
R13: 00007ffd6edeedc8 R14: 00005594c0c02169 R15: 00007f2bd5bd8a80
 </TASK>

Allocated by task 11344:
 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]
 kmem_cache_alloc_trace+0x143/0x290 mm/slub.c:3247
 kmalloc include/linux/slab.h:591 [inline]
 kzalloc include/linux/slab.h:721 [inline]
 nsim_bus_dev_new drivers/net/netdevsim/bus.c:408 [inline]
 new_device_store+0x238/0x910 drivers/net/netdevsim/bus.c:302
 kernfs_fop_write_iter+0x3a2/0x4f0 fs/kernfs/file.c:296
 call_write_iter include/linux/fs.h:2172 [inline]
 new_sync_write fs/read_write.c:507 [inline]
 vfs_write+0xacd/0xe50 fs/read_write.c:594
 ksys_write+0x1a2/0x2c0 fs/read_write.c:647
 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 11441:
 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
 nsim_bus_dev_del drivers/net/netdevsim/bus.c:457 [inline]
 del_device_store+0x36f/0x470 drivers/net/netdevsim/bus.c:354
 kernfs_fop_write_iter+0x3a2/0x4f0 fs/kernfs/file.c:296
 call_write_iter include/linux/fs.h:2172 [inline]
 new_sync_write fs/read_write.c:507 [inline]
 vfs_write+0xacd/0xe50 fs/read_write.c:594
 ksys_write+0x1a2/0x2c0 fs/read_write.c:647
 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

Last potentially related work creation:
 kasan_save_stack+0x36/0x60 mm/kasan/common.c:38
 kasan_record_aux_stack+0xba/0x100 mm/kasan/generic.c:348
 __call_rcu kernel/rcu/tree.c:3007 [inline]
 call_rcu+0x1c4/0xa70 kernel/rcu/tree.c:3087
 in6_dev_put include/net/addrconf.h:386 [inline]
 addrconf_ifdown+0x193c/0x1bb0 net/ipv6/addrconf.c:3934
 addrconf_notify+0x432/0xf30
 notifier_call_chain kernel/notifier.c:83 [inline]
 raw_notifier_call_chain+0xd0/0x170 kernel/notifier.c:391
 call_netdevice_notifiers_info net/core/dev.c:2018 [inline]
 call_netdevice_notifiers_extack net/core/dev.c:2030 [inline]
 call_netdevice_notifiers net/core/dev.c:2044 [inline]
 unregister_netdevice_many+0xf1b/0x18f0 net/core/dev.c:11094
 unregister_netdevice_queue+0x2e6/0x350 net/core/dev.c:11027
 unregister_netdevice include/linux/netdevice.h:3012 [inline]
 nsim_destroy+0x44/0x140 drivers/net/netdevsim/netdev.c:382
 __nsim_dev_port_del+0x153/0x1b0 drivers/net/netdevsim/dev.c:1349
 nsim_dev_port_del_all drivers/net/netdevsim/dev.c:1362 [inline]
 nsim_dev_reload_destroy+0x15e/0x240 drivers/net/netdevsim/dev.c:1561
 nsim_dev_reload_down+0x103/0x160 drivers/net/netdevsim/dev.c:883
 devlink_reload+0x247/0x750 net/core/devlink.c:3963
 devlink_pernet_pre_exit+0x1ca/0x350 net/core/devlink.c:11543
 ops_pre_exit_list net/core/net_namespace.c:162 [inline]
 cleanup_net+0x59c/0xb60 net/core/net_namespace.c:587
 process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
 worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
 kthread+0x3f6/0x4f0 kernel/kthread.c:334
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:287

Second to last potentially related work creation:
 kasan_save_stack+0x36/0x60 mm/kasan/common.c:38
 kasan_record_aux_stack+0xba/0x100 mm/kasan/generic.c:348
 insert_work+0x54/0x3e0 kernel/workqueue.c:1366
 __queue_work+0x963/0xd00 kernel/workqueue.c:1532
 call_timer_fn+0x16d/0x560 kernel/time/timer.c:1451
 expire_timers kernel/time/timer.c:1491 [inline]
 __run_timers+0x6a8/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

The buggy address belongs to the object at ffff88807c6b0000
 which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 60 bytes inside of
 2048-byte region [ffff88807c6b0000, ffff88807c6b0800)
The buggy address belongs to the page:
page:ffffea0001f1ac00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7c6b0
head:ffffea0001f1ac00 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 dead000000000100 dead000000000122 ffff888017042000
raw: 0000000000000000 0000000000080008 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 8957, ts 217852181809, free_ts 217784253086
 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]
 slab_alloc mm/slub.c:3228 [inline]
 __kmalloc+0x1c9/0x300 mm/slub.c:4403
 kmalloc_array include/linux/slab.h:631 [inline]
 kcalloc include/linux/slab.h:660 [inline]
 cache_create_net+0x7f/0x260 net/sunrpc/cache.c:1733
 nfsd_export_init+0x54/0x1e0 fs/nfsd/export.c:1352
 nfsd_init_net+0x29/0x1c0 fs/nfsd/nfsctl.c:1455
 ops_init+0x35d/0x610 net/core/net_namespace.c:138
 setup_net+0x358/0x9e0 net/core/net_namespace.c:332
 copy_net_ns+0x392/0x5d0 net/core/net_namespace.c:476
 create_new_namespaces+0x425/0x7a0 kernel/nsproxy.c:110
 unshare_nsproxy_namespaces+0x11e/0x170 kernel/nsproxy.c:226
 ksys_unshare+0x580/0xb20 kernel/fork.c:3101
 __do_sys_unshare kernel/fork.c:3175 [inline]
 __se_sys_unshare kernel/fork.c:3173 [inline]
 __x64_sys_unshare+0x34/0x40 kernel/fork.c:3173
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80
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
 free_slab mm/slub.c:2015 [inline]
 discard_slab mm/slub.c:2021 [inline]
 __unfreeze_partials+0x1b7/0x210 mm/slub.c:2507
 put_cpu_partial+0x132/0x1a0 mm/slub.c:2587
 do_slab_free mm/slub.c:3487 [inline]
 ___cache_free+0xe3/0x100 mm/slub.c:3506
 qlist_free_all+0x36/0x90 mm/kasan/quarantine.c:176
 kasan_quarantine_reduce+0x162/0x180 mm/kasan/quarantine.c:283
 __kasan_slab_alloc+0x2f/0xc0 mm/kasan/common.c:444
 kasan_slab_alloc include/linux/kasan.h:254 [inline]
 slab_post_alloc_hook+0x53/0x380 mm/slab.h:519
 slab_alloc_node mm/slub.c:3220 [inline]
 kmem_cache_alloc_node+0x121/0x2c0 mm/slub.c:3256
 __alloc_skb+0xdd/0x590 net/core/skbuff.c:415
 alloc_skb include/linux/skbuff.h:1167 [inline]
 alloc_skb_with_frags+0xa3/0x780 net/core/skbuff.c:6170
 sock_alloc_send_pskb+0x915/0xa50 net/core/sock.c:2530
 unix_dgram_sendmsg+0x6fd/0x2090 net/unix/af_unix.c:1798
 sock_sendmsg_nosec net/socket.c:704 [inline]
 __sock_sendmsg net/socket.c:716 [inline]
 __sys_sendto+0x564/0x720 net/socket.c:2058
 __do_sys_sendto net/socket.c:2070 [inline]
 __se_sys_sendto net/socket.c:2066 [inline]
 __x64_sys_sendto+0xda/0xf0 net/socket.c:2066

Memory state around the buggy address:
 ffff88807c6aff00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff88807c6aff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88807c6b0000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                        ^
 ffff88807c6b0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88807c6b0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/09/17 22:55 linux-5.15.y 3a5928702e71 c673ca06 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan-perf KASAN: use-after-free Read in device_shutdown
2024/09/13 11:26 linux-5.15.y 3a5928702e71 73e8a465 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan KASAN: use-after-free Read in device_shutdown
2024/09/12 16:06 linux-5.15.y 3a5928702e71 60e1a995 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan KASAN: use-after-free Read in device_shutdown
* Struck through repros no longer work on HEAD.