Skip to contentSkip to conversation

ALSA: dice: fix buffer overflow in detect_stream_formats()

PATCH In review Junrui Luo 3 participants 3 messages Nov 28, 2025 – Nov 29, 2025

Subsystems (3)
lore
Share & tools
lore

Junrui Luo

author
#0 lore raw

PATCH 1/1 ALSA: dice: fix buffer overflow in detect_stream_formats()

The function detect_stream_formats() reads the stream_count value directly from a FireWire device without validating it. This can lead to out-of-bounds writes when a malicious device provides a stream_count value greater than MAX_STREAMS.

Fix by applying the same validation to both TX and RX stream counts in detect_stream_formats().

Fixes 58579c056c1c ("ALSA: dice: use extended protocol to detect available stream formats")
---
 sound/firewire/dice/dice-extension.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/firewire/dice/dice-extension.c +2 -2
index 02f4a8318e38..48bfb3ad93ce 100644
@@ -116,7 +116,7 @@ static int detect_stream_formats(struct snd_dice *dice, u64 section_addr)
 			break;
 
 		base_offset += EXT_APP_STREAM_ENTRIES;
-		stream_count = be32_to_cpu(reg[0]);
+		stream_count = min_t(unsigned int, be32_to_cpu(reg[0]), MAX_STREAMS);
 		err = read_stream_entries(dice, section_addr, base_offset,
 					  stream_count, mode,
 					  dice->tx_pcm_chs,
@@ -125,7 +125,7 @@ static int detect_stream_formats(struct snd_dice *dice, u64 section_addr)
 			break;
 
 		base_offset += stream_count * EXT_APP_STREAM_ENTRY_SIZE;
-		stream_count = be32_to_cpu(reg[1]);
+		stream_count = min_t(unsigned int, be32_to_cpu(reg[1]), MAX_STREAMS);
 		err = read_stream_entries(dice, section_addr, base_offset,
 					  stream_count,
 					  mode, dice->rx_pcm_chs,

---
base-commit: aa7243aaf1947a0cb54c44337795d6759493fe02
change-id: 20251128-fixes-658c1dc7a517

Best regards,

Signature · 1 line
Junrui Luo <[email protected]>
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 8 lines · Junrui Luo

The function detect_stream_formats() reads the stream_count value directly from a FireWire device without validating it. This can lead to out-of-bounds writes when a malicious device provides a stream_count value greater than MAX_STREAMS.

Fix by applying the same validation to both TX and RX stream counts in detect_stream_formats().

Quoted 8 lines
Fixes 58579c056c1c ("ALSA: dice: use extended protocol to detect available stream formats")
---
 sound/firewire/dice/dice-extension.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Looks good to me.

Regards

Takashi Sakamoto

#2 lore raw
In reply to Junrui Luo
Quoted 6 lines · Junrui Luo

The function detect_stream_formats() reads the stream_count value directly from a FireWire device without validating it. This can lead to out-of-bounds writes when a malicious device provides a stream_count value greater than MAX_STREAMS.

Quoted 8 lines

Fix by applying the same validation to both TX and RX stream counts in detect_stream_formats().

Fixes 58579c056c1c ("ALSA: dice: use extended protocol to detect available stream formats")

Applied now. Thanks.

Takashi