Re: [PATCH] MIPS: validate DT bootargs before appending them
From: Sergey Shtylyov
Date: Fri Apr 03 2026 - 03:58:41 EST
On 4/3/26 8:41 AM, Pengpeng Hou wrote:
> 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@xxxxxxxxxxx>
> ---
> arch/mips/kernel/setup.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index f9b228e33f3b..dd7915110820 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
[...]
> @@ -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 (!memchr(p, '\0', l))
Maybe strnlen()?
[...]
MBR, Sergey