diff options
author | Heikki Krogerus <[email protected]> | 2024-08-16 16:58:55 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <[email protected]> | 2024-08-23 18:47:38 +0800 |
commit | 1d05c382ddb4e43ce251a50f308df5e42a2f6088 (patch) | |
tree | e690b2a63ddbb8c6dc3672233e61c9d93a35c84d | |
parent | 9ecf52153b6f6681853b60c9912231e03857dff4 (diff) |
usb: typec: ucsi: Don't truncate the reads
That may silently corrupt the data. Instead, failing attempts
to read more than the interface can handle.
Signed-off-by: Heikki Krogerus <[email protected]>
Reviewed-by: Abhishek Pandit-Subedi <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
-rw-r--r-- | drivers/usb/typec/ucsi/ucsi.c | 8 | ||||
-rw-r--r-- | drivers/usb/typec/ucsi/ucsi.h | 2 |
2 files changed, 4 insertions, 6 deletions
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 546352b53bc4..250bd20f2cd9 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -99,12 +99,8 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, *cci = 0; - /* - * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the - * reads here. - */ - if (ucsi->version <= UCSI_VERSION_1_2) - size = clamp(size, 0, 16); + if (size > UCSI_MAX_DATA_LENGTH(ucsi)) + return -EINVAL; ret = ucsi->ops->sync_control(ucsi, command); if (ret) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 6359baa22858..e8ece3fdcbf2 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -415,6 +415,8 @@ struct ucsi { #define UCSI_DELAY_DEVICE_PDOS BIT(1) /* Reading PDOs fails until the parter is in PD mode */ }; +#define UCSI_MAX_DATA_LENGTH(u) (((u)->version < UCSI_VERSION_2_0) ? 0x10 : 0xff) + #define UCSI_MAX_SVID 5 #define UCSI_MAX_ALTMODES (UCSI_MAX_SVID * 6) |