All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] zram: Fix buffer size passed to strlcpy()
@ 2017-07-28 17:12 Matthias Kaehlcke
  2017-08-02 22:54 ` Doug Anderson
  0 siblings, 1 reply; 4+ messages in thread
From: Matthias Kaehlcke @ 2017-07-28 17:12 UTC (permalink / raw)
  To: Minchan Kim, Nitin Gupta, Sergey Senozhatsky
  Cc: linux-kernel, Doug Anderson, Matthias Kaehlcke

comp_algorithm_store() passes the size of the source buffer to strlcpy()
instead of the destination buffer size, fix this.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 drivers/block/zram/zram_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 856d5dc02451..7d2ddffad361 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -327,7 +327,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
 		return -EBUSY;
 	}
 
-	strlcpy(zram->compressor, compressor, sizeof(compressor));
+	strlcpy(zram->compressor, compressor, sizeof(zram->compressor));
 	up_write(&zram->init_lock);
 	return len;
 }
-- 
2.14.0.rc0.400.g1c36432dff-goog

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

* Re: [PATCH] zram: Fix buffer size passed to strlcpy()
  2017-07-28 17:12 [PATCH] zram: Fix buffer size passed to strlcpy() Matthias Kaehlcke
@ 2017-08-02 22:54 ` Doug Anderson
  2017-08-02 23:44   ` Minchan Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Doug Anderson @ 2017-08-02 22:54 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Minchan Kim, Nitin Gupta, Sergey Senozhatsky, linux-kernel

Hi,

On Fri, Jul 28, 2017 at 10:12 AM, Matthias Kaehlcke <mka@chromium.org> wrote:
> comp_algorithm_store() passes the size of the source buffer to strlcpy()
> instead of the destination buffer size, fix this.

This was introduced in commit 415403be37e2 ("zram: use crypto api to
check alg availability"), but probably don't need a "Fixes" since
there's not really a bug (see below)

> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
>  drivers/block/zram/zram_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 856d5dc02451..7d2ddffad361 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -327,7 +327,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
>                 return -EBUSY;
>         }
>
> -       strlcpy(zram->compressor, compressor, sizeof(compressor));
> +       strlcpy(zram->compressor, compressor, sizeof(zram->compressor));

As far as I can tell the two sizes are identical.  In struct zram:

char compressor[CRYPTO_MAX_ALG_NAME];

Locally here:

char compressor[CRYPTO_MAX_ALG_NAME];

...so there is no bug per say unless there's a hidden "#undef".
...but your change does make it a little clearer, plus if someone ever
changed one of these arrays it would be safer.  Thus:

Reviewed-by: Douglas Anderson <dianders@chromium.org>


I suppose another option would be to define the local array based on
the size of the structure.  AKA locally in the function:

  char compressor[ARRAY_SIZE(zram->compressor)];

...if you did that you could replace the strlcpy() below with a simple
strcpy() since you'd be guaranteed that there's be enough space.
...but I'm probably overthinking it too much. ;-P


-Doug

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

* Re: [PATCH] zram: Fix buffer size passed to strlcpy()
  2017-08-02 22:54 ` Doug Anderson
@ 2017-08-02 23:44   ` Minchan Kim
  2017-08-02 23:59     ` Matthias Kaehlcke
  0 siblings, 1 reply; 4+ messages in thread
From: Minchan Kim @ 2017-08-02 23:44 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Matthias Kaehlcke, Nitin Gupta, Sergey Senozhatsky, linux-kernel

Hi Doug,

On Wed, Aug 02, 2017 at 03:54:32PM -0700, Doug Anderson wrote:
> Hi,
> 
> On Fri, Jul 28, 2017 at 10:12 AM, Matthias Kaehlcke <mka@chromium.org> wrote:
> > comp_algorithm_store() passes the size of the source buffer to strlcpy()
> > instead of the destination buffer size, fix this.
> 
> This was introduced in commit 415403be37e2 ("zram: use crypto api to
> check alg availability"), but probably don't need a "Fixes" since
> there's not really a bug (see below)
> 
> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> > ---
> >  drivers/block/zram/zram_drv.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> > index 856d5dc02451..7d2ddffad361 100644
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -327,7 +327,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
> >                 return -EBUSY;
> >         }
> >
> > -       strlcpy(zram->compressor, compressor, sizeof(compressor));
> > +       strlcpy(zram->compressor, compressor, sizeof(zram->compressor));
> 
> As far as I can tell the two sizes are identical.  In struct zram:
> 
> char compressor[CRYPTO_MAX_ALG_NAME];
> 
> Locally here:
> 
> char compressor[CRYPTO_MAX_ALG_NAME];
> 
> ...so there is no bug per say unless there's a hidden "#undef".
> ...but your change does make it a little clearer, plus if someone ever
> changed one of these arrays it would be safer.  Thus:
> 
> Reviewed-by: Douglas Anderson <dianders@chromium.org>
> 
> 
> I suppose another option would be to define the local array based on
> the size of the structure.  AKA locally in the function:
> 
>   char compressor[ARRAY_SIZE(zram->compressor)];
> 
> ...if you did that you could replace the strlcpy() below with a simple
> strcpy() since you'd be guaranteed that there's be enough space.
> ...but I'm probably overthinking it too much. ;-P

First of all, Thanks for the patch, Matthias. You are correct and you
patch doesn't have any problem. However, I think Doug's suggestion
looks better. Could you mind resending?

Thanks.

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

* Re: [PATCH] zram: Fix buffer size passed to strlcpy()
  2017-08-02 23:44   ` Minchan Kim
@ 2017-08-02 23:59     ` Matthias Kaehlcke
  0 siblings, 0 replies; 4+ messages in thread
From: Matthias Kaehlcke @ 2017-08-02 23:59 UTC (permalink / raw)
  To: Minchan Kim; +Cc: Doug Anderson, Nitin Gupta, Sergey Senozhatsky, linux-kernel

El Thu, Aug 03, 2017 at 08:44:37AM +0900 Minchan Kim ha dit:

> Hi Doug,
> 
> On Wed, Aug 02, 2017 at 03:54:32PM -0700, Doug Anderson wrote:
> > Hi,
> > 
> > On Fri, Jul 28, 2017 at 10:12 AM, Matthias Kaehlcke <mka@chromium.org> wrote:
> > > comp_algorithm_store() passes the size of the source buffer to strlcpy()
> > > instead of the destination buffer size, fix this.
> > 
> > This was introduced in commit 415403be37e2 ("zram: use crypto api to
> > check alg availability"), but probably don't need a "Fixes" since
> > there's not really a bug (see below)
> > 
> > > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> > > ---
> > >  drivers/block/zram/zram_drv.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> > > index 856d5dc02451..7d2ddffad361 100644
> > > --- a/drivers/block/zram/zram_drv.c
> > > +++ b/drivers/block/zram/zram_drv.c
> > > @@ -327,7 +327,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
> > >                 return -EBUSY;
> > >         }
> > >
> > > -       strlcpy(zram->compressor, compressor, sizeof(compressor));
> > > +       strlcpy(zram->compressor, compressor, sizeof(zram->compressor));
> > 
> > As far as I can tell the two sizes are identical.  In struct zram:
> > 
> > char compressor[CRYPTO_MAX_ALG_NAME];
> > 
> > Locally here:
> > 
> > char compressor[CRYPTO_MAX_ALG_NAME];
> > 
> > ...so there is no bug per say unless there's a hidden "#undef".
> > ...but your change does make it a little clearer, plus if someone ever
> > changed one of these arrays it would be safer.  Thus:
> > 
> > Reviewed-by: Douglas Anderson <dianders@chromium.org>
> > 
> > 
> > I suppose another option would be to define the local array based on
> > the size of the structure.  AKA locally in the function:
> > 
> >   char compressor[ARRAY_SIZE(zram->compressor)];
> > 
> > ...if you did that you could replace the strlcpy() below with a simple
> > strcpy() since you'd be guaranteed that there's be enough space.
> > ...but I'm probably overthinking it too much. ;-P
> 
> First of all, Thanks for the patch, Matthias. You are correct and you
> patch doesn't have any problem. However, I think Doug's suggestion
> looks better. Could you mind resending?

Sure, I can rework the patch.

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

end of thread, other threads:[~2017-08-02 23:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-28 17:12 [PATCH] zram: Fix buffer size passed to strlcpy() Matthias Kaehlcke
2017-08-02 22:54 ` Doug Anderson
2017-08-02 23:44   ` Minchan Kim
2017-08-02 23:59     ` Matthias Kaehlcke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.