Skip to contentSkip to conversation

m68k/kernel: array out of bound access in process_uboot_commandline

PATCH Superseded Hangyu Hua 2 participants 5 messages Dec 27, 2021 m68k architecture

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 m68k/kernel: array out of bound access in process_uboot_commandline

When the size of commandp >= size, array out of bound write occurs because len == 0.

---
 arch/m68k/kernel/uboot.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/m68k/kernel/uboot.c +4 -1
index 928dbd33fc4a..05eca6f653b5 100644
@@ -101,5 +101,8 @@ __init void process_uboot_commandline(char *commandp, int size)
 	}
 
 	parse_uboot_commandline(commandp, len);
-	commandp[len - 1] = 0;
+	if (len > 0)
+		commandp[len - 1] = 0;
+	else
+		commandp[0] = 0;
 }
Signature · 1 line
2.25.1
#1 lore raw

arch/m68k/kernel/uboot.c __init void process_uboot_commandline(char *commandp, int size) · line 107

Quoted 13 lines · Hangyu Hua
arch/m68k/kernel/uboot.c +4 -1
index 928dbd33fc4a..05eca6f653b5 100644
@@ -101,5 +101,8 @@ __init void process_uboot_commandline(char *commandp, int size)
 	}
 
 	parse_uboot_commandline(commandp, len);
-	commandp[len - 1] = 0;
+	if (len > 0)
+		commandp[len - 1] = 0;
+	else
+		commandp[0] = 0;

If len == 0 then even commandp[0] is OOB.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
author
#2 lore raw

But commandp[len -1] is used to add a zero-terminated. If we don't use commandp[0]=0 in len == 0,
than commandp will not have a zero-terminated. I think strings may make some errors beacause of this.

Thanks.

Quoted 23 lines · Andreas Schwab <[email protected]> 于2021年12月27日周一 17:19写道:

arch/m68k/kernel/uboot.c __init void process_uboot_commandline(char *commandp, int size) · line 107

Quoted 13 lines · Hangyu Hua
arch/m68k/kernel/uboot.c +4 -1
index 928dbd33fc4a..05eca6f653b5 100644
@@ -101,5 +101,8 @@ __init void process_uboot_commandline(char *commandp, int size)
      }
 
      parse_uboot_commandline(commandp, len);
-     commandp[len - 1] = 0;
+     if (len > 0)
+             commandp[len - 1] = 0;
+     else
+             commandp[0] = 0;

If len == 0 then even commandp[0] is OOB.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."

#3 lore raw
Quoted 3 lines · Hangyu Hua

If we don't use
commandp[0]=0 in len == 0,
than commandp will not have a zero-terminated.

That doesn't make sense. There is no room for the zero.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
author
#4 lore raw

You are right. I will resubmit the patch later.

Thanks.

Quoted 13 lines · Andreas Schwab <[email protected]> 于2021年12月27日周一 19:56写道:
Quoted 3 lines · Hangyu Hua

If we don't use
commandp[0]=0 in len == 0,
than commandp will not have a zero-terminated.

That doesn't make sense. There is no room for the zero.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."