syzbot


KASAN: use-after-free Read in cpu_map_generic_redirect

Status: premoderation: reported on 2024/08/21 09:12
Reported-by: syzbot+1862cdb60c88d59ad169@syzkaller.appspotmail.com
First crash: 46d, last: 40d
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-6.1 KASAN: use-after-free Read in cpu_map_generic_redirect 1 23d 23d 0/3 upstream: reported on 2024/09/13 03:13

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in cpu_map_generic_redirect+0x1c7/0x780 kernel/bpf/cpumap.c:788
Read of size 8 at addr ffff888115b3d018 by task syz.4.2267/6177

CPU: 1 PID: 6177 Comm: syz.4.2267 Not tainted 6.1.90-syzkaller-00030-g370ea8bc2e0b #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/27/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x151/0x1b7 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:316 [inline]
 print_report+0x158/0x4e0 mm/kasan/report.c:427
 kasan_report+0x13c/0x170 mm/kasan/report.c:531
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/report_generic.c:351
 cpu_map_generic_redirect+0x1c7/0x780 kernel/bpf/cpumap.c:788
 xdp_do_generic_redirect_map net/core/filter.c:4367 [inline]
 xdp_do_generic_redirect+0x3b5/0xad0 net/core/filter.c:4412
 do_xdp_generic+0x53e/0x800 net/core/dev.c:4954
 tun_get_user+0x238a/0x3a90 drivers/net/tun.c:1920
 tun_chr_write_iter+0x129/0x210 drivers/net/tun.c:2044
 call_write_iter include/linux/fs.h:2274 [inline]
 new_sync_write fs/read_write.c:491 [inline]
 vfs_write+0x902/0xeb0 fs/read_write.c:584
 ksys_write+0x199/0x2c0 fs/read_write.c:637
 __do_sys_write fs/read_write.c:649 [inline]
 __se_sys_write fs/read_write.c:646 [inline]
 __x64_sys_write+0x7b/0x90 fs/read_write.c:646
 x64_sys_call+0x2f/0x9a0 arch/x86/include/generated/asm/syscalls_64.h:2
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:81
 entry_SYSCALL_64_after_hwframe+0x68/0xd2
RIP: 0033:0x7fa4d4b7895f
Code: 89 54 24 18 48 89 74 24 10 89 7c 24 08 e8 c9 8d 02 00 48 8b 54 24 18 48 8b 74 24 10 41 89 c0 8b 7c 24 08 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 31 44 89 c7 48 89 44 24 08 e8 1c 8e 02 00 48
RSP: 002b:00007fa4d5955000 EFLAGS: 00000293 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fa4d4d15f80 RCX: 00007fa4d4b7895f
RDX: 0000000000000d86 RSI: 0000000020001580 RDI: 00000000000000c8
RBP: 00007fa4d4be793e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000d86 R11: 0000000000000293 R12: 0000000000000000
R13: 0000000000000000 R14: 00007fa4d4d15f80 R15: 00007fffcba76568
 </TASK>

Allocated by task 5239:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
 kasan_save_alloc_info+0x1f/0x30 mm/kasan/generic.c:505
 ____kasan_kmalloc mm/kasan/common.c:379 [inline]
 __kasan_kmalloc+0x9c/0xb0 mm/kasan/common.c:388
 kasan_kmalloc include/linux/kasan.h:212 [inline]
 kmalloc_trace+0x44/0xa0 mm/slab_common.c:1052
 kmalloc include/linux/slab.h:556 [inline]
 kzalloc include/linux/slab.h:692 [inline]
 ____ip_mc_inc_group+0x215/0x8d0 net/ipv4/igmp.c:1452
 __ip_mc_inc_group net/ipv4/igmp.c:1487 [inline]
 ip_mc_inc_group net/ipv4/igmp.c:1493 [inline]
 ip_mc_up+0x10f/0x1e0 net/ipv4/igmp.c:1792
 inetdev_event+0xc80/0x1110 net/ipv4/devinet.c:1577
 notifier_call_chain kernel/notifier.c:87 [inline]
 raw_notifier_call_chain+0x8c/0xf0 kernel/notifier.c:455
 __dev_notify_flags+0x304/0x610
 dev_change_flags+0xf0/0x1a0 net/core/dev.c:8668
 do_setlink+0xdb8/0x4060 net/core/rtnetlink.c:2801
 __rtnl_newlink net/core/rtnetlink.c:3576 [inline]
 rtnl_newlink+0x170f/0x2030 net/core/rtnetlink.c:3623
 rtnetlink_rcv_msg+0x9a5/0xca0 net/core/rtnetlink.c:6121
 netlink_rcv_skb+0x1cd/0x410 net/netlink/af_netlink.c:2518
 rtnetlink_rcv+0x1c/0x20 net/core/rtnetlink.c:6139
 netlink_unicast_kernel net/netlink/af_netlink.c:1327 [inline]
 netlink_unicast+0x906/0xab0 net/netlink/af_netlink.c:1353
 netlink_sendmsg+0xa15/0xd30 net/netlink/af_netlink.c:1875
 sock_sendmsg_nosec net/socket.c:716 [inline]
 __sock_sendmsg net/socket.c:728 [inline]
 __sys_sendto+0x480/0x600 net/socket.c:2138
 __do_sys_sendto net/socket.c:2150 [inline]
 __se_sys_sendto net/socket.c:2146 [inline]
 __x64_sys_sendto+0xe5/0x100 net/socket.c:2146
 x64_sys_call+0x15c/0x9a0 arch/x86/include/generated/asm/syscalls_64.h:45
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:81
 entry_SYSCALL_64_after_hwframe+0x68/0xd2

Freed by task 310:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:516
 ____kasan_slab_free+0x131/0x180 mm/kasan/common.c:241
 __kasan_slab_free+0x11/0x20 mm/kasan/common.c:249
 kasan_slab_free include/linux/kasan.h:178 [inline]
 slab_free_hook mm/slub.c:1745 [inline]
 slab_free_freelist_hook mm/slub.c:1771 [inline]
 slab_free mm/slub.c:3684 [inline]
 kmem_cache_free_bulk+0x636/0x7a0 mm/slub.c:3802
 kfree_bulk include/linux/slab.h:468 [inline]
 kfree_rcu_work+0x2ae/0x760 kernel/rcu/tree.c:3130
 process_one_work+0x73d/0xcb0 kernel/workqueue.c:2299
 worker_thread+0xa60/0x1260 kernel/workqueue.c:2446
 kthread+0x26d/0x300 kernel/kthread.c:386
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

Last potentially related work creation:
 kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xb4/0xc0 mm/kasan/generic.c:486
 kasan_record_aux_stack_noalloc+0xb/0x10 mm/kasan/generic.c:496
 kvfree_call_rcu+0x9f/0x800 kernel/rcu/tree.c:3444
 ip_ma_put+0xea/0x130 net/ipv4/igmp.c:171
 __ip_mc_dec_group+0x4b2/0x590 net/ipv4/igmp.c:1697
 ip_mc_dec_group include/linux/igmp.h:135 [inline]
 ip_mc_down+0x1a4/0x240 net/ipv4/igmp.c:1752
 inetdev_event+0x2ce/0x1110 net/ipv4/devinet.c:1588
 notifier_call_chain kernel/notifier.c:87 [inline]
 raw_notifier_call_chain+0x8c/0xf0 kernel/notifier.c:455
 call_netdevice_notifiers_info net/core/dev.c:1977 [inline]
 call_netdevice_notifiers_extack net/core/dev.c:2015 [inline]
 call_netdevice_notifiers net/core/dev.c:2029 [inline]
 dev_close_many+0x37c/0x530 net/core/dev.c:1577
 unregister_netdevice_many+0x4d1/0x1740 net/core/dev.c:10862
 default_device_exit_batch+0x975/0xa00 net/core/dev.c:11401
 ops_exit_list net/core/net_namespace.c:174 [inline]
 cleanup_net+0x6c9/0xbf0 net/core/net_namespace.c:601
 process_one_work+0x73d/0xcb0 kernel/workqueue.c:2299
 worker_thread+0xa60/0x1260 kernel/workqueue.c:2446
 kthread+0x26d/0x300 kernel/kthread.c:386
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

Second to last potentially related work creation:
 kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xb4/0xc0 mm/kasan/generic.c:486
 kasan_record_aux_stack_noalloc+0xb/0x10 mm/kasan/generic.c:496
 kvfree_call_rcu+0x9f/0x800 kernel/rcu/tree.c:3444
 ip_ma_put+0xea/0x130 net/ipv4/igmp.c:171
 __ip_mc_dec_group+0x4b2/0x590 net/ipv4/igmp.c:1697
 ip_mc_dec_group include/linux/igmp.h:135 [inline]
 ip_mc_down+0x1a4/0x240 net/ipv4/igmp.c:1752
 inetdev_event+0x2ce/0x1110 net/ipv4/devinet.c:1588
 notifier_call_chain kernel/notifier.c:87 [inline]
 raw_notifier_call_chain+0x8c/0xf0 kernel/notifier.c:455
 call_netdevice_notifiers_info net/core/dev.c:1977 [inline]
 call_netdevice_notifiers_extack net/core/dev.c:2015 [inline]
 call_netdevice_notifiers net/core/dev.c:2029 [inline]
 dev_close_many+0x37c/0x530 net/core/dev.c:1577
 unregister_netdevice_many+0x4d1/0x1740 net/core/dev.c:10862
 ip6gre_exit_batch_net+0x5b5/0x600 net/ipv6/ip6_gre.c:1669
 ops_exit_list net/core/net_namespace.c:174 [inline]
 cleanup_net+0x6c9/0xbf0 net/core/net_namespace.c:601
 process_one_work+0x73d/0xcb0 kernel/workqueue.c:2299
 worker_thread+0xa60/0x1260 kernel/workqueue.c:2446
 kthread+0x26d/0x300 kernel/kthread.c:386
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308

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

The buggy address belongs to the physical page:
page:ffffea000456cf40 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888115b3dd00 pfn:0x115b3d
flags: 0x4000000000000200(slab|zone=1)
raw: 4000000000000200 ffffea0004558048 ffffea000425a4c8 ffff888100042c00
raw: ffff888115b3dd00 000000000010000a 00000001ffffffff 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 0x12cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY), pid 107, tgid 107 (udevd), ts 4159931140, free_ts 0
 set_page_owner include/linux/page_owner.h:33 [inline]
 post_alloc_hook+0x213/0x220 mm/page_alloc.c:2590
 prep_new_page+0x1b/0x110 mm/page_alloc.c:2597
 get_page_from_freelist+0x27ea/0x2870 mm/page_alloc.c:4425
 __alloc_pages+0x3a1/0x780 mm/page_alloc.c:5714
 alloc_slab_page+0x6c/0xf0
 allocate_slab mm/slub.c:1962 [inline]
 new_slab+0x90/0x3e0 mm/slub.c:2015
 ___slab_alloc+0x6f9/0xb80 mm/slub.c:3203
 __slab_alloc+0x5d/0xa0 mm/slub.c:3302
 slab_alloc_node mm/slub.c:3387 [inline]
 __kmem_cache_alloc_node+0x1af/0x250 mm/slub.c:3460
 kmalloc_trace+0x2a/0xa0 mm/slab_common.c:1047
 kmalloc include/linux/slab.h:556 [inline]
 kzalloc include/linux/slab.h:692 [inline]
 kernfs_fop_open+0x350/0xb10 fs/kernfs/file.c:666
 do_dentry_open+0x891/0x1250 fs/open.c:884
 vfs_open+0x73/0x80 fs/open.c:1015
 do_open fs/namei.c:3627 [inline]
 path_openat+0x2532/0x2d60 fs/namei.c:3784
 do_filp_open+0x230/0x480 fs/namei.c:3811
 do_sys_openat2+0x151/0x890 fs/open.c:1341
page_owner free stack trace missing

Memory state around the buggy address:
 ffff888115b3cf00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff888115b3cf80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff888115b3d000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                            ^
 ffff888115b3d080: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
 ffff888115b3d100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
BUG: kernel NULL pointer dereference, address: 0000000000000004
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
PGD 11e26e067 P4D 11e26e067 PUD 11e272067 PMD 0 
Oops: 0002 [#1] PREEMPT SMP KASAN
CPU: 1 PID: 6177 Comm: syz.4.2267 Tainted: G    B              6.1.90-syzkaller-00030-g370ea8bc2e0b #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/27/2024
RIP: 0010:atomic_try_cmpxchg_acquire include/linux/atomic/atomic-instrumented.h:543 [inline]
RIP: 0010:queued_spin_lock include/asm-generic/qspinlock.h:111 [inline]
RIP: 0010:do_raw_spin_lock include/linux/spinlock.h:187 [inline]
RIP: 0010:__raw_spin_lock include/linux/spinlock_api_smp.h:134 [inline]
RIP: 0010:_raw_spin_lock+0xba/0x1b0 kernel/locking/spinlock.c:154
Code: 00 00 e8 59 5f 9d fc 4c 89 ff be 04 00 00 00 e8 4c 5f 9d fc 43 0f b6 04 26 84 c0 0f 85 a9 00 00 00 8b 44 24 20 b9 01 00 00 00 <f0> 41 0f b1 4d 00 75 33 48 c7 04 24 0e 36 e0 45 49 c7 04 1c 00 00
RSP: 0018:ffffc90007167680 EFLAGS: 00010297
RAX: 0000000000000000 RBX: 1ffff92000e2ced0 RCX: 0000000000000001
RDX: 0000000000000001 RSI: 0000000000000004 RDI: ffffc900071676a0
RBP: ffffc90007167710 R08: dffffc0000000000 R09: 0000000000000003
R10: ffffffffffffffff R11: dffffc0000000001 R12: dffffc0000000000
R13: 0000000000000004 R14: 1ffff92000e2ced4 R15: ffffc900071676a0
FS:  00007fa4d59556c0(0000) GS:ffff8881f7100000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000004 CR3: 000000011a41b000 CR4: 00000000003506a0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 spin_lock include/linux/spinlock.h:351 [inline]
 ptr_ring_produce include/linux/ptr_ring.h:128 [inline]
 cpu_map_generic_redirect+0x1f4/0x780 kernel/bpf/cpumap.c:788
 xdp_do_generic_redirect_map net/core/filter.c:4367 [inline]
 xdp_do_generic_redirect+0x3b5/0xad0 net/core/filter.c:4412
 do_xdp_generic+0x53e/0x800 net/core/dev.c:4954
 tun_get_user+0x238a/0x3a90 drivers/net/tun.c:1920
 tun_chr_write_iter+0x129/0x210 drivers/net/tun.c:2044
 call_write_iter include/linux/fs.h:2274 [inline]
 new_sync_write fs/read_write.c:491 [inline]
 vfs_write+0x902/0xeb0 fs/read_write.c:584
 ksys_write+0x199/0x2c0 fs/read_write.c:637
 __do_sys_write fs/read_write.c:649 [inline]
 __se_sys_write fs/read_write.c:646 [inline]
 __x64_sys_write+0x7b/0x90 fs/read_write.c:646
 x64_sys_call+0x2f/0x9a0 arch/x86/include/generated/asm/syscalls_64.h:2
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:81
 entry_SYSCALL_64_after_hwframe+0x68/0xd2
RIP: 0033:0x7fa4d4b7895f
Code: 89 54 24 18 48 89 74 24 10 89 7c 24 08 e8 c9 8d 02 00 48 8b 54 24 18 48 8b 74 24 10 41 89 c0 8b 7c 24 08 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 31 44 89 c7 48 89 44 24 08 e8 1c 8e 02 00 48
RSP: 002b:00007fa4d5955000 EFLAGS: 00000293 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fa4d4d15f80 RCX: 00007fa4d4b7895f
RDX: 0000000000000d86 RSI: 0000000020001580 RDI: 00000000000000c8
RBP: 00007fa4d4be793e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000d86 R11: 0000000000000293 R12: 0000000000000000
R13: 0000000000000000 R14: 00007fa4d4d15f80 R15: 00007fffcba76568
 </TASK>
Modules linked in:
CR2: 0000000000000004
---[ end trace 0000000000000000 ]---
RIP: 0010:atomic_try_cmpxchg_acquire include/linux/atomic/atomic-instrumented.h:543 [inline]
RIP: 0010:queued_spin_lock include/asm-generic/qspinlock.h:111 [inline]
RIP: 0010:do_raw_spin_lock include/linux/spinlock.h:187 [inline]
RIP: 0010:__raw_spin_lock include/linux/spinlock_api_smp.h:134 [inline]
RIP: 0010:_raw_spin_lock+0xba/0x1b0 kernel/locking/spinlock.c:154
Code: 00 00 e8 59 5f 9d fc 4c 89 ff be 04 00 00 00 e8 4c 5f 9d fc 43 0f b6 04 26 84 c0 0f 85 a9 00 00 00 8b 44 24 20 b9 01 00 00 00 <f0> 41 0f b1 4d 00 75 33 48 c7 04 24 0e 36 e0 45 49 c7 04 1c 00 00
RSP: 0018:ffffc90007167680 EFLAGS: 00010297
RAX: 0000000000000000 RBX: 1ffff92000e2ced0 RCX: 0000000000000001
RDX: 0000000000000001 RSI: 0000000000000004 RDI: ffffc900071676a0
RBP: ffffc90007167710 R08: dffffc0000000000 R09: 0000000000000003
R10: ffffffffffffffff R11: dffffc0000000001 R12: dffffc0000000000
R13: 0000000000000004 R14: 1ffff92000e2ced4 R15: ffffc900071676a0
FS:  00007fa4d59556c0(0000) GS:ffff8881f7100000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000004 CR3: 000000011a41b000 CR4: 00000000003506a0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
   0:	00 00                	add    %al,(%rax)
   2:	e8 59 5f 9d fc       	call   0xfc9d5f60
   7:	4c 89 ff             	mov    %r15,%rdi
   a:	be 04 00 00 00       	mov    $0x4,%esi
   f:	e8 4c 5f 9d fc       	call   0xfc9d5f60
  14:	43 0f b6 04 26       	movzbl (%r14,%r12,1),%eax
  19:	84 c0                	test   %al,%al
  1b:	0f 85 a9 00 00 00    	jne    0xca
  21:	8b 44 24 20          	mov    0x20(%rsp),%eax
  25:	b9 01 00 00 00       	mov    $0x1,%ecx
* 2a:	f0 41 0f b1 4d 00    	lock cmpxchg %ecx,0x0(%r13) <-- trapping instruction
  30:	75 33                	jne    0x65
  32:	48 c7 04 24 0e 36 e0 	movq   $0x45e0360e,(%rsp)
  39:	45
  3a:	49                   	rex.WB
  3b:	c7                   	.byte 0xc7
  3c:	04 1c                	add    $0x1c,%al

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/08/26 17:31 android14-6.1 370ea8bc2e0b 9aee4e0b .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-6-1 KASAN: use-after-free Read in cpu_map_generic_redirect
2024/08/26 17:30 android14-6.1 370ea8bc2e0b 9aee4e0b .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-6-1 KASAN: use-after-free Read in cpu_map_generic_redirect
2024/08/21 09:11 android14-6.1 edca080b95df db5852f9 .config console log report info [disk image] [vmlinux] [kernel image] ci2-android-6-1 KASAN: use-after-free Read in cpu_map_generic_redirect
* Struck through repros no longer work on HEAD.