From: Paul Walmsley <pjw@kernel.org>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>
Cc: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Nutty Liu <liujingqi@lanxincomputing.com>,
Junhui Liu <junhui.liu@pigmoral.tech>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] riscv: pi: validate early FDT string properties before string use
Date: Tue, 24 Nov 2026 20:50:52 -0700 (MST) [thread overview]
Message-ID: <36ac8dd9-aaea-ade9-cdd6-dcd470771633@kernel.org> (raw)
In-Reply-To: <20260403005904.8904D166EA5F@hppdeMacBook-Pro.local>
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@iscas.ac.cn>
> ---
> 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
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-11-25 3:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 0:47 [PATCH] riscv: pi: validate early FDT string properties before string use Pengpeng Hou
2026-11-25 3:50 ` Paul Walmsley [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-04-03 0:47 Pengpeng Hou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=36ac8dd9-aaea-ade9-cdd6-dcd470771633@kernel.org \
--to=pjw@kernel.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=junhui.liu@pigmoral.tech \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=liujingqi@lanxincomputing.com \
--cc=palmer@dabbelt.com \
--cc=pengpeng@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox