* [PATCH v2] usb: typec: ucsi: validate connector number in ucsi_connector_change()
@ 2026-03-12 5:58 Nathan Rebello
2026-03-12 6:02 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Nathan Rebello @ 2026-03-12 5:58 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, heikki.krogerus, kyungtae.kim, stable, Nathan Rebello
ucsi_connector_change() uses the connector number from the CCI as an
index into the connector array without first verifying it falls within
the valid range. The connector number is extracted from the CCI register
via UCSI_CCI_CONNECTOR(), which returns a 7-bit value (0-127), but the
connector array is typically only 2-4 entries.
A malicious or malfunctioning device could report an out-of-range
connector number, causing an out-of-bounds array access.
Add a bounds check in ucsi_connector_change() itself, before the array
dereference, as it is the single function through which all connector
change events flow.
Fixes: bdc62f2bae8f ("usb: typec: ucsi: Simplified registration and I/O API")
Cc: stable@vger.kernel.org
Signed-off-by: Nathan Rebello <nathan.c.rebello@gmail.com>
---
drivers/usb/typec/ucsi/ucsi.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index a7b388dc7fa0..b4f630154aba 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1345,7 +1345,14 @@ static void ucsi_handle_connector_change(struct work_struct *work)
*/
void ucsi_connector_change(struct ucsi *ucsi, u8 num)
{
- struct ucsi_connector *con = &ucsi->connector[num - 1];
+ struct ucsi_connector *con;
+
+ if (num < 1 || num > ucsi->cap.num_connectors) {
+ dev_warn(ucsi->dev, "bogus connector change event: connector %u\n", num);
+ return;
+ }
+
+ con = &ucsi->connector[num - 1];
if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) {
dev_dbg(ucsi->dev, "Early connector change event\n");
--
2.43.0.windows.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: validate connector number in ucsi_connector_change()
2026-03-12 5:58 [PATCH v2] usb: typec: ucsi: validate connector number in ucsi_connector_change() Nathan Rebello
@ 2026-03-12 6:02 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-03-12 6:02 UTC (permalink / raw)
To: Nathan Rebello; +Cc: linux-usb, heikki.krogerus, kyungtae.kim, stable
On Thu, Mar 12, 2026 at 01:58:15AM -0400, Nathan Rebello wrote:
> ucsi_connector_change() uses the connector number from the CCI as an
> index into the connector array without first verifying it falls within
> the valid range. The connector number is extracted from the CCI register
> via UCSI_CCI_CONNECTOR(), which returns a 7-bit value (0-127), but the
> connector array is typically only 2-4 entries.
>
> A malicious or malfunctioning device could report an out-of-range
> connector number, causing an out-of-bounds array access.
>
> Add a bounds check in ucsi_connector_change() itself, before the array
> dereference, as it is the single function through which all connector
> change events flow.
>
> Fixes: bdc62f2bae8f ("usb: typec: ucsi: Simplified registration and I/O API")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nathan Rebello <nathan.c.rebello@gmail.com>
> ---
> drivers/usb/typec/ucsi/ucsi.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index a7b388dc7fa0..b4f630154aba 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1345,7 +1345,14 @@ static void ucsi_handle_connector_change(struct work_struct *work)
> */
> void ucsi_connector_change(struct ucsi *ucsi, u8 num)
> {
> - struct ucsi_connector *con = &ucsi->connector[num - 1];
> + struct ucsi_connector *con;
> +
> + if (num < 1 || num > ucsi->cap.num_connectors) {
> + dev_warn(ucsi->dev, "bogus connector change event: connector %u\n", num);
> + return;
> + }
> +
> + con = &ucsi->connector[num - 1];
>
> if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) {
> dev_dbg(ucsi->dev, "Early connector change event\n");
> --
> 2.43.0.windows.1
>
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- This looks like a new version of a previously submitted patch, but you
did not list below the --- line any changes from the previous version.
Please read the section entitled "The canonical patch format" in the
kernel file, Documentation/process/submitting-patches.rst for what
needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-12 6:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 5:58 [PATCH v2] usb: typec: ucsi: validate connector number in ucsi_connector_change() Nathan Rebello
2026-03-12 6:02 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox