Commit 21b7b62e authored by Young Xiao's avatar Young Xiao Committed by Stefan Bader

Drivers: misc: fix out-of-bounds access in function param_set_kgdbts_var

BugLink: https://bugs.launchpad.net/bugs/1836666

[ Upstream commit b281218a ]

There is an out-of-bounds access to "config[len - 1]" array when the
variable "len" is zero.

See commit dada6a43 ("kgdboc: fix KASAN global-out-of-bounds bug
in param_set_kgdboc_var()") for details.
Signed-off-by: default avatarYoung Xiao <YangX92@hotmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent e02cf1c8
...@@ -1132,7 +1132,7 @@ static void kgdbts_put_char(u8 chr) ...@@ -1132,7 +1132,7 @@ static void kgdbts_put_char(u8 chr)
static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp) static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp)
{ {
int len = strlen(kmessage); size_t len = strlen(kmessage);
if (len >= MAX_CONFIG_LEN) { if (len >= MAX_CONFIG_LEN) {
printk(KERN_ERR "kgdbts: config string too long\n"); printk(KERN_ERR "kgdbts: config string too long\n");
...@@ -1152,7 +1152,7 @@ static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp) ...@@ -1152,7 +1152,7 @@ static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp)
strcpy(config, kmessage); strcpy(config, kmessage);
/* Chop out \n char as a result of echo */ /* Chop out \n char as a result of echo */
if (config[len - 1] == '\n') if (len && config[len - 1] == '\n')
config[len - 1] = '\0'; config[len - 1] = '\0';
/* Go and configure with the new params. */ /* Go and configure with the new params. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment