Re: KASAN: use-after-free Write in get_block

From: syzbot
Date: Thu May 14 2020 - 12:14:16 EST


syzbot has found a reproducer for the following crash on:

HEAD commit: ac935d22 Add linux-next specific files for 20200415
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=148bf748100000
kernel config: https://syzkaller.appspot.com/x/.config?x=bc498783097e9019
dashboard link: https://syzkaller.appspot.com/bug?extid=c7d9ec7a1a7272dd71b3
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10844a8c100000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17978806100000

Bisection is inconclusive: the bug happens on the oldest tested release.

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=135471e4100000
final crash: https://syzkaller.appspot.com/x/report.txt?x=10d471e4100000
console output: https://syzkaller.appspot.com/x/log.txt?x=175471e4100000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+c7d9ec7a1a7272dd71b3@xxxxxxxxxxxxxxxxxxxxxxxxx

==================================================================
BUG: KASAN: use-after-free in alloc_branch fs/minix/itree_common.c:92 [inline]
BUG: KASAN: use-after-free in get_block+0x1202/0x1380 fs/minix/itree_common.c:191
Write of size 2 at addr ffff88808ae27ba4 by task syz-executor461/7083

CPU: 0 PID: 7083 Comm: syz-executor461 Not tainted 5.7.0-rc1-next-20200415-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+0x188/0x20d lib/dump_stack.c:118
print_address_description.constprop.0.cold+0xd3/0x315 mm/kasan/report.c:382
__kasan_report.cold+0x35/0x4d mm/kasan/report.c:511
kasan_report+0x33/0x50 mm/kasan/common.c:625
alloc_branch fs/minix/itree_common.c:92 [inline]
get_block+0x1202/0x1380 fs/minix/itree_common.c:191
minix_get_block+0xe5/0x110 fs/minix/inode.c:376
__block_write_begin_int+0x490/0x1b00 fs/buffer.c:2039
__block_write_begin fs/buffer.c:2089 [inline]
block_write_begin+0x58/0x2e0 fs/buffer.c:2148
minix_write_begin+0x35/0xe0 fs/minix/inode.c:412
generic_perform_write+0x20a/0x4e0 mm/filemap.c:3308
__generic_file_write_iter+0x24c/0x610 mm/filemap.c:3437
generic_file_write_iter+0x3f3/0x630 mm/filemap.c:3469
call_write_iter include/linux/fs.h:1907 [inline]
new_sync_write+0x4a2/0x700 fs/read_write.c:484
__vfs_write+0xc9/0x100 fs/read_write.c:497
__kernel_write+0x11c/0x3a0 fs/read_write.c:516
do_acct_process+0xcdc/0x10e0 kernel/acct.c:522
acct_pin_kill+0x29/0xf0 kernel/acct.c:174
pin_kill+0x175/0x7c0 fs/fs_pin.c:44
mnt_pin_kill+0x6c/0x1c0 fs/fs_pin.c:81
cleanup_mnt+0x3c4/0x4b0 fs/namespace.c:1092
task_work_run+0xf4/0x1b0 kernel/task_work.c:123
exit_task_work include/linux/task_work.h:22 [inline]
do_exit+0xb53/0x2e10 kernel/exit.c:795
do_group_exit+0x125/0x340 kernel/exit.c:893
__do_sys_exit_group kernel/exit.c:904 [inline]
__se_sys_exit_group kernel/exit.c:902 [inline]
__x64_sys_exit_group+0x3a/0x50 kernel/exit.c:902
do_syscall_64+0xf6/0x7d0 arch/x86/entry/common.c:295
entry_SYSCALL_64_after_hwframe+0x49/0xb3
RIP: 0033:0x44b9e8
Code: Bad RIP value.
RSP: 002b:00007fff686f4e68 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 000000000044b9e8
RDX: 0000000000000001 RSI: 000000000000003c RDI: 0000000000000001
RBP: 00000000004d0a10 R08: 00000000000000e7 R09: ffffffffffffffd4
R10: 0000000000000005 R11: 0000000000000246 R12: 0000000000000001
R13: 00000000006ea9a0 R14: 0000000000000000 R15: 00007fff686f62d0

The buggy address belongs to the page:
page:ffffea00022b89c0 refcount:0 mapcount:0 mapping:00000000722a657b index:0x1
flags: 0xfffe0000000000()
raw: 00fffe0000000000 ffffea00022b1448 ffffea000231b808 0000000000000000
raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff88808ae27a80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff88808ae27b00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff88808ae27b80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
^
ffff88808ae27c00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ffff88808ae27c80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================