All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Masney <masneyb@onstation.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Jon Brenner <jbrenner@taosinc.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Eva Rachel Retuya <eraretuya@gmail.com>,
	linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] iio: tsl2583: off by one in in_illuminance_lux_table_store()
Date: Fri, 18 Nov 2016 14:03:26 +0000	[thread overview]
Message-ID: <20161118140326.GA20458@basecamp.onstation.org> (raw)
In-Reply-To: <20161118115153.GC3281@mwanda>

On Fri, Nov 18, 2016 at 02:51:54PM +0300, Dan Carpenter wrote:
> The value[] array has "max_ints" elements so this should be >= instead
> of >.
> 
> Fixes: ac4f6eee8fe8 ("staging: iio: TAOS tsl258x: Device driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
> index 0b87f6a..faef6bd 100644
> --- a/drivers/iio/light/tsl2583.c
> +++ b/drivers/iio/light/tsl2583.c
> @@ -580,7 +580,7 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
>  	 * and the last table entry is all 0.
>  	 */
>  	n = value[0];
> -	if ((n % 3) || n < 6 || n > max_ints) {
> +	if ((n % 3) || n < 6 || n >= max_ints) {
>  		dev_err(dev,
>  			"%s: The number of entries in the lux table must be a multiple of 3 and within the range [6, %d]\n",
>  			__func__, max_ints);

Hi Dan,
   Good catch! I believe that this should use a different fix though.
The definition of value in in_illuminance_lux_table_store() should be
changed from:

int value[TSL2583_MAX_LUX_TABLE_ENTRIES * 3];

to:

int value[(TSL2583_MAX_LUX_TABLE_ENTRIES * 3) + 1];

This will allow storing the extra integer from get_options() containing
the integer count.

Otherwise, with your propsed change, someone would only be able to use
9 entries in the device lux table rather than the 10 that are set aside.

Also, this may be (well is) nit picking, but I had [6, 33] in the error
message to mark the range as inclusive on both ends. If it was exclusive
on the upper end, then the error message should have also been changed
to be [6, 33).

Brian


WARNING: multiple messages have this Message-ID (diff)
From: Brian Masney <masneyb@onstation.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Jon Brenner <jbrenner@taosinc.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Eva Rachel Retuya <eraretuya@gmail.com>,
	linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] iio: tsl2583: off by one in in_illuminance_lux_table_store()
Date: Fri, 18 Nov 2016 09:03:26 -0500	[thread overview]
Message-ID: <20161118140326.GA20458@basecamp.onstation.org> (raw)
In-Reply-To: <20161118115153.GC3281@mwanda>

On Fri, Nov 18, 2016 at 02:51:54PM +0300, Dan Carpenter wrote:
> The value[] array has "max_ints" elements so this should be >= instead
> of >.
> 
> Fixes: ac4f6eee8fe8 ("staging: iio: TAOS tsl258x: Device driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
> index 0b87f6a..faef6bd 100644
> --- a/drivers/iio/light/tsl2583.c
> +++ b/drivers/iio/light/tsl2583.c
> @@ -580,7 +580,7 @@ static ssize_t in_illuminance_lux_table_store(struct device *dev,
>  	 * and the last table entry is all 0.
>  	 */
>  	n = value[0];
> -	if ((n % 3) || n < 6 || n > max_ints) {
> +	if ((n % 3) || n < 6 || n >= max_ints) {
>  		dev_err(dev,
>  			"%s: The number of entries in the lux table must be a multiple of 3 and within the range [6, %d]\n",
>  			__func__, max_ints);

Hi Dan,
   Good catch! I believe that this should use a different fix though.
The definition of value in in_illuminance_lux_table_store() should be
changed from:

int value[TSL2583_MAX_LUX_TABLE_ENTRIES * 3];

to:

int value[(TSL2583_MAX_LUX_TABLE_ENTRIES * 3) + 1];

This will allow storing the extra integer from get_options() containing
the integer count.

Otherwise, with your propsed change, someone would only be able to use
9 entries in the device lux table rather than the 10 that are set aside.

Also, this may be (well is) nit picking, but I had [6, 33] in the error
message to mark the range as inclusive on both ends. If it was exclusive
on the upper end, then the error message should have also been changed
to be [6, 33).

Brian

  reply	other threads:[~2016-11-18 14:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18 11:51 [patch] iio: tsl2583: off by one in in_illuminance_lux_table_store() Dan Carpenter
2016-11-18 11:51 ` Dan Carpenter
2016-11-18 14:03 ` Brian Masney [this message]
2016-11-18 14:03   ` Brian Masney
2016-11-24 13:38   ` [patch] iio: tsl2583: make array large enough Dan Carpenter
2016-11-24 13:38     ` Dan Carpenter
2016-11-24 15:48     ` Brian Masney
2016-11-24 15:48       ` Brian Masney
2016-11-24 16:54       ` walter harms
2016-11-24 16:54         ` walter harms
2016-11-24 17:51         ` Brian Masney
2016-11-24 17:51           ` Brian Masney
2016-11-24 20:12           ` Jonathan Cameron
2016-11-24 20:12             ` Jonathan Cameron
2016-11-25  8:53           ` walter harms
2016-11-25  8:53             ` walter harms

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161118140326.GA20458@basecamp.onstation.org \
    --to=masneyb@onstation.org \
    --cc=dan.carpenter@oracle.com \
    --cc=eraretuya@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbrenner@taosinc.com \
    --cc=jic23@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.