[PATCH v2] USB: serial: mxuport: validate firmware header size

Pengpeng Hou posted 1 patch 4 days, 14 hours ago
drivers/usb/serial/mxuport.c | 7 +++++++
1 file changed, 7 insertions(+)
[PATCH v2] USB: serial: mxuport: validate firmware header size
Posted by Pengpeng Hou 4 days, 14 hours ago
mxuport_probe() reads version bytes at fixed offsets after
request_firmware() succeeds. Firmware loading success does not prove that
the blob reaches the highest version offset.

Reject short firmware images before reading the version bytes. This is
source-level parser hardening; no affected device or crash was observed.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
Changes since v1: https://lore.kernel.org/all/20260715084611.45995-1-pengpeng@iscas.ac.cn/
- drop the Fixes tag and stable implication because no regression report is
  known
- carry Andrew Lunn's Reviewed-by
- rebase onto v7.2-rc4

 drivers/usb/serial/mxuport.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/serial/mxuport.c b/drivers/usb/serial/mxuport.c
index e3c5a1b97542..088d5dd8abb5 100644
--- a/drivers/usb/serial/mxuport.c
+++ b/drivers/usb/serial/mxuport.c
@@ -1080,6 +1080,13 @@ static int mxuport_probe(struct usb_serial *serial,
 		/* Use the firmware already in the device */
 		err = 0;
 	} else {
+		if (fw_p->size <= VER_ADDR_3) {
+			dev_err(&serial->interface->dev,
+				"Firmware %s is too short\n", buf);
+			err = -EINVAL;
+			goto out;
+		}
+
 		local_ver = ((fw_p->data[VER_ADDR_1] << 16) |
 			     (fw_p->data[VER_ADDR_2] << 8) |
 			     fw_p->data[VER_ADDR_3]);