syzbot


KASAN: use-after-free Read in mon_bin_flush

Status: upstream: reported C repro on 2022/09/18 10:24
Reported-by: syzbot+43438abe71dab88140c2@syzkaller.appspotmail.com
First crash: 73d, last: 18d

Cause bisection: failed (bisect log)
similar bugs (3):
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
android-5-10 KASAN: use-after-free Read in mon_bin_flush C error 2 70d 71d 2/2 fixed on 2022/10/19 01:02
android-5-15 KASAN: use-after-free Read in mon_bin_flush 1 44d 44d 0/2 premoderation: reported on 2022/10/13 20:34
android-54 general protection fault in mon_bin_flush C 2 70d 71d 0/2 upstream: reported C repro on 2022/09/16 06:36
Patch testing requests:
Created Duration User Patch Repo Result
2022/09/19 16:10 19m tadeusz.struk@linaro.org patch upstream report log
2022/09/18 21:25 12m tadeusz.struk@linaro.org patch upstream report log

Sample crash report:
hub 9-0:1.0: USB hub found
hub 9-0:1.0: 8 ports detected
==================================================================
BUG: KASAN: use-after-free in MON_OFF2HDR drivers/usb/mon/mon_bin.c:207 [inline]
BUG: KASAN: use-after-free in mon_bin_flush+0x26f/0x290 drivers/usb/mon/mon_bin.c:884
Read of size 8 at addr ffff88807df1c3b8 by task syz-executor119/6549

CPU: 0 PID: 6549 Comm: syz-executor119 Not tainted 6.0.0-rc6-syzkaller-00030-g06f7db949993 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/16/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:317 [inline]
 print_report.cold+0x2ba/0x719 mm/kasan/report.c:433
 kasan_report+0xb1/0x1e0 mm/kasan/report.c:495
 MON_OFF2HDR drivers/usb/mon/mon_bin.c:207 [inline]
 mon_bin_flush+0x26f/0x290 drivers/usb/mon/mon_bin.c:884
 mon_bin_ioctl+0x198/0xcc0 drivers/usb/mon/mon_bin.c:1091
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl fs/ioctl.c:856 [inline]
 __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7ffb9e3e8be9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 d1 18 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:00007ffb9e38a2f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007ffb9e3e8be9
RDX: 0000000020000500 RSI: 00000000c0109207 RDI: 0000000000000004
RBP: 00007ffb9e4674a8 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffb9e4674a0
R13: 00007ffb9e4674ac R14: 00007ffb9e4336dc R15: 6273752f7665642f
 </TASK>

Allocated by task 6255:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:437 [inline]
 ____kasan_kmalloc mm/kasan/common.c:516 [inline]
 ____kasan_kmalloc mm/kasan/common.c:475 [inline]
 __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:525
 kmalloc include/linux/slab.h:605 [inline]
 tomoyo_realpath_from_path+0xc3/0x620 security/tomoyo/realpath.c:254
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_number_perm+0x1d5/0x590 security/tomoyo/file.c:723
 security_file_ioctl+0x50/0xb0 security/security.c:1552
 __do_sys_ioctl fs/ioctl.c:864 [inline]
 __se_sys_ioctl fs/ioctl.c:856 [inline]
 __x64_sys_ioctl+0xb3/0x200 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 6255:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:45
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:367 [inline]
 ____kasan_slab_free+0x166/0x1c0 mm/kasan/common.c:329
 kasan_slab_free include/linux/kasan.h:200 [inline]
 slab_free_hook mm/slub.c:1754 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1780
 slab_free mm/slub.c:3534 [inline]
 kfree+0xe2/0x580 mm/slub.c:4562
 tomoyo_realpath_from_path+0x191/0x620 security/tomoyo/realpath.c:291
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_number_perm+0x1d5/0x590 security/tomoyo/file.c:723
 security_file_ioctl+0x50/0xb0 security/security.c:1552
 __do_sys_ioctl fs/ioctl.c:864 [inline]
 __se_sys_ioctl fs/ioctl.c:856 [inline]
 __x64_sys_ioctl+0xb3/0x200 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff88807df1c000
 which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 952 bytes inside of
 4096-byte region [ffff88807df1c000, ffff88807df1d000)

The buggy address belongs to the physical page:
page:ffffea0001f7c600 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7df18
head:ffffea0001f7c600 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 ffffea0001f7c200 dead000000000002 ffff888011842140
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 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 2981, tgid 2981 (udevd), ts 19275703015, free_ts 19264460821
 prep_new_page mm/page_alloc.c:2532 [inline]
 get_page_from_freelist+0x109b/0x2ce0 mm/page_alloc.c:4283
 __alloc_pages+0x1c7/0x510 mm/page_alloc.c:5515
 alloc_pages+0x1a6/0x270 mm/mempolicy.c:2270
 alloc_slab_page mm/slub.c:1824 [inline]
 allocate_slab+0x27e/0x3d0 mm/slub.c:1969
 new_slab mm/slub.c:2029 [inline]
 ___slab_alloc+0x7f1/0xe10 mm/slub.c:3031
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3118
 slab_alloc_node mm/slub.c:3209 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 __kmalloc+0x32b/0x340 mm/slub.c:4420
 kmalloc include/linux/slab.h:605 [inline]
 tomoyo_realpath_from_path+0xc3/0x620 security/tomoyo/realpath.c:254
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x21b/0x400 security/tomoyo/file.c:822
 security_inode_getattr+0xcf/0x140 security/security.c:1345
 vfs_getattr fs/stat.c:157 [inline]
 vfs_statx+0x16a/0x390 fs/stat.c:232
 vfs_fstatat+0x8c/0xb0 fs/stat.c:255
 __do_sys_newfstatat+0x91/0x110 fs/stat.c:425
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/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:1449 [inline]
 free_pcp_prepare+0x5e4/0xd20 mm/page_alloc.c:1499
 free_unref_page_prepare mm/page_alloc.c:3380 [inline]
 free_unref_page+0x19/0x4d0 mm/page_alloc.c:3476
 __unfreeze_partials+0x17c/0x1a0 mm/slub.c:2548
 qlink_free mm/kasan/quarantine.c:168 [inline]
 qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:187
 kasan_quarantine_reduce+0x180/0x200 mm/kasan/quarantine.c:294
 __kasan_slab_alloc+0xa2/0xc0 mm/kasan/common.c:447
 kasan_slab_alloc include/linux/kasan.h:224 [inline]
 slab_post_alloc_hook mm/slab.h:727 [inline]
 slab_alloc_node mm/slub.c:3243 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 __kmem_cache_alloc_lru mm/slub.c:3258 [inline]
 kmem_cache_alloc+0x267/0x3b0 mm/slub.c:3268
 getname_flags.part.0+0x50/0x4f0 fs/namei.c:139
 getname_flags+0x9a/0xe0 include/linux/audit.h:320
 vfs_fstatat+0x73/0xb0 fs/stat.c:254
 __do_sys_newfstatat+0x91/0x110 fs/stat.c:425
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Memory state around the buggy address:
 ffff88807df1c280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88807df1c300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88807df1c380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                        ^
 ffff88807df1c400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88807df1c480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Fix bisection attempts:
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce 2022/11/08 06:57 upstream 59f2f4b8a757 60af5050 .config log report syz C
* Struck through repros no longer work on HEAD.
Crashes (15):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce 2022/09/22 09:19 upstream 06f7db949993 60af5050 .config log report syz C KASAN: use-after-free Read in mon_bin_flush
ci-upstream-kasan-gce-root 2022/09/22 10:51 upstream 06f7db949993 60af5050 .config log report syz C general protection fault in mon_bin_flush
ci-upstream-kasan-gce 2022/09/18 01:56 upstream a335366bad13 dd9a85ff .config log report syz C general protection fault in mon_bin_flush
ci-upstream-kasan-gce-root 2022/09/17 22:53 upstream a335366bad13 dd9a85ff .config log report syz C KASAN: slab-out-of-bounds Read in mon_bin_flush
ci-upstream-kasan-gce 2022/09/16 07:46 upstream 3245cb65fd91 dd9a85ff .config log report syz C general protection fault in mon_bin_flush
ci-upstream-kasan-gce-root 2022/09/16 06:15 upstream 3245cb65fd91 dd9a85ff .config log report syz C general protection fault in mon_bin_flush
ci-upstream-linux-next-kasan-gce-root 2022/10/08 04:32 linux-next aaa11ce2ffc8 0de35f24 .config log report syz C KASAN: global-out-of-bounds Read in mon_bin_flush
ci-upstream-gce-arm64 2022/09/17 23:02 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci a6b443748715 dd9a85ff .config log report syz C BUG: unable to handle kernel NULL pointer dereference in mon_bin_flush
ci-upstream-gce-arm64 2022/09/16 16:36 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci a6b443748715 dd9a85ff .config log report syz C BUG: unable to handle kernel NULL pointer dereference in mon_bin_flush
ci-upstream-gce-arm64 2022/09/22 05:39 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci aa49f95768a9 60af5050 .config log report syz BUG: unable to handle kernel NULL pointer dereference in mon_bin_flush
ci-upstream-kasan-gce 2022/09/14 10:21 upstream d1221cea11fc b884348d .config log report info KASAN: use-after-free Read in mon_bin_flush
ci-upstream-kasan-gce 2022/10/04 07:53 upstream 4fe89d07dcc2 feb56351 .config log report info general protection fault in mon_bin_flush
ci-upstream-kasan-gce 2022/09/19 18:14 upstream 521a547ced64 dd9a85ff .config log report info KASAN: slab-out-of-bounds Read in mon_bin_flush
ci-upstream-kasan-gce 2022/09/18 08:15 upstream a335366bad13 dd9a85ff .config log report info general protection fault in mon_bin_flush
ci-upstream-kasan-gce-root 2022/09/16 05:49 upstream 3245cb65fd91 dd9a85ff .config log report info KASAN: slab-out-of-bounds Read in mon_bin_flush
* Struck through repros no longer work on HEAD.