Commit 210d77cc authored by Junrui Luo's avatar Junrui Luo Committed by Takashi Iwai
Browse files

ALSA: firewire-motu: fix buffer overflow in hwdep read for DSP events



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: default avatarYuhao Jiang <danisjiang@gmail.com>
Reported-by: default avatarJunrui Luo <moonafterrain@outlook.com>
Fixes: 634ec0b2 ("ALSA: firewire-motu: notify event for parameter change in register DSP model")
Signed-off-by: default avatarJunrui Luo <moonafterrain@outlook.com>
Link: https://patch.msgid.link/SYBPR01MB78810656377E79E58350D951AFD9A@SYBPR01MB7881.ausprd01.prod.outlook.com


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c34b04cc
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -83,10 +83,11 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
		event.motu_register_dsp_change.type = SNDRV_FIREWIRE_EVENT_MOTU_REGISTER_DSP_CHANGE;
		event.motu_register_dsp_change.count =
			(consumed - sizeof(event.motu_register_dsp_change)) / 4;
		if (copy_to_user(buf, &event, sizeof(event.motu_register_dsp_change)))
		if (copy_to_user(buf, &event,
				 min_t(long, count, sizeof(event.motu_register_dsp_change))))
			return -EFAULT;

		count = consumed;
		count = min_t(long, count, consumed);
	} else {
		spin_unlock_irq(&motu->lock);