Skip to content

Commit c0a1fe1

Browse files
avasummergregkh
authored andcommitted
ALSA: dice: fix buffer overflow in detect_stream_formats()
commit 324f3e0 upstream. 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(). Reported-by: Yuhao Jiang <danisjiang@gmail.com> Reported-by: Junrui Luo <moonafterrain@outlook.com> Fixes: 58579c0 ("ALSA: dice: use extended protocol to detect available stream formats") Cc: stable@vger.kernel.org Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Junrui Luo <moonafterrain@outlook.com> Link: https://patch.msgid.link/SYBPR01MB7881B043FC68B4C0DA40B73DAFDCA@SYBPR01MB7881.ausprd01.prod.outlook.com Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8404a1b commit c0a1fe1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sound/firewire/dice/dice-extension.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int detect_stream_formats(struct snd_dice *dice, u64 section_addr)
116116
break;
117117

118118
base_offset += EXT_APP_STREAM_ENTRIES;
119-
stream_count = be32_to_cpu(reg[0]);
119+
stream_count = min_t(unsigned int, be32_to_cpu(reg[0]), MAX_STREAMS);
120120
err = read_stream_entries(dice, section_addr, base_offset,
121121
stream_count, mode,
122122
dice->tx_pcm_chs,
@@ -125,7 +125,7 @@ static int detect_stream_formats(struct snd_dice *dice, u64 section_addr)
125125
break;
126126

127127
base_offset += stream_count * EXT_APP_STREAM_ENTRY_SIZE;
128-
stream_count = be32_to_cpu(reg[1]);
128+
stream_count = min_t(unsigned int, be32_to_cpu(reg[1]), MAX_STREAMS);
129129
err = read_stream_entries(dice, section_addr, base_offset,
130130
stream_count,
131131
mode, dice->rx_pcm_chs,

0 commit comments

Comments
 (0)