public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Dipanjan Das <mail.dipanjan.das@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	perex@perex.cz, tiwai@suse.com, consult.awy@gmail.com,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	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 07:25:33 +0200	[thread overview]
Message-ID: <87tu73p1o2.wl-tiwai@suse.de> (raw)
In-Reply-To: <CANX2M5Ywm+GpYY3+GsOWCLH24Nhy0M0LjBE-pHC8wFcd7SO=wQ@mail.gmail.com>

On Tue, 26 Jul 2022 23:40:48 +0200,
Dipanjan Das 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.

Thanks for the analysis.  A good news is that, at least for the
vmalloc() case, it's a kind of false-positive; vmalloc() always takes
the full pages, so practically seen, the size is page-aligned.  It's
fooling the memory checker, though.

But the similar problem could be seen with genalloc calls, and this
was fixed by the upstream commit
5c1733e33c888a3cb7f576564d8ad543d5ad4a9e
    ALSA: memalloc: Align buffer allocations in page size

I suppose you can simply backport this commit to 5.10.y.  Could you
confirm that this fixes your problem?


thanks,

Takashi

  parent reply	other threads:[~2022-07-27  5:25 UTC|newest]

Thread overview: 9+ 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-23  7:00 ` Greg KH
2022-07-23 10:16   ` Takashi Iwai
2022-07-26 21:40     ` Dipanjan Das
2022-07-27  4:06       ` Lukas Bulwahn
2022-07-27  5:25       ` Takashi Iwai [this message]
2022-07-28 23:24         ` Dipanjan Das
2022-07-29  6:07           ` Takashi Iwai
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=87tu73p1o2.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --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 \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox