KASAN: use-after-free Write in snd_rawmidi_kernel_write1

37 views
Skip to first unread message

syzbot

unread,
Apr 14, 2020, 8:40:47 AM4/14/20
to syzkaller...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: c10b57a5 Linux 4.14.176
git tree: linux-4.14.y
console output: https://syzkaller.appspot.com/x/log.txt?x=12988be0100000
kernel config: https://syzkaller.appspot.com/x/.config?x=457897b554d08537
dashboard link: https://syzkaller.appspot.com/bug?extid=1a1608c81aaa3b70b8f5
compiler: gcc (GCC) 9.0.0 20181231 (experimental)

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

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+1a1608...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in _copy_from_user+0xaf/0x100 lib/usercopy.c:12
Write of size 4096 at addr ffff88808809ae00 by task syz-executor.3/29636

CPU: 1 PID: 29636 Comm: syz-executor.3 Not tainted 4.14.176-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:17 [inline]
dump_stack+0x13e/0x194 lib/dump_stack.c:58
print_address_description.cold+0x7c/0x1e2 mm/kasan/report.c:252
kasan_report_error mm/kasan/report.c:351 [inline]
kasan_report mm/kasan/report.c:409 [inline]
kasan_report.cold+0xa9/0x2ae mm/kasan/report.c:393
_copy_from_user+0xaf/0x100 lib/usercopy.c:12
copy_from_user include/linux/uaccess.h:147 [inline]
snd_rawmidi_kernel_write1+0x2e3/0x680 sound/core/rawmidi.c:1283
snd_rawmidi_write+0x275/0x970 sound/core/rawmidi.c:1348
__vfs_write+0xe4/0x630 fs/read_write.c:480
vfs_write+0x192/0x4e0 fs/read_write.c:544
SYSC_write fs/read_write.c:590 [inline]
SyS_write+0xf2/0x210 fs/read_write.c:582
do_syscall_64+0x1d5/0x640 arch/x86/entry/common.c:292
entry_SYSCALL_64_after_hwframe+0x42/0xb7
RIP: 0033:0x45c889
RSP: 002b:00007fa98a058c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fa98a0596d4 RCX: 000000000045c889
RDX: 0000000020000339 RSI: 00000000200001c0 RDI: 0000000000000003
RBP: 000000000076bf00 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
R13: 0000000000000c4e R14: 00000000004ca0d5 R15: 000000000076bf0c

Allocated by task 29636:
save_stack+0x32/0xa0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_kmalloc mm/kasan/kasan.c:551 [inline]
kasan_kmalloc+0xbf/0xe0 mm/kasan/kasan.c:529
kmem_cache_alloc_trace+0x14d/0x7b0 mm/slab.c:3618
kmalloc include/linux/slab.h:488 [inline]
snd_rawmidi_runtime_create sound/core/rawmidi.c:128 [inline]
open_substream+0x324/0x7d0 sound/core/rawmidi.c:267
rawmidi_open_priv+0x44b/0x580 sound/core/rawmidi.c:318
snd_rawmidi_open+0x3b9/0x9b1 sound/core/rawmidi.c:417
snd_open+0x1f7/0x3b0 sound/core/sound.c:175
chrdev_open+0x1fc/0x540 fs/char_dev.c:423
do_dentry_open+0x732/0xe90 fs/open.c:777
vfs_open+0x105/0x220 fs/open.c:888
do_last fs/namei.c:3428 [inline]
path_openat+0x8ca/0x3c50 fs/namei.c:3569
do_filp_open+0x18e/0x250 fs/namei.c:3603
do_sys_open+0x29d/0x3f0 fs/open.c:1081
do_syscall_64+0x1d5/0x640 arch/x86/entry/common.c:292
entry_SYSCALL_64_after_hwframe+0x42/0xb7

Freed by task 29641:
save_stack+0x32/0xa0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_slab_free+0x75/0xc0 mm/kasan/kasan.c:524
__cache_free mm/slab.c:3496 [inline]
kfree+0xcb/0x260 mm/slab.c:3815
snd_rawmidi_output_params+0x286/0x440 sound/core/rawmidi.c:663
snd_rawmidi_ioctl+0x51c/0x620 sound/core/rawmidi.c:764
vfs_ioctl fs/ioctl.c:46 [inline]
file_ioctl fs/ioctl.c:500 [inline]
do_vfs_ioctl+0x75a/0xfe0 fs/ioctl.c:684
SYSC_ioctl fs/ioctl.c:701 [inline]
SyS_ioctl+0x7f/0xb0 fs/ioctl.c:692
do_syscall_64+0x1d5/0x640 arch/x86/entry/common.c:292
entry_SYSCALL_64_after_hwframe+0x42/0xb7

The buggy address belongs to the object at ffff88808809ae00
which belongs to the cache kmalloc-4096 of size 4096
The buggy address is located 0 bytes inside of
4096-byte region [ffff88808809ae00, ffff88808809be00)
The buggy address belongs to the page:
page:ffffea0002202680 count:1 mapcount:0 mapping:ffff88808809ae00 index:0x0 compound_mapcount: 0
flags: 0xfffe0000008100(slab|head)
raw: 00fffe0000008100 ffff88808809ae00 0000000000000000 0000000100000001
raw: ffffea0001459aa0 ffffea00005c6420 ffff88812fe56dc0 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff88808809ad00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88808809ad80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88808809ae00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88808809ae80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88808809af00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
ebt_among: dst integrity fail: 155


---
This bug 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 syzk...@googlegroups.com.

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

syzbot

unread,
Apr 15, 2020, 8:19:17 AM4/15/20
to syzkaller...@googlegroups.com
Hello,

syzbot found the following crash on:

HEAD commit: 6dd0e326 Linux 4.19.115
git tree: linux-4.19.y
console output: https://syzkaller.appspot.com/x/log.txt?x=105cc73fe00000
kernel config: https://syzkaller.appspot.com/x/.config?x=75bfa32b46e7b6cf
dashboard link: https://syzkaller.appspot.com/bug?extid=3b8760a9c613d52813e1
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=11abb86fe00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1438173fe00000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+3b8760...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: use-after-free in _copy_from_user+0xef/0x140 lib/usercopy.c:12
Write of size 32 at addr ffff8880a534b3a0 by task syz-executor745/6430

CPU: 1 PID: 6430 Comm: syz-executor745 Not tainted 4.19.115-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.cold+0x7c/0x212 mm/kasan/report.c:256
kasan_report_error mm/kasan/report.c:354 [inline]
kasan_report mm/kasan/report.c:412 [inline]
kasan_report.cold+0x88/0x2b9 mm/kasan/report.c:396
_copy_from_user+0xef/0x140 lib/usercopy.c:12
copy_from_user include/linux/uaccess.h:147 [inline]
snd_rawmidi_kernel_write1+0x301/0x6c0 sound/core/rawmidi.c:1282
snd_rawmidi_write+0x2e4/0xb50 sound/core/rawmidi.c:1348
__vfs_write+0xf7/0x760 fs/read_write.c:485
vfs_write+0x206/0x550 fs/read_write.c:549
ksys_write+0x12b/0x2a0 fs/read_write.c:599
do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x44a3f9
Code: e8 5c b3 02 00 48 83 c4 18 c3 0f 1f 80 00 00 00 00 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 cc fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f571e99bdb8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00000000006dbc28 RCX: 000000000044a3f9
RDX: 0000000020000339 RSI: 00000000200001c0 RDI: 0000000000000003
RBP: 00000000006dbc20 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000006dbc2c
R13: 00007fff8662259f R14: 00007f571e99c9c0 R15: 20c49ba5e353f7cf

Allocated by task 6430:
set_track mm/kasan/kasan.c:460 [inline]
kasan_kmalloc mm/kasan/kasan.c:553 [inline]
kasan_kmalloc+0xbf/0xe0 mm/kasan/kasan.c:531
__do_kmalloc_node mm/slab.c:3689 [inline]
__kmalloc_node+0x4c/0x70 mm/slab.c:3696
kmalloc_node include/linux/slab.h:557 [inline]
kvmalloc_node+0x61/0xf0 mm/util.c:423
kvmalloc include/linux/mm.h:577 [inline]
kvzalloc include/linux/mm.h:585 [inline]
snd_rawmidi_runtime_create sound/core/rawmidi.c:133 [inline]
open_substream+0x332/0x800 sound/core/rawmidi.c:277
rawmidi_open_priv+0x58e/0x6e0 sound/core/rawmidi.c:328
snd_rawmidi_open+0x449/0xaf0 sound/core/rawmidi.c:425
snd_open+0x212/0x3e2 sound/core/sound.c:175
chrdev_open+0x219/0x5c0 fs/char_dev.c:423
do_dentry_open+0x4a8/0x1160 fs/open.c:796
do_last fs/namei.c:3421 [inline]
path_openat+0x1031/0x4200 fs/namei.c:3537
do_filp_open+0x1a1/0x280 fs/namei.c:3567
do_sys_open+0x3c0/0x500 fs/open.c:1085
do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 6431:
set_track mm/kasan/kasan.c:460 [inline]
__kasan_slab_free+0xf7/0x140 mm/kasan/kasan.c:521
__cache_free mm/slab.c:3503 [inline]
kfree+0xce/0x220 mm/slab.c:3822
kvfree+0x59/0x60 mm/util.c:452
resize_runtime_buffer+0x29e/0x370 sound/core/rawmidi.c:669
snd_rawmidi_output_params+0x128/0x170 sound/core/rawmidi.c:682
snd_rawmidi_ioctl+0x640/0x740 sound/core/rawmidi.c:759
vfs_ioctl fs/ioctl.c:46 [inline]
file_ioctl fs/ioctl.c:501 [inline]
do_vfs_ioctl+0xcda/0x12e0 fs/ioctl.c:688
ksys_ioctl+0x9b/0xc0 fs/ioctl.c:705
__do_sys_ioctl fs/ioctl.c:712 [inline]
__se_sys_ioctl fs/ioctl.c:710 [inline]
__x64_sys_ioctl+0x6f/0xb0 fs/ioctl.c:710
do_syscall_64+0xf9/0x620 arch/x86/entry/common.c:293
entry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff8880a534a640
which belongs to the cache kmalloc-4096 of size 4096
The buggy address is located 3424 bytes inside of
4096-byte region [ffff8880a534a640, ffff8880a534b640)
The buggy address belongs to the page:
page:ffffea000294d280 count:1 mapcount:0 mapping:ffff88812c3dcdc0 index:0x0 compound_mapcount: 0
flags: 0xfffe0000008100(slab|head)
raw: 00fffe0000008100 ffffea0002942988 ffffea0002920208 ffff88812c3dcdc0
raw: 0000000000000000 ffff8880a534a640 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8880a534b280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880a534b300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880a534b380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880a534b400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880a534b480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


---
This bug 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 syzk...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

syzbot

unread,
Jun 14, 2020, 1:48:04 PM6/14/20
to syzkaller...@googlegroups.com
syzbot suspects this bug was fixed by commit:

commit a507658fdb2ad8ca282b0eb42f2a40b805deb1e6
Author: Takashi Iwai <ti...@suse.de>
Date: Thu May 7 11:44:56 2020 +0000

ALSA: rawmidi: Fix racy buffer resize under concurrent accesses

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=1569132e100000
start commit: 6dd0e326 Linux 4.19.115
git tree: linux-4.19.y
If the result looks correct, please mark the bug fixed by replying with:

#syz fix: ALSA: rawmidi: Fix racy buffer resize under concurrent accesses

For information about bisection process see: https://goo.gl/tpsmEJ#bisection

syzbot

unread,
Aug 12, 2020, 8:40:10 AM8/12/20
to syzkaller...@googlegroups.com
Auto-closing this bug as obsolete.
Crashes did not happen for a while, no reproducer and no activity.
Reply all
Reply to author
Forward
0 new messages