syzbot


KASAN: use-after-free Write in vcs_read

Status: fixed on 2020/11/16 12:12
Reported-by: syzbot+ad1f53726c3bd11180cb@syzkaller.appspotmail.com
Fix commit: 52c3c3a59234 Revert "vc_screen: extract vcs_read_buf_header"
First crash: 768d, last: 762d

Cause bisection: introduced by (bisect log) :
commit b1c32fcfadf5593ab7a63261cc8a5747c36e627e
Author: Jiri Slaby <jslaby@suse.cz>
Date: Tue Aug 18 08:57:05 2020 +0000

  vc_screen: extract vcs_read_buf_header

Crash: BUG: Bad page map (log)
Repro: C syz .config

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in vcs_read_buf drivers/tty/vt/vc_screen.c:357 [inline]
BUG: KASAN: use-after-free in vcs_read+0xaa7/0xb40 drivers/tty/vt/vc_screen.c:449
Write of size 2 at addr ffff8880983c6000 by task syz-executor929/6850

CPU: 1 PID: 6850 Comm: syz-executor929 Not tainted 5.9.0-rc2-next-20200824-syzkaller #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+0x18f/0x20d lib/dump_stack.c:118
 print_address_description.constprop.0.cold+0xae/0x497 mm/kasan/report.c:383
 __kasan_report mm/kasan/report.c:513 [inline]
 kasan_report.cold+0x1f/0x37 mm/kasan/report.c:530
 vcs_read_buf drivers/tty/vt/vc_screen.c:357 [inline]
 vcs_read+0xaa7/0xb40 drivers/tty/vt/vc_screen.c:449
 do_loop_readv_writev fs/read_write.c:734 [inline]
 do_loop_readv_writev fs/read_write.c:721 [inline]
 do_iter_read+0x48e/0x6e0 fs/read_write.c:955
 vfs_readv+0xe5/0x150 fs/read_write.c:1073
 do_preadv fs/read_write.c:1165 [inline]
 __do_sys_preadv fs/read_write.c:1215 [inline]
 __se_sys_preadv fs/read_write.c:1210 [inline]
 __x64_sys_preadv+0x231/0x310 fs/read_write.c:1210
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x440339
Code: 23 02 00 85 c0 b8 00 00 00 00 48 0f 44 c3 5b c3 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 0f 83 1b 13 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffc1f157e58 EFLAGS: 00000246 ORIG_RAX: 0000000000000127
RAX: ffffffffffffffda RBX: 00007ffc1f157e60 RCX: 0000000000440339
RDX: 0000000000000006 RSI: 0000000020001b00 RDI: 0000000000000003
RBP: 00000000006cb018 R08: 0000000000000000 R09: 6c616b7a79732f2e
R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000401ae0
R13: 0000000000401b70 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 6850:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
 kasan_set_track mm/kasan/common.c:56 [inline]
 __kasan_kmalloc.constprop.0+0xbf/0xd0 mm/kasan/common.c:461
 __do_kmalloc mm/slab.c:3655 [inline]
 __kmalloc+0x1a8/0x320 mm/slab.c:3664
 kmalloc include/linux/slab.h:559 [inline]
 tomoyo_realpath_from_path+0xc3/0x620 security/tomoyo/realpath.c:254
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x212/0x3f0 security/tomoyo/file.c:822
 security_inode_getattr+0xcf/0x140 security/security.c:1278
 vfs_getattr fs/stat.c:121 [inline]
 vfs_statx_fd+0x70/0xf0 fs/stat.c:151
 vfs_fstat include/linux/fs.h:3186 [inline]
 __do_sys_newfstat+0x88/0x100 fs/stat.c:398
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 6850:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
 kasan_set_track+0x1c/0x30 mm/kasan/common.c:56
 kasan_set_free_info+0x1b/0x30 mm/kasan/generic.c:355
 __kasan_slab_free+0xd8/0x120 mm/kasan/common.c:422
 __cache_free mm/slab.c:3418 [inline]
 kfree+0x103/0x2c0 mm/slab.c:3756
 tomoyo_realpath_from_path+0x191/0x620 security/tomoyo/realpath.c:291
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x212/0x3f0 security/tomoyo/file.c:822
 security_inode_getattr+0xcf/0x140 security/security.c:1278
 vfs_getattr fs/stat.c:121 [inline]
 vfs_statx_fd+0x70/0xf0 fs/stat.c:151
 vfs_fstat include/linux/fs.h:3186 [inline]
 __do_sys_newfstat+0x88/0x100 fs/stat.c:398
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff8880983c6000
 which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 0 bytes inside of
 4096-byte region [ffff8880983c6000, ffff8880983c7000)
The buggy address belongs to the page:
page:00000000b618e75c refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x983c6
head:00000000b618e75c order:1 compound_mapcount:0
flags: 0xfffe0000010200(slab|head)
raw: 00fffe0000010200 ffffea000251f308 ffffea0002381808 ffff8880aa040900
raw: 0000000000000000 ffff8880983c6000 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8880983c5f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff8880983c5f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff8880983c6000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff8880983c6080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880983c6100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (11):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-linux-next-kasan-gce-root 2020/08/24 13:59 linux-next d8be0e12a522 67b599d1 .config log report syz C
ci-upstream-linux-next-kasan-gce-root 2020/08/23 17:06 linux-next 494d311a82bb cef5ae68 .config log report syz C
ci-upstream-linux-next-kasan-gce-root 2020/08/23 01:19 linux-next 494d311a82bb 1da71ab0 .config log report syz C
ci-upstream-linux-next-kasan-gce-root 2020/08/22 04:16 linux-next 494d311a82bb 6436ce4b .config log report syz C
ci-upstream-linux-next-kasan-gce-root 2020/08/26 07:31 linux-next 3a00d3dfd4b6 344da168 .config log report
ci-upstream-linux-next-kasan-gce-root 2020/08/25 19:55 linux-next 3a00d3dfd4b6 344da168 .config log report
ci-upstream-linux-next-kasan-gce-root 2020/08/24 01:46 linux-next 494d311a82bb cef5ae68 .config log report
ci-upstream-linux-next-kasan-gce-root 2020/08/22 15:34 linux-next 494d311a82bb 6436ce4b .config log report
ci-upstream-linux-next-kasan-gce-root 2020/08/22 15:12 linux-next 494d311a82bb 6436ce4b .config log report
ci-upstream-linux-next-kasan-gce-root 2020/08/22 14:29 linux-next 494d311a82bb 6436ce4b .config log report
ci-upstream-linux-next-kasan-gce-root 2020/08/20 06:55 linux-next 605cbf3d5f20 ed282a3a .config log report
* Struck through repros no longer work on HEAD.