Re: [PATCH] riscv: pi: validate early FDT string properties before string use

From: Paul Walmsley

Date: Tue Nov 24 2026 - 22:50:59 EST


On Fri, 3 Apr 2026, Pengpeng Hou wrote:

> The early RISC-V FDT parser reads status, riscv,isa, and mmu-type
> directly from the DTB and then passes them to strcmp() or
> isa_string_contains(), which in turn uses strlen() and other C string
> helpers. DT string properties come from external firmware input and are
> not locally proven to be NUL-terminated within the property bounds.
>
> Use fdt_stringlist_get() before treating these properties as C strings
> so malformed unterminated properties are rejected instead of being read
> past their declared length.
>
> Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
> ---
> arch/riscv/kernel/pi/fdt_early.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/arch/riscv/kernel/pi/fdt_early.c b/arch/riscv/kernel/pi/fdt_early.c
> index a12ff8090f19..a44afd460d70 100644
> --- a/arch/riscv/kernel/pi/fdt_early.c
> +++ b/arch/riscv/kernel/pi/fdt_early.c
> @@ -38,16 +38,13 @@ u64 get_kaslr_seed(uintptr_t dtb_pa)
> static bool fdt_device_is_available(const void *fdt, int node)
> {
> const char *status;
> - int statlen;
>
> - status = fdt_getprop(fdt, node, "status", &statlen);
> + status = fdt_stringlist_get(fdt, node, "status", 0, NULL);
> if (!status)
> return true;

Sashiko points out that fdt_stringlist_get() can return NULL not just
when the property is missing, but also when the property is empty or not
NULL-terminated. Those cases will now all be treated the same way.
This seems to conflict somewhat with the apparent intention of the patch?

> @@ -210,7 +207,7 @@ 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);
> + mmu_type = fdt_stringlist_get(fdt, node, "mmu-type", 0, NULL);
> if (!mmu_type)
> break;

And again here.


- Paul