syzbot


KASAN: use-after-free Read in task_work_run

Status: closed as invalid on 2022/03/01 11:23
Reported-by: syzbot+8fa8e4ef31ced8c1784e@syzkaller.appspotmail.com
First crash: 1119d, last: 1115d
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in task_work_run (2) kernel C unreliable 18 715d 807d 22/28 fixed on 2023/02/24 13:50
upstream KASAN: use-after-free Read in task_work_run kernel 3 1548d 1535d 0/28 auto-closed as invalid on 2020/12/24 10:55

Sample crash report:
==================================================================
BUG: KASAN: double-free or invalid-free in slab_free mm/slub.c:3204 [inline]
BUG: KASAN: double-free or invalid-free in kfree+0xd5/0x320 mm/slub.c:4192

CPU: 1 PID: 6895 Comm: io_wq_manager Tainted: G        W         5.10.76-syzkaller-01178-g4944ec82ebb9 #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+0x8d/0x3d0 mm/kasan/report.c:233
 kasan_report_invalid_free+0x58/0x130 mm/kasan/report.c:358
 ____kasan_slab_free+0x14b/0x170 mm/kasan/common.c:362
 __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:1596 [inline]
 slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1622
 slab_free mm/slub.c:3204 [inline]
 kfree+0xd5/0x320 mm/slub.c:4192
 __io_queue_deferred fs/io_uring.c:1541 [inline]
 io_commit_cqring+0x76a/0xa00 fs/io_uring.c:1587
 __io_req_task_cancel+0x64/0x720 fs/io_uring.c:2065
 io_req_task_cancel+0x51/0x130 fs/io_uring.c:2078
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 io_wq_manager+0x1aa/0x8b0 fs/io-wq.c:797
 kthread+0x371/0x390 kernel/kthread.c:313
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Allocated by task 6889:
 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]
 kmem_cache_alloc_trace+0x210/0x3a0 mm/slub.c:2975
 kmalloc include/linux/slab.h:552 [inline]
 io_req_defer+0x40e/0x11b0 fs/io_uring.c:5921
 io_queue_sqe+0x2a/0x1180 fs/io_uring.c:6397
 io_submit_sqe+0x385/0xfd0 fs/io_uring.c:6487
 io_submit_sqes+0x1050/0x2da0 fs/io_uring.c:6715
 __do_sys_io_uring_enter fs/io_uring.c:9110 [inline]
 __se_sys_io_uring_enter+0x322/0x12b0 fs/io_uring.c:9052
 __x64_sys_io_uring_enter+0xe5/0x100 fs/io_uring.c:9052
 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 6889:
 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+0x133/0x170 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:1596 [inline]
 slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1622
 slab_free mm/slub.c:3204 [inline]
 kfree+0xd5/0x320 mm/slub.c:4192
 __io_queue_deferred fs/io_uring.c:1541 [inline]
 io_commit_cqring+0x76a/0xa00 fs/io_uring.c:1587
 io_iopoll_complete fs/io_uring.c:2378 [inline]
 io_do_iopoll+0x1e18/0x23f0 fs/io_uring.c:2431
 io_iopoll_try_reap_events+0x116/0x290 fs/io_uring.c:2470
 io_ring_ctx_wait_and_kill+0x295/0x670 fs/io_uring.c:8575
 io_uring_release+0x5b/0x70 fs/io_uring.c:8602
 __fput+0x348/0x7d0 fs/file_table.c:281
 ____fput+0x15/0x20 fs/file_table.c:314
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 exit_task_work include/linux/task_work.h:30 [inline]
 do_exit+0x70e/0x23a0 kernel/exit.c:813
 do_group_exit+0x16a/0x2d0 kernel/exit.c:910
 get_signal+0x133e/0x1f80 kernel/signal.c:2790
 arch_do_signal+0x8d/0x620 arch/x86/kernel/signal.c:805
 exit_to_user_mode_loop kernel/entry/common.c:161 [inline]
 exit_to_user_mode_prepare+0xaa/0xe0 kernel/entry/common.c:191
 syscall_exit_to_user_mode+0x24/0x40 kernel/entry/common.c:266
 do_syscall_64+0x3d/0x70 arch/x86/entry/common.c:56
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff88815bda6680
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 0 bytes inside of
 32-byte region [ffff88815bda6680, ffff88815bda66a0)
The buggy address belongs to the page:
page:ffffea00056f6980 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x15bda6
flags: 0x8000000000000200(slab)
raw: 8000000000000200 dead000000000100 dead000000000122 ffff888100043980
raw: 0000000000000000 0000000000400040 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112a20(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_HARDWALL), pid 853, ts 111659560800, free_ts 109997492621
 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+0xa74/0xa90 mm/page_alloc.c:4063
 __alloc_pages_nodemask+0x3c8/0x820 mm/page_alloc.c:5106
 alloc_slab_page mm/slub.c:1807 [inline]
 allocate_slab+0x6b/0x350 mm/slub.c:1809
 new_slab mm/slub.c:1870 [inline]
 new_slab_objects mm/slub.c:2629 [inline]
 ___slab_alloc+0x143/0x2f0 mm/slub.c:2792
 __slab_alloc mm/slub.c:2832 [inline]
 slab_alloc_node mm/slub.c:2914 [inline]
 slab_alloc mm/slub.c:2956 [inline]
 __kmalloc_track_caller+0x299/0x3b0 mm/slub.c:4535
 kmemdup+0x24/0x50 mm/util.c:131
 sidtab_sid2str_get+0x127/0x2a0 security/selinux/ss/sidtab.c:615
 sidtab_entry_to_string security/selinux/ss/services.c:1287 [inline]
 security_sid_to_context_core+0x2b1/0x490 security/selinux/ss/services.c:1380
 security_sid_to_context+0x33/0x40 security/selinux/ss/services.c:1402
 avc_audit_post_callback+0x1ad/0xb00 security/selinux/avc.c:724
 common_lsm_audit+0xd58/0x1b30 security/lsm_audit.c:469
 slow_avc_audit+0x25c/0x3b0 security/selinux/avc.c:798
 avc_xperms_audit security/selinux/avc.c:433 [inline]
 avc_has_extended_perms+0xab2/0x1270 security/selinux/avc.c:1118
 ioctl_has_perm security/selinux/hooks.c:3669 [inline]
 selinux_file_ioctl+0x72f/0x990 security/selinux/hooks.c:3712
 security_file_ioctl+0x68/0xd0 security/security.c:1456
 __do_sys_ioctl fs/ioctl.c:747 [inline]
 __se_sys_ioctl+0x4e/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+0xbe7/0xc20 mm/page_alloc.c:1611
 free_the_page mm/page_alloc.c:5167 [inline]
 __free_pages+0x2d6/0x4a0 mm/page_alloc.c:5173
 kfree+0x29d/0x320 mm/slub.c:4189
 tipc_nametbl_stop+0x139e/0x1400 net/tipc/name_table.c:917
 tipc_exit_net+0x9e/0x160 net/tipc/core.c:119
 ops_exit_list net/core/net_namespace.c:187 [inline]
 cleanup_net+0x6d4/0xd60 net/core/net_namespace.c:604
 process_one_work+0x6b4/0xfb0 kernel/workqueue.c:2289
 worker_thread+0xb15/0x1600 kernel/workqueue.c:2435
 kthread+0x371/0x390 kernel/kthread.c:313
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Memory state around the buggy address:
 ffff88815bda6580: 00 00 00 00 fc fc fc fc 00 00 00 00 fc fc fc fc
 ffff88815bda6600: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
>ffff88815bda6680: fa fb fb fb fc fc fc fc 00 00 00 00 fc fc fc fc
                   ^
 ffff88815bda6700: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc
 ffff88815bda6780: 00 00 00 00 fc fc fc fc fa fb fb fb fc fc fc fc
==================================================================
==================================================================
BUG: KASAN: use-after-free in task_work_run+0x126/0x1b0 kernel/task_work.c:153
Read of size 8 at addr ffff888154f3ca98 by task io_wq_manager/6895

CPU: 0 PID: 6895 Comm: io_wq_manager Tainted: G    B   W         5.10.76-syzkaller-01178-g4944ec82ebb9 #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+0x8d/0x3d0 mm/kasan/report.c:233
 __kasan_report+0x142/0x220 mm/kasan/report.c:419
 kasan_report+0x51/0x70 mm/kasan/report.c:436
 __asan_report_load8_noabort+0x14/0x20 mm/kasan/report_generic.c:309
 task_work_run+0x126/0x1b0 kernel/task_work.c:153
 io_wq_manager+0x1aa/0x8b0 fs/io-wq.c:797
 kthread+0x371/0x390 kernel/kthread.c:313
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Allocated by task 6889:
 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_slab_alloc+0xb2/0xe0 mm/kasan/common.c:461
 kasan_slab_alloc include/linux/kasan.h:259 [inline]
 slab_post_alloc_hook mm/slab.h:583 [inline]
 kmem_cache_alloc_bulk+0x2d5/0x3f0 mm/slub.c:3406
 io_alloc_req fs/io_uring.c:1857 [inline]
 io_submit_sqes+0x6bf/0x2da0 fs/io_uring.c:6695
 __do_sys_io_uring_enter fs/io_uring.c:9110 [inline]
 __se_sys_io_uring_enter+0x322/0x12b0 fs/io_uring.c:9052
 __x64_sys_io_uring_enter+0xe5/0x100 fs/io_uring.c:9052
 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 6895:
 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+0x133/0x170 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:1596 [inline]
 slab_free_freelist_hook+0xcc/0x1a0 mm/slub.c:1622
 slab_free mm/slub.c:3204 [inline]
 kmem_cache_free+0xb5/0x1f0 mm/slub.c:3220
 __io_free_req+0x20e/0x380 fs/io_uring.c:1912
 io_free_req fs/io_uring.c:2135 [inline]
 io_double_put_req fs/io_uring.c:2275 [inline]
 __io_req_task_cancel+0x144/0x720 fs/io_uring.c:2070
 io_req_task_cancel+0x51/0x130 fs/io_uring.c:2078
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 io_wq_manager+0x1aa/0x8b0 fs/io-wq.c:797
 kthread+0x371/0x390 kernel/kthread.c:313
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Last potentially related work creation:
 kasan_save_stack+0x36/0x60 mm/kasan/common.c:38
 kasan_record_aux_stack+0xd3/0xf0 mm/kasan/generic.c:345
 task_work_add+0xa7/0x320 kernel/task_work.c:39
 io_req_task_queue fs/io_uring.c:2119 [inline]
 __io_queue_deferred fs/io_uring.c:1540 [inline]
 io_commit_cqring+0x756/0xa00 fs/io_uring.c:1587
 __io_req_task_cancel+0x64/0x720 fs/io_uring.c:2065
 io_req_task_cancel+0x51/0x130 fs/io_uring.c:2078
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 io_wq_manager+0x1aa/0x8b0 fs/io-wq.c:797
 kthread+0x371/0x390 kernel/kthread.c:313
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

The buggy address belongs to the object at ffff888154f3ca00
 which belongs to the cache io_kiocb of size 216
The buggy address is located 152 bytes inside of
 216-byte region [ffff888154f3ca00, ffff888154f3cad8)
The buggy address belongs to the page:
page:ffffea000553cf00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x154f3c
flags: 0x8000000000000200(slab)
raw: 8000000000000200 dead000000000100 dead000000000122 ffff8881047be180
raw: 0000000000000000 00000000000c000c 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112cc0(GFP_USER|__GFP_NOWARN|__GFP_NORETRY), pid 6889, ts 648611747795, free_ts 648509088450
 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+0xa74/0xa90 mm/page_alloc.c:4063
 __alloc_pages_nodemask+0x3c8/0x820 mm/page_alloc.c:5106
 alloc_slab_page mm/slub.c:1807 [inline]
 allocate_slab+0x6b/0x350 mm/slub.c:1809
 new_slab mm/slub.c:1870 [inline]
 new_slab_objects mm/slub.c:2629 [inline]
 ___slab_alloc+0x143/0x2f0 mm/slub.c:2792
 kmem_cache_alloc_bulk+0x167/0x3f0 mm/slub.c:3385
 io_alloc_req fs/io_uring.c:1857 [inline]
 io_submit_sqes+0x6bf/0x2da0 fs/io_uring.c:6695
 __do_sys_io_uring_enter fs/io_uring.c:9110 [inline]
 __se_sys_io_uring_enter+0x322/0x12b0 fs/io_uring.c:9052
 __x64_sys_io_uring_enter+0xe5/0x100 fs/io_uring.c:9052
 do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
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_pcp_prepare+0x18f/0x1c0 mm/page_alloc.c:1405
 free_unref_page_prepare mm/page_alloc.c:3291 [inline]
 free_unref_page mm/page_alloc.c:3341 [inline]
 free_the_page mm/page_alloc.c:5165 [inline]
 __free_pages+0x2e3/0x4a0 mm/page_alloc.c:5173
 __vunmap+0x856/0x980 mm/vmalloc.c:2275
 free_work+0x66/0x90 mm/vmalloc.c:68
 process_one_work+0x6b4/0xfb0 kernel/workqueue.c:2289
 worker_thread+0xb15/0x1600 kernel/workqueue.c:2435
 kthread+0x371/0x390 kernel/kthread.c:313
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

Memory state around the buggy address:
 ffff888154f3c980: fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888154f3ca00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888154f3ca80: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
                            ^
 ffff888154f3cb00: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
 ffff888154f3cb80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================
------------[ cut here ]------------
refcount_t: underflow; use-after-free.
WARNING: CPU: 1 PID: 6895 at lib/refcount.c:28 refcount_warn_saturate+0x165/0x1b0 lib/refcount.c:28
Modules linked in:
CPU: 1 PID: 6895 Comm: io_wq_manager Tainted: G    B   W         5.10.76-syzkaller-01178-g4944ec82ebb9 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:refcount_warn_saturate+0x165/0x1b0 lib/refcount.c:28
Code: c7 e0 b2 49 85 31 c0 e8 99 7b eb fe 0f 0b eb 83 e8 f0 98 18 ff c6 05 9e cc 68 04 01 48 c7 c7 40 b3 49 85 31 c0 e8 7b 7b eb fe <0f> 0b e9 62 ff ff ff e8 cf 98 18 ff c6 05 7e cc 68 04 01 48 c7 c7
RSP: 0018:ffffc900018e7d20 EFLAGS: 00010246
RAX: 5d4c68a5b2f80100 RBX: 0000000000000003 RCX: 1ffff9200031cf5c
RDX: 0000000000000000 RSI: 0000000080000000 RDI: 0000000000000000
RBP: ffffc900018e7d30 R08: ffffffff81545288 R09: ffffed103ee295d8
R10: ffffed103ee295d8 R11: 0000000000000000 R12: ffff888154f3ca58
R13: ffff888154f3ca00 R14: 0000000000000003 R15: ffff888154f3ca5c
FS:  0000000000000000(0000) GS:ffff8881f7100000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ff66c01f000 CR3: 000000015e131000 CR4: 00000000003526a0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 __refcount_sub_and_test include/linux/refcount.h:283 [inline]
 refcount_sub_and_test include/linux/refcount.h:310 [inline]
 io_double_put_req fs/io_uring.c:2274 [inline]
 __io_req_task_cancel+0x1c3/0x720 fs/io_uring.c:2070
 io_req_task_cancel+0x51/0x130 fs/io_uring.c:2078
 task_work_run+0x147/0x1b0 kernel/task_work.c:154
 io_wq_manager+0x1aa/0x8b0 fs/io-wq.c:797
 kthread+0x371/0x390 kernel/kthread.c:313
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
---[ end trace d8e29c9899ad8998 ]---

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2021/11/01 16:12 android12-5.10-lts 4944ec82ebb9 098b5d53 .config console log report info ci2-android-5-10 KASAN: use-after-free Read in task_work_run
2021/10/29 02:45 android12-5.10-lts 4944ec82ebb9 be531bb4 .config console log report info ci2-android-5-10 KASAN: use-after-free Read in task_work_run
* Struck through repros no longer work on HEAD.