ALSA: core: fix buffer overflow in test_format_fill_silence()
Subsystems (2)
PATCH v2 1/1 ALSA: core: fix buffer overflow in test_format_fill_silence()
From: Arnd Bergmann <[email protected]>
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.
---
v2: use a named constant as suggested by Ivan Orlov
--- sound/core/sound_kunit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/core/sound_kunit.c +3 -2
@@ -8,7 +8,8 @@#include <sound/core.h> #include <sound/pcm.h> -#define SILENCE_BUFFER_SIZE 2048 +#define SILENCE_BUFFER_MAX_FRAMES 260 +#define SILENCE_BUFFER_SIZE (sizeof(u64) * SILENCE_BUFFER_MAX_FRAMES)#define SILENCE (...) { __VA_ARGS__ }#define DEFINE_FORMAT (fmt, pbits, wd, endianness, signd, silence_arr) { \ .format = SNDRV_PCM_FORMAT_##fmt, .physical_bits = pbits, \
@@ -165,7 +166,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *static void test_format_fill_silence (struct kunit *test) { -u32 buf_samples[] = {10 ,20 ,32 ,64 ,129 ,260 }; +u32 buf_samples[] = {10 ,20 ,32 ,64 ,129 ,SILENCE_BUFFER_MAX_FRAMES };u8 *buffer;u32 i, j;
Signature · 1 line
2.39.2
Quoted 57 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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/0x20Replace the incorrect size with the correct length of 260 64-bit samples.
Reported-by Naresh Kamboju <[email protected]>Suggested-by Ivan Orlov <[email protected]>Fixes 3e39acf56ede ("ALSA: core: Add sound core KUnit test")Signed-off-by Arnd Bergmann <[email protected]>---
v2: use a named constant as suggested by Ivan Orlov--- sound/core/sound_kunit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)sound/core/sound_kunit.c +2
-1@@ -8,7 +8,8 @@#include <sound/core.h> #include <sound/pcm.h> -#define SILENCE_BUFFER_SIZE 2048 +#define SILENCE_BUFFER_MAX_FRAMES 260 +#define SILENCE_BUFFER_SIZE (sizeof(u64) * SILENCE_BUFFER_MAX_FRAMES)#define SILENCE (...) { __VA_ARGS__ }#define DEFINE_FORMAT (fmt, pbits, wd, endianness, signd, silence_arr) { \ .format = SNDRV_PCM_FORMAT_##fmt, .physical_bits = pbits, \
sound/core/sound_kunit.c static void _test_fill_silence(struct kunit *test, struct snd_format_test_data * · line 172
Quoted 8 lines
sound/core/sound_kunit.c +1
-1@@ -165,7 +166,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *static void test_format_fill_silence (struct kunit *test) { -u32 buf_samples[] = {10 ,20 ,32 ,64 ,129 ,260 }; +u32 buf_samples[] = {10 ,20 ,32 ,64 ,129 ,SILENCE_BUFFER_MAX_FRAMES };u8 *buffer;u32 i, j;
Signature · 2 lines
Kind regards, Ivan Orlov
Quoted 31 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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
Quoted 6 lines
Replace the incorrect size with the correct length of 260 64-bit samples.
Reported-by Naresh Kamboju <[email protected]>Suggested-by Ivan Orlov <[email protected]>Fixes 3e39acf56ede ("ALSA: core: Add sound core KUnit test")Signed-off-by Arnd Bergmann <[email protected]>
Quoted 30 lines
---
v2: use a named constant as suggested by Ivan Orlov--- sound/core/sound_kunit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)sound/core/sound_kunit.c +3
-3@@ -8,7 +8,8 @@#include <sound/core.h> #include <sound/pcm.h> -#define SILENCE_BUFFER_SIZE 2048 +#define SILENCE_BUFFER_MAX_FRAMES 260 +#define SILENCE_BUFFER_SIZE (sizeof(u64) * SILENCE_BUFFER_MAX_FRAMES)#define SILENCE (...) { __VA_ARGS__ }#define DEFINE_FORMAT (fmt, pbits, wd, endianness, signd, silence_arr) { \ .format = SNDRV_PCM_FORMAT_##fmt, .physical_bits = pbits, \@@ -165,7 +166,7 @@ static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *static void test_format_fill_silence (struct kunit *test) { -u32 buf_samples[] = {10 ,20 ,32 ,64 ,129 ,260 }; +u32 buf_samples[] = {10 ,20 ,32 ,64 ,129 ,SILENCE_BUFFER_MAX_FRAMES };u8 *buffer;u32 i, j; --
Quoted 2 lines
2.39.2
--
Linaro LKFT
https://lkft.linaro.org
Takashi Iwai
AppliedQuoted 31 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
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
Quoted 8 lines
Replace the incorrect size with the correct length of 260 64-bit samples.
Reported-by Naresh Kamboju <[email protected]>Suggested-by Ivan Orlov <[email protected]>Fixes 3e39acf56ede ("ALSA: core: Add sound core KUnit test")Signed-off-by Arnd Bergmann <[email protected]>---
v2: use a named constant as suggested by Ivan Orlov
Thanks, applied now.
Takashi