* [PATCH] usb: gadget: serial: reject port counts exceeding the array size
@ 2026-11-18 9:38 Ju Nan
0 siblings, 0 replies; only message 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 [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 9:45 UTC | newest]
Thread overview: (only message) (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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®