Skip to content

Commit 1eaed53

Browse files
Dan Carpentergregkh
authored andcommitted
media: gspca: Add bounds checking to firmware parser
commit aef89c0 upstream. This sd_init() function reads the firmware. The firmware data holds a series of records and the function reads each record and sends the data to the device. The request_ihex_firmware() function calls ihex_validate_fw() which ensures that the total length of all the records won't read out of bounds of the fw->data[]. However, a potential issue is if there is a single very large record (larger than PAGE_SIZE) and that would result in memory corruption. Generally we trust the firmware, but it's always better to double check. Fixes: 49b61ec ("[media] gspca: Add new vicam subdriver") Cc: stable@vger.kernel.org Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8f4cb3d commit 1eaed53

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/media/usb/gspca/vicam.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
227227
const struct ihex_binrec *rec;
228228
const struct firmware *fw;
229229
u8 *firmware_buf;
230+
int len;
230231

231232
ret = request_ihex_firmware(&fw, VICAM_FIRMWARE,
232233
&gspca_dev->dev->dev);
@@ -241,9 +242,14 @@ static int sd_init(struct gspca_dev *gspca_dev)
241242
goto exit;
242243
}
243244
for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) {
244-
memcpy(firmware_buf, rec->data, be16_to_cpu(rec->len));
245+
len = be16_to_cpu(rec->len);
246+
if (len > PAGE_SIZE) {
247+
ret = -EINVAL;
248+
break;
249+
}
250+
memcpy(firmware_buf, rec->data, len);
245251
ret = vicam_control_msg(gspca_dev, 0xff, 0, 0, firmware_buf,
246-
be16_to_cpu(rec->len));
252+
len);
247253
if (ret < 0)
248254
break;
249255
}

0 commit comments

Comments
 (0)