Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: serial: reject port counts exceeding the array size
@ 2026-11-18  9:38 Ju Nan
  2026-11-18  9:53 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ju Nan @ 2026-11-18  9:38 UTC (permalink / raw)
  To: Neill Kapron, Greg Kroah-Hartman, Ju Nan; +Cc: linux-usb, linux-kernel

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.

Signed-off-by: Ju Nan <junan76@163.com>
---
 drivers/usb/gadget/legacy/serial.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/legacy/serial.c b/drivers/usb/gadget/legacy/serial.c
index 4974bee6049a..20e89f052952 100644
--- a/drivers/usb/gadget/legacy/serial.c
+++ b/drivers/usb/gadget/legacy/serial.c
@@ -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.
 	 */
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18  9:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18  9:38 [PATCH] usb: gadget: serial: reject port counts exceeding the array size Ju Nan
2026-11-18  9:53 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox