Skip to content

Commit 70edd31

Browse files
Dan Carpentervijay-suman
authored andcommitted
usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
commit e56aac6 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 13f2ec3 ("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]> (cherry picked from commit e15fd96c0b701c53f9006bcc836eaeb35a05a023) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent ccc9ef4 commit 70edd31

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
@@ -573,6 +573,10 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
573573
uc->has_multiple_dp) {
574574
con_index = (uc->last_cmd_sent >> 16) &
575575
UCSI_CMD_CONNECTOR_MASK;
576+
if (con_index == 0) {
577+
ret = -EINVAL;
578+
goto unlock;
579+
}
576580
con = &uc->ucsi->connector[con_index - 1];
577581
ucsi_ccg_update_set_new_cam_cmd(uc, con, (u64 *)val);
578582
}
@@ -588,6 +592,7 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
588592
err_clear_bit:
589593
clear_bit(DEV_CMD_PENDING, &uc->flags);
590594
pm_runtime_put_sync(uc->dev);
595+
unlock:
591596
mutex_unlock(&uc->lock);
592597

593598
return ret;

0 commit comments

Comments
 (0)