syzbot


KASAN: use-after-free Read in free_netdev

Status: upstream: reported C repro on 2022/06/18 00:20
Reported-by: syzbot+e69efa892d4c43e82d34@syzkaller.appspotmail.com
Fix commit: bec1be0a745a net: tun: unlink NAPI from device on destruction
Patched on: [ci2-android-5-10 ci2-android-5-10-perf], missing on: []
First crash: 865d, last: 833d
Cause bisection: failed (error log, bisect log)
  
Similar bugs (6)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.19 KASAN: use-after-free Read in free_netdev C error 142 652d 1698d 0/1 upstream: reported C repro on 2020/03/07 10:14
upstream KASAN: use-after-free Read in free_netdev (2) net C done done 1715 1065d 1699d 20/28 fixed on 2022/03/08 16:11
android-54 KASAN: use-after-free Read in free_netdev C 427 798d 1699d 0/2 auto-obsoleted due to no activity on 2023/04/24 02:54
upstream KASAN: use-after-free Read in free_netdev (3) net C inconclusive 130 706d 861d 22/28 fixed on 2023/02/24 13:50
upstream KASAN: use-after-free Read in free_netdev net C 42 2546d 2569d 3/28 fixed on 2017/11/28 03:36
upstream general protection fault in free_netdev (2) net 1 1225d 1225d 0/28 auto-closed as invalid on 2021/09/20 23:14

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in free_netdev+0x18d/0x390 net/core/dev.c:10695
Read of size 8 at addr ffff888111dc3578 by task syz-executor301/534

CPU: 0 PID: 534 Comm: syz-executor301 Not tainted 5.10.117-syzkaller-00814-gfdd06dc6b0f8 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack_lvl+0x1e2/0x24b lib/dump_stack.c:118
 print_address_description+0x81/0x3c0 mm/kasan/report.c:233
 __kasan_report mm/kasan/report.c:419 [inline]
 kasan_report+0x1a4/0x1f0 mm/kasan/report.c:436
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/report_generic.c:309
 free_netdev+0x18d/0x390 net/core/dev.c:10695
 netdev_run_todo+0xc0b/0xe10 net/core/dev.c:10409
 rtnl_unlock net/core/rtnetlink.c:112 [inline]
 rtnetlink_rcv_msg+0xb1b/0xc60 net/core/rtnetlink.c:5583
 netlink_rcv_skb+0x1f0/0x460 net/netlink/af_netlink.c:2515
 rtnetlink_rcv+0x1c/0x20 net/core/rtnetlink.c:5600
 netlink_unicast_kernel net/netlink/af_netlink.c:1313 [inline]
 netlink_unicast+0x91a/0xb10 net/netlink/af_netlink.c:1339
 netlink_sendmsg+0xa40/0xd00 net/netlink/af_netlink.c:1934
 sock_sendmsg_nosec net/socket.c:652 [inline]
 sock_sendmsg net/socket.c:672 [inline]
 ____sys_sendmsg+0x597/0x8e0 net/socket.c:2343
 ___sys_sendmsg net/socket.c:2397 [inline]
 __sys_sendmsg+0x37b/0x460 net/socket.c:2430
 __do_sys_sendmsg net/socket.c:2439 [inline]
 __se_sys_sendmsg net/socket.c:2437 [inline]
 __x64_sys_sendmsg+0x7f/0x90 net/socket.c:2437
 do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7ff790c62a99
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 11 15 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:00007ff790c14308 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007ff790cea428 RCX: 00007ff790c62a99
RDX: 0000000000000000 RSI: 0000000020000180 RDI: 0000000000000004
RBP: 00007ff790cea420 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ff790cea42c
R13: 00007ff790cb8064 R14: 74656e2f7665642f R15: 0000000000022000

Allocated by task 534:
 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:428 [inline]
 ____kasan_kmalloc+0xdc/0x110 mm/kasan/common.c:507
 __kasan_kmalloc+0x9/0x10 mm/kasan/common.c:516
 kasan_kmalloc include/linux/kasan.h:269 [inline]
 __kmalloc+0x1f7/0x360 mm/slub.c:4042
 kmalloc include/linux/slab.h:557 [inline]
 sk_prot_alloc+0xbc/0x250 net/core/sock.c:1692
 sk_alloc+0x38/0x4c0 net/core/sock.c:1746
 tun_chr_open+0x7b/0x4a0 drivers/net/tun.c:3415
 misc_open+0x3ea/0x440 drivers/char/misc.c:141
 chrdev_open+0x5fb/0x680 fs/char_dev.c:414
 do_dentry_open+0x7a2/0x1090 fs/open.c:819
 vfs_open+0x73/0x80 fs/open.c:942
 do_open fs/namei.c:3327 [inline]
 path_openat+0x2638/0x2fd0 fs/namei.c:3444
 do_filp_open+0x200/0x440 fs/namei.c:3471
 do_sys_openat2+0x13b/0x470 fs/open.c:1211
 do_sys_open fs/open.c:1227 [inline]
 __do_sys_openat fs/open.c:1243 [inline]
 __se_sys_openat fs/open.c:1238 [inline]
 __x64_sys_openat+0x243/0x290 fs/open.c:1238
 do_syscall_64+0x34/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 535:
 kasan_save_stack mm/kasan/common.c:38 [inline]
 kasan_set_track+0x4c/0x80 mm/kasan/common.c:46
 kasan_set_free_info+0x23/0x40 mm/kasan/generic.c:357
 ____kasan_slab_free+0x121/0x160 mm/kasan/common.c:360
 __kasan_slab_free+0x11/0x20 mm/kasan/common.c:368
 kasan_slab_free include/linux/kasan.h:235 [inline]
 slab_free_hook mm/slub.c:1604 [inline]
 slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1630
 slab_free mm/slub.c:3212 [inline]
 kfree+0xc3/0x290 mm/slub.c:4200
 sk_prot_free net/core/sock.c:1729 [inline]
 __sk_destruct+0x48d/0x540 net/core/sock.c:1815
 sk_destruct net/core/sock.c:1830 [inline]
 __sk_free+0x364/0x470 net/core/sock.c:1841
 sk_free+0x51/0x90 net/core/sock.c:1852
 sock_put include/net/sock.h:1802 [inline]
 __tun_detach+0x1649/0x1c20 drivers/net/tun.c:686
 tun_detach drivers/net/tun.c:698 [inline]
 tun_chr_close+0xb8/0xd0 drivers/net/tun.c:3451
 __fput+0x348/0x7c0 fs/file_table.c:281
 ____fput+0x15/0x20 fs/file_table.c:314
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 ptrace_notify+0x29a/0x340 kernel/signal.c:2278
 ptrace_report_syscall include/linux/tracehook.h:66 [inline]
 tracehook_report_syscall_exit include/linux/tracehook.h:129 [inline]
 arch_syscall_exit_tracehook include/linux/entry-common.h:284 [inline]
 syscall_exit_work+0x7c/0x130 kernel/entry/common.c:231
 syscall_exit_to_user_mode_prepare kernel/entry/common.c:258 [inline]
 syscall_exit_to_user_mode+0x6a/0xa0 kernel/entry/common.c:264
 do_syscall_64+0x40/0x70 arch/x86/entry/common.c:56
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff888111dc3000
 which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 1400 bytes inside of
 2048-byte region [ffff888111dc3000, ffff888111dc3800)
The buggy address belongs to the page:
page:ffffea0004477000 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x111dc0
head:ffffea0004477000 order:3 compound_mapcount:0 compound_pincount:0
flags: 0x8000000000010200(slab|head)
raw: 8000000000010200 dead000000000100 dead000000000122 ffff888100042d80
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 0xd28c0(GFP_NOWAIT|__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 532, ts 23581540832, free_ts 23579296667
 set_page_owner include/linux/page_owner.h:35 [inline]
 post_alloc_hook mm/page_alloc.c:2385 [inline]
 prep_new_page mm/page_alloc.c:2391 [inline]
 get_page_from_freelist+0x745/0x760 mm/page_alloc.c:4067
 __alloc_pages_nodemask+0x3b6/0x890 mm/page_alloc.c:5117
 alloc_slab_page mm/slub.c:1815 [inline]
 allocate_slab+0x78/0x540 mm/slub.c:1817
 new_slab mm/slub.c:1878 [inline]
 new_slab_objects mm/slub.c:2637 [inline]
 ___slab_alloc+0x131/0x2e0 mm/slub.c:2800
 __slab_alloc+0x63/0xa0 mm/slub.c:2840
 slab_alloc_node mm/slub.c:2922 [inline]
 slab_alloc mm/slub.c:2964 [inline]
 __kmalloc_track_caller+0x23e/0x350 mm/slub.c:4545
 __kmalloc_reserve net/core/skbuff.c:143 [inline]
 pskb_expand_head+0x127/0x1140 net/core/skbuff.c:1639
 netlink_trim+0x197/0x230 net/netlink/af_netlink.c:1295
 netlink_broadcast_filtered+0x76/0x1200 net/netlink/af_netlink.c:1500
 netlink_broadcast net/netlink/af_netlink.c:1545 [inline]
 nlmsg_multicast include/net/netlink.h:1033 [inline]
 nlmsg_notify+0x100/0x1d0 net/netlink/af_netlink.c:2558
 rtnl_notify net/core/rtnetlink.c:737 [inline]
 rtmsg_ifinfo_send net/core/rtnetlink.c:3843 [inline]
 rtmsg_ifinfo_event net/core/rtnetlink.c:3858 [inline]
 rtmsg_ifinfo+0xe6/0x120 net/core/rtnetlink.c:3864
 register_netdevice+0x150f/0x1790 net/core/dev.c:10166
 tun_set_iff+0xb27/0x1100 drivers/net/tun.c:2808
 __tun_chr_ioctl+0x8ab/0x2130 drivers/net/tun.c:3084
 tun_chr_ioctl+0x2a/0x40 drivers/net/tun.c:3360
 vfs_ioctl fs/ioctl.c:48 [inline]
 __do_sys_ioctl fs/ioctl.c:753 [inline]
 __se_sys_ioctl+0x115/0x190 fs/ioctl.c:739
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:28 [inline]
 free_pages_prepare mm/page_alloc.c:1331 [inline]
 __free_pages_ok+0x7f8/0x830 mm/page_alloc.c:1611
 free_the_page mm/page_alloc.c:5178 [inline]
 __free_pages+0x2d2/0x4c0 mm/page_alloc.c:5184
 __free_slab+0xd3/0x190 mm/slub.c:1903
 free_slab mm/slub.c:1918 [inline]
 discard_slab mm/slub.c:1924 [inline]
 unfreeze_partials+0x17d/0x1b0 mm/slub.c:2418
 put_cpu_partial+0xc8/0x190 mm/slub.c:2454
 __slab_free+0x2d8/0x3a0 mm/slub.c:3104
 do_slab_free mm/slub.c:3200 [inline]
 ___cache_free+0x11f/0x140 mm/slub.c:3219
 qlink_free+0x38/0x40 mm/kasan/quarantine.c:146
 qlist_free_all+0x4c/0xc0 mm/kasan/quarantine.c:165
 kasan_quarantine_reduce+0x15a/0x170 mm/kasan/quarantine.c:272
 __kasan_slab_alloc+0x2f/0xe0 mm/kasan/common.c:438
 kasan_slab_alloc include/linux/kasan.h:259 [inline]
 slab_post_alloc_hook mm/slab.h:583 [inline]
 slab_alloc_node mm/slub.c:2956 [inline]
 slab_alloc mm/slub.c:2964 [inline]
 kmem_cache_alloc+0x16c/0x300 mm/slub.c:2969
 vm_area_dup+0x22/0x130 kernel/fork.c:362
 __split_vma+0xb4/0x3f0 mm/mmap.c:2836
 split_vma+0x7a/0xd0 mm/mmap.c:2894
 mprotect_fixup+0x6fe/0x8e0 mm/mprotect.c:467

Memory state around the buggy address:
 ffff888111dc3400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888111dc3480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888111dc3500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                                ^
 ffff888111dc3580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888111dc3600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/06/18 00:19 android12-5.10-lts fdd06dc6b0f8 8f633d84 .config strace log report syz C ci2-android-5-10 KASAN: use-after-free Read in free_netdev
2022/07/20 00:56 android12-5.10-lts ebc9fb07d294 775344bc .config console log report info ci2-android-5-10 KASAN: use-after-free Read in free_netdev
* Struck through repros no longer work on HEAD.