]> git.itanic.dy.fi Git - linux-stable/commitdiff
riscv: Fix an off-by-one in get_early_cmdline()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 29 Oct 2023 07:20:40 +0000 (08:20 +0100)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 11 Jan 2024 16:04:18 +0000 (08:04 -0800)
The ending NULL is not taken into account by strncat(), so switch to
strlcat() to correctly compute the size of the available memory when
appending CONFIG_CMDLINE to 'early_cmdline'.

Fixes: 26e7aacb83df ("riscv: Allow to downgrade paging mode from the command line")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/9f66d2b58c8052d4055e90b8477ee55d9a0914f9.1698564026.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/kernel/pi/cmdline_early.c

index 68e786c84c949b23b9fa529686fc21ce89e94d64..f6d4dedffb8422051a3598ead6cea3d0bac96d7a 100644 (file)
@@ -38,8 +38,7 @@ static char *get_early_cmdline(uintptr_t dtb_pa)
        if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
            IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
            fdt_cmdline_size == 0 /* CONFIG_CMDLINE_FALLBACK */) {
-               strncat(early_cmdline, CONFIG_CMDLINE,
-                       COMMAND_LINE_SIZE - fdt_cmdline_size);
+               strlcat(early_cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
        }
 
        return early_cmdline;