usb: typec: ucsi: displayport: Fix OOB altmode array index
Subsystems (3)
PATCH v2 1/1 usb: typec: ucsi: displayport: Fix OOB altmode array index
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.
---
Changes in v2:
- removed 0xff alt mode assignement when GET_CURRENT_CAM returns an error.
- return -EINVAL when alt mode index above UCSI_MAX_ALTMODES is returned.
drivers/usb/typec/ucsi/displayport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/typec/ucsi/displayport.c +5 -2
@@ -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; }
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
Signature · 1 line
2.55.0.979.g7e5102b832-goog
Quoted 6 lines · Jameson Thies
The UCSI displayport driver indexes the connector's port altmode array with the
GET_CURRENT_CAMresponse after checking it is not0xff. The port altmode array isUCSI_MAX_ALTMODESelements long. If the PPM returns an invalidGET_CURRENT_CAMresponse aboveUCSI_MAX_ALTMODESand not equal to0xff, the kernel may crash with an array index OOB error.
Quoted 6 lines
Update the UCSI displayport driver to verify the current cam is less than
UCSI_MAX_ALTMODESbefore accessing the port altmode array.Fixes af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")Signed-off-by Jameson Thies <[email protected]>
Quoted 34 lines
---
Changes in v2:
- removed0xffalt mode assignement whenGET_CURRENT_CAMreturns an error.
- return-EINVALwhen alt mode index aboveUCSI_MAX_ALTMODESis returned.drivers/usb/typec/ucsi/displayport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/typec/ucsi/displayport.c +5
-2@@ -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; }base-commit:
cee9395acd8043be0644b25c34bfa86623f2b935Signature · 1 line
2.55.0.979.g7e5102b832-goog
Quoted 7 lines · Jameson Thies
The UCSI displayport driver indexes the connector's port altmode array with the
GET_CURRENT_CAMresponse after checking it is not0xff. The port altmode array isUCSI_MAX_ALTMODESelements long. If the PPM returns an invalidGET_CURRENT_CAMresponse aboveUCSI_MAX_ALTMODESand not equal to0xff, the kernel may crash with an array index OOB error.
Quoted 6 lines
Update the UCSI displayport driver to verify the current cam is less than
UCSI_MAX_ALTMODESbefore accessing the port altmode array.Fixes af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")Signed-off-by Jameson Thies <[email protected]>
Quoted 34 lines
---
Changes in v2:
- removed0xffalt mode assignement whenGET_CURRENT_CAMreturns an error.
- return-EINVALwhen alt mode index aboveUCSI_MAX_ALTMODESis returned.drivers/usb/typec/ucsi/displayport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/typec/ucsi/displayport.c +5
-2@@ -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; }base-commit:
cee9395acd8043be0644b25c34bfa86623f2b935--
2.55.0.979.g7e5102b832-goog
Quoted 6 lines · Jameson Thies
The UCSI displayport driver indexes the connector's port altmode array with the
GET_CURRENT_CAMresponse after checking it is not0xff. The port altmode array isUCSI_MAX_ALTMODESelements long. If the PPM returns an invalidGET_CURRENT_CAMresponse aboveUCSI_MAX_ALTMODESand not equal to0xff, the kernel may crash with an array index OOB error.
Quoted 6 lines
Update the UCSI displayport driver to verify the current cam is less than
UCSI_MAX_ALTMODESbefore accessing the port altmode array.Fixes af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")Signed-off-by Jameson Thies <[email protected]>
Quoted 33 lines
---
Changes in v2:
- removed0xffalt mode assignement whenGET_CURRENT_CAMreturns an error.
- return-EINVALwhen alt mode index aboveUCSI_MAX_ALTMODESis returned.drivers/usb/typec/ucsi/displayport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/typec/ucsi/displayport.c +5
-2@@ -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; }base-commit:
cee9395acd8043be0644b25c34bfa86623f2b935Signature · 1 line
2.55.0.979.g7e5102b832-goog
Signature · 1 line
heikki
Greg KH
maintainerQuoted 9 lines · Jameson Thies
The UCSI displayport driver indexes the connector's port altmode array with the
GET_CURRENT_CAMresponse after checking it is not0xff. The port altmode array isUCSI_MAX_ALTMODESelements long. If the PPM returns an invalidGET_CURRENT_CAMresponse aboveUCSI_MAX_ALTMODESand not equal to0xff, 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_ALTMODESbefore accessing the port altmode array.
Quoted 7 lines
Fixes af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")Signed-off-by Jameson Thies <[email protected]>---
Changes in v2:
- removed0xffalt mode assignement whenGET_CURRENT_CAMreturns an error.
- return-EINVALwhen alt mode index aboveUCSI_MAX_ALTMODESis returned.
Does not apply against 7.3-rc2 :(
Hi Greg.
Quoted 1 line
Does not apply against 7.3-rc2 :(
7.3-rc2 and usb-next include the v1 version of this patch which fixes the OOB issue but doesn't incorporate Heikki's or Andrei's feedback. I'll send a quick series to revert the existing change and followup with the v2 version.
- Jameson
Greg KH
maintainerQuoted 8 lines · Jameson Thies
Hi Greg.
Quoted 1 line
Does not apply against 7.3-rc2 :(
7.3-rc2 and usb-next include the v1 version of this patch which fixes the OOB issue but doesn't incorporate Heikki's or Andrei's feedback. I'll send a quick series to revert the existing change and followup with the v2 version.
Why not just a fixup patch instead?
Quoted 1 line · Greg KH
Why not just a fixup patch instead?
Sorry, wasn't aware this was an option. I'll send a fixup patch to address this.