* [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index
@ 2026-08-25 23:45 Jameson Thies
2026-08-26 21:03 ` Benson Leung
2026-08-31 10:37 ` Heikki Krogerus
0 siblings, 2 replies; 5+ messages in thread
From: Jameson Thies @ 2026-08-25 23:45 UTC (permalink / raw)
To: heikki.krogerus, linux-usb, linux-kernel
Cc: bleung, gregkh, akuchynski, Jameson Thies, stable
The UCSI displayport driver indexes the connector's port altmode array
with the GET_CURRENT_CAM response after checking it is not 0xff. The
port altmode array is UCSI_MAX_ALTMODES elements long. If the PPM
returns an invalid GET_CURRENT_CAM response above UCSI_MAX_ALTMODES and
not equal to 0xff, the kernel may crash with an array index OOB error.
Update the UCSI displayport driver to verify the current cam is less
than UCSI_MAX_ALTMODES before accessing the port altmode array.
Fixes: af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")
Cc: stable@vger.kernel.org
Signed-off-by: Jameson Thies <jthies@google.com>
---
drivers/usb/typec/ucsi/displayport.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c
index 7067f2561b84..8d2032d0762c 100644
--- a/drivers/usb/typec/ucsi/displayport.c
+++ b/drivers/usb/typec/ucsi/displayport.c
@@ -74,7 +74,7 @@ static int ucsi_displayport_enter(struct typec_altmode *alt, u32 *vdo)
cur = 0xff;
}
- if (cur != 0xff) {
+ if (cur < UCSI_MAX_ALTMODES) {
ret = dp->con->port_altmode[cur] == alt ? 0 : -EBUSY;
goto err_unlock;
}
base-commit: e1e6e541c5c9cf548e9fdc35fc26808c82074440
--
2.55.0.860.g4b6b3295ed-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index
2026-08-25 23:45 [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index Jameson Thies
@ 2026-08-26 21:03 ` Benson Leung
2026-08-31 10:37 ` Heikki Krogerus
1 sibling, 0 replies; 5+ messages in thread
From: Benson Leung @ 2026-08-26 21:03 UTC (permalink / raw)
To: Jameson Thies
Cc: heikki.krogerus, linux-usb, linux-kernel, bleung, gregkh,
akuchynski, stable
[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]
On Tue, Aug 25, 2026 at 11:45:45PM +0000, Jameson Thies wrote:
> The UCSI displayport driver indexes the connector's port altmode array
> with the GET_CURRENT_CAM response after checking it is not 0xff. The
> port altmode array is UCSI_MAX_ALTMODES elements long. If the PPM
> returns an invalid GET_CURRENT_CAM response above UCSI_MAX_ALTMODES and
> not equal to 0xff, the kernel may crash with an array index OOB error.
>
> Update the UCSI displayport driver to verify the current cam is less
> than UCSI_MAX_ALTMODES before accessing the port altmode array.
>
> Fixes: af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jameson Thies <jthies@google.com>
Reviewed-by: Benson Leung <bleung@chromium.org>
> ---
> drivers/usb/typec/ucsi/displayport.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c
> index 7067f2561b84..8d2032d0762c 100644
> --- a/drivers/usb/typec/ucsi/displayport.c
> +++ b/drivers/usb/typec/ucsi/displayport.c
> @@ -74,7 +74,7 @@ static int ucsi_displayport_enter(struct typec_altmode *alt, u32 *vdo)
> cur = 0xff;
> }
>
> - if (cur != 0xff) {
> + if (cur < UCSI_MAX_ALTMODES) {
> ret = dp->con->port_altmode[cur] == alt ? 0 : -EBUSY;
> goto err_unlock;
> }
>
> base-commit: e1e6e541c5c9cf548e9fdc35fc26808c82074440
> --
> 2.55.0.860.g4b6b3295ed-goog
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index
2026-08-25 23:45 [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index Jameson Thies
2026-08-26 21:03 ` Benson Leung
@ 2026-08-31 10:37 ` Heikki Krogerus
2026-08-31 11:35 ` Andrei Kuchynski
1 sibling, 1 reply; 5+ messages in thread
From: Heikki Krogerus @ 2026-08-31 10:37 UTC (permalink / raw)
To: Jameson Thies; +Cc: linux-usb, linux-kernel, bleung, gregkh, akuchynski, stable
On Tue, Aug 25, 2026 at 11:45:45PM +0000, Jameson Thies wrote:
> The UCSI displayport driver indexes the connector's port altmode array
> with the GET_CURRENT_CAM response after checking it is not 0xff. The
> port altmode array is UCSI_MAX_ALTMODES elements long. If the PPM
> returns an invalid GET_CURRENT_CAM response above UCSI_MAX_ALTMODES and
> not equal to 0xff, the kernel may crash with an array index OOB error.
>
> Update the UCSI displayport driver to verify the current cam is less
> than UCSI_MAX_ALTMODES before accessing the port altmode array.
>
> Fixes: af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jameson Thies <jthies@google.com>
> ---
> drivers/usb/typec/ucsi/displayport.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c
> index 7067f2561b84..8d2032d0762c 100644
> --- a/drivers/usb/typec/ucsi/displayport.c
> +++ b/drivers/usb/typec/ucsi/displayport.c
> @@ -74,7 +74,7 @@ static int ucsi_displayport_enter(struct typec_altmode *alt, u32 *vdo)
> cur = 0xff;
Can you remove the above line while at it?
> }
>
> - if (cur != 0xff) {
> + if (cur < UCSI_MAX_ALTMODES) {
Shouldn't that be the other way around?
> ret = dp->con->port_altmode[cur] == alt ? 0 : -EBUSY;
> goto err_unlock;
> }
Thanks,
--
heikki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index
2026-08-31 10:37 ` Heikki Krogerus
@ 2026-08-31 11:35 ` Andrei Kuchynski
2026-09-02 1:15 ` Jameson Thies
0 siblings, 1 reply; 5+ messages in thread
From: Andrei Kuchynski @ 2026-08-31 11:35 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Jameson Thies, linux-usb, linux-kernel, bleung, gregkh, stable
On Mon, Aug 31, 2026 at 12:37 PM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> On Tue, Aug 25, 2026 at 11:45:45PM +0000, Jameson Thies wrote:
> > The UCSI displayport driver indexes the connector's port altmode array
> > with the GET_CURRENT_CAM response after checking it is not 0xff. The
> > port altmode array is UCSI_MAX_ALTMODES elements long. If the PPM
> > returns an invalid GET_CURRENT_CAM response above UCSI_MAX_ALTMODES and
> > not equal to 0xff, the kernel may crash with an array index OOB error.
> >
> > Update the UCSI displayport driver to verify the current cam is less
> > than UCSI_MAX_ALTMODES before accessing the port altmode array.
> >
> > Fixes: af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Jameson Thies <jthies@google.com>
> > ---
> > drivers/usb/typec/ucsi/displayport.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c
> > index 7067f2561b84..8d2032d0762c 100644
> > --- a/drivers/usb/typec/ucsi/displayport.c
> > +++ b/drivers/usb/typec/ucsi/displayport.c
> > @@ -74,7 +74,7 @@ static int ucsi_displayport_enter(struct typec_altmode *alt, u32 *vdo)
> > cur = 0xff;
>
> Can you remove the above line while at it?
>
> > }
> >
> > - if (cur != 0xff) {
> > + if (cur < UCSI_MAX_ALTMODES) {
>
> Shouldn't that be the other way around?
>
Looks fine, but shouldn't we return an error if an invalid value is
received, similar to the Thunderbolt implementation?
if (cur != 0xff) {
if (cur >= UCSI_MAX_ALTMODES ||
dp->con->port_altmode[cur] != alt)
ret = -EBUSY;
else
ret = 0;
goto err_unlock;
Thanks,
Andrei
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index
2026-08-31 11:35 ` Andrei Kuchynski
@ 2026-09-02 1:15 ` Jameson Thies
0 siblings, 0 replies; 5+ messages in thread
From: Jameson Thies @ 2026-09-02 1:15 UTC (permalink / raw)
To: Andrei Kuchynski
Cc: Heikki Krogerus, linux-usb, linux-kernel, bleung, gregkh, stable
Hi Heikki and Andrei,
thanks for taking a look. I'll follow up with a v2 of this patch to
address your comments. Answers below with some additional comments.
> > Can you remove the above line while at it?
Will remove in v2.
> > Shouldn't that be the other way around?
I'm not sure I understand. Because UCSI_MAX_ALTMODES is set to 30 in
ucsi.h, verifying 'cur' is less than UCSI_MAX_ALTMODES will still
evaluate to false if 'cur' is 0xff. This update maintains the existing
functionality and prevents the driver from using an out of bounds
index.
> Looks fine, but shouldn't we return an error if an invalid value is
> received, similar to the Thunderbolt implementation?
Sounds good to me, but I think we should split up the
UCSI_MAX_ALTMODES check and the port_altmode check. Returning EBUSY
doesn't seem like an appropriate error code if the PPM returns an out
of range option. I think we should return EINVAL here.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-02 1:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-25 23:45 [PATCH v1] usb: typec: ucsi: displayport: Fix OOB altmode array index Jameson Thies
2026-08-26 21:03 ` Benson Leung
2026-08-31 10:37 ` Heikki Krogerus
2026-08-31 11:35 ` Andrei Kuchynski
2026-09-02 1:15 ` Jameson Thies
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®