public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ivan Orlov <ivan.orlov0322@gmail.com>
To: Arnd Bergmann <arnd@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Naresh Kamboju <naresh.kamboju@linaro.org>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ALSA: core: fix buffer overflow in test_format_fill_silence()
Date: Fri, 16 Feb 2024 23:05:22 +0000	[thread overview]
Message-ID: <90cde49e-072d-4236-bcb9-affb0a1ce6af@gmail.com> (raw)
In-Reply-To: <20240216130050.3786789-1-arnd@kernel.org>

On 2/16/24 13:00, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> KASAN caught a buffer overflow with the hardcoded 2048 byte buffer
> size, when 2080 bytes are written to it:
> 
>   BUG: KASAN: slab-out-of-bounds in snd_pcm_format_set_silence+0x3bc/0x3e4
>   Write of size 8 at addr ffff0000c8149800 by task kunit_try_catch/1297
> 
>   CPU: 0 PID: 1297 Comm: kunit_try_catch Tainted: G N 6.8.0-rc4-next-20240216 #1
>   Hardware name: linux,dummy-virt (DT)
>   Call trace:
>    kasan_report+0x78/0xc0
>    __asan_report_store_n_noabort+0x1c/0x28
>    snd_pcm_format_set_silence+0x3bc/0x3e4
>    _test_fill_silence+0xdc/0x298
>    test_format_fill_silence+0x110/0x228
>    kunit_try_run_case+0x144/0x3bc
>    kunit_generic_run_threadfn_adapter+0x50/0x94
>    kthread+0x330/0x3e8
>    ret_from_fork+0x10/0x20
> 
>   Allocated by task 1297:
>    __kmalloc+0x17c/0x2f0
>    kunit_kmalloc_array+0x2c/0x78
>    test_format_fill_silence+0xcc/0x228
>    kunit_try_run_case+0x144/0x3bc
>    kunit_generic_run_threadfn_adapter+0x50/0x94
>    kthread+0x330/0x3e8
>    ret_from_fork+0x10/0x20
> 
> Replace the incorrect size with the correct length of 260 64-bit samples.
> 
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Fixes: 3e39acf56ede ("ALSA: core: Add sound core KUnit test")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> Naresh, I slightly changed the patch to make the computation more obvious,
> can you test again to make sure I got this right?
> ---
>   sound/core/sound_kunit.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/core/sound_kunit.c b/sound/core/sound_kunit.c
> index 5d5a7bf88de4..7f16101ece7a 100644
> --- a/sound/core/sound_kunit.c
> +++ b/sound/core/sound_kunit.c
> @@ -8,7 +8,7 @@
>   #include <sound/core.h>
>   #include <sound/pcm.h>
>   
> -#define SILENCE_BUFFER_SIZE 2048
> +#define SILENCE_BUFFER_SIZE (sizeof(u64) * 260)

I believe it would be good to define FILL_SILENCE_MAX_FRAMES to 260, 
update the 'buf_samples' array correspondingly and define the 
SILENCE_BUFFER_SIZE as (sizeof(u64) * FILL_SILENCE_MAX_FRAMES), so it 
would be more clear where '260' came from.

Thank you for fixing this!
-- 
Kind regards,
Ivan Orlov


      reply	other threads:[~2024-02-16 23:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16 13:00 [PATCH] ALSA: core: fix buffer overflow in test_format_fill_silence() Arnd Bergmann
2024-02-16 23:05 ` Ivan Orlov [this message]

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=90cde49e-072d-4236-bcb9-affb0a1ce6af@gmail.com \
    --to=ivan.orlov0322@gmail.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=naresh.kamboju@linaro.org \
    --cc=perex@perex.cz \
    --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