From: Ju Nan <junan76@163.com>
To: Neill Kapron <nkapron@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Ju Nan <junan76@163.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: gadget: serial: reject port counts exceeding the array size
Date: Wed, 18 Nov 2026 17:38:40 +0800 [thread overview]
Message-ID: <20261118093838.87616-3-junan76@163.com> (raw)
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
next reply other threads:[~2026-11-18 9:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:38 Ju Nan [this message]
2026-11-18 9:53 ` [PATCH] usb: gadget: serial: reject port counts exceeding the array size sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118093838.87616-3-junan76@163.com \
--to=junan76@163.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox