Skip to content

Commit 5ac80ce

Browse files
00xcpathakraul
authored andcommitted
lib: device_power: avoid potential buffer overflows
The device power domain ID is used to index into the domain list, so it should be smaller than the total amount of domains. Fix the bounds check to avoid accessing `dpwr_group->dpwr_tree` out of bounds. Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
1 parent 4089b5e commit 5ac80ce

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/rpmi_service_group_device_power.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ rpmi_dpwr_get_attributes(struct rpmi_service_group *group,
211211
rpmi_uint32_t dpwrid = rpmi_to_xe32(trans->is_be,
212212
((const rpmi_uint32_t *)request_data)[0]);
213213

214-
if (dpwrid > dpwrgrp->dpwr_count) {
214+
if (dpwrid >= dpwrgrp->dpwr_count) {
215215
resp[0] = rpmi_to_xe32(trans->is_be,
216216
(rpmi_uint32_t)RPMI_ERR_INVALID_PARAM);
217217
goto done;
@@ -256,7 +256,7 @@ rpmi_dpwr_get_state(struct rpmi_service_group *group,
256256
rpmi_uint32_t dpwrid = rpmi_to_xe32(trans->is_be,
257257
((const rpmi_uint32_t *)request_data)[0]);
258258

259-
if (dpwrid > dpwrgrp->dpwr_count) {
259+
if (dpwrid >= dpwrgrp->dpwr_count) {
260260
resp[0] = rpmi_to_xe32(trans->is_be,
261261
(rpmi_uint32_t)RPMI_ERR_INVALID_PARAM);
262262
goto done;
@@ -297,7 +297,7 @@ rpmi_dpwr_set_state(struct rpmi_service_group *group,
297297
rpmi_uint32_t dpwr_state = rpmi_to_xe32(trans->is_be,
298298
((const rpmi_uint32_t *)request_data)[1]);
299299

300-
if (dpwrid > dpwrgrp->dpwr_count) {
300+
if (dpwrid >= dpwrgrp->dpwr_count) {
301301
resp[0] = rpmi_to_xe32(trans->is_be,
302302
(rpmi_uint32_t)RPMI_ERR_INVALID_PARAM);
303303
goto done;

0 commit comments

Comments
 (0)