linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] m68k/kernel: array out of bound access in process_uboot_commandline
@ 2021-12-27  9:09 Hangyu Hua
  2021-12-27  9:19 ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Hangyu Hua @ 2021-12-27  9:09 UTC (permalink / raw)
  To: geert; +Cc: linux-m68k, linux-kernel, Hangyu Hua

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

Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 arch/m68k/kernel/uboot.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/m68k/kernel/uboot.c b/arch/m68k/kernel/uboot.c
index 928dbd33fc4a..05eca6f653b5 100644
--- a/arch/m68k/kernel/uboot.c
+++ b/arch/m68k/kernel/uboot.c
@@ -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;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] m68k/kernel: array out of bound access in process_uboot_commandline
  2021-12-27  9:09 [PATCH] m68k/kernel: array out of bound access in process_uboot_commandline Hangyu Hua
@ 2021-12-27  9:19 ` Andreas Schwab
  2021-12-27 11:52   ` Hangyu Hua
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2021-12-27  9:19 UTC (permalink / raw)
  To: Hangyu Hua; +Cc: geert, linux-m68k, linux-kernel

On Dez 27 2021, Hangyu Hua wrote:

> diff --git a/arch/m68k/kernel/uboot.c b/arch/m68k/kernel/uboot.c
> index 928dbd33fc4a..05eca6f653b5 100644
> --- a/arch/m68k/kernel/uboot.c
> +++ b/arch/m68k/kernel/uboot.c
> @@ -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, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] m68k/kernel: array out of bound access in process_uboot_commandline
  2021-12-27  9:19 ` Andreas Schwab
@ 2021-12-27 11:52   ` Hangyu Hua
  2021-12-27 11:56     ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Hangyu Hua @ 2021-12-27 11:52 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: geert, linux-m68k, linux-kernel

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.


Andreas Schwab <schwab@linux-m68k.org> 于2021年12月27日周一 17:19写道:
>
> On Dez 27 2021, Hangyu Hua wrote:
>
> > diff --git a/arch/m68k/kernel/uboot.c b/arch/m68k/kernel/uboot.c
> > index 928dbd33fc4a..05eca6f653b5 100644
> > --- a/arch/m68k/kernel/uboot.c
> > +++ b/arch/m68k/kernel/uboot.c
> > @@ -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, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] m68k/kernel: array out of bound access in process_uboot_commandline
  2021-12-27 11:52   ` Hangyu Hua
@ 2021-12-27 11:56     ` Andreas Schwab
  2021-12-27 12:50       ` Hangyu Hua
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2021-12-27 11:56 UTC (permalink / raw)
  To: Hangyu Hua; +Cc: geert, linux-m68k, linux-kernel

On Dez 27 2021, Hangyu Hua wrote:

> 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, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] m68k/kernel: array out of bound access in process_uboot_commandline
  2021-12-27 11:56     ` Andreas Schwab
@ 2021-12-27 12:50       ` Hangyu Hua
  0 siblings, 0 replies; 5+ messages in thread
From: Hangyu Hua @ 2021-12-27 12:50 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: geert, linux-m68k, linux-kernel

You are right. I will resubmit the patch later.

Thanks.

Andreas Schwab <schwab@linux-m68k.org> 于2021年12月27日周一 19:56写道:
>
> On Dez 27 2021, Hangyu Hua wrote:
>
> > 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, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-27 12:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-27  9:09 [PATCH] m68k/kernel: array out of bound access in process_uboot_commandline Hangyu Hua
2021-12-27  9:19 ` Andreas Schwab
2021-12-27 11:52   ` Hangyu Hua
2021-12-27 11:56     ` Andreas Schwab
2021-12-27 12:50       ` Hangyu Hua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).