* [PATCH 6.6.y 1/2] usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
@ 2025-04-15 1:56 bin.lan.cn
2025-04-15 1:56 ` [PATCH 6.6.y 2/2] usb: typec: fix pm usage counter imbalance " bin.lan.cn
2025-04-15 21:43 ` [PATCH 6.6.y 1/2] usb: typec: fix potential array underflow " Sasha Levin
0 siblings, 2 replies; 4+ messages in thread
From: bin.lan.cn @ 2025-04-15 1:56 UTC (permalink / raw)
To: gregkh, stable
Cc: dan.carpenter, stable, heikki.krogerus, bin.lan.cn, gongruiqi1
From: Dan Carpenter <dan.carpenter@linaro.org>
[ Upstream commit 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: 170a6726d0e2 ("usb: typec: ucsi: add support for separate DP altmode devices")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/c69ef0b3-61b0-4dde-98dd-97b97f81d912@stanley.mountain
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[Minor context change fixed.
13f2ec3115c8 ("usb: typec: ucsi: simplify command sending API") rename
ucsi_ccg_sync_write to ucsi_ccg_sync_control in v6.11, so this patch is
applied in ucsi_ccg_sync_write in v6.6.]
Signed-off-by: Bin Lan <bin.lan.cn@windriver.com>
Signed-off-by: He Zhe <zhe.he@windriver.com>
---
Build test passed.
---
drivers/usb/typec/ucsi/ucsi_ccg.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
index 7c7f388aac96..3ef02d35bfbe 100644
--- a/drivers/usb/typec/ucsi/ucsi_ccg.c
+++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
@@ -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 unlock;
+ }
con = &uc->ucsi->connector[con_index - 1];
ucsi_ccg_update_set_new_cam_cmd(uc, con, (u64 *)val);
}
@@ -600,6 +604,7 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
err_clear_bit:
clear_bit(DEV_CMD_PENDING, &uc->flags);
pm_runtime_put_sync(uc->dev);
+unlock:
mutex_unlock(&uc->lock);
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 6.6.y 2/2] usb: typec: fix pm usage counter imbalance in ucsi_ccg_sync_control()
2025-04-15 1:56 [PATCH 6.6.y 1/2] usb: typec: fix potential array underflow in ucsi_ccg_sync_control() bin.lan.cn
@ 2025-04-15 1:56 ` bin.lan.cn
2025-04-15 21:43 ` Sasha Levin
2025-04-15 21:43 ` [PATCH 6.6.y 1/2] usb: typec: fix potential array underflow " Sasha Levin
1 sibling, 1 reply; 4+ messages in thread
From: bin.lan.cn @ 2025-04-15 1:56 UTC (permalink / raw)
To: gregkh, stable
Cc: dan.carpenter, stable, heikki.krogerus, bin.lan.cn, gongruiqi1
From: GONG Ruiqi <gongruiqi1@huawei.com>
[ Upstream commit b0e525d7a22ea350e75e2aec22e47fcfafa4cacd ]
The error handling for the case `con_index == 0` should involve dropping
the pm usage counter, as ucsi_ccg_sync_control() gets it at the
beginning. Fix it.
Cc: stable <stable@kernel.org>
Fixes: e56aac6e5a25 ("usb: typec: fix potential array underflow in ucsi_ccg_sync_control()")
Signed-off-by: GONG Ruiqi <gongruiqi1@huawei.com>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20250107015750.2778646-1-gongruiqi1@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[Minor context change fixed]
Signed-off-by: Bin Lan <bin.lan.cn@windriver.com>
Signed-off-by: He Zhe <zhe.he@windriver.com>
---
Build test passed.
---
drivers/usb/typec/ucsi/ucsi_ccg.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
index 3ef02d35bfbe..35f4c4482fca 100644
--- a/drivers/usb/typec/ucsi/ucsi_ccg.c
+++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
@@ -587,7 +587,7 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
UCSI_CMD_CONNECTOR_MASK;
if (con_index == 0) {
ret = -EINVAL;
- goto unlock;
+ goto err_put;
}
con = &uc->ucsi->connector[con_index - 1];
ucsi_ccg_update_set_new_cam_cmd(uc, con, (u64 *)val);
@@ -603,8 +603,8 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
err_clear_bit:
clear_bit(DEV_CMD_PENDING, &uc->flags);
+err_put:
pm_runtime_put_sync(uc->dev);
-unlock:
mutex_unlock(&uc->lock);
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 6.6.y 2/2] usb: typec: fix pm usage counter imbalance in ucsi_ccg_sync_control()
2025-04-15 1:56 ` [PATCH 6.6.y 2/2] usb: typec: fix pm usage counter imbalance " bin.lan.cn
@ 2025-04-15 21:43 ` Sasha Levin
0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2025-04-15 21:43 UTC (permalink / raw)
To: stable; +Cc: bin.lan.cn, Sasha Levin
[ Sasha's backport helper bot ]
Hi,
✅ All tests passed successfully. No issues detected.
No action required from the submitter.
The upstream commit SHA1 provided is correct: b0e525d7a22ea350e75e2aec22e47fcfafa4cacd
WARNING: Author mismatch between patch and upstream commit:
Backport author: bin.lan.cn@windriver.com
Commit author: GONG Ruiqi<gongruiqi1@huawei.com>
Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.13.y | Present (exact SHA1)
6.12.y | Present (different SHA1: 976544bdb40a)
Note: The patch differs from the upstream commit:
---
1: b0e525d7a22ea < -: ------------- usb: typec: fix pm usage counter imbalance in ucsi_ccg_sync_control()
-: ------------- > 1: 4cf6fea3b1723 usb: typec: fix pm usage counter imbalance in ucsi_ccg_sync_control()
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.12.y | Success | Success |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 6.6.y 1/2] usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
2025-04-15 1:56 [PATCH 6.6.y 1/2] usb: typec: fix potential array underflow in ucsi_ccg_sync_control() bin.lan.cn
2025-04-15 1:56 ` [PATCH 6.6.y 2/2] usb: typec: fix pm usage counter imbalance " bin.lan.cn
@ 2025-04-15 21:43 ` Sasha Levin
1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2025-04-15 21:43 UTC (permalink / raw)
To: stable, bin.lan.cn; +Cc: Sasha Levin
[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Found follow-up fixes in mainline
The upstream commit SHA1 provided is correct: e56aac6e5a25630645607b6856d4b2a17b2311a5
WARNING: Author mismatch between patch and upstream commit:
Backport author: bin.lan.cn@windriver.com
Commit author: Dan Carpenter<dan.carpenter@linaro.org>
Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.13.y | Present (exact SHA1)
6.12.y | Present (different SHA1: 56971710cd54)
Found fixes commits:
b0e525d7a22e usb: typec: fix pm usage counter imbalance in ucsi_ccg_sync_control()
Note: The patch differs from the upstream commit:
---
1: e56aac6e5a256 < -: ------------- usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
-: ------------- > 1: 0d00efada893e usb: typec: fix potential array underflow in ucsi_ccg_sync_control()
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.6.y | Success | Success |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-15 21:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 1:56 [PATCH 6.6.y 1/2] usb: typec: fix potential array underflow in ucsi_ccg_sync_control() bin.lan.cn
2025-04-15 1:56 ` [PATCH 6.6.y 2/2] usb: typec: fix pm usage counter imbalance " bin.lan.cn
2025-04-15 21:43 ` Sasha Levin
2025-04-15 21:43 ` [PATCH 6.6.y 1/2] usb: typec: fix potential array underflow " Sasha Levin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.