m68k/kernel: array out of bound access in process_uboot_commandline
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
@@ -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
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@@ -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."
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@@ -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."
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."
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."