syzbot


KASAN: slab-use-after-free Read in xsk_diag_dump

Status: fixed on 2023/10/12 12:48
Subsystems: net bpf
[Documentation on labels]
Reported-by: syzbot+822d1359297e2694f873@syzkaller.appspotmail.com
Fix commit: 3e019d8a05a3 xsk: Fix xsk_diag use-after-free error during socket cleanup
First crash: 277d, last: 264d
Cause bisection: introduced by (bisect log) :
commit 18b1ab7aa76bde181bdb1ab19a87fa9523c32f21
Author: Magnus Karlsson <magnus.karlsson@intel.com>
Date: Mon Feb 28 09:45:52 2022 +0000

  xsk: Fix race at socket teardown

Crash: KASAN: use-after-free Read in xsk_diag_dump (log)
Repro: C syz .config
  
Discussions (3)
Title Replies (including bot) Last reply
[PATCH bpf v2] xsk: fix xsk_diag use-after-free error during socket cleanup 4 (4) 2023/08/31 11:30
[PATCH bpf] xsk: fix xsk_diag use-after-free error during socket cleanup 6 (6) 2023/08/31 05:21
[syzbot] [bpf?] [net?] KASAN: slab-use-after-free Read in xsk_diag_dump 3 (4) 2023/08/29 13:00
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-6.1 KASAN: use-after-free Read in xsk_diag_dump 2 270d 275d 0/3 auto-obsoleted due to no activity on 2023/12/09 18:57
linux-5.15 KASAN: use-after-free Read in xsk_diag_dump 2 264d 272d 0/3 auto-obsoleted due to no activity on 2023/12/16 03:15
Last patch testing requests (1)
Created Duration User Patch Repo Result
2023/08/30 12:40 24m magnus.karlsson@intel.com patch https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git 35d2b7ffffc1d9b3dc6c761010aa3338da49165b OK log

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in xsk_diag_put_info net/xdp/xsk_diag.c:21 [inline]
BUG: KASAN: slab-use-after-free in xsk_diag_fill net/xdp/xsk_diag.c:114 [inline]
BUG: KASAN: slab-use-after-free in xsk_diag_dump+0x1573/0x15c0 net/xdp/xsk_diag.c:163
Read of size 4 at addr ffff8880789da0e0 by task syz-executor370/5025

CPU: 1 PID: 5025 Comm: syz-executor370 Not tainted 6.5.0-rc7-syzkaller-00108-g5c905279a1b7 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd9/0x1b0 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:364 [inline]
 print_report+0xc4/0x620 mm/kasan/report.c:475
 kasan_report+0xda/0x110 mm/kasan/report.c:588
 xsk_diag_put_info net/xdp/xsk_diag.c:21 [inline]
 xsk_diag_fill net/xdp/xsk_diag.c:114 [inline]
 xsk_diag_dump+0x1573/0x15c0 net/xdp/xsk_diag.c:163
 netlink_dump+0x588/0xca0 net/netlink/af_netlink.c:2269
 __netlink_dump_start+0x6d0/0x9c0 net/netlink/af_netlink.c:2376
 netlink_dump_start include/linux/netlink.h:330 [inline]
 xsk_diag_handler_dump+0x1a6/0x240 net/xdp/xsk_diag.c:190
 __sock_diag_cmd net/core/sock_diag.c:238 [inline]
 sock_diag_rcv_msg+0x316/0x440 net/core/sock_diag.c:269
 netlink_rcv_skb+0x16b/0x440 net/netlink/af_netlink.c:2549
 sock_diag_rcv+0x2a/0x40 net/core/sock_diag.c:280
 netlink_unicast_kernel net/netlink/af_netlink.c:1339 [inline]
 netlink_unicast+0x539/0x800 net/netlink/af_netlink.c:1365
 netlink_sendmsg+0x93c/0xe30 net/netlink/af_netlink.c:1914
 sock_sendmsg_nosec net/socket.c:725 [inline]
 sock_sendmsg+0xd9/0x180 net/socket.c:748
 sock_write_iter+0x29b/0x3d0 net/socket.c:1129
 call_write_iter include/linux/fs.h:1877 [inline]
 do_iter_readv_writev+0x21e/0x3c0 fs/read_write.c:735
 do_iter_write+0x17f/0x830 fs/read_write.c:860
 vfs_writev+0x221/0x700 fs/read_write.c:933
 do_writev+0x285/0x370 fs/read_write.c:976
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fd9ce8b9df9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 c1 17 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:00007ffc3b052168 EFLAGS: 00000246 ORIG_RAX: 0000000000000014
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fd9ce8b9df9
RDX: 0000000000000001 RSI: 00000000200003c0 RDI: 0000000000000006
RBP: 0000000000000000 R08: 0000000000000006 R09: 0000000000000006
R10: 0000000000000006 R11: 0000000000000246 R12: 0000000000000000
R13: 431bde82d7b634db R14: 0000000000000001 R15: 0000000000000001
 </TASK>

Allocated by task 5025:
 kasan_save_stack+0x33/0x50 mm/kasan/common.c:45
 kasan_set_track+0x25/0x30 mm/kasan/common.c:52
 ____kasan_kmalloc mm/kasan/common.c:374 [inline]
 __kasan_kmalloc+0xa2/0xb0 mm/kasan/common.c:383
 kasan_kmalloc include/linux/kasan.h:196 [inline]
 __do_kmalloc_node mm/slab_common.c:985 [inline]
 __kmalloc_node+0x60/0x100 mm/slab_common.c:992
 kmalloc_node include/linux/slab.h:602 [inline]
 kvmalloc_node+0x99/0x1a0 mm/util.c:604
 kvmalloc include/linux/slab.h:720 [inline]
 kvzalloc include/linux/slab.h:728 [inline]
 alloc_netdev_mqs+0x9b/0x1240 net/core/dev.c:10594
 rtnl_create_link+0xc9c/0xfd0 net/core/rtnetlink.c:3350
 rtnl_newlink_create net/core/rtnetlink.c:3476 [inline]
 __rtnl_newlink+0x108e/0x1940 net/core/rtnetlink.c:3706
 rtnl_newlink+0x67/0xa0 net/core/rtnetlink.c:3719
 rtnetlink_rcv_msg+0x439/0xd30 net/core/rtnetlink.c:6445
 netlink_rcv_skb+0x16b/0x440 net/netlink/af_netlink.c:2549
 netlink_unicast_kernel net/netlink/af_netlink.c:1339 [inline]
 netlink_unicast+0x539/0x800 net/netlink/af_netlink.c:1365
 netlink_sendmsg+0x93c/0xe30 net/netlink/af_netlink.c:1914
 sock_sendmsg_nosec net/socket.c:725 [inline]
 sock_sendmsg+0xd9/0x180 net/socket.c:748
 ____sys_sendmsg+0x6ac/0x940 net/socket.c:2494
 ___sys_sendmsg+0x135/0x1d0 net/socket.c:2548
 __sys_sendmsg+0x117/0x1e0 net/socket.c:2577
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 5025:
 kasan_save_stack+0x33/0x50 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:522
 ____kasan_slab_free mm/kasan/common.c:236 [inline]
 ____kasan_slab_free+0x15e/0x1b0 mm/kasan/common.c:200
 kasan_slab_free include/linux/kasan.h:162 [inline]
 slab_free_hook mm/slub.c:1792 [inline]
 slab_free_freelist_hook+0x10b/0x1e0 mm/slub.c:1818
 slab_free mm/slub.c:3801 [inline]
 __kmem_cache_free+0xb8/0x2f0 mm/slub.c:3814
 kvfree+0x47/0x50 mm/util.c:650
 device_release+0xa1/0x240 drivers/base/core.c:2484
 kobject_cleanup lib/kobject.c:682 [inline]
 kobject_release lib/kobject.c:713 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1f7/0x5b0 lib/kobject.c:730
 netdev_run_todo+0x7dd/0x11d0 net/core/dev.c:10366
 rtnl_unlock net/core/rtnetlink.c:151 [inline]
 rtnetlink_rcv_msg+0x446/0xd30 net/core/rtnetlink.c:6446
 netlink_rcv_skb+0x16b/0x440 net/netlink/af_netlink.c:2549
 netlink_unicast_kernel net/netlink/af_netlink.c:1339 [inline]
 netlink_unicast+0x539/0x800 net/netlink/af_netlink.c:1365
 netlink_sendmsg+0x93c/0xe30 net/netlink/af_netlink.c:1914
 sock_sendmsg_nosec net/socket.c:725 [inline]
 sock_sendmsg+0xd9/0x180 net/socket.c:748
 ____sys_sendmsg+0x6ac/0x940 net/socket.c:2494
 ___sys_sendmsg+0x135/0x1d0 net/socket.c:2548
 __sys_sendmsg+0x117/0x1e0 net/socket.c:2577
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff8880789da000
 which belongs to the cache kmalloc-cg-4k of size 4096
The buggy address is located 224 bytes inside of
 freed 4096-byte region [ffff8880789da000, ffff8880789db000)

The buggy address belongs to the physical page:
page:ffffea0001e27600 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x789d8
head:ffffea0001e27600 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
anon flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000010200 ffff88801284f500 0000000000000000 0000000000000001
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 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4479, tgid 4479 (udevd), ts 29735533397, free_ts 28964079298
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook+0x2d2/0x350 mm/page_alloc.c:1570
 prep_new_page mm/page_alloc.c:1577 [inline]
 get_page_from_freelist+0x10a9/0x31e0 mm/page_alloc.c:3221
 __alloc_pages+0x1d0/0x4a0 mm/page_alloc.c:4477
 alloc_pages+0x1a9/0x270 mm/mempolicy.c:2292
 alloc_slab_page mm/slub.c:1862 [inline]
 allocate_slab+0x24e/0x380 mm/slub.c:2009
 new_slab mm/slub.c:2062 [inline]
 ___slab_alloc+0x8bc/0x1570 mm/slub.c:3215
 __slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3314
 __slab_alloc_node mm/slub.c:3367 [inline]
 slab_alloc_node mm/slub.c:3460 [inline]
 __kmem_cache_alloc_node+0x137/0x350 mm/slub.c:3509
 __do_kmalloc_node mm/slab_common.c:984 [inline]
 __kmalloc_node+0x4f/0x100 mm/slab_common.c:992
 kmalloc_node include/linux/slab.h:602 [inline]
 kvmalloc_node+0x99/0x1a0 mm/util.c:604
 kvmalloc include/linux/slab.h:720 [inline]
 seq_buf_alloc fs/seq_file.c:38 [inline]
 seq_read_iter+0x80b/0x1280 fs/seq_file.c:210
 kernfs_fop_read_iter+0x4c8/0x680 fs/kernfs/file.c:279
 call_read_iter include/linux/fs.h:1871 [inline]
 new_sync_read fs/read_write.c:389 [inline]
 vfs_read+0x4e0/0x930 fs/read_write.c:470
 ksys_read+0x12f/0x250 fs/read_write.c:613
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1161 [inline]
 free_unref_page_prepare+0x508/0xb90 mm/page_alloc.c:2348
 free_unref_page+0x33/0x3b0 mm/page_alloc.c:2443
 qlink_free mm/kasan/quarantine.c:166 [inline]
 qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:185
 kasan_quarantine_reduce+0x18b/0x1d0 mm/kasan/quarantine.c:292
 __kasan_slab_alloc+0x65/0x90 mm/kasan/common.c:305
 kasan_slab_alloc include/linux/kasan.h:186 [inline]
 slab_post_alloc_hook mm/slab.h:762 [inline]
 slab_alloc_node mm/slub.c:3470 [inline]
 slab_alloc mm/slub.c:3478 [inline]
 __kmem_cache_alloc_lru mm/slub.c:3485 [inline]
 kmem_cache_alloc+0x172/0x3b0 mm/slub.c:3494
 getname_flags.part.0+0x50/0x4d0 fs/namei.c:140
 getname_flags include/linux/audit.h:319 [inline]
 getname+0x90/0xe0 fs/namei.c:219
 do_sys_openat2+0x100/0x1e0 fs/open.c:1401
 do_sys_open fs/open.c:1422 [inline]
 __do_sys_openat fs/open.c:1438 [inline]
 __se_sys_openat fs/open.c:1433 [inline]
 __x64_sys_openat+0x175/0x210 fs/open.c:1433
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Memory state around the buggy address:
 ffff8880789d9f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8880789da000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880789da080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                       ^
 ffff8880789da100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880789da180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (9):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/08/27 04:53 net 5c905279a1b7 03d9c195 .config strace log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-net-this-kasan-gce KASAN: slab-use-after-free Read in xsk_diag_dump
2023/08/27 04:52 net-next b32add2d20ea 03d9c195 .config strace log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-net-kasan-gce KASAN: slab-use-after-free Read in xsk_diag_dump
2023/08/26 22:45 upstream 7d2f353b2682 03d9c195 .config console log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root KFENCE: use-after-free in xsk_diag_dump
2023/09/07 10:07 upstream 7ba2090ca64e 72324844 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: slab-use-after-free Read in xsk_diag_dump
2023/08/31 03:03 upstream ef2a0b7cdbc5 84803932 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: slab-use-after-free Read in xsk_diag_dump
2023/08/26 15:50 upstream 7d2f353b2682 03d9c195 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root KASAN: slab-use-after-free Read in xsk_diag_dump
2023/08/25 12:31 upstream 4f9e7fabf864 03d9c195 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root KASAN: slab-use-after-free Read in xsk_diag_dump
2023/08/26 14:06 upstream 7d2f353b2682 03d9c195 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: slab-out-of-bounds Read in xsk_diag_dump
2023/08/26 14:03 upstream 7d2f353b2682 03d9c195 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: use-after-free Read in xsk_diag_dump
* Struck through repros no longer work on HEAD.