* [PATCH v1 1/4] firmware: arm_scpi: fix device_node leak in scpi_dev_domain_id
2026-07-27 2:19 [PATCH v1 0/4] firmware/clk: arm_scpi hardening (leak, OPP bounds, cpufreq) Xixin Liu
@ 2026-07-27 2:19 ` Xixin Liu
2026-07-27 2:19 ` [PATCH v1 3/4] clk: scpi: bound-check DVFS index in scpi_dvfs_recalc_rate Xixin Liu
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Xixin Liu @ 2026-07-27 2:19 UTC (permalink / raw)
To: arm-scmi
Cc: sudeep.holla, cristian.marussi, mturquette, sboyd,
linux-arm-kernel, linux-clk, linux-kernel, liuxixin
of_parse_phandle_with_args() takes a reference on clkspec.np that must be
released with of_node_put(). scpi_dev_domain_id() returned clkspec.args[0]
without dropping that reference, so every domain lookup leaked a device
node. Paths such as scpi_dvfs_info() / cpufreq init call this per CPU, so
the leak accumulates over time.
Save the domain id, of_node_put(clkspec.np), then return the saved value.
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
drivers/firmware/arm_scpi.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c
index 87c323de17b9..6056754ef48c 100644
--- a/drivers/firmware/arm_scpi.c
+++ b/drivers/firmware/arm_scpi.c
@@ -660,12 +660,15 @@ static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain)
static int scpi_dev_domain_id(struct device *dev)
{
struct of_phandle_args clkspec;
+ int domain;
if (of_parse_phandle_with_args(dev->of_node, "clocks", "#clock-cells",
0, &clkspec))
return -EINVAL;
- return clkspec.args[0];
+ domain = clkspec.args[0];
+ of_node_put(clkspec.np);
+ return domain;
}
static struct scpi_dvfs_info *scpi_dvfs_info(struct device *dev)
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 3/4] clk: scpi: bound-check DVFS index in scpi_dvfs_recalc_rate
2026-07-27 2:19 [PATCH v1 0/4] firmware/clk: arm_scpi hardening (leak, OPP bounds, cpufreq) Xixin Liu
2026-07-27 2:19 ` [PATCH v1 1/4] firmware: arm_scpi: fix device_node leak in scpi_dev_domain_id Xixin Liu
@ 2026-07-27 2:19 ` Xixin Liu
2026-07-27 2:19 ` [PATCH v1 2/4] firmware: arm_scpi: reject DVFS OPP count above MAX_DVFS_OPPS Xixin Liu
2026-07-27 2:19 ` [PATCH v1 4/4] clk: scpi: register scpi-cpufreq once and clear on failure Xixin Liu
3 siblings, 0 replies; 5+ messages in thread
From: Xixin Liu @ 2026-07-27 2:19 UTC (permalink / raw)
To: arm-scmi
Cc: sudeep.holla, cristian.marussi, mturquette, sboyd,
linux-arm-kernel, linux-clk, linux-kernel, liuxixin
dvfs_get_idx() may return an out-of-range index if the SCP firmware is
buggy or returns a stale value. Only negative indexes were rejected, so a
large index walked past info->opps and could treat garbage as a clock rate
(KASAN OOB / wrong frequency to consumers).
Treat indexes >= opp count as invalid and return 0, same as idx < 0.
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
drivers/clk/clk-scpi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/clk-scpi.c b/drivers/clk/clk-scpi.c
index 19d530d52e64..4e22ba12b157 100644
--- a/drivers/clk/clk-scpi.c
+++ b/drivers/clk/clk-scpi.c
@@ -85,7 +85,7 @@ static unsigned long scpi_dvfs_recalc_rate(struct clk_hw *hw,
int idx = clk->scpi_ops->dvfs_get_idx(clk->id);
const struct scpi_opp *opp;
- if (idx < 0)
+ if (idx < 0 || idx >= clk->info->count)
return 0;
opp = clk->info->opps + idx;
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 2/4] firmware: arm_scpi: reject DVFS OPP count above MAX_DVFS_OPPS
2026-07-27 2:19 [PATCH v1 0/4] firmware/clk: arm_scpi hardening (leak, OPP bounds, cpufreq) Xixin Liu
2026-07-27 2:19 ` [PATCH v1 1/4] firmware: arm_scpi: fix device_node leak in scpi_dev_domain_id Xixin Liu
2026-07-27 2:19 ` [PATCH v1 3/4] clk: scpi: bound-check DVFS index in scpi_dvfs_recalc_rate Xixin Liu
@ 2026-07-27 2:19 ` Xixin Liu
2026-07-27 2:19 ` [PATCH v1 4/4] clk: scpi: register scpi-cpufreq once and clear on failure Xixin Liu
3 siblings, 0 replies; 5+ messages in thread
From: Xixin Liu @ 2026-07-27 2:19 UTC (permalink / raw)
To: arm-scmi
Cc: sudeep.holla, cristian.marussi, mturquette, sboyd,
linux-arm-kernel, linux-clk, linux-kernel, liuxixin
scpi_dvfs_get_info() already rejected a zero opp_count, but still trusted
any larger value from the SCP firmware. The shared-memory reply only holds
MAX_DVFS_OPPS entries in buf.opps[]; a bigger count over-reads that array
and then sizes the allocated OPP table incorrectly (garbage OPPs / OOB).
Reject zero and out-of-range counts in one check and return -EINVAL.
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
drivers/firmware/arm_scpi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c
index 6056754ef48c..5db58bdfc947 100644
--- a/drivers/firmware/arm_scpi.c
+++ b/drivers/firmware/arm_scpi.c
@@ -630,8 +630,8 @@ static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain)
if (ret)
return ERR_PTR(ret);
- if (!buf.opp_count)
- return ERR_PTR(-ENOENT);
+ if (!buf.opp_count || buf.opp_count > MAX_DVFS_OPPS)
+ return ERR_PTR(-EINVAL);
info = kmalloc(sizeof(*info), GFP_KERNEL);
if (!info)
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 4/4] clk: scpi: register scpi-cpufreq once and clear on failure
2026-07-27 2:19 [PATCH v1 0/4] firmware/clk: arm_scpi hardening (leak, OPP bounds, cpufreq) Xixin Liu
` (2 preceding siblings ...)
2026-07-27 2:19 ` [PATCH v1 2/4] firmware: arm_scpi: reject DVFS OPP count above MAX_DVFS_OPPS Xixin Liu
@ 2026-07-27 2:19 ` Xixin Liu
3 siblings, 0 replies; 5+ messages in thread
From: Xixin Liu @ 2026-07-27 2:19 UTC (permalink / raw)
To: arm-scmi
Cc: sudeep.holla, cristian.marussi, mturquette, sboyd,
linux-arm-kernel, linux-clk, linux-kernel, liuxixin
scpi_clk_probe() walks clock children and, for each DVFS provider, calls
platform_device_register_simple("scpi-cpufreq"). Two related bugs:
1) Multiple DVFS children each spawned another virtual cpufreq device.
If cpufreq_dev is already set, continue and skip a second register.
2) On IS_ERR, the pointer still held ERR_PTR (e.g. -ENOMEM). remove()
treats any non-NULL cpufreq_dev as live and would call
platform_device_unregister() on the error pointer (oops). Clear
cpufreq_dev to NULL after the failure warn so remove() skips it.
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
drivers/clk/clk-scpi.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/clk-scpi.c b/drivers/clk/clk-scpi.c
index 4e22ba12b157..ce6baea8f82e 100644
--- a/drivers/clk/clk-scpi.c
+++ b/drivers/clk/clk-scpi.c
@@ -283,10 +283,14 @@ static int scpi_clocks_probe(struct platform_device *pdev)
if (match->data != &scpi_dvfs_ops)
continue;
/* Add the virtual cpufreq device if it's DVFS clock provider */
+ if (cpufreq_dev)
+ continue;
cpufreq_dev = platform_device_register_simple("scpi-cpufreq",
-1, NULL, 0);
- if (IS_ERR(cpufreq_dev))
+ if (IS_ERR(cpufreq_dev)) {
pr_warn("unable to register cpufreq device");
+ cpufreq_dev = NULL;
+ }
}
return 0;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 0/4] firmware/clk: arm_scpi hardening (leak, OPP bounds, cpufreq)
@ 2026-07-27 2:19 Xixin Liu
2026-07-27 2:19 ` [PATCH v1 1/4] firmware: arm_scpi: fix device_node leak in scpi_dev_domain_id Xixin Liu
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Xixin Liu @ 2026-07-27 2:19 UTC (permalink / raw)
To: arm-scmi
Cc: sudeep.holla, cristian.marussi, mturquette, sboyd,
linux-arm-kernel, linux-clk, linux-kernel, liuxixin
Hi,
This series hardens the OF SCPI firmware and clock paths against a few
real defects found while reviewing linux-next:
1) device_node leak in scpi_dev_domain_id() after
of_parse_phandle_with_args()
2) DVFS OPP count from SCP trusted beyond MAX_DVFS_OPPS (OOB read /
bad OPP table size)
3) DVFS index used as clock rate without an upper bound check
4) scpi-cpufreq registered once only, and cleared on register failure
so remove() does not unregister an ERR_PTR
Please review.
Thanks,
Xixin Liu
---
Xixin Liu (4):
firmware: arm_scpi: fix device_node leak in scpi_dev_domain_id
firmware: arm_scpi: reject DVFS OPP count above MAX_DVFS_OPPS
clk: scpi: bound-check DVFS index in scpi_dvfs_recalc_rate
clk: scpi: register scpi-cpufreq once and clear on failure
drivers/clk/clk-scpi.c | 8 ++++++--
drivers/firmware/arm_scpi.c | 9 ++++++---
2 files changed, 12 insertions(+), 5 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-27 2:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-27 2:19 [PATCH v1 0/4] firmware/clk: arm_scpi hardening (leak, OPP bounds, cpufreq) Xixin Liu
2026-07-27 2:19 ` [PATCH v1 1/4] firmware: arm_scpi: fix device_node leak in scpi_dev_domain_id Xixin Liu
2026-07-27 2:19 ` [PATCH v1 3/4] clk: scpi: bound-check DVFS index in scpi_dvfs_recalc_rate Xixin Liu
2026-07-27 2:19 ` [PATCH v1 2/4] firmware: arm_scpi: reject DVFS OPP count above MAX_DVFS_OPPS Xixin Liu
2026-07-27 2:19 ` [PATCH v1 4/4] clk: scpi: register scpi-cpufreq once and clear on failure Xixin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox