syzbot


KASAN: use-after-free Read in p9_req_put

Status: upstream: reported on 2022/08/17 05:36
Reported-by: syzbot+de52531662ebb8823b26@syzkaller.appspotmail.com
Fix commit: 9p: p9_client_create: use p9_client_destroy on failure
Patched on: [ci-upstream-linux-next-kasan-gce-root], missing on: [ci-qemu-upstream ci-qemu-upstream-386 ci-qemu2-arm32 ci-qemu2-arm64 ci-qemu2-arm64-compat ci-qemu2-arm64-mte ci-qemu2-riscv64 ci-upstream-bpf-kasan-gce ci-upstream-bpf-next-kasan-gce ci-upstream-gce-arm64 ci-upstream-gce-leak ci-upstream-kasan-gce ci-upstream-kasan-gce-386 ci-upstream-kasan-gce-root ci-upstream-kasan-gce-selinux-root ci-upstream-kasan-gce-smack-root ci-upstream-kmsan-gce ci-upstream-kmsan-gce-386 ci-upstream-net-kasan-gce ci-upstream-net-this-kasan-gce ci2-upstream-fs ci2-upstream-kcsan-gce ci2-upstream-usb]
First crash: 177d, last: 5d20h

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in __lock_acquire+0x3ee7/0x56d0 kernel/locking/lockdep.c:4925
Read of size 8 at addr ffff88801b1a4818 by task syz-executor.0/21899

CPU: 0 PID: 21899 Comm: syz-executor.0 Not tainted 6.2.0-rc6-syzkaller-00009-g58706f7fb045 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
Call Trace:
 <IRQ>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd1/0x138 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:306 [inline]
 print_report+0x15e/0x461 mm/kasan/report.c:417
 kasan_report+0xbf/0x1f0 mm/kasan/report.c:517
 __lock_acquire+0x3ee7/0x56d0 kernel/locking/lockdep.c:4925
 lock_acquire kernel/locking/lockdep.c:5668 [inline]
 lock_acquire+0x1e3/0x630 kernel/locking/lockdep.c:5633
 __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
 _raw_spin_lock_irqsave+0x3d/0x60 kernel/locking/spinlock.c:162
 p9_tag_remove net/9p/client.c:390 [inline]
 p9_req_put net/9p/client.c:398 [inline]
 p9_req_put+0xca/0x250 net/9p/client.c:395
 req_done+0x1e2/0x2e0 net/9p/trans_virtio.c:147
 vring_interrupt drivers/virtio/virtio_ring.c:2470 [inline]
 vring_interrupt+0x2a1/0x3d0 drivers/virtio/virtio_ring.c:2445
 __handle_irq_event_percpu+0x264/0x970 kernel/irq/handle.c:158
 handle_irq_event_percpu kernel/irq/handle.c:193 [inline]
 handle_irq_event+0xab/0x1e0 kernel/irq/handle.c:210
 handle_edge_irq+0x263/0xd00 kernel/irq/chip.c:819
 generic_handle_irq_desc include/linux/irqdesc.h:158 [inline]
 handle_irq arch/x86/kernel/irq.c:231 [inline]
 __common_interrupt+0xa1/0x210 arch/x86/kernel/irq.c:250
 common_interrupt+0xa8/0xd0 arch/x86/kernel/irq.c:240
 </IRQ>
 <TASK>
 asm_common_interrupt+0x26/0x40 arch/x86/include/asm/idtentry.h:640
RIP: 0010:lock_is_held_type+0x103/0x140 kernel/locking/lockdep.c:5716
Code: 00 00 b8 ff ff ff ff 65 0f c1 05 b0 a0 fc 75 83 f8 01 75 29 9c 58 f6 c4 02 75 3d 48 f7 04 24 00 02 00 00 74 01 fb 48 83 c4 08 <44> 89 e8 5b 5d 41 5c 41 5d 41 5e 41 5f c3 45 31 ed eb b9 0f 0b 48
RSP: 0018:ffffc90002f5f648 EFLAGS: 00000286
RAX: 0000000000000046 RBX: 0000000000000001 RCX: 0000000000000001
RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000
RBP: ffffffff8c78ea80 R08: 0000000000000000 R09: ffffffff8e722e17
R10: fffffbfff1ce45c2 R11: 00000000bfdcf87f R12: ffff88802774c180
R13: 0000000000000000 R14: 00000000ffffffff R15: ffff88802774cbb8
 lock_is_held include/linux/lockdep.h:283 [inline]
 rcu_read_lock_sched_held+0x3e/0x70 kernel/rcu/update.c:125
 trace_lock_acquire include/trace/events/lock.h:24 [inline]
 lock_acquire+0x500/0x630 kernel/locking/lockdep.c:5639
 __fs_reclaim_acquire mm/page_alloc.c:4674 [inline]
 fs_reclaim_acquire+0x11d/0x160 mm/page_alloc.c:4688
 might_alloc include/linux/sched/mm.h:271 [inline]
 slab_pre_alloc_hook mm/slab.h:720 [inline]
 slab_alloc_node mm/slab.c:3247 [inline]
 __kmem_cache_alloc_node+0x3b/0x510 mm/slab.c:3546
 __do_kmalloc_node mm/slab_common.c:967 [inline]
 __kmalloc_node+0x4d/0xd0 mm/slab_common.c:975
 kmalloc_node include/linux/slab.h:610 [inline]
 kvmalloc_node+0xa2/0x1a0 mm/util.c:581
 kvmalloc include/linux/slab.h:737 [inline]
 kvzalloc include/linux/slab.h:745 [inline]
 netif_alloc_netdev_queues net/core/dev.c:9908 [inline]
 alloc_netdev_mqs+0x9be/0x1180 net/core/dev.c:10645
 ip6_tnl_init_net+0x217/0x890 net/ipv6/ip6_tunnel.c:2239
 ops_init+0xb9/0x670 net/core/net_namespace.c:135
 setup_net+0x793/0xe60 net/core/net_namespace.c:333
 copy_net_ns+0x31b/0x6b0 net/core/net_namespace.c:483
 create_new_namespaces+0x3f6/0xb20 kernel/nsproxy.c:110
 copy_namespaces+0x3b3/0x4a0 kernel/nsproxy.c:179
 copy_process+0x30d3/0x7520 kernel/fork.c:2269
 kernel_clone+0xeb/0x990 kernel/fork.c:2681
 __do_sys_clone3+0x1cd/0x2e0 kernel/fork.c:2980
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f169e48c0c9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f169f1f6038 EFLAGS: 00000246 ORIG_RAX: 00000000000001b3
RAX: ffffffffffffffda RBX: 00007f169e5abf80 RCX: 00007f169e48c0c9
RDX: 0000000000000000 RSI: 0000000000000058 RDI: 00007f169f1f6050
RBP: 00007f169e4e7ae9 R08: 0000000000000000 R09: 0000000000000058
R10: 00007f169f1f6050 R11: 0000000000000246 R12: 0000000000000058
R13: 00007ffc5a20a0df R14: 00007f169f1f6300 R15: 0000000000022000
 </TASK>

Allocated by task 21905:
 kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
 kasan_set_track+0x25/0x30 mm/kasan/common.c:52
 ____kasan_kmalloc mm/kasan/common.c:371 [inline]
 ____kasan_kmalloc mm/kasan/common.c:330 [inline]
 __kasan_kmalloc+0xa3/0xb0 mm/kasan/common.c:380
 kmalloc include/linux/slab.h:580 [inline]
 p9_client_create+0xb3/0x1070 net/9p/client.c:975
 v9fs_session_init+0x1e6/0x18b0 fs/9p/v9fs.c:407
 v9fs_mount+0xbe/0xca0 fs/9p/vfs_super.c:125
 legacy_get_tree+0x109/0x220 fs/fs_context.c:610
 vfs_get_tree+0x8d/0x2f0 fs/super.c:1489
 do_new_mount fs/namespace.c:3145 [inline]
 path_mount+0x132a/0x1e20 fs/namespace.c:3475
 do_mount fs/namespace.c:3488 [inline]
 __do_sys_mount fs/namespace.c:3697 [inline]
 __se_sys_mount fs/namespace.c:3674 [inline]
 __x64_sys_mount+0x283/0x300 fs/namespace.c:3674
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 21905:
 kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
 kasan_set_track+0x25/0x30 mm/kasan/common.c:52
 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:518
 ____kasan_slab_free mm/kasan/common.c:236 [inline]
 ____kasan_slab_free+0x13b/0x1a0 mm/kasan/common.c:200
 kasan_slab_free include/linux/kasan.h:177 [inline]
 __cache_free mm/slab.c:3396 [inline]
 __do_kmem_cache_free mm/slab.c:3582 [inline]
 __kmem_cache_free+0xcd/0x3b0 mm/slab.c:3589
 p9_client_create+0x7aa/0x1070 net/9p/client.c:1046
 v9fs_session_init+0x1e6/0x18b0 fs/9p/v9fs.c:407
 v9fs_mount+0xbe/0xca0 fs/9p/vfs_super.c:125
 legacy_get_tree+0x109/0x220 fs/fs_context.c:610
 vfs_get_tree+0x8d/0x2f0 fs/super.c:1489
 do_new_mount fs/namespace.c:3145 [inline]
 path_mount+0x132a/0x1e20 fs/namespace.c:3475
 do_mount fs/namespace.c:3488 [inline]
 __do_sys_mount fs/namespace.c:3697 [inline]
 __se_sys_mount fs/namespace.c:3674 [inline]
 __x64_sys_mount+0x283/0x300 fs/namespace.c:3674
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Last potentially related work creation:
 kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
 __kasan_record_aux_stack+0x7b/0x90 mm/kasan/generic.c:488
 kvfree_call_rcu+0x78/0x8f0 kernel/rcu/tree.c:3376
 ma_put net/ipv6/mcast.c:869 [inline]
 ma_put+0x11c/0x180 net/ipv6/mcast.c:865
 __ipv6_dev_mc_dec+0x27c/0x340 net/ipv6/mcast.c:982
 ipv6_mc_destroy_dev+0x2ca/0x630 net/ipv6/mcast.c:2800
 addrconf_ifdown.isra.0+0x12c2/0x1920 net/ipv6/addrconf.c:3893
 addrconf_notify+0x109/0x1c80 net/ipv6/addrconf.c:3673
 notifier_call_chain+0xb5/0x200 kernel/notifier.c:87
 call_netdevice_notifiers_info+0xb5/0x130 net/core/dev.c:1944
 call_netdevice_notifiers_extack net/core/dev.c:1982 [inline]
 call_netdevice_notifiers net/core/dev.c:1996 [inline]
 unregister_netdevice_many_notify+0xa2b/0x19e0 net/core/dev.c:10839
 vti6_exit_batch_net+0x3a4/0x670 net/ipv6/ip6_vti.c:1188
 ops_exit_list+0x125/0x170 net/core/net_namespace.c:174
 cleanup_net+0x4ee/0xb10 net/core/net_namespace.c:606
 process_one_work+0x9bf/0x1710 kernel/workqueue.c:2289
 worker_thread+0x669/0x1090 kernel/workqueue.c:2436
 kthread+0x2e8/0x3a0 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

Second to last potentially related work creation:
 kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
 __kasan_record_aux_stack+0x7b/0x90 mm/kasan/generic.c:488
 __call_rcu_common.constprop.0+0x99/0x820 kernel/rcu/tree.c:2755
 __ip_vs_cleanup_batch+0x99/0x120 net/netfilter/ipvs/ip_vs_core.c:2356
 ops_exit_list+0x125/0x170 net/core/net_namespace.c:174
 cleanup_net+0x4ee/0xb10 net/core/net_namespace.c:606
 process_one_work+0x9bf/0x1710 kernel/workqueue.c:2289
 worker_thread+0x669/0x1090 kernel/workqueue.c:2436
 kthread+0x2e8/0x3a0 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

The buggy address belongs to the object at ffff88801b1a4800
 which belongs to the cache kmalloc-512 of size 512
The buggy address is located 24 bytes inside of
 512-byte region [ffff88801b1a4800, ffff88801b1a4a00)

The buggy address belongs to the physical page:
page:ffffea00006c6900 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1b1a4
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffff888012440600 ffffea00009666d0 ffffea000075c450
raw: 0000000000000000 ffff88801b1a4000 0000000100000004 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 0x2420c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_COMP|__GFP_THISNODE), pid 433, tgid 433 (kworker/u17:3), ts 10333944194, free_ts 10277494553
 prep_new_page mm/page_alloc.c:2531 [inline]
 get_page_from_freelist+0x119c/0x2ce0 mm/page_alloc.c:4283
 __alloc_pages+0x1cb/0x5b0 mm/page_alloc.c:5549
 __alloc_pages_node include/linux/gfp.h:237 [inline]
 kmem_getpages mm/slab.c:1363 [inline]
 cache_grow_begin+0x94/0x390 mm/slab.c:2576
 cache_alloc_refill+0x27f/0x380 mm/slab.c:2949
 ____cache_alloc mm/slab.c:3025 [inline]
 ____cache_alloc mm/slab.c:3008 [inline]
 __do_cache_alloc mm/slab.c:3208 [inline]
 slab_alloc_node mm/slab.c:3256 [inline]
 __kmem_cache_alloc_node+0x44f/0x510 mm/slab.c:3546
 kmalloc_trace+0x26/0x60 mm/slab_common.c:1062
 kmalloc include/linux/slab.h:580 [inline]
 kzalloc include/linux/slab.h:720 [inline]
 alloc_bprm+0x51/0x900 fs/exec.c:1510
 kernel_execve+0xaf/0x500 fs/exec.c:1981
 call_usermodehelper_exec_async+0x2e7/0x580 kernel/umh.c:113
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1446 [inline]
 free_pcp_prepare+0x65c/0xc00 mm/page_alloc.c:1496
 free_unref_page_prepare mm/page_alloc.c:3369 [inline]
 free_unref_page+0x1d/0x490 mm/page_alloc.c:3464
 __folio_put_small mm/swap.c:106 [inline]
 __folio_put+0xc5/0x140 mm/swap.c:129
 folio_put include/linux/mm.h:1250 [inline]
 put_page include/linux/mm.h:1319 [inline]
 free_page_and_swap_cache+0x257/0x2c0 mm/swap_state.c:299
 __tlb_remove_table arch/x86/include/asm/tlb.h:34 [inline]
 __tlb_remove_table_free mm/mmu_gather.c:153 [inline]
 tlb_remove_table_rcu+0x89/0xe0 mm/mmu_gather.c:208
 rcu_do_batch kernel/rcu/tree.c:2246 [inline]
 rcu_core+0x81f/0x1980 kernel/rcu/tree.c:2506
 __do_softirq+0x1fb/0xadc kernel/softirq.c:571

Memory state around the buggy address:
 ffff88801b1a4700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff88801b1a4780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88801b1a4800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                            ^
 ffff88801b1a4880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88801b1a4900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
----------------
Code disassembly (best guess):
   0:	00 00                	add    %al,(%rax)
   2:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
   7:	65 0f c1 05 b0 a0 fc 	xadd   %eax,%gs:0x75fca0b0(%rip)        # 0x75fca0bf
   e:	75
   f:	83 f8 01             	cmp    $0x1,%eax
  12:	75 29                	jne    0x3d
  14:	9c                   	pushfq
  15:	58                   	pop    %rax
  16:	f6 c4 02             	test   $0x2,%ah
  19:	75 3d                	jne    0x58
  1b:	48 f7 04 24 00 02 00 	testq  $0x200,(%rsp)
  22:	00
  23:	74 01                	je     0x26
  25:	fb                   	sti
  26:	48 83 c4 08          	add    $0x8,%rsp
* 2a:	44 89 e8             	mov    %r13d,%eax <-- trapping instruction
  2d:	5b                   	pop    %rbx
  2e:	5d                   	pop    %rbp
  2f:	41 5c                	pop    %r12
  31:	41 5d                	pop    %r13
  33:	41 5e                	pop    %r14
  35:	41 5f                	pop    %r15
  37:	c3                   	retq
  38:	45 31 ed             	xor    %r13d,%r13d
  3b:	eb b9                	jmp    0xfffffff6
  3d:	0f 0b                	ud2
  3f:	48                   	rex.W

Crashes (19):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets Title
ci-qemu-upstream 2023/01/31 23:45 upstream 58706f7fb045 7374c4e5 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2023/01/26 06:26 upstream 7c46948a6e9c 7374c4e5 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2023/01/16 07:17 upstream 5dc4c995db9e a63719e7 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2023/01/07 18:52 upstream 0a71553536d2 1dac8c7a .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2022/11/28 10:28 upstream b7b275e60bcd 950c3e02 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2022/11/11 21:49 upstream eb037f16f7e8 f42ee5d8 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2022/10/02 12:56 upstream b357fd1c2afc feb56351 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2022/09/17 04:54 upstream a335366bad13 dd9a85ff .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2022/08/23 03:49 upstream 072e51356cd5 26a13b38 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream 2022/08/13 05:00 upstream c3adefb5baf3 8dfcaa3d .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2023/01/19 11:05 upstream 7287904c8771 7374c4e5 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2023/01/08 00:27 upstream 0a71553536d2 1dac8c7a .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2023/01/02 08:57 upstream 150aae354b81 ab32d508 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2022/12/23 07:07 upstream 8395ae05cb5a 9da18ae8 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2022/12/23 01:01 upstream 8395ae05cb5a 9da18ae8 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2022/11/14 00:50 upstream af7a05689189 7ba4d859 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2022/11/10 21:28 upstream 1767a722a708 3ead01ad .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2022/09/07 20:43 upstream 0066f1b0e275 c5b7bc57 .config console log report info KASAN: use-after-free Read in p9_req_put
ci-qemu-upstream-386 2022/09/01 00:27 upstream c5e4d5e99162 51e54e30 .config console log report info KASAN: use-after-free Read in p9_req_put
* Struck through repros no longer work on HEAD.