Skip to contentSkip to conversation

usb: gadget: serial: reject port counts exceeding the array size

PATCH New Ju Nan 2 participants 2 messages Nov 18 USB

lore
Share & tools
lore

Ju Nan

author
#0 lore raw

PATCH 1/1 usb: gadget: serial: reject port counts exceeding the array size

The n_ports module parameter has no upper bound check, while fi_serial and f_serial each contain only MAX_U_SERIAL_PORTS entries.

Reject n_ports values greater than MAX_U_SERIAL_PORTS in gserial_init(), before registering the composite driver.

---
 drivers/usb/gadget/legacy/serial.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/gadget/legacy/serial.c +3 -0
index 4974bee6049a..20e89f052952 100644
@@ -286,6 +286,9 @@ static int switch_gserial_enable(bool do_enable)
 
 static int __init gserial_init(void)
 {
+	if (n_ports > MAX_U_SERIAL_PORTS)
+		return -EINVAL;
+
 	/* We *could* export two configs; that'd be much cleaner...
 	 * but neither of these product IDs was defined that way.
 	 */
Signature · 1 line
2.56.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

The n_ports module parameter has no upper bound check, while fi_serial and f_serial each contain only MAX_U_SERIAL_PORTS entries.

Reject n_ports values greater than MAX_U_SERIAL_PORTS in gserial_init(), before registering the composite driver.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1