Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1598460 > unrolled thread

Re: [Outreachy kernel] [PATCH] staging: android: Replace strcpy with strlcpy

Started byJulia Lawall <julia.lawall@lip6.fr>
First post2017-03-11 21:50 +0100
Last post2017-03-12 02:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [Outreachy kernel] [PATCH] staging: android: Replace strcpy with  strlcpy Julia Lawall <julia.lawall@lip6.fr> - 2017-03-11 21:50 +0100
    Re: [Outreachy kernel] [PATCH] staging: android: Replace strcpy with  strlcpy Al Viro <viro@ZenIV.linux.org.uk> - 2017-03-12 02:20 +0100

#1598460 — Re: [Outreachy kernel] [PATCH] staging: android: Replace strcpy with strlcpy

FromJulia Lawall <julia.lawall@lip6.fr>
Date2017-03-11 21:50 +0100
SubjectRe: [Outreachy kernel] [PATCH] staging: android: Replace strcpy with strlcpy
Message-ID<tjW7D-827-3@gated-at.bofh.it>

On Sun, 12 Mar 2017, simran singhal wrote:

> Replace strcpy with strlcpy as strcpy does not check for buffer
> overflow.
> This is found using Flawfinder.
>
> Signed-off-by: simran singhal <singhalsimran0@gmail.com>
> ---
>  drivers/staging/android/ashmem.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
> index 7cbad0d..eb2f4ef 100644
> --- a/drivers/staging/android/ashmem.c
> +++ b/drivers/staging/android/ashmem.c
> @@ -548,7 +548,8 @@ static int set_name(struct ashmem_area *asma, void __user *name)
>  	if (unlikely(asma->file))
>  		ret = -EINVAL;
>  	else
> -		strcpy(asma->name + ASHMEM_NAME_PREFIX_LEN, local_name);
> +		strlcpy(asma->name + ASHMEM_NAME_PREFIX_LEN, local_name,
> +			sizeof(asma->name + ASHMEM_NAME_PREFIX_LEN));

There is a parenthesis in the wrong place.

julia

>
>  	mutex_unlock(&ashmem_mutex);
>  	return ret;
> --
> 2.7.4
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170311204001.GA13301%40singhal-Inspiron-5558.
> For more options, visit https://groups.google.com/d/optout.
>

[toc] | [next] | [standalone]


#1598519

FromAl Viro <viro@ZenIV.linux.org.uk>
Date2017-03-12 02:20 +0100
Message-ID<tk0kV-2EU-1@gated-at.bofh.it>
In reply to#1598460
On Sat, Mar 11, 2017 at 09:47:30PM +0100, Julia Lawall wrote:
> 
> 
> On Sun, 12 Mar 2017, simran singhal wrote:
> 
> > Replace strcpy with strlcpy as strcpy does not check for buffer
> > overflow.
> > This is found using Flawfinder.
> >
> > Signed-off-by: simran singhal <singhalsimran0@gmail.com>
> > ---
> >  drivers/staging/android/ashmem.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
> > index 7cbad0d..eb2f4ef 100644
> > --- a/drivers/staging/android/ashmem.c
> > +++ b/drivers/staging/android/ashmem.c
> > @@ -548,7 +548,8 @@ static int set_name(struct ashmem_area *asma, void __user *name)
> >  	if (unlikely(asma->file))
> >  		ret = -EINVAL;
> >  	else
> > -		strcpy(asma->name + ASHMEM_NAME_PREFIX_LEN, local_name);
> > +		strlcpy(asma->name + ASHMEM_NAME_PREFIX_LEN, local_name,
> > +			sizeof(asma->name + ASHMEM_NAME_PREFIX_LEN));
> 
> There is a parenthesis in the wrong place.

Worse - moving parenthesis to just after asma->name would result in
interestingly bogus value (size + amount skipped instead of size -
amount skipped).

Folks, blind changes in name of security are seriously counterproductive;
fortunately, in this particular case overflow prevention is taken care
of by earlier code (source of strcpy is a local array of size that
isn't enough to cause trouble and it is NUL-terminated), so that
particular strlcpy() is simply pointless, but if not for that...
Variant with sizeof(asma->name) + ASHMEM_NAME_PREFIX_LEN would've
invited an overflow *and* made it harder to spot in the future -
"it uses strlcpy, no worries about overflows here"...

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web