mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	pengpeng@iscas.ac.cn
Subject: [PATCH] riscv: pi: validate early bootargs before string use
Date: Fri, 3 Apr 2026 11:55:50 +0800	[thread overview]
Message-ID: <20260403143003.3-riscv-pi-bootargs-pengpeng@iscas.ac.cn> (raw)

get_early_cmdline() fetches bootargs directly from the FDT and
immediately passes the raw property pointer to strlen() before copying
it into the early command-line buffer. Flat DT properties are external
boot input, and this path does not prove that bootargs is
NUL-terminated within its declared bounds.

Use fdt_stringlist_get() so malformed unterminated bootargs are
rejected before any C-string helpers walk them.

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 arch/riscv/kernel/pi/cmdline_early.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/riscv/kernel/pi/cmdline_early.c b/arch/riscv/kernel/pi/cmdline_early.c
index 389d086a0718..ac55f1c7ca70 100644
--- a/arch/riscv/kernel/pi/cmdline_early.c
+++ b/arch/riscv/kernel/pi/cmdline_early.c
@@ -13,16 +13,17 @@ static char early_cmdline[COMMAND_LINE_SIZE];
 static char *get_early_cmdline(uintptr_t dtb_pa)
 {
 	const char *fdt_cmdline = NULL;
-	unsigned int fdt_cmdline_size = 0;
+	int fdt_cmdline_size = 0;
 	int chosen_node;
 
 	if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
 		chosen_node = fdt_path_offset((void *)dtb_pa, "/chosen");
 		if (chosen_node >= 0) {
-			fdt_cmdline = fdt_getprop((void *)dtb_pa, chosen_node,
-						  "bootargs", NULL);
-			if (fdt_cmdline) {
-				fdt_cmdline_size = strlen(fdt_cmdline);
+			fdt_cmdline = fdt_stringlist_get((void *)dtb_pa,
+							 chosen_node,
+							 "bootargs", 0,
+							 &fdt_cmdline_size);
+			if (fdt_cmdline && fdt_cmdline_size > 0) {
 				strscpy(early_cmdline, fdt_cmdline,
 					COMMAND_LINE_SIZE);
 			}
-- 
2.50.1 (Apple Git-155)


                 reply	other threads:[~2026-04-03  4:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260403143003.3-riscv-pi-bootargs-pengpeng@iscas.ac.cn \
    --to=pengpeng@iscas.ac.cn \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    /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

all inboxes | Powered by JetHome®