Skip to content

Commit e56aac6

Browse files
Dan Carpentergregkh
authored andcommitted
usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
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]>
1 parent 2481af7 commit e56aac6

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
@@ -642,13 +642,18 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command)
642642
uc->has_multiple_dp) {
643643
con_index = (uc->last_cmd_sent >> 16) &
644644
UCSI_CMD_CONNECTOR_MASK;
645+
if (con_index == 0) {
646+
ret = -EINVAL;
647+
goto unlock;
648+
}
645649
con = &uc->ucsi->connector[con_index - 1];
646650
ucsi_ccg_update_set_new_cam_cmd(uc, con, &command);
647651
}
648652

649653
ret = ucsi_sync_control_common(ucsi, command);
650654

651655
pm_runtime_put_sync(uc->dev);
656+
unlock:
652657
mutex_unlock(&uc->lock);
653658

654659
return ret;

0 commit comments

Comments
 (0)