Commit b129d636 authored by Dan Carpenter's avatar Dan Carpenter Committed by GONG Ruiqi
Browse files

usb: typec: fix potential array underflow in ucsi_ccg_sync_control()

mainline inclusion
from mainline-v6.13-rc1
commit e56aac6e5a25630645607b6856d4b2a17b2311a5
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBEAFV
CVE: CVE-2024-53203

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e56aac6e5a25630645607b6856d4b2a17b2311a5



--------------------------------

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: 170a6726 ("usb: typec: ucsi: add support for separate DP altmode devices")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/c69ef0b3-61b0-4dde-98dd-97b97f81d912@stanley.mountain


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Conflicts:
	drivers/usb/typec/ucsi/ucsi_ccg.c
[It comes from two reasons: 1. the lack of commit 13f2ec3115c8, which
refactors ucsi_ccg_sync_write() to ucsi_ccg_sync_control(); 2. a
possible error within the original upstream patch, causing the imbalance
of pm_runtime_{get,put}_sync().]
Signed-off-by: default avatarGONG Ruiqi <gongruiqi1@huawei.com>
parent 874edbaf
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -585,6 +585,10 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
		    uc->has_multiple_dp) {
			con_index = (uc->last_cmd_sent >> 16) &
				    UCSI_CMD_CONNECTOR_MASK;
			if (con_index == 0) {
				ret = -EINVAL;
				goto err_clear_bit;
			}
			con = &uc->ucsi->connector[con_index - 1];
			ucsi_ccg_update_set_new_cam_cmd(uc, con, (u64 *)val);
		}