]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
MIPS: validate DT bootargs before appending them
authorPengpeng Hou <pengpeng@iscas.ac.cn>
Tue, 7 Apr 2026 01:57:03 +0000 (09:57 +0800)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Mon, 13 Apr 2026 13:36:36 +0000 (15:36 +0200)
bootcmdline_scan_chosen() fetches the raw flat-DT bootargs property and
passes it straight to bootcmdline_append(). That helper later feeds the
same pointer into strlcat(), which computes strlen(src) before copying.
Flat DT properties are external boot input, and this path does not
prove that bootargs is NUL-terminated within its declared bounds.

Reject unterminated bootargs properties before appending them to the
kernel command line.

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
arch/mips/kernel/setup.c

index f9b228e33f3b941dcc532b146d4f0b15abe4427d..1ae6d0c0e1d67e4448b6d01a0d1c9700f7b96381 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/of_fdt.h>
 #include <linux/dmi.h>
 #include <linux/crash_dump.h>
+#include <linux/string.h>
 
 #include <asm/addrspace.h>
 #include <asm/bootinfo.h>
@@ -541,6 +542,9 @@ static int __init bootcmdline_scan_chosen(unsigned long node, const char *uname,
 
        p = of_get_flat_dt_prop(node, "bootargs", &l);
        if (p != NULL && l > 0) {
+               if (strnlen(p, l) >= l)
+                       return 1;
+
                bootcmdline_append(p, min(l, COMMAND_LINE_SIZE));
                *dt_bootargs = true;
        }