All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: cs46xx: fix unit mismatch in DSP code area bounds check
@ 2026-10-14 10:26 Denis Arefev
  2026-10-14 12:45 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Arefev @ 2026-10-14 10:26 UTC (permalink / raw)
  To: Jaroslav Kysela
  Cc: Takashi Iwai, Kees Cook, linux-sound, linux-kernel, lvc-project,
	stable

ins->code.offset and code->size are measured in 32-bit words, while
DSP_CODE_BYTE_SIZE is the size of the DSP code area in bytes. The
check ins->code.offset + code->size > DSP_CODE_BYTE_SIZE in
cs46xx_dsp_load_module() therefore allowed up to four times more code
than the code area can hold.

The shadow buffer ins->code.data is allocated with
kmalloc(DSP_CODE_BYTE_SIZE), i.e. it holds DSP_CODE_BYTE_SIZE/4
words. A firmware file with a code segment larger than
DSP_CODE_BYTE_SIZE/4 words (28 KiB) passed the check and caused an
out-of-bounds write in shadow_and_reallocate_code() and an
out-of-bounds read in snd_cs46xx_download().

Compare the sum in words against DSP_CODE_BYTE_SIZE/4 and cast it to
u64 so that the sum cannot wrap for large code->size values.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
 Compile tested only
 sound/pci/cs46xx/dsp_spos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/pci/cs46xx/dsp_spos.c b/sound/pci/cs46xx/dsp_spos.c
index 6fd4f629d1d5..a77e6f5a14ad 100644
--- a/sound/pci/cs46xx/dsp_spos.c
+++ b/sound/pci/cs46xx/dsp_spos.c
@@ -393,7 +393,7 @@ int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * m
 		dev_dbg(chip->card->dev,
 			"dsp_spos: module got no code segment\n");
 	} else {
-		if (ins->code.offset + code->size > DSP_CODE_BYTE_SIZE) {
+		if ((u64)ins->code.offset + code->size > DSP_CODE_BYTE_SIZE / 4) {
 			dev_err(chip->card->dev,
 				"dsp_spos: no space available in DSP\n");
 			return -ENOMEM;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: cs46xx: fix unit mismatch in DSP code area bounds check
  2026-10-14 10:26 [PATCH] ALSA: cs46xx: fix unit mismatch in DSP code area bounds check Denis Arefev
@ 2026-10-14 12:45 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-10-14 12:45 UTC (permalink / raw)
  To: Denis Arefev
  Cc: Jaroslav Kysela, Takashi Iwai, Kees Cook, linux-sound,
	linux-kernel, lvc-project, stable

On Wed, 14 Oct 2026 12:26:18 +0200,
Denis Arefev wrote:
> 
> ins->code.offset and code->size are measured in 32-bit words, while
> DSP_CODE_BYTE_SIZE is the size of the DSP code area in bytes. The
> check ins->code.offset + code->size > DSP_CODE_BYTE_SIZE in
> cs46xx_dsp_load_module() therefore allowed up to four times more code
> than the code area can hold.
> 
> The shadow buffer ins->code.data is allocated with
> kmalloc(DSP_CODE_BYTE_SIZE), i.e. it holds DSP_CODE_BYTE_SIZE/4
> words. A firmware file with a code segment larger than
> DSP_CODE_BYTE_SIZE/4 words (28 KiB) passed the check and caused an
> out-of-bounds write in shadow_and_reallocate_code() and an
> out-of-bounds read in snd_cs46xx_download().
> 
> Compare the sum in words against DSP_CODE_BYTE_SIZE/4 and cast it to
> u64 so that the sum cannot wrap for large code->size values.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Denis Arefev <arefev@swemel.ru>

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-14 12:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-14 10:26 [PATCH] ALSA: cs46xx: fix unit mismatch in DSP code area bounds check Denis Arefev
2026-10-14 12:45 ` Takashi Iwai

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.