Skip to content

Commit a89f355

Browse files
Mani-Sadhasivamandersson
authored andcommitted
soc: qcom: aoss: Fix the out of bound usage of cooling_devs
In "qmp_cooling_devices_register", the count value is initially QMP_NUM_COOLING_RESOURCES, which is 2. Based on the initial count value, the memory for cooling_devs is allocated. Then while calling the "qmp_cooling_device_add" function, count value is post-incremented for each child node. This makes the out of bound access to the cooling_dev array. Fix it by passing the QMP_NUM_COOLING_RESOURCES definition to devm_kzalloc() and initializing the count to 0. While at it, let's also free the memory allocated to cooling_dev if no cooling device is found in DT and during unroll phase. Cc: stable@vger.kernel.org # 5.4 Fixes: 05589b3 ("soc: qcom: Extend AOSS QMP driver to support resources that are used to wake up the SoC.") Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Link: https://lore.kernel.org/r/20210629153249.73428-1-manivannan.sadhasivam@linaro.org Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
1 parent b42000e commit a89f355

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎drivers/soc/qcom/qcom_aoss.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,12 @@ static int qmp_cooling_device_add(struct qmp *qmp,
476476
static int qmp_cooling_devices_register(struct qmp *qmp)
477477
{
478478
struct device_node *np, *child;
479-
int count = QMP_NUM_COOLING_RESOURCES;
479+
int count = 0;
480480
int ret;
481481

482482
np = qmp->dev->of_node;
483483

484-
qmp->cooling_devs = devm_kcalloc(qmp->dev, count,
484+
qmp->cooling_devs = devm_kcalloc(qmp->dev, QMP_NUM_COOLING_RESOURCES,
485485
sizeof(*qmp->cooling_devs),
486486
GFP_KERNEL);
487487

@@ -497,12 +497,16 @@ static int qmp_cooling_devices_register(struct qmp *qmp)
497497
goto unroll;
498498
}
499499

500+
if (!count)
501+
devm_kfree(qmp->dev, qmp->cooling_devs);
502+
500503
return 0;
501504

502505
unroll:
503506
while (--count >= 0)
504507
thermal_cooling_device_unregister
505508
(qmp->cooling_devs[count].cdev);
509+
devm_kfree(qmp->dev, qmp->cooling_devs);
506510

507511
return ret;
508512
}

0 commit comments

Comments
 (0)