Re: sound: use-after-free in snd_timer_interrupt

From: Takashi Iwai
Date: Fri Jan 15 2016 - 10:21:18 EST


On Fri, 15 Jan 2016 15:38:58 +0100,
Dmitry Vyukov wrote:
>
> On Fri, Jan 15, 2016 at 2:51 PM, Takashi Iwai <tiwai@xxxxxxx> wrote:
> > On Fri, 15 Jan 2016 12:03:17 +0100,
> > Dmitry Vyukov wrote:
> >>
> >> On Fri, Jan 15, 2016 at 12:00 PM, Takashi Iwai <tiwai@xxxxxxx> wrote:
> >> > On Fri, 15 Jan 2016 09:06:10 +0100,
> >> > Dmitry Vyukov wrote:
> >> >>
> >> >> On Thu, Jan 14, 2016 at 5:09 PM, Takashi Iwai <tiwai@xxxxxxx> wrote:
> >> >> > On Wed, 13 Jan 2016 21:54:10 +0100,
> >> >> > Takashi Iwai wrote:
> >> >> >>
> >> >> >> OK, then this might be a possible race at the current snd_timer_stop()
> >> >> >> implementation. There is no sync action there, so the ISR might be
> >> >> >> still alive after snd_timer_close() call. Or might be another race.
> >> >> >> This pattern looks a bit different, as it's involved with hrtimer.
> >> >> >>
> >> >> >> I'll take a look at it tomorrow.
> >> >> >
> >> >> > I've audited the code today, but the open window doesn't look like
> >> >> > what I expected. I found only some possible cases with slave timer
> >> >> > instances.
> >> >> >
> >> >> > In anyway, below is a test fix patch. Since I couldn't reproduce the
> >> >> > issue on my local machines, it's hard to say whether this covers the
> >> >> > holes you fell. Let's see...
> >> >>
> >> >>
> >> >> Hi Takashi,
> >> >>
> >> >> I would be interested to understand why other people can't reproduce
> >> >> issues that I hit pretty reliably.
> >> >> I suspect that it can be due to .config. Please try with the following
> >> >> config values.
> >> >
> >> > I guess rather other config, e.g. the kernel debug options.
> >> > I suppose you enabled KASAN and DEBUG_LIST. What else?
> >>
> >> I've attached my config (you will need to disable CONFIG_KCOV, it is
> >> not upstreamed).
> >
> > Hm, that has lots of other drivers built-in...
> >
> >> >> I also start qemu with "-soundhw all" arg.
> >> >
> >> > OK, so you're testing with VM? This makes easier to recheck.
> >>
> >> Yes, I start qemu as:
> >>
> >> qemu-system-x86_64 -hda wheezy.img -net
> >> user,host=10.0.2.10,hostfwd=tcp::10022-:22 -net nic -nographic -kernel
> >> arch/x86/boot/bzImage -append "console=ttyS0 root=/dev/sda debug
> >> earlyprintk=serial slub_debug=UZ" -enable-kvm -m 2G -numa
> >> node,nodeid=0,cpus=0-1 -numa node,nodeid=1,cpus=2-3 -smp
> >> sockets=2,cores=2,threads=1 -usb -usbdevice mouse -usbdevice tablet
> >> -soundhw all
> >
> > And which test did trigger use-after-free, even with all previous
> > patches?
>
> I will try to extract a new reproducer now.
> Meanwhile, can you try to reproduce this one:
> https://groups.google.com/forum/#!msg/syzkaller/bbtG9_h1ONU/CPLblMC6FAAJ
> ? I run the program in a tight parallel loop.

So you're running this in parallel? Or a tight sequential loop?
I did the latter, and I tried even this on a bare metal, but couldn't
trigger the Oops, so far.

Meanwhile, I pushed the tree including all fixes at for-linus branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-linus

It'd be appreciated if you can test this one.


thanks,

Takashi