All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Bulwahn <lukas.bulwahn@gmail.com>
To: Dipanjan Das <mail.dipanjan.das@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	Greg KH <gregkh@linuxfoundation.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	consult.awy@gmail.com, alsa-devel@alsa-project.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	syzkaller <syzkaller@googlegroups.com>,
	fleischermarius@googlemail.com, its.priyanka.bose@gmail.com
Subject: Re: KASAN: vmalloc-out-of-bounds Write in snd_pcm_hw_params
Date: Wed, 27 Jul 2022 06:06:45 +0200	[thread overview]
Message-ID: <CAKXUXMz6EmQJqKg6UNC+qD8GLUpmHfhS7OH9X6tWKpLjFpKfSg@mail.gmail.com> (raw)
In-Reply-To: <CANX2M5Ywm+GpYY3+GsOWCLH24Nhy0M0LjBE-pHC8wFcd7SO=wQ@mail.gmail.com>

On Tue, Jul 26, 2022 at 11:41 PM Dipanjan Das
<mail.dipanjan.das@gmail.com> wrote:
>
> On Sat, Jul 23, 2022 at 3:17 AM Takashi Iwai <tiwai@suse.de> wrote:
> >
> > On Sat, 23 Jul 2022 09:00:08 +0200,
> > Greg KH wrote:
> > >
> > > Wondeful, do you have a fix for this that solves the reported problem
> > > that you have tested with the reproducer?
> >
> > ... or at least more detailed information.
>
> Here is our analysis of the bug in the kernel v5.10.131.
>
> During allocation, the `size` of the DMA buffer is not page-aligned:
> https://elixir.bootlin.com/linux/v5.10.131/source/sound/core/memalloc.c#L149.
> However, in sound/core/pcm_native.c:798
> (https://elixir.bootlin.com/linux/v5.10.131/source/sound/core/pcm_native.c#L798),
> the `size` variable is page-aligned before memset-ing the `dma_area`.
> From the other BUG_ON assertions in other parts of the code, it looks
> like the DMA area is not supposed to be equal to or greater than
> 0x200000 bytes. However, due to page-alignment, the `size` can indeed
> get rounded up to 0x200000 which causes the out of bound access.
>
> > Last but not least, you should check whether it's specific to your
> > 5.10.x kernel or it's also seen with the latest upstream, too.
>
> The bug is not reproducible on the latest mainline, because in
> sound/core/memalloc.c:66
> (https://github.com/torvalds/linux/blob/5de64d44968e4ae66ebdb0a2d08b443f189d3651/sound/core/memalloc.c#L66)
> the allocation function `snd_dma_alloc_dir_pages()` now page-aligns
> the `size` right before allocating the DMA buffer. Therefore, any
> subsequent page-alignment, like the one in `snd_pcm_hw_params()` does
> not cause an out of bound access.
>

Great analysis!

Now, you would just need to identify the specific commit in the
mainline repository, where 'function `snd_dma_alloc_dir_pages()` now
page-aligns the `size` right before allocating the DMA buffer.', and
then ask for applying that commit to the v5.10 stable branch,
following the guide from
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html.
Greg KH and Sasha Levin are then going to let you know if that works
or needs rework to backport.


Lukas

WARNING: multiple messages have this Message-ID (diff)
From: Lukas Bulwahn <lukas.bulwahn@gmail.com>
To: Dipanjan Das <mail.dipanjan.das@gmail.com>
Cc: alsa-devel@alsa-project.org, fleischermarius@googlemail.com,
	Takashi Iwai <tiwai@suse.de>,
	Greg KH <gregkh@linuxfoundation.org>,
	Takashi Iwai <tiwai@suse.com>,
	consult.awy@gmail.com, syzkaller <syzkaller@googlegroups.com>,
	its.priyanka.bose@gmail.com,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: KASAN: vmalloc-out-of-bounds Write in snd_pcm_hw_params
Date: Wed, 27 Jul 2022 06:06:45 +0200	[thread overview]
Message-ID: <CAKXUXMz6EmQJqKg6UNC+qD8GLUpmHfhS7OH9X6tWKpLjFpKfSg@mail.gmail.com> (raw)
In-Reply-To: <CANX2M5Ywm+GpYY3+GsOWCLH24Nhy0M0LjBE-pHC8wFcd7SO=wQ@mail.gmail.com>

On Tue, Jul 26, 2022 at 11:41 PM Dipanjan Das
<mail.dipanjan.das@gmail.com> wrote:
>
> On Sat, Jul 23, 2022 at 3:17 AM Takashi Iwai <tiwai@suse.de> wrote:
> >
> > On Sat, 23 Jul 2022 09:00:08 +0200,
> > Greg KH wrote:
> > >
> > > Wondeful, do you have a fix for this that solves the reported problem
> > > that you have tested with the reproducer?
> >
> > ... or at least more detailed information.
>
> Here is our analysis of the bug in the kernel v5.10.131.
>
> During allocation, the `size` of the DMA buffer is not page-aligned:
> https://elixir.bootlin.com/linux/v5.10.131/source/sound/core/memalloc.c#L149.
> However, in sound/core/pcm_native.c:798
> (https://elixir.bootlin.com/linux/v5.10.131/source/sound/core/pcm_native.c#L798),
> the `size` variable is page-aligned before memset-ing the `dma_area`.
> From the other BUG_ON assertions in other parts of the code, it looks
> like the DMA area is not supposed to be equal to or greater than
> 0x200000 bytes. However, due to page-alignment, the `size` can indeed
> get rounded up to 0x200000 which causes the out of bound access.
>
> > Last but not least, you should check whether it's specific to your
> > 5.10.x kernel or it's also seen with the latest upstream, too.
>
> The bug is not reproducible on the latest mainline, because in
> sound/core/memalloc.c:66
> (https://github.com/torvalds/linux/blob/5de64d44968e4ae66ebdb0a2d08b443f189d3651/sound/core/memalloc.c#L66)
> the allocation function `snd_dma_alloc_dir_pages()` now page-aligns
> the `size` right before allocating the DMA buffer. Therefore, any
> subsequent page-alignment, like the one in `snd_pcm_hw_params()` does
> not cause an out of bound access.
>

Great analysis!

Now, you would just need to identify the specific commit in the
mainline repository, where 'function `snd_dma_alloc_dir_pages()` now
page-aligns the `size` right before allocating the DMA buffer.', and
then ask for applying that commit to the v5.10 stable branch,
following the guide from
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html.
Greg KH and Sasha Levin are then going to let you know if that works
or needs rework to backport.


Lukas

  reply	other threads:[~2022-07-27  4:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 16:37 KASAN: vmalloc-out-of-bounds Write in snd_pcm_hw_params Dipanjan Das
2022-07-22 16:37 ` Dipanjan Das
2022-07-23  7:00 ` Greg KH
2022-07-23  7:00   ` Greg KH
2022-07-23 10:16   ` Takashi Iwai
2022-07-23 10:16     ` Takashi Iwai
2022-07-26 21:40     ` Dipanjan Das
2022-07-26 21:40       ` Dipanjan Das
2022-07-27  4:06       ` Lukas Bulwahn [this message]
2022-07-27  4:06         ` Lukas Bulwahn
2022-07-27  5:25       ` Takashi Iwai
2022-07-27  5:25         ` Takashi Iwai
2022-07-28 23:24         ` Dipanjan Das
2022-07-28 23:24           ` Dipanjan Das
2022-07-29  6:07           ` Takashi Iwai
2022-07-29  6:07             ` Takashi Iwai
2022-07-29  8:13           ` Greg KH
2022-07-29  8:13             ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKXUXMz6EmQJqKg6UNC+qD8GLUpmHfhS7OH9X6tWKpLjFpKfSg@mail.gmail.com \
    --to=lukas.bulwahn@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=consult.awy@gmail.com \
    --cc=fleischermarius@googlemail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=its.priyanka.bose@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mail.dipanjan.das@gmail.com \
    --cc=perex@perex.cz \
    --cc=syzkaller@googlegroups.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.