]> git.itanic.dy.fi Git - linux-stable/commitdiff
kdb: Fix a potential buffer overflow in kdb_local()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 25 Nov 2023 12:05:04 +0000 (13:05 +0100)
committerDaniel Thompson <daniel.thompson@linaro.org>
Wed, 17 Jan 2024 17:19:06 +0000 (17:19 +0000)
When appending "[defcmd]" to 'kdb_prompt_str', the size of the string
already in the buffer should be taken into account.

An option could be to switch from strncat() to strlcat() which does the
correct test to avoid such an overflow.

However, this actually looks as dead code, because 'defcmd_in_progress'
can't be true here.
See a more detailed explanation at [1].

[1]: https://lore.kernel.org/all/CAD=FV=WSh7wKN7Yp-3wWiDgX4E3isQ8uh0LCzTmd1v9Cg9j+nQ@mail.gmail.com/

Fixes: 5d5314d6795f ("kdb: core for kgdb back end (1 of 2)")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
kernel/debug/kdb/kdb_main.c

index 6b213c8252d62df7a30dd2b0f861e6bb1895be36..d05066cb40b2ee504d780b5f9ea5d16e17bcbbd1 100644 (file)
@@ -1348,8 +1348,6 @@ static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs,
                /* PROMPT can only be set if we have MEM_READ permission. */
                snprintf(kdb_prompt_str, CMD_BUFLEN, kdbgetenv("PROMPT"),
                         raw_smp_processor_id());
-               if (defcmd_in_progress)
-                       strncat(kdb_prompt_str, "[defcmd]", CMD_BUFLEN);
 
                /*
                 * Fetch command from keyboard