usb: typec: wcove: don't write past struct pd_message in wcove_read_rx_buffer()
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 1/8 usb: typec: wcove: don't write past struct pd_message in wcove_read_rx_buffer()
wcove_read_rx_buffer() copies the PD RX FIFO into the caller's struct pd_message with
for (i = 0; i < USBC_RXINFO_RXBYTES(info); i++) regmap_read(wcove->regmap, USBC_RX_DATA + i, msg + i);
which has two problems:
USBC_RXINFO_RXBYTES() is a 5-bit field (max 31) while struct pd_message is 30 bytes (__le16 header + __le32 payload[PD_MAX_PAYLOAD], packed). The byte count latched in RXINFO is the number of bytes the port partner put on the wire, so a malicious partner that transmits a 31-byte frame can drive the loop one byte past the destination if the WCOVE BMC receiver does not enforce the PD object-count limit in hardware. The existing FIXME flagged this as unverified.
Independently, regmap_read() takes an unsigned int * and stores a full unsigned int at the destination. Passing the byte pointer msg + i means each iteration writes four bytes; the high three are zero (val_bits is
8) and are normally overwritten by the next iteration, but the final iteration's high bytes are not. With RXBYTES == 30 the i == 29 iteration already writes three zero bytes past msg, which sits on the IRQ thread's stack in wcove_typec_irq().
Clamp the loop to sizeof(struct pd_message) and read each register into a local before storing only its low byte, so the copy can never exceed the destination regardless of what RXINFO reports.
--- drivers/usb/typec/tcpm/wcove.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/typec/tcpm/wcove.c +8 -5
@@ -444,9 +444,11 @@ static int wcove_start_toggling(struct tcpc_dev *tcpc,return regmap_write (wcove->regmap,USBC_CONTROL1 , usbc_ctrl); } -static int wcove_read_rx_buffer (struct wcove_typec *wcove,void *msg) +static int wcove_read_rx_buffer (struct wcove_typec *wcove, +struct pd_message *msg) { -unsigned int info; +unsigned int info, val, len; +u8 *buf = (u8 *)msg;int ret;int i;
@@ -454,12 +456,13 @@ static int wcove_read_rx_buffer(struct wcove_typec *wcove, void *msg)if (ret)return ret; -/* FIXME: Check that USBC_RXINFO_RXBYTES(info) matches the header */ + len =min (USBC_RXINFO_RXBYTES (info),sizeof (*msg)); -for (i =0 ; i <USBC_RXINFO_RXBYTES (info); i++) { - ret =regmap_read (wcove->regmap,USBC_RX_DATA + i, msg + i); +for (i =0 ; i < len; i++) { + ret =regmap_read (wcove->regmap,USBC_RX_DATA + i, &val);if (ret)return ret; + buf[i] = val; } return regmap_write(wcove->regmap, USBC_RXSTATUS,
Signature · 1 line
2.54.0
Greg Kroah-Hartman
maintainerPATCH 2/8 usb: typec: altmodes/displayport: validate count before reading Status Update VDO
A broken/malicious device can send the incorrect count for a status update VDO, which will cause the kernel to read uninitialized stack data and send it off elsewhere.
Fix this up by correctly verifying the count for the update object.
--- drivers/usb/typec/altmodes/displayport.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/typec/altmodes/displayport.c +2 -0
@@ -405,6 +405,8 @@ static int dp_altmode_vdm(struct typec_altmode *alt, dp->state =DP_STATE_EXIT_PRIME ;break ;case DP_CMD_STATUS_UPDATE : +if (count <2 ) +break ; dp->data.status = *vdo; ret =dp_altmode_status_update (dp);break ;
Signature · 1 line
2.54.0
Re: [PATCH 2/8] usb: typec: altmodes/displayport: validate count before reading Status Update VDO
Quoted 10 lines · Greg Kroah-Hartman
A broken/malicious device can send the incorrect count for a status update VDO, which will cause the kernel to read uninitialized stack data and send it off elsewhere.
Fix this up by correctly verifying the count for the update object.
Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 19 lines
--- drivers/usb/typec/altmodes/displayport.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/typec/altmodes/displayport.c +2
-0@@ -405,6 +405,8 @@ static int dp_altmode_vdm(struct typec_altmode *alt, dp->state =DP_STATE_EXIT_PRIME ;break ;case DP_CMD_STATUS_UPDATE : +if (count <2 ) +break ; dp->data.status = *vdo; ret =dp_altmode_status_update (dp);break ;Signature · 1 line
2.54.0
Signature · 1 line
heikki
Re: [PATCH 2/8] usb: typec: altmodes/displayport: validate count before reading Status Update VDO
In reply to Greg Kroah-HartmanQuoted 11 lines · Greg Kroah-Hartman
A broken/malicious device can send the incorrect count for a status update VDO, which will cause the kernel to read uninitialized stack data and send it off elsewhere.
Fix this up by correctly verifying the count for the update object.
Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 21 lines
--- drivers/usb/typec/altmodes/displayport.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/typec/altmodes/displayport.c +2
-1@@ -405,6 +405,8 @@ static int dp_altmode_vdm(struct typec_altmode *alt, dp->state =DP_STATE_EXIT_PRIME ;break ;case DP_CMD_STATUS_UPDATE : +if (count <2 ) +break ; dp->data.status = *vdo; ret =dp_altmode_status_update (dp);break ; --2.54.0
Greg Kroah-Hartman
maintainerPATCH 3/8 usb: typec: tcpm/tcpci_maxim: validate header NDO against RX_BYTE_CNT
In reply to Greg Kroah-HartmanA broken/malicious port can transmit a CRC-valid frame whose header advertises up to seven data objects but whose body carries fewer than that. Check for this, and rightfully reject the message, instead of reading from uninitialized stack memory.
--- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/usb/typec/tcpm/tcpci_maxim_core.c +9 -0
@@ -181,6 +181,15 @@ static void process_rx(struct max_tcpci_chip *chip, u16 status) rx_buf_ptr = rx_buf +TCPC_RECEIVE_BUFFER_RX_BYTE_BUF_OFFSET ; msg.header =cpu_to_le16 (*(u16 *)rx_buf_ptr); rx_buf_ptr = rx_buf_ptr +sizeof (msg.header); + +if (count <TCPC_RECEIVE_BUFFER_RX_BYTE_BUF_OFFSET +sizeof (msg.header) + +pd_header_cnt_le (msg.header) *sizeof (msg.payload[0 ])) { +max_tcpci_write16 (chip,TCPC_ALERT ,TCPC_ALERT_RX_STATUS ); +dev_err (chip->dev,"Invalid TCPC_RX_BYTE_CNT %d for header cnt %d\n" , + count,pd_header_cnt_le (msg.header)); +return ; + } +for (payload_index =0 ; payload_index <pd_header_cnt_le (msg.header); payload_index++, rx_buf_ptr +=sizeof (msg.payload[0 ])) msg.payload[payload_index] =cpu_to_le32 (*(u32 *)rx_buf_ptr);
Signature · 1 line
2.54.0
Greg Kroah-Hartman
maintainerPATCH 4/8 usb: typec: tcpm: validate VDO count in Discover Identity ACK handlers
In reply to Greg Kroah-HartmanProperly validate the count passed from a device when calling svdm_consume_identity() or svdm_consume_identity_sop_prime() as the device-controlled value could index off of the static arrays, which could leak data.
--- drivers/usb/typec/tcpm/tcpm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/usb/typec/tcpm/tcpm.c +7 -1
@@ -1855,6 +1855,9 @@ static void svdm_consume_identity(struct tcpm_port *port, const u32 *p, int cnt)u32 vdo = p[VDO_INDEX_IDH ];u32 product = p[VDO_INDEX_PRODUCT ]; +if (cnt <=VDO_INDEX_PRODUCT ) +return ; +memset (&port->mode_data,0 ,sizeof (port->mode_data)); port->partner_ident.id_header = vdo;
@@ -1875,6 +1878,9 @@ static void svdm_consume_identity_sop_prime(struct tcpm_port *port, const u32 *pu32 product = p[VDO_INDEX_PRODUCT ];int svdm_version; +if (cnt <=VDO_INDEX_CABLE_1 ) +return ; +/* * Attempt to consume identity only if cable currently is not set */
@@ -1898,7 +1904,7 @@ static void svdm_consume_identity_sop_prime(struct tcpm_port *port, const u32 *pswitch (port->negotiated_rev_prime) {case PD_REV30 : port->cable_desc.pd_revision =0x0300 ; -if (port->cable_desc.active) +if (port->cable_desc.active && cnt >VDO_INDEX_CABLE_2 ) port->cable_ident.vdo[1 ] = p[VDO_INDEX_CABLE_2 ];break ;case PD_REV20 :
Signature · 1 line
2.54.0
Re: [PATCH 4/8] usb: typec: tcpm: validate VDO count in Discover Identity ACK handlers
Quoted 11 lines · Greg Kroah-Hartman
Properly validate the count passed from a device when calling
svdm_consume_identity()orsvdm_consume_identity_sop_prime()as the device-controlled value could index off of the static arrays, which could leak data.Assisted-by gkh_clanker_t1000Cc Badhri Jagan Sridharan <[email protected]>Cc Heikki Krogerus <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 40 lines
--- drivers/usb/typec/tcpm/tcpm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/usb/typec/tcpm/tcpm.c +7
-2@@ -1855,6 +1855,9 @@ static void svdm_consume_identity(struct tcpm_port *port, const u32 *p, int cnt)u32 vdo = p[VDO_INDEX_IDH ];u32 product = p[VDO_INDEX_PRODUCT ]; +if (cnt <=VDO_INDEX_PRODUCT ) +return ; +memset (&port->mode_data,0 ,sizeof (port->mode_data)); port->partner_ident.id_header = vdo;@@ -1875,6 +1878,9 @@ static void svdm_consume_identity_sop_prime(struct tcpm_port *port, const u32 *pu32 product = p[VDO_INDEX_PRODUCT ];int svdm_version; +if (cnt <=VDO_INDEX_CABLE_1 ) +return ; +/* * Attempt to consume identity only if cable currently is not set */ @@ -1898,7 +1904,7 @@ static void svdm_consume_identity_sop_prime(struct tcpm_port *port, const u32 *pswitch (port->negotiated_rev_prime) {case PD_REV30 : port->cable_desc.pd_revision =0x0300 ; -if (port->cable_desc.active) +if (port->cable_desc.active && cnt >VDO_INDEX_CABLE_2 ) port->cable_ident.vdo[1 ] = p[VDO_INDEX_CABLE_2 ];break ;case PD_REV20 : --2.54.0
Greg Kroah-Hartman
maintainerPATCH 5/8 usb: typec: tcpm: validate VDO count before reading Attention status VDO
In reply to Greg Kroah-HartmanA broken/malicious device can send the incorrect count for an attention status VDO, which will cause the kernel to read uninitialized stack data and send it off elsewhere.
Fix this up by correctly verifying the count for the attention object.
--- drivers/usb/typec/tcpm/tcpm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +2 -0
@@ -2639,6 +2639,8 @@ static void tcpm_handle_vdm_request(struct tcpm_port *port, }break ;case ADEV_ATTENTION : +if (cnt <2 ) +break ;if (typec_altmode_attention (adev, p[1 ]))tcpm_log (port,"typec_altmode_attention no port partner altmode" );break ;
Signature · 1 line
2.54.0
Badhri Jagan Sridharan
maintainerRe: [PATCH 5/8] usb: typec: tcpm: validate VDO count before reading Attention status VDO
Quoted 21 lines · Greg Kroah-Hartman
A broken/malicious device can send the incorrect count for an attention status VDO, which will cause the kernel to read uninitialized stack data and send it off elsewhere.
Fix this up by correctly verifying the count for the attention object.
Assisted-by gkh_clanker_t1000Cc Badhri Jagan Sridharan <[email protected]>Cc Heikki Krogerus <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/typec/tcpm/tcpm.c +0
-0
drivers/usb/typec/tcpm/tcpm.c static void tcpm_handle_vdm_request(struct tcpm_port *port,
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +2
-1@@ -2639,6 +2639,8 @@ static void tcpm_handle_vdm_request(struct tcpm_port *port, }break ;case ADEV_ATTENTION : +if (cnt <2 ) +break ;if (typec_altmode_attention (adev, p[1 ]))tcpm_log (port,"typec_altmode_attention no port partner altmode" );break ; --
Hi Greg,
While the cnt check helps fix this specific case, I do see multiple other instances in the same function where the validity of p[0] and p[1] seems to be assumed (for instance calls to typec_altmode_vdm(adev, p[0], &p[1], cnt)). To make the patch more complete and robust, shouldn't p also be initialized to 0? This will prevent leaking uninitialized stack data in those instances too.
Quoted 2 lines
2.54.0
Greg Kroah-Hartman
maintainerRe: [PATCH 5/8] usb: typec: tcpm: validate VDO count before reading Attention status VDO
Quoted 35 lines · Badhri Jagan Sridharan
Quoted 21 lines · Greg Kroah-Hartman
A broken/malicious device can send the incorrect count for an attention status VDO, which will cause the kernel to read uninitialized stack data and send it off elsewhere.
Fix this up by correctly verifying the count for the attention object.
Assisted-by gkh_clanker_t1000Cc Badhri Jagan Sridharan <[email protected]>Cc Heikki Krogerus <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/typec/tcpm/tcpm.c +0
-0drivers/usb/typec/tcpm/tcpm.c static void tcpm_handle_vdm_request(struct tcpm_port *port,
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +2
-1@@ -2639,6 +2639,8 @@ static void tcpm_handle_vdm_request(struct tcpm_port *port, }break ;case ADEV_ATTENTION : +if (cnt <2 ) +break ;if (typec_altmode_attention (adev, p[1 ]))tcpm_log (port,"typec_altmode_attention no port partner altmode" );break ; --Hi Greg,
Quoted 6 lines
While the
cntcheck helps fix this specific case, I do see multiple other instances in the same function where the validity of p[0] and p[1] seems to be assumed (for instance calls totypec_altmode_vdm(adev, p[0], &p[1], cnt)). To make the patch more complete and robust, shouldn't p also be initialized to 0? This will prevent leaking uninitialized stack data in those instances too.
Good point, we should be checking this for all of these, not just this one instance. I'll fix this up and do a new version, thanks.
greg k-h
Greg Kroah-Hartman
maintainerPATCH 6/8 usb: typec: tcpm: bound altmode_desc[] per iteration in svdm_consume_modes()
In reply to Greg Kroah-Hartmansvdm_consume_modes() checks pmdata->altmodes against the array size once before the loop over the count, but forgot to check the bound at every point in the loop.
In the well-behaved SVDM discovery flow this is harmless because each of at most SVID_DISCOVERY_MAX SVIDs contributes at most MODE_DISCOVERY_MAX modes, exactly filling altmode_desc[ALTMODE_DISCOVERY_MAX]. But the CMDT_RSP_ACK handler in tcpm_pd_svdm() does not correlate an incoming ACK with any request the port actually sent. Once port->partner is set, an unsolicited Discover Modes ACK is consumed unconditionally. A broken or malicious port partner can therefore drive altmodes to ALTMODE_DISCOVERY_MAX - 1 via the normal flow, and then send one extra Discover Modes ACK with seven VDOs. Because the pre-loop check passes, the loop could then writes up to five entries past altmode_desc[]. For mode_data_prime the next field in struct tcpm_port is the partner_altmode[] pointer array, which then receives partner-chosen SVID/VDO bytes.
Move the bound check inside the loop so the array can never be indexed past ALTMODE_DISCOVERY_MAX regardless of how many VDOs the partner supplies or how the function was reached.
--- drivers/usb/typec/tcpm/tcpm.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +4 -8
@@ -1992,23 +1992,19 @@ static void svdm_consume_modes(struct tcpm_port *port, const u32 *p, int cnt,switch (rx_sop_type) {case TCPC_TX_SOP_PRIME : pmdata = &port->mode_data_prime; -if (pmdata->altmodes >=ARRAY_SIZE (port->plug_prime_altmode)) { -/* Already logged in svdm_consume_svids() */ -return ; - }break ;case TCPC_TX_SOP : pmdata = &port->mode_data; -if (pmdata->altmodes >=ARRAY_SIZE (port->partner_altmode)) { -/* Already logged in svdm_consume_svids() */ -return ; - }break ;default :return ; }for (i =1 ; i < cnt; i++) { +if (pmdata->altmodes >=ALTMODE_DISCOVERY_MAX ) { +/* Already logged in svdm_consume_svids() */ +return ; + } paltmode = &pmdata->altmode_desc[pmdata->altmodes];memset (paltmode,0 ,sizeof (*paltmode));
Signature · 1 line
2.54.0
Greg Kroah-Hartman
maintainerPATCH 7/8 usb: typec: ucsi: displayport: NAK DP_CMD_CONFIGURE without a payload VDO
In reply to Greg Kroah-Hartmanucsi_displayport_vdm() handles a DP_CMD_CONFIGURE by copying the first payload VDO from data[], but unlike the equivalent handler in altmodes/displayport.c it does not check that count covers a VDO beyond the header. A header-only Configure VDM (count == 1) would read one u32 past the caller's array.
In the normal UCSI path the caller controls count, so this is hardening for non-standard delivery paths. NAK and bail when no configuration VDO is present, matching the generic DP altmode driver's existing guard.
--- drivers/usb/typec/ucsi/displayport.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/typec/ucsi/displayport.c +4 -0
@@ -240,6 +240,10 @@ static int ucsi_displayport_vdm(struct typec_altmode *alt, dp->header |=VDO_CMDT (CMDT_RSP_ACK );break ;case DP_CMD_CONFIGURE : +if (count <2 ) { + dp->header |=VDO_CMDT (CMDT_RSP_NAK ); +break ; + } dp->data.conf = *data;if (ucsi_displayport_configure (dp)) { dp->header |=VDO_CMDT (CMDT_RSP_NAK );
Signature · 1 line
2.54.0
Re: [PATCH 7/8] usb: typec: ucsi: displayport: NAK DP_CMD_CONFIGURE without a payload VDO
Wed, May 13, 2026 at 05:52:54PM +0200, Greg Kroah-Hartman kirjoitti:
Quoted 10 lines
ucsi_displayport_vdm()handles aDP_CMD_CONFIGUREby copying the first payload VDO from data[], but unlike the equivalent handler inaltmodes/displayport.cit does not check that count covers a VDO beyond the header. A header-only Configure VDM (count == 1) would read one u32 past the caller's array.In the normal UCSI path the caller controls count, so this is hardening for non-standard delivery paths. NAK and bail when no configuration VDO is present, matching the generic DP altmode driver's existing guard.
Quoted 6 lines
Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc Pooja Katiyar <[email protected]>Cc Johan Hovold <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 21 lines
--- drivers/usb/typec/ucsi/displayport.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/typec/ucsi/displayport.c +4
-0@@ -240,6 +240,10 @@ static int ucsi_displayport_vdm(struct typec_altmode *alt, dp->header |=VDO_CMDT (CMDT_RSP_ACK );break ;case DP_CMD_CONFIGURE : +if (count <2 ) { + dp->header |=VDO_CMDT (CMDT_RSP_NAK ); +break ; + } dp->data.conf = *data;if (ucsi_displayport_configure (dp)) { dp->header |=VDO_CMDT (CMDT_RSP_NAK );Signature · 1 line
2.54.0
Signature · 1 line
heikki
Re: [PATCH 7/8] usb: typec: ucsi: displayport: NAK DP_CMD_CONFIGURE without a payload VDO
In reply to Greg Kroah-HartmanQuoted 11 lines · Greg Kroah-Hartman
ucsi_displayport_vdm()handles aDP_CMD_CONFIGUREby copying the first payload VDO from data[], but unlike the equivalent handler inaltmodes/displayport.cit does not check that count covers a VDO beyond the header. A header-only Configure VDM (count == 1) would read one u32 past the caller's array.In the normal UCSI path the caller controls count, so this is hardening for non-standard delivery paths. NAK and bail when no configuration VDO is present, matching the generic DP altmode driver's existing guard.
Quoted 6 lines
Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc Pooja Katiyar <[email protected]>Cc Johan Hovold <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 23 lines
--- drivers/usb/typec/ucsi/displayport.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/typec/ucsi/displayport.c +4
-1@@ -240,6 +240,10 @@ static int ucsi_displayport_vdm(struct typec_altmode *alt, dp->header |=VDO_CMDT (CMDT_RSP_ACK );break ;case DP_CMD_CONFIGURE : +if (count <2 ) { + dp->header |=VDO_CMDT (CMDT_RSP_NAK ); +break ; + } dp->data.conf = *data;if (ucsi_displayport_configure (dp)) { dp->header |=VDO_CMDT (CMDT_RSP_NAK ); --2.54.0
Greg Kroah-Hartman
maintainerPATCH 8/8 usb: typec: ucsi: validate connector number in ucsi_connector_change()
In reply to Greg Kroah-HartmanThe connector number in a UCSI CCI notification is a 7-bit field supplied by the PPM. ucsi_connector_change() uses it to index the ucsi->connector[] array without checking it against the number of connectors the PPM reported at init time, so a buggy or malicious PPM (EC firmware, or an I2C-attached UCSI controller on the ccg / stm32g0 / glink transports) can drive schedule_work() on memory past the end of the array.
Reject connector numbers that are zero or exceed cap.num_connectors before dereferencing the array.
--- drivers/usb/typec/ucsi/ucsi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/usb/typec/ucsi/ucsi.c +10 -1
@@ -1380,13 +1380,22 @@ 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 (!(ucsi->ntfy &UCSI_ENABLE_NTFY_CONNECTOR_CHANGE )) {dev_dbg (ucsi->dev,"Early connector change event\n" );return ; } +if (!num || num > ucsi->cap.num_connectors) { +dev_warn_ratelimited (ucsi->dev, +"Bogus connector change on %u (max %u)\n" , + num, ucsi->cap.num_connectors); +return ; + } + + con = &ucsi->connector[num -1 ]; +if (!test_and_set_bit (EVENT_PENDING , &ucsi->flags))schedule_work (&con->work); }
Signature · 1 line
2.54.0
Re: [PATCH 8/8] usb: typec: ucsi: validate connector number in ucsi_connector_change()
Quoted 11 lines · Greg Kroah-Hartman
The connector number in a UCSI CCI notification is a 7-bit field supplied by the PPM.
ucsi_connector_change()uses it to index the ucsi->connector[] array without checking it against the number of connectors the PPM reported at init time, so a buggy or malicious PPM (EC firmware, or an I2C-attached UCSI controller on the ccg / stm32g0 / glink transports) can driveschedule_work()on memory past the end of the array.Reject connector numbers that are zero or exceed cap.num_connectors before dereferencing the array.
Quoted 11 lines
Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc Benson Leung <[email protected]>Cc Jameson Thies <[email protected]>Cc Nathan Rebello <[email protected]>Cc Johan Hovold <[email protected]>Cc Pooja Katiyar <[email protected]>Cc Hsin-Te Yuan <[email protected]>Cc Abel Vesa <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 35 lines
--- drivers/usb/typec/ucsi/ucsi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/usb/typec/ucsi/ucsi.c +10
-1@@ -1380,13 +1380,22 @@ 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 (!(ucsi->ntfy &UCSI_ENABLE_NTFY_CONNECTOR_CHANGE )) {dev_dbg (ucsi->dev,"Early connector change event\n" );return ; } +if (!num || num > ucsi->cap.num_connectors) { +dev_warn_ratelimited (ucsi->dev, +"Bogus connector change on %u (max %u)\n" , + num, ucsi->cap.num_connectors); +return ; + } + + con = &ucsi->connector[num -1 ]; +if (!test_and_set_bit (EVENT_PENDING , &ucsi->flags))schedule_work (&con->work); }Signature · 1 line
2.54.0
Re: [PATCH 8/8] usb: typec: ucsi: validate connector number in ucsi_connector_change()
In reply to Greg Kroah-HartmanQuoted 11 lines · Greg Kroah-Hartman
The connector number in a UCSI CCI notification is a 7-bit field supplied by the PPM.
ucsi_connector_change()uses it to index the ucsi->connector[] array without checking it against the number of connectors the PPM reported at init time, so a buggy or malicious PPM (EC firmware, or an I2C-attached UCSI controller on the ccg / stm32g0 / glink transports) can driveschedule_work()on memory past the end of the array.Reject connector numbers that are zero or exceed cap.num_connectors before dereferencing the array.
Quoted 11 lines
Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc Benson Leung <[email protected]>Cc Jameson Thies <[email protected]>Cc Nathan Rebello <[email protected]>Cc Johan Hovold <[email protected]>Cc Pooja Katiyar <[email protected]>Cc Hsin-Te Yuan <[email protected]>Cc Abel Vesa <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Re: [PATCH 8/8] usb: typec: ucsi: validate connector number in ucsi_connector_change()
In reply to Greg Kroah-HartmanQuoted 11 lines · Greg Kroah-Hartman
The connector number in a UCSI CCI notification is a 7-bit field supplied by the PPM.
ucsi_connector_change()uses it to index the ucsi->connector[] array without checking it against the number of connectors the PPM reported at init time, so a buggy or malicious PPM (EC firmware, or an I2C-attached UCSI controller on the ccg / stm32g0 / glink transports) can driveschedule_work()on memory past the end of the array.Reject connector numbers that are zero or exceed cap.num_connectors before dereferencing the array.
Quoted 11 lines
Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc Benson Leung <[email protected]>Cc Jameson Thies <[email protected]>Cc Nathan Rebello <[email protected]>Cc Johan Hovold <[email protected]>Cc Pooja Katiyar <[email protected]>Cc Hsin-Te Yuan <[email protected]>Cc Abel Vesa <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 34 lines
--- drivers/usb/typec/ucsi/ucsi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/usb/typec/ucsi/ucsi.c +10
-1@@ -1380,13 +1380,22 @@ 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 (!(ucsi->ntfy &UCSI_ENABLE_NTFY_CONNECTOR_CHANGE )) {dev_dbg (ucsi->dev,"Early connector change event\n" );return ; } +if (!num || num > ucsi->cap.num_connectors) { +dev_warn_ratelimited (ucsi->dev, +"Bogus connector change on %u (max %u)\n" , + num, ucsi->cap.num_connectors); +return ; + } + + con = &ucsi->connector[num -1 ]; +if (!test_and_set_bit (EVENT_PENDING , &ucsi->flags))schedule_work (&con->work); }Signature · 1 line
2.54.0
Signature · 1 line
heikki
Re: [PATCH 8/8] usb: typec: ucsi: validate connector number in ucsi_connector_change()
In reply to Greg Kroah-HartmanQuoted 12 lines · Greg Kroah-Hartman
The connector number in a UCSI CCI notification is a 7-bit field supplied by the PPM.
ucsi_connector_change()uses it to index the ucsi->connector[] array without checking it against the number of connectors the PPM reported at init time, so a buggy or malicious PPM (EC firmware, or an I2C-attached UCSI controller on the ccg / stm32g0 / glink transports) can driveschedule_work()on memory past the end of the array.Reject connector numbers that are zero or exceed cap.num_connectors before dereferencing the array.
Quoted 11 lines
Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc Benson Leung <[email protected]>Cc Jameson Thies <[email protected]>Cc Nathan Rebello <[email protected]>Cc Johan Hovold <[email protected]>Cc Pooja Katiyar <[email protected]>Cc Hsin-Te Yuan <[email protected]>Cc Abel Vesa <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 36 lines
--- drivers/usb/typec/ucsi/ucsi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/usb/typec/ucsi/ucsi.c +10
-2@@ -1380,13 +1380,22 @@ 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 (!(ucsi->ntfy &UCSI_ENABLE_NTFY_CONNECTOR_CHANGE )) {dev_dbg (ucsi->dev,"Early connector change event\n" );return ; } +if (!num || num > ucsi->cap.num_connectors) { +dev_warn_ratelimited (ucsi->dev, +"Bogus connector change on %u (max %u)\n" , + num, ucsi->cap.num_connectors); +return ; + } + + con = &ucsi->connector[num -1 ]; +if (!test_and_set_bit (EVENT_PENDING , &ucsi->flags))schedule_work (&con->work); } --2.54.0
Quoted 24 lines · Greg Kroah-Hartman
wcove_read_rx_buffer()copies the PD RX FIFO into the caller's structpd_messagewithfor (i = 0; i < USBC_RXINFO_RXBYTES(info); i++) regmap_read(wcove->regmap, USBC_RX_DATA + i, msg + i);which has two problems:
USBC_RXINFO_RXBYTES()is a 5-bit field (max 31) while structpd_messageis 30 bytes (__le16header +__le32payload[PD_MAX_PAYLOAD], packed). The byte count latched in RXINFO is the number of bytes the port partner put on the wire, so a malicious partner that transmits a 31-byte frame can drive the loop one byte past the destination if the WCOVE BMC receiver does not enforce the PD object-count limit in hardware. The existing FIXME flagged this as unverified.Independently,
regmap_read()takes an unsigned int * and stores a full unsigned int at the destination. Passing the byte pointer msg + i means each iteration writes four bytes; the high three are zero (val_bitsis
8) and are normally overwritten by the next iteration, but the final iteration's high bytes are not. With RXBYTES == 30 the i == 29 iteration already writes three zero bytes past msg, which sits on the IRQ thread's stack inwcove_typec_irq().
Quoted 8 lines
Clamp the loop to
sizeof(struct pd_message)and read each register into a local before storing only its low byte, so the copy can never exceed the destination regardless of what RXINFO reports.Assisted-by gkh_clanker_t1000Cc Heikki Krogerus <[email protected]>Cc stable <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 41 lines
--- drivers/usb/typec/tcpm/wcove.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/usb/typec/tcpm/wcove.c +8
-5@@ -444,9 +444,11 @@ static int wcove_start_toggling(struct tcpc_dev *tcpc,return regmap_write (wcove->regmap,USBC_CONTROL1 , usbc_ctrl); } -static int wcove_read_rx_buffer (struct wcove_typec *wcove,void *msg) +static int wcove_read_rx_buffer (struct wcove_typec *wcove, +struct pd_message *msg) { -unsigned int info; +unsigned int info, val, len; +u8 *buf = (u8 *)msg;int ret;int i;@@ -454,12 +456,13 @@ static int wcove_read_rx_buffer(struct wcove_typec *wcove, void *msg)if (ret)return ret; -/* FIXME: Check that USBC_RXINFO_RXBYTES(info) matches the header */ + len =min (USBC_RXINFO_RXBYTES (info),sizeof (*msg)); -for (i =0 ; i <USBC_RXINFO_RXBYTES (info); i++) { - ret =regmap_read (wcove->regmap,USBC_RX_DATA + i, msg + i); +for (i =0 ; i < len; i++) { + ret =regmap_read (wcove->regmap,USBC_RX_DATA + i, &val);if (ret)return ret; + buf[i] = val; } return regmap_write(wcove->regmap, USBC_RXSTATUS,Signature · 1 line
2.54.0
Signature · 1 line
heikki