From: Pengpeng Hou Date: Tue, 7 Apr 2026 01:57:03 +0000 (+0800) Subject: MIPS: validate DT bootargs before appending them X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f992846d0b45691a02d0a9775c5c2a50956e62a5;p=thirdparty%2Fkernel%2Flinux.git MIPS: validate DT bootargs before appending them 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 Signed-off-by: Thomas Bogendoerfer --- diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index f9b228e33f3b9..1ae6d0c0e1d67 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -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; }