KASAN: use-after-free Read in task_work_run

From: syzbot
Date: Tue Sep 08 2020 - 03:36:38 EST


Hello,

syzbot found the following issue on:

HEAD commit: d012a719 Linux 5.9-rc2
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17c0f046900000
kernel config: https://syzkaller.appspot.com/x/.config?x=978db74cb30aa994
dashboard link: https://syzkaller.appspot.com/bug?extid=4b87ce204f0f200f214c
compiler: gcc (GCC) 10.1.0-syz 20200507

Unfortunately, I don't have any reproducer for this issue yet.

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

==================================================================
BUG: KASAN: use-after-free in task_work_run+0x116/0x190 kernel/task_work.c:140
Read of size 8 at addr ffff888064be5cc0 by task syz-executor.4/18932

CPU: 0 PID: 18932 Comm: syz-executor.4 Not tainted 5.9.0-rc2-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
task_work_run+0x116/0x190 kernel/task_work.c:140
tracehook_notify_resume include/linux/tracehook.h:188 [inline]
exit_to_user_mode_loop kernel/entry/common.c:140 [inline]
exit_to_user_mode_prepare+0x195/0x1c0 kernel/entry/common.c:167
syscall_exit_to_user_mode+0x59/0x2b0 kernel/entry/common.c:242
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x45d579
Code: 5d b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 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 2b b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f9e22616c78 EFLAGS: 00000246 ORIG_RAX: 00000000000000e9
RAX: 0000000000000000 RBX: 0000000000002ac0 RCX: 000000000045d579
RDX: 0000000000000004 RSI: 0000000000000001 RDI: 0000000000000005
RBP: 000000000118cf88 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000020000000 R11: 0000000000000246 R12: 000000000118cf4c
R13: 00007ffc50988d1f R14: 00007f9e226179c0 R15: 000000000118cf4c

Allocated by task 18946:
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
slab_post_alloc_hook mm/slab.h:518 [inline]
slab_alloc mm/slab.c:3312 [inline]
kmem_cache_alloc+0x138/0x3a0 mm/slab.c:3482
kmem_cache_zalloc include/linux/slab.h:656 [inline]
__alloc_file+0x21/0x350 fs/file_table.c:101
alloc_empty_file+0x6d/0x170 fs/file_table.c:151
alloc_file+0x5e/0x5a0 fs/file_table.c:193
alloc_file_pseudo+0x165/0x250 fs/file_table.c:233
sock_alloc_file+0x4f/0x190 net/socket.c:411
sock_map_fd net/socket.c:435 [inline]
__sys_socket+0x13d/0x200 net/socket.c:1524
__do_sys_socket net/socket.c:1529 [inline]
__se_sys_socket net/socket.c:1527 [inline]
__x64_sys_socket+0x6f/0xb0 net/socket.c:1527
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 18942:
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]
kmem_cache_free.part.0+0x67/0x1f0 mm/slab.c:3693
rcu_do_batch kernel/rcu/tree.c:2428 [inline]
rcu_core+0x5c7/0x1190 kernel/rcu/tree.c:2656
__do_softirq+0x2de/0xa24 kernel/softirq.c:298

Last call_rcu():
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_record_aux_stack+0x82/0xb0 mm/kasan/generic.c:346
__call_rcu kernel/rcu/tree.c:2894 [inline]
call_rcu+0x14f/0x7e0 kernel/rcu/tree.c:2968
task_work_run+0xdd/0x190 kernel/task_work.c:141
tracehook_notify_resume include/linux/tracehook.h:188 [inline]
exit_to_user_mode_loop kernel/entry/common.c:140 [inline]
exit_to_user_mode_prepare+0x195/0x1c0 kernel/entry/common.c:167
syscall_exit_to_user_mode+0x59/0x2b0 kernel/entry/common.c:242
entry_SYSCALL_64_after_hwframe+0x44/0xa9

Second to last call_rcu():
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_record_aux_stack+0x82/0xb0 mm/kasan/generic.c:346
__call_rcu kernel/rcu/tree.c:2894 [inline]
call_rcu+0x14f/0x7e0 kernel/rcu/tree.c:2968
task_work_run+0xdd/0x190 kernel/task_work.c:141
tracehook_notify_resume include/linux/tracehook.h:188 [inline]
exit_to_user_mode_loop kernel/entry/common.c:140 [inline]
exit_to_user_mode_prepare+0x195/0x1c0 kernel/entry/common.c:167
syscall_exit_to_user_mode+0x59/0x2b0 kernel/entry/common.c:242
entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff888064be5cc0
which belongs to the cache filp of size 488
The buggy address is located 0 bytes inside of
488-byte region [ffff888064be5cc0, ffff888064be5ea8)
The buggy address belongs to the page:
page:000000004592002e refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x64be5
flags: 0xfffe0000000200(slab)
raw: 00fffe0000000200 ffffea000250bd88 ffffea000288a788 ffff8880aa241800
raw: 0000000000000000 ffff888064be5040 0000000100000006 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff888064be5b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888064be5c00: fb fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc
>ffff888064be5c80: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
^
ffff888064be5d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888064be5d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@xxxxxxxxxxxxxxxx.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.