[PATCH v1 2/2] usb: typec: ucsi: displayport: Check CAM to fix OOB altmode array index
From: Jameson Thies
Date: Thu Sep 10 2026 - 19:37:09 EST
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. If the
current CAM is greater than UCSI_MAX_ALTMODES and not 0xff, return an
invalid error from ucsi_displayport_enter().
Reviewed-by: Benson Leung <bleung@xxxxxxxxxxxx>
Reviewed-by: Andrei Kuchynski <akuchynski@xxxxxxxxxxxx>
Reviewed-by: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
Signed-off-by: Jameson Thies <jthies@xxxxxxxxxx>
---
drivers/usb/typec/ucsi/displayport.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/displayport.c
index 7067f2561b84..572da7bbd29c 100644
--- a/drivers/usb/typec/ucsi/displayport.c
+++ b/drivers/usb/typec/ucsi/displayport.c
@@ -71,11 +71,14 @@ static int ucsi_displayport_enter(struct typec_altmode *alt, u32 *vdo)
if (ret < 0) {
if (ucsi->version > 0x0100)
goto err_unlock;
- cur = 0xff;
}
if (cur != 0xff) {
- ret = dp->con->port_altmode[cur] == alt ? 0 : -EBUSY;
+ if (cur < UCSI_MAX_ALTMODES)
+ ret = dp->con->port_altmode[cur] == alt ? 0 : -EBUSY;
+ else
+ ret = -EINVAL;
+
goto err_unlock;
}
--
2.55.0.1007.g17ff1f9808-goog