Skip to contentSkip to conversation

media: s2255: check firmware size before reading trailing marker

PATCH Superseded Lei Huang 1 participant 1 message Jul 14 Media (V4L/DVB)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Lei Huang

author
#0 lore raw

PATCH 1/1 media: s2255: check firmware size before reading trailing marker

From: Lei Huang <[email protected]>

s2255_probe() reads a 4-byte marker and version from the last 8 bytes of the firmware blob (fw->data[fw_size - 8] and [fw_size - 4]). If the firmware file is shorter than 8 bytes, fw_size - 8 underflows and the access reads out of bounds. Validate the firmware size before indexing.

Fixes 14d962602c8b ("V4L/DVB (8752): s2255drv: firmware improvement patch")
---
 drivers/media/usb/s2255/s2255drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/usb/s2255/s2255drv.c +5 -0
index 0b8182edf8e4..3917913c3b47 100644
@@ -2277,6 +2277,11 @@ static int s2255_probe(struct usb_interface *interface,
 	}
 	/* check the firmware is valid */
 	fw_size = dev->fw_data->fw->size;
+	if (fw_size < 8) {
+		dev_err(&interface->dev, "Firmware invalid: too small.\n");
+		retval = -ENODEV;
+		goto errorFWMARKER;
+	}
 	pdata = (__le32 *) &dev->fw_data->fw->data[fw_size - 8];
 
 	if (*pdata != S2255_FW_MARKER) {
Signature · 1 line
2.25.1