KASAN: use-after-free Read in snd_timer_user_info_compat

15 views
Skip to first unread message

syzbot

unread,
Oct 27, 2017, 4:34:02 AM10/27/17
to alsa-...@alsa-project.org, linux-...@vger.kernel.org, pe...@perex.cz, syzkall...@googlegroups.com, ti...@suse.com
Hello,

syzkaller hit the following crash on
33d930e59a98fa10a0db9f56c7fa2f21a4aef9b9
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/master
compiler: gcc (GCC) 7.1.1 20170620
.config is attached
Raw console output is attached.

syzkaller reproducer is attached. See https://goo.gl/kgGztJ
for information about syzkaller reproducers


BUG: KASAN: use-after-free in snd_timer_user_info_compat.isra.6+0x46c/0x480
sound/core/timer_compat.c:71
Read of size 8 at addr ffff8801d0dd9d00 by task syz-executor0/3342

CPU: 1 PID: 3342 Comm: syz-executor0 Not tainted 4.14.0-rc5+ #44
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:16 [inline]
dump_stack+0x194/0x257 lib/dump_stack.c:52
print_address_description+0x73/0x250 mm/kasan/report.c:252
kasan_report_error mm/kasan/report.c:351 [inline]
kasan_report+0x25b/0x340 mm/kasan/report.c:409
__asan_report_load8_noabort+0x14/0x20 mm/kasan/report.c:430
snd_timer_user_info_compat.isra.6+0x46c/0x480 sound/core/timer_compat.c:71
snd_timer_user_ioctl_compat+0x464/0x821 sound/core/timer_compat.c:160
C_SYSC_ioctl fs/compat_ioctl.c:1593 [inline]
compat_SyS_ioctl+0x1d7/0x3290 fs/compat_ioctl.c:1540
do_syscall_32_irqs_on arch/x86/entry/common.c:329 [inline]
do_fast_syscall_32+0x3f2/0xf05 arch/x86/entry/common.c:391
entry_SYSENTER_compat+0x51/0x60 arch/x86/entry/entry_64_compat.S:124
RIP: 0023:0xf7fd4c79
RSP: 002b:00000000f7faf05c EFLAGS: 00000296 ORIG_RAX: 0000000000000036
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000080e05411
RDX: 0000000020db8fe5 RSI: 0000000000000000 RDI: 0000000000000000
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 3341:
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
save_stack+0x43/0xd0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:551
kmem_cache_alloc_trace+0x136/0x750 mm/slab.c:3627
kmalloc include/linux/slab.h:493 [inline]
kzalloc include/linux/slab.h:666 [inline]
snd_timer_instance_new+0xda/0x610 sound/core/timer.c:108
snd_timer_open+0x180/0x1790 sound/core/timer.c:253
snd_timer_user_tselect sound/core/timer.c:1655 [inline]
__snd_timer_user_ioctl sound/core/timer.c:1918 [inline]
snd_timer_user_ioctl+0x96f/0x32e0 sound/core/timer.c:1948
snd_timer_user_ioctl_compat+0x615/0x821 sound/core/timer_compat.c:156
C_SYSC_ioctl fs/compat_ioctl.c:1593 [inline]
compat_SyS_ioctl+0x1d7/0x3290 fs/compat_ioctl.c:1540
do_syscall_32_irqs_on arch/x86/entry/common.c:329 [inline]
do_fast_syscall_32+0x3f2/0xf05 arch/x86/entry/common.c:391
entry_SYSENTER_compat+0x51/0x60 arch/x86/entry/entry_64_compat.S:124

Freed by task 3341:
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
save_stack+0x43/0xd0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_slab_free+0x71/0xc0 mm/kasan/kasan.c:524
__cache_free mm/slab.c:3503 [inline]
kfree+0xca/0x250 mm/slab.c:3820
snd_timer_close+0xa02/0xf20 sound/core/timer.c:374
snd_timer_user_tselect sound/core/timer.c:1645 [inline]
__snd_timer_user_ioctl sound/core/timer.c:1918 [inline]
snd_timer_user_ioctl+0x80d/0x32e0 sound/core/timer.c:1948
snd_timer_user_ioctl_compat+0x615/0x821 sound/core/timer_compat.c:156
C_SYSC_ioctl fs/compat_ioctl.c:1593 [inline]
compat_SyS_ioctl+0x1d7/0x3290 fs/compat_ioctl.c:1540
do_syscall_32_irqs_on arch/x86/entry/common.c:329 [inline]
do_fast_syscall_32+0x3f2/0xf05 arch/x86/entry/common.c:391
entry_SYSENTER_compat+0x51/0x60 arch/x86/entry/entry_64_compat.S:124

The buggy address belongs to the object at ffff8801d0dd9d00
which belongs to the cache kmalloc-256 of size 256
The buggy address is located 0 bytes inside of
256-byte region [ffff8801d0dd9d00, ffff8801d0dd9e00)
The buggy address belongs to the page:
page:ffffea0007437640 count:1 mapcount:0 mapping:ffff8801d0dd9080 index:0x0
flags: 0x200000000000100(slab)
raw: 0200000000000100 ffff8801d0dd9080 0000000000000000 000000010000000c
raw: ffffea000741b4a0 ffffea0007400820 ffff8801dac007c0 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
ffff8801d0dd9c00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8801d0dd9c80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
> ffff8801d0dd9d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8801d0dd9d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8801d0dd9e00: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
==================================================================


---
This bug is generated by a dumb bot. It may contain errors.
See https://goo.gl/tpsmEJ for details.
Direct all questions to syzk...@googlegroups.com.

syzbot will keep track of this bug report.
Once a fix for this bug is committed, please reply to this email with:
#syz fix: exact-commit-title
To mark this as a duplicate of another syzbot report, please reply with:
#syz dup: exact-subject-of-another-report
If it's a one-off invalid bug report, please reply with:
#syz invalid
Note: if the crash happens again, it will cause creation of a new bug
report.
config.txt
raw.log
repro.txt

Takashi Iwai

unread,
Oct 29, 2017, 6:10:22 AM10/29/17
to syzbot, alsa-...@alsa-project.org, syzkall...@googlegroups.com, pe...@perex.cz, linux-...@vger.kernel.org
On Fri, 27 Oct 2017 10:34:01 +0200,
syzbot wrote:
>
> Hello,
>
> syzkaller hit the following crash on
> 33d930e59a98fa10a0db9f56c7fa2f21a4aef9b9
> git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/master
> compiler: gcc (GCC) 7.1.1 20170620
> .config is attached
> Raw console output is attached.
>
> syzkaller reproducer is attached. See https://goo.gl/kgGztJ
> for information about syzkaller reproducers
>
>
> BUG: KASAN: use-after-free in
> snd_timer_user_info_compat.isra.6+0x46c/0x480
> sound/core/timer_compat.c:71
> Read of size 8 at addr ffff8801d0dd9d00 by task syz-executor0/3342

OK, this is a real bug, and obviously a forgotten code path from the
previous fixes. The patch below should address it, but I checked only
compile-tested, so far. Let me know if it really works.


thanks,

Takashi

-- 8< --
From: Takashi Iwai <ti...@suse.de>
Subject: [PATCH] ALSA: timer: Add missing mutex lock for compat ioctls

The races among ioctl and other operations were protected by the
commit af368027a49a ("ALSA: timer: Fix race among timer ioctls") and
later fixes, but one code path was forgotten in the scenario: the
32bit compat ioctl. As syzkaller recently spotted, a very similar
use-after-free may happen with the combination of compat ioctls.

The fix is simply to apply the same ioctl_lock to the compat_ioctl
callback, too.

Fixes: af368027a49a ("ALSA: timer: Fix race among timer ioctls")
Reference: http://lkml.kernel.org/r/089e082686ac9b...@google.com
Reported-by: syzbot <bot+e5f3c9783e7048a742...@syzkaller.appspotmail.com>
Cc: <sta...@vger.kernel.org>
Signed-off-by: Takashi Iwai <ti...@suse.de>
---
sound/core/timer_compat.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/sound/core/timer_compat.c b/sound/core/timer_compat.c
index 6a437eb66115..59127b6ef39e 100644
--- a/sound/core/timer_compat.c
+++ b/sound/core/timer_compat.c
@@ -133,7 +133,8 @@ enum {
#endif /* CONFIG_X86_X32 */
};

-static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
+static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
+ unsigned long arg)
{
void __user *argp = compat_ptr(arg);

@@ -153,7 +154,7 @@ static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, uns
case SNDRV_TIMER_IOCTL_PAUSE:
case SNDRV_TIMER_IOCTL_PAUSE_OLD:
case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
- return snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
+ return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp);
case SNDRV_TIMER_IOCTL_GPARAMS32:
return snd_timer_user_gparams_compat(file, argp);
case SNDRV_TIMER_IOCTL_INFO32:
@@ -167,3 +168,15 @@ static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, uns
}
return -ENOIOCTLCMD;
}
+
+static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+ struct snd_timer_user *tu = file->private_data;
+ long ret;
+
+ mutex_lock(&tu->ioctl_lock);
+ ret = __snd_timer_user_ioctl_compat(file, cmd, arg);
+ mutex_unlock(&tu->ioctl_lock);
+ return ret;
+}
--
2.14.2

Dmitry Vyukov

unread,
Nov 21, 2017, 10:30:46 AM11/21/17
to Takashi Iwai, syzbot, alsa-...@alsa-project.org, syzkall...@googlegroups.com, Jaroslav Kysela, LKML
#syz fix: ALSA: timer: Add missing mutex lock for compat ioctls
Reply all
Reply to author
Forward
0 new messages