Skip to content

Commit cdda0d0

Browse files
avasummergregkh
authored andcommitted
ALSA: firewire-motu: fix buffer overflow in hwdep read for DSP events
[ Upstream commit 210d77c ] The DSP event handling code in hwdep_read() could write more bytes to the user buffer than requested, when a user provides a buffer smaller than the event header size (8 bytes). Fix by using min_t() to clamp the copy size, This ensures we never copy more than the user requested. Reported-by: Yuhao Jiang <danisjiang@gmail.com> Reported-by: Junrui Luo <moonafterrain@outlook.com> Fixes: 634ec0b ("ALSA: firewire-motu: notify event for parameter change in register DSP model") Signed-off-by: Junrui Luo <moonafterrain@outlook.com> Link: https://patch.msgid.link/SYBPR01MB78810656377E79E58350D951AFD9A@SYBPR01MB7881.ausprd01.prod.outlook.com Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8fee481 commit cdda0d0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sound/firewire/motu/motu-hwdep.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
8383
event.motu_register_dsp_change.type = SNDRV_FIREWIRE_EVENT_MOTU_REGISTER_DSP_CHANGE;
8484
event.motu_register_dsp_change.count =
8585
(consumed - sizeof(event.motu_register_dsp_change)) / 4;
86-
if (copy_to_user(buf, &event, sizeof(event.motu_register_dsp_change)))
86+
if (copy_to_user(buf, &event,
87+
min_t(long, count, sizeof(event.motu_register_dsp_change))))
8788
return -EFAULT;
8889

89-
count = consumed;
90+
count = min_t(long, count, consumed);
9091
} else {
9192
spin_unlock_irq(&motu->lock);
9293

0 commit comments

Comments
 (0)