Skip to content

Commit 58fc127

Browse files
maoyixietiwai
authored andcommitted
ALSA: caiaq: bound the length in the EP1 input parsers
snd_caiaq_input_read_erp() and snd_caiaq_input_read_io() can be reached from snd_usb_caiaq_input_dispatch(). They read fixed byte offsets from the reply buffer without checking the reported length. On a short reply they decode stale bytes left from a previous, longer report and feed them to the input layer. This is not an out-of-bounds access. Every offset is a compile-time driver constant. The largest is buf[21] in the Maschine ERP case. The EP1 transfer buffer ep1_in_buf is EP1_BUFSIZE (64) bytes, and the USB core caps actual_length at 64, so a short reply only reads in-bounds stale data. Acting on data the device did not send is still wrong, so bail out per usb_id case when the reply is shorter than the bytes that case consumes. read_erp: AK1 needs 2 bytes, Kore needs 16, Maschine needs 22. read_io: the Kore case needs 5 bytes (buf[4]) and the Traktor Kontrol X1 case needs 7 (buf[5]/buf[6]). The preceding key bit loop is already bounded by "i < len * 8" and is left untouched. snd_caiaq_input_read_analog() and snd_usb_caiaq_maschine_dispatch() are not changed. Their callers already floor the reply length. Suggested-by: Takashi Iwai <tiwai@suse.com> Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com> Link: https://patch.msgid.link/178176259547.3343534.6659489917322808916@maoyixie.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent f7f3f9f commit 58fc127

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

sound/usb/caiaq/input.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,16 @@ static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *cdev,
237237

238238
switch (cdev->chip.usb_id) {
239239
case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
240+
if (len < 2)
241+
return;
240242
i = decode_erp(buf[0], buf[1]);
241243
input_report_abs(input_dev, ABS_X, i);
242244
input_sync(input_dev);
243245
break;
244246
case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
245247
case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
248+
if (len < 16)
249+
return;
246250
i = decode_erp(buf[7], buf[5]);
247251
input_report_abs(input_dev, ABS_HAT0X, i);
248252
i = decode_erp(buf[12], buf[14]);
@@ -263,6 +267,8 @@ static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *cdev,
263267
break;
264268

265269
case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
270+
if (len < 22)
271+
return;
266272
/* 4 under the left screen */
267273
input_report_abs(input_dev, ABS_HAT0X, decode_erp(buf[21], buf[20]));
268274
input_report_abs(input_dev, ABS_HAT0Y, decode_erp(buf[15], buf[14]));
@@ -308,9 +314,13 @@ static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *cdev,
308314
switch (cdev->chip.usb_id) {
309315
case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
310316
case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
317+
if (len < 5)
318+
return;
311319
input_report_abs(cdev->input_dev, ABS_MISC, 255 - buf[4]);
312320
break;
313321
case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
322+
if (len < 7)
323+
return;
314324
/* rotary encoders */
315325
input_report_abs(cdev->input_dev, ABS_X, buf[5] & 0xf);
316326
input_report_abs(cdev->input_dev, ABS_Y, buf[5] >> 4);

0 commit comments

Comments
 (0)