Skip to content

Commit 865ed67

Browse files
sudeep-hollaarndb
authored andcommitted
firmware: arm_scpi: Fix string overflow in SCPI genpd driver
Without the bound checks for scpi_pd->name, it could result in the buffer overflow when copying the SCPI device name from the corresponding device tree node as the name string is set at maximum size of 30. Let us fix it by using devm_kasprintf so that the string buffer is allocated dynamically. Fixes: 8bec433 ("firmware: scpi: add device power domain support using genpd") Reported-by: Pedro Batista <[email protected]> Signed-off-by: Sudeep Holla <[email protected]> Cc: [email protected] Cc: Cristian Marussi <[email protected]> Link: https://lore.kernel.org/r/[email protected]' Signed-off-by: Arnd Bergmann <[email protected]>
1 parent 38d5b29 commit 865ed67

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/firmware/scpi_pm_domain.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ struct scpi_pm_domain {
1616
struct generic_pm_domain genpd;
1717
struct scpi_ops *ops;
1818
u32 domain;
19-
char name[30];
2019
};
2120

2221
/*
@@ -110,8 +109,13 @@ static int scpi_pm_domain_probe(struct platform_device *pdev)
110109

111110
scpi_pd->domain = i;
112111
scpi_pd->ops = scpi_ops;
113-
sprintf(scpi_pd->name, "%pOFn.%d", np, i);
114-
scpi_pd->genpd.name = scpi_pd->name;
112+
scpi_pd->genpd.name = devm_kasprintf(dev, GFP_KERNEL,
113+
"%pOFn.%d", np, i);
114+
if (!scpi_pd->genpd.name) {
115+
dev_err(dev, "Failed to allocate genpd name:%pOFn.%d\n",
116+
np, i);
117+
continue;
118+
}
115119
scpi_pd->genpd.power_off = scpi_pd_power_off;
116120
scpi_pd->genpd.power_on = scpi_pd_power_on;
117121

0 commit comments

Comments
 (0)