[PATCH v2] riscv: pi: bound early CPU property strings

From: Pengpeng Hou

Date: Wed Dec 02 2026 - 22:46:42 EST


The early CPU walker compares status and mmu-type as strings and passes
the legacy ISA property to an unbounded string parser. Check for an
in-property terminator before those uses.

Only a missing status defaults to available. An empty or malformed
status does not enable the node. An unusable mmu-type keeps the existing
no-override result for the first available CPU; do not silently select a
later CPU instead.

Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
Changes since v1:
Distinguish missing status from an empty or malformed value. Preserve the
first-available-CPU rule for mmu-type.
Review of v1: https://lore-kernel.gnuweeb.org/linux-riscv/36ac8dd9-aaea-ade9-cdd6-dcd470771633@xxxxxxxxxx/

Codex assisted with patch preparation and the changelog.
Current review: Codex (Assisted-by: gpt 5).
Static review only; this revision was not built.

arch/riscv/kernel/pi/fdt_early.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/riscv/kernel/pi/fdt_early.c b/arch/riscv/kernel/pi/fdt_early.c
index a12ff8090f190331f555d9e22ce4d1b3e940bceb..6a853fc52a6f8cd5a800a04f8815fbfce4ab53b2 100644
--- a/arch/riscv/kernel/pi/fdt_early.c
+++ b/arch/riscv/kernel/pi/fdt_early.c
@@ -42,9 +42,9 @@ static bool fdt_device_is_available(const void *fdt, int node)

status = fdt_getprop(fdt, node, "status", &statlen);
if (!status)
- return true;
+ return statlen == -FDT_ERR_NOTFOUND;

- if (statlen > 0) {
+ if (statlen > 0 && memchr(status, '\0', statlen)) {
if (!strcmp(status, "okay") || !strcmp(status, "ok"))
return true;
}
@@ -145,7 +145,8 @@ static bool early_cpu_isa_ext_available(const void *fdt, int node, const char *e
return true;

prop = fdt_getprop(fdt, node, "riscv,isa", &len);
- if (prop && isa_string_contains(prop, ext_name))
+ if (prop && len > 0 && memchr(prop, '\0', len) &&
+ isa_string_contains(prop, ext_name))
return true;

return false;
@@ -197,7 +198,7 @@ u64 set_satp_mode_from_fdt(uintptr_t dtb_pa)
{
const void *fdt = (const void *)dtb_pa;
const char *mmu_type;
- int node, parent;
+ int node, parent, len;

parent = fdt_path_offset(fdt, "/cpus");
if (parent < 0)
@@ -210,8 +211,8 @@ u64 set_satp_mode_from_fdt(uintptr_t dtb_pa)
if (!fdt_device_is_available(fdt, node))
continue;

- mmu_type = fdt_getprop(fdt, node, "mmu-type", NULL);
- if (!mmu_type)
+ mmu_type = fdt_getprop(fdt, node, "mmu-type", &len);
+ if (!mmu_type || len <= 0 || !memchr(mmu_type, '\0', len))
break;

if (!strcmp(mmu_type, "riscv,sv39"))

base-commit: 0810bd27d7bbccb4f579f1fbb1afc98687c4c7c3