public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Karol Wrona <k.wrona@samsung.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] iio: ssp_sensors: add more range checking in ssp_parse_dataframe()
Date: Sat, 11 Sep 2021 16:42:53 +0100	[thread overview]
Message-ID: <20210911164253.260be729@jic23-huawei> (raw)
In-Reply-To: <20210909091336.GA26312@kili>

On Thu, 9 Sep 2021 12:13:36 +0300
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> The "idx" is validated at the start of the loop but it gets incremented
> during the iteration so it needs to be checked again.
> 
> Fixes: 50dd64d57eee ("iio: common: ssp_sensors: Add sensorhub driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

This is only a fix if we assume that the len value check is there
as a protection against buffer overrun rather than as a termination condition
that occurs when parsing a valid record.

There is more paranoid checking in ssp_print_mc_debug() so it seems we aren't assuming
valid data in there at least.

Still is this perhaps a case of hardening rather than a fix or am I missing something?

As an aside, if that ssp_print_mcu_debug() reads a negative char it is then
returned directly so we get a random small negative number as the error code which
isn't going to be very useful.

Jonathan


> ---
>  drivers/iio/common/ssp_sensors/ssp_spi.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/common/ssp_sensors/ssp_spi.c b/drivers/iio/common/ssp_sensors/ssp_spi.c
> index 4864c38b8d1c..387551eac184 100644
> --- a/drivers/iio/common/ssp_sensors/ssp_spi.c
> +++ b/drivers/iio/common/ssp_sensors/ssp_spi.c
> @@ -273,6 +273,8 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
>  	for (idx = 0; idx < len;) {
>  		switch (dataframe[idx++]) {
>  		case SSP_MSG2AP_INST_BYPASS_DATA:
> +			if (idx >= len)
> +				return -EPROTO;
>  			sd = dataframe[idx++];
>  			if (sd < 0 || sd >= SSP_SENSOR_MAX) {
>  				dev_err(SSP_DEV,
> @@ -282,10 +284,13 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
>  
>  			if (indio_devs[sd]) {
>  				spd = iio_priv(indio_devs[sd]);
> -				if (spd->process_data)
> +				if (spd->process_data) {
> +					if (idx >= len)
> +						return -EPROTO;
>  					spd->process_data(indio_devs[sd],
>  							  &dataframe[idx],
>  							  data->timestamp);
> +				}
>  			} else {
>  				dev_err(SSP_DEV, "no client for frame\n");
>  			}
> @@ -293,6 +298,8 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
>  			idx += ssp_offset_map[sd];
>  			break;
>  		case SSP_MSG2AP_INST_DEBUG_DATA:
> +			if (idx >= len)
> +				return -EPROTO;
>  			sd = ssp_print_mcu_debug(dataframe, &idx, len);
>  			if (sd) {
>  				dev_err(SSP_DEV,


  reply	other threads:[~2021-09-11 15:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09  9:13 [PATCH] iio: ssp_sensors: add more range checking in ssp_parse_dataframe() Dan Carpenter
2021-09-11 15:42 ` Jonathan Cameron [this message]
2021-09-13  7:37   ` Dan Carpenter
2021-09-18 18:12     ` Jonathan Cameron

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=20210911164253.260be729@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=dan.carpenter@oracle.com \
    --cc=k.wrona@samsung.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox