lkml.org 
[lkml]   [2022]   [Jul]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectKASAN: invalid-free in __io_uring_register
Hi,

We would like to report the following bug which has been found by our
modified version of syzkaller.

======================================================
description: KASAN: invalid-free in __io_uring_register
affected file: fs/io_uring.c
kernel version: 5.19-rc6
kernel commit: 32346491ddf24599decca06190ebca03ff9de7f8
git tree: upstream
kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=cd73026ceaed1402
crash reproducer: attached
======================================================
Crash log:
======================================================
BUG: KASAN: double-free or invalid-free in io_register_pbuf_ring
fs/io_uring.c:12975 [inline]
BUG: KASAN: double-free or invalid-free in
__io_uring_register+0x16aa/0x19d0 fs/io_uring.c:13151

CPU: 1 PID: 16619 Comm: syz-executor.4 Tainted: G OE
5.19.0-rc6-g2eae0556bb9d #2
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
1.13.0-1ubuntu1.1 04/01/2014
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:313 [inline]
print_report.cold+0xe5/0x659 mm/kasan/report.c:429
kasan_report_invalid_free+0x5c/0x160 mm/kasan/report.c:458
____kasan_slab_free mm/kasan/common.c:351 [inline]
__kasan_slab_free+0x182/0x1a0 mm/kasan/common.c:379
kasan_slab_free include/linux/kasan.h:200 [inline]
slab_free_hook mm/slub.c:1754 [inline]
slab_free_freelist_hook mm/slub.c:1780 [inline]
slab_free mm/slub.c:3536 [inline]
kfree+0xec/0x4b0 mm/slub.c:4584
io_register_pbuf_ring fs/io_uring.c:12975 [inline]
__io_uring_register+0x16aa/0x19d0 fs/io_uring.c:13151
__do_sys_io_uring_register fs/io_uring.c:13187 [inline]
__se_sys_io_uring_register fs/io_uring.c:13167 [inline]
__x64_sys_io_uring_register+0x2f2/0x650 fs/io_uring.c:13167
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+0x46/0xb0
RIP: 0033:0x7f7aa1a8d4ed
Code: 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa 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:00007f7aa2b31be8 EFLAGS: 00000246 ORIG_RAX: 00000000000001ab
RAX: ffffffffffffffda RBX: 00007f7aa1babf60 RCX: 00007f7aa1a8d4ed
RDX: 0000000020000000 RSI: 0000000000000016 RDI: 0000000000000006
RBP: 00007f7aa1af92e1 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fff95597e6f R14: 00007f7aa1babf60 R15: 00007f7aa2b31d80
</TASK>

Allocated by task 16619:
kasan_save_stack+0x1e/0x40 mm/kasan/common.c:39
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:441 [inline]
____kasan_kmalloc mm/kasan/common.c:526 [inline]
____kasan_kmalloc mm/kasan/common.c:479 [inline]
__kasan_kmalloc+0xb5/0xe0 mm/kasan/common.c:535
kasan_kmalloc include/linux/kasan.h:234 [inline]
__kmalloc+0x1c9/0x4c0 mm/slub.c:4446
kcalloc include/linux/slab.h:671 [inline]
io_init_bl_list.isra.0+0x24/0x102 fs/io_uring.c:5703
io_register_pbuf_ring fs/io_uring.c:12955 [inline]
__io_uring_register.cold+0xd/0x10b5 fs/io_uring.c:13151
__do_sys_io_uring_register fs/io_uring.c:13187 [inline]
__se_sys_io_uring_register fs/io_uring.c:13167 [inline]
__x64_sys_io_uring_register+0x2f2/0x650 fs/io_uring.c:13167
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+0x46/0xb0

Last potentially related work creation:
kasan_save_stack+0x1e/0x40 mm/kasan/common.c:39
__kasan_record_aux_stack+0xbe/0xd0 mm/kasan/generic.c:356
call_rcu kernel/rcu/tree.c:3126 [inline]
call_rcu+0x99/0x740 kernel/rcu/tree.c:3101
netlink_release+0xe42/0x1cb0 net/netlink/af_netlink.c:815
__sock_release+0xcd/0x280 net/socket.c:650
sock_close+0x18/0x20 net/socket.c:1365
__fput+0x277/0x9d0 fs/file_table.c:317
task_work_run+0xe0/0x1a0 kernel/task_work.c:177
resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
exit_to_user_mode_loop kernel/entry/common.c:169 [inline]
exit_to_user_mode_prepare+0x253/0x260 kernel/entry/common.c:201
__syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
entry_SYSCALL_64_after_hwframe+0x46/0xb0

Second to last potentially related work creation:
kasan_save_stack+0x1e/0x40 mm/kasan/common.c:39
__kasan_record_aux_stack+0xbe/0xd0 mm/kasan/generic.c:356
call_rcu kernel/rcu/tree.c:3126 [inline]
call_rcu+0x99/0x740 kernel/rcu/tree.c:3101
netlink_release+0xe42/0x1cb0 net/netlink/af_netlink.c:815
__sock_release+0xcd/0x280 net/socket.c:650
sock_close+0x18/0x20 net/socket.c:1365
__fput+0x277/0x9d0 fs/file_table.c:317
task_work_run+0xe0/0x1a0 kernel/task_work.c:177
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0xb1e/0x2dd0 kernel/exit.c:797
do_group_exit+0xd2/0x2f0 kernel/exit.c:927
get_signal+0x2842/0x2870 kernel/signal.c:2857
arch_do_signal_or_restart+0x82/0x2270 arch/x86/kernel/signal.c:869
exit_to_user_mode_loop kernel/entry/common.c:166 [inline]
exit_to_user_mode_prepare+0x174/0x260 kernel/entry/common.c:201
__syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
ret_from_fork+0x15/0x30 arch/x86/entry/entry_64.S:295

The buggy address belongs to the object at ffff88815f2b7000
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 256 bytes inside of
2048-byte region [ffff88815f2b7000, ffff88815f2b7800)

The buggy address belongs to the physical page:
page:ffffea00057cac00 refcount:1 mapcount:0 mapping:0000000000000000
index:0x0 pfn:0x15f2b0
head:ffffea00057cac00 order:3 compound_mapcount:0 compound_pincount:0
flags: 0x17ff00000010200(slab|head|node=0|zone=2|lastcpupid=0x7ff)
raw: 017ff00000010200 dead000000000100 dead000000000122 ffff888100042000
raw: 0000000000000000 0000000080080008 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
0xd2a20(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC),
pid 6687, tgid 6687 (syz-executor.3), ts 55285345771, free_ts
54261940067
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook mm/page_alloc.c:2449 [inline]
prep_new_page+0x297/0x330 mm/page_alloc.c:2456
get_page_from_freelist+0x2142/0x3c80 mm/page_alloc.c:4198
__alloc_pages+0x321/0x710 mm/page_alloc.c:5426
alloc_pages+0x119/0x250 mm/mempolicy.c:2272
alloc_slab_page mm/slub.c:1824 [inline]
allocate_slab mm/slub.c:1969 [inline]
new_slab+0x2a9/0x3f0 mm/slub.c:2029
___slab_alloc+0xd5a/0x1140 mm/slub.c:3031
__slab_alloc.isra.0+0x4d/0xa0 mm/slub.c:3118
slab_alloc_node mm/slub.c:3209 [inline]
__kmalloc_node_track_caller+0x321/0x440 mm/slub.c:4979
kmalloc_reserve+0x32/0xd0 net/core/skbuff.c:354
__alloc_skb+0x11f/0x370 net/core/skbuff.c:426
alloc_skb include/linux/skbuff.h:1426 [inline]
nlmsg_new include/net/netlink.h:953 [inline]
inet6_ifinfo_notify+0x72/0x150 net/ipv6/addrconf.c:6039
addrconf_notify+0x49b/0x1bb0 net/ipv6/addrconf.c:3653
notifier_call_chain+0xb5/0x200 kernel/notifier.c:87
call_netdevice_notifiers_info net/core/dev.c:1945 [inline]
call_netdevice_notifiers_info+0xb5/0x130 net/core/dev.c:1930
call_netdevice_notifiers_extack net/core/dev.c:1983 [inline]
call_netdevice_notifiers net/core/dev.c:1997 [inline]
__dev_notify_flags+0x121/0x2c0 net/core/dev.c:8571
dev_change_flags+0x112/0x170 net/core/dev.c:8609
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1371 [inline]
free_pcp_prepare+0x51f/0xd00 mm/page_alloc.c:1421
free_unref_page_prepare mm/page_alloc.c:3343 [inline]
free_unref_page+0x19/0x5b0 mm/page_alloc.c:3438
__vunmap+0x6ff/0xaa0 mm/vmalloc.c:2665
__vfree+0x3c/0xd0 mm/vmalloc.c:2713
vfree+0x5a/0x90 mm/vmalloc.c:2744
kcov_put kernel/kcov.c:421 [inline]
kcov_put+0x26/0x40 kernel/kcov.c:417
kcov_close+0xc/0x10 kernel/kcov.c:517
__fput+0x277/0x9d0 fs/file_table.c:317
task_work_run+0xe0/0x1a0 kernel/task_work.c:177
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0xb1e/0x2dd0 kernel/exit.c:797
do_group_exit+0xd2/0x2f0 kernel/exit.c:927
__do_sys_exit_group kernel/exit.c:938 [inline]
__se_sys_exit_group kernel/exit.c:936 [inline]
__x64_sys_exit_group+0x3a/0x50 kernel/exit.c:936
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+0x46/0xb0

Memory state around the buggy address:
ffff88815f2b7000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff88815f2b7080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff88815f2b7100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
ffff88815f2b7180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff88815f2b7200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================

--
Thanks and Regards,

Dipanjan
[unhandled content-type:application/octet-stream]// autogenerated by syzkaller (https://github.com/google/syzkaller)

#define _GNU_SOURCE

#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>

#ifndef __NR_io_uring_register
#define __NR_io_uring_register 427
#endif
#ifndef __NR_io_uring_setup
#define __NR_io_uring_setup 425
#endif

uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0};

int main(void)
{
syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
intptr_t res = 0;
*(uint32_t*)0x20000000 = 0;
*(uint32_t*)0x20000004 = 2;
*(uint32_t*)0x20000008 = 8;
*(uint32_t*)0x2000000c = 8;
syscall(__NR_setsockopt, -1, 0x107, 5, 0x20000000ul, 0x10ul);
*(uint32_t*)0x20000284 = 0;
*(uint32_t*)0x20000288 = 0;
*(uint32_t*)0x2000028c = 0;
*(uint32_t*)0x20000290 = 0;
*(uint32_t*)0x20000298 = -1;
memset((void*)0x2000029c, 0, 12);
res = syscall(__NR_io_uring_setup, 0x1224, 0x20000280ul);
if (res != -1)
r[0] = res;
*(uint32_t*)0x20000284 = 0;
*(uint32_t*)0x20000288 = 0;
*(uint32_t*)0x2000028c = 0;
*(uint32_t*)0x20000290 = 0;
*(uint32_t*)0x20000298 = -1;
memset((void*)0x2000029c, 0, 12);
res = syscall(__NR_io_uring_setup, 0x1224, 0x20000280ul);
if (res != -1)
r[1] = res;
res = syscall(__NR_io_uring_register, r[1], 9ul, 0ul, 0ul);
if (res != -1)
r[2] = res;
syscall(__NR_io_uring_register, r[0], 0x16ul, 0x20000000ul, r[2]);
return 0;
}
\
 
 \ /
  Last update: 2022-07-21 04:11    [W:0.037 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site