Skip to content

Commit e441894

Browse files
Dan Carpentergregkh
authored andcommitted
usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
commit e56aac6e5a25630645607b6856d4b2a17b2311a5 upstream. The "command" variable can be controlled by the user via debugfs. The worry is that if con_index is zero then "&uc->ucsi->connector[con_index - 1]" would be an array underflow. Fixes: 170a672 ("usb: typec: ucsi: add support for separate DP altmode devices") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> [ The function ucsi_ccg_sync_write() is renamed to ucsi_ccg_sync_control() in commit 13f2ec3115c8 ("usb: typec: ucsi:simplify command sending API"). Apply this patch to ucsi_ccg_sync_write() in 6.1.y accordingly. ] Signed-off-by: Bin Lan <[email protected]> Signed-off-by: He Zhe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f1c5dda commit e441894

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/usb/typec/ucsi/ucsi_ccg.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,10 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
585585
uc->has_multiple_dp) {
586586
con_index = (uc->last_cmd_sent >> 16) &
587587
UCSI_CMD_CONNECTOR_MASK;
588+
if (con_index == 0) {
589+
ret = -EINVAL;
590+
goto unlock;
591+
}
588592
con = &uc->ucsi->connector[con_index - 1];
589593
ucsi_ccg_update_set_new_cam_cmd(uc, con, (u64 *)val);
590594
}
@@ -600,6 +604,7 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
600604
err_clear_bit:
601605
clear_bit(DEV_CMD_PENDING, &uc->flags);
602606
pm_runtime_put_sync(uc->dev);
607+
unlock:
603608
mutex_unlock(&uc->lock);
604609

605610
return ret;

0 commit comments

Comments
 (0)