All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: "Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Alexandru Ardelean" <alexandru.ardelean@analog.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
	"Miaoqian Lin" <linmq006@gmail.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 03/10] iio: bmc150-accel-core: Fix unsafe buffer attributes
Date: Sun, 16 Oct 2022 12:13:32 +0100	[thread overview]
Message-ID: <20221016121332.4240fe60@jic23-huawei> (raw)
In-Reply-To: <cf8a56658fc38db8bed64f456d898f5ad5a2814f.1664782676.git.mazziesaccount@gmail.com>

On Mon, 3 Oct 2022 11:11:12 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:

> The iio_triggered_buffer_setup_ext() was changed by
> commit 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
> to silently expect that all attributes given in buffer_attrs array are
> device-attributes. This expectation was not forced by the API - and some
> drivers did register attributes created by IIO_CONST_ATTR().
> 
> The added attribute "wrapping" does not copy the pointer to stored
> string constant and when the sysfs file is read the kernel will access
> to invalid location.
> 
> Change the IIO_CONST_ATTRs from the driver to IIO_DEVICE_ATTR in order
> to prevent the invalid memory access.
> 
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> Fixes: 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

> 
> ---
> 
> v2 => v3:
> Split change to own patch for simpler fix backporting.
> ---
>  drivers/iio/accel/bmc150-accel-core.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 57e8a8350cd1..92f8b139acce 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -925,17 +925,30 @@ static const struct iio_chan_spec_ext_info bmc150_accel_ext_info[] = {
>  	{ }
>  };
>  
> -static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
> -static IIO_CONST_ATTR(hwfifo_watermark_max,
> -		      __stringify(BMC150_ACCEL_FIFO_LENGTH));
> +static ssize_t hwfifo_watermark_min_show(struct device *dev,
> +					 struct device_attribute *attr,
> +					 char *buf)
> +{
> +	return sysfs_emit(buf, "%s\n", "1");
> +}
> +
> +static ssize_t hwfifo_watermark_max_show(struct device *dev,
> +					 struct device_attribute *attr,
> +					 char *buf)
> +{
> +	return sysfs_emit(buf, "%s\n", __stringify(BMC150_ACCEL_FIFO_LENGTH));
> +}
> +
> +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
> +static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
>  static IIO_DEVICE_ATTR(hwfifo_enabled, S_IRUGO,
>  		       bmc150_accel_get_fifo_state, NULL, 0);
>  static IIO_DEVICE_ATTR(hwfifo_watermark, S_IRUGO,
>  		       bmc150_accel_get_fifo_watermark, NULL, 0);
>  
>  static const struct attribute *bmc150_accel_fifo_attributes[] = {
> -	&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
> -	&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
> +	&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
> +	&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
>  	&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
>  	&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
>  	NULL,


  reply	other threads:[~2022-10-16 11:13 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-03  8:09 [PATCH v3 00/10] iio: Fix unsafe buffer attributes Matti Vaittinen
2022-10-03  8:09 ` Matti Vaittinen
2022-10-03  8:10 ` [PATCH v3 01/10] iio: adxl367: " Matti Vaittinen
2022-10-16 11:12   ` Jonathan Cameron
2022-10-03  8:10 ` [PATCH v3 02/10] iio: adxl372: " Matti Vaittinen
2022-10-16 11:12   ` Jonathan Cameron
2022-10-03  8:11 ` [PATCH v3 03/10] iio: bmc150-accel-core: " Matti Vaittinen
2022-10-16 11:13   ` Jonathan Cameron [this message]
2022-10-03  8:11 ` [PATCH v3 04/10] iio: at91-sama5d2_adc: " Matti Vaittinen
2022-10-03  8:11   ` Matti Vaittinen
2022-10-06  8:34   ` Claudiu.Beznea
2022-10-06  8:34     ` Claudiu.Beznea
2022-10-16 11:14     ` Jonathan Cameron
2022-10-16 11:14       ` Jonathan Cameron
2022-10-03  8:12 ` [PATCH v3 05/10] iio: Add IIO_STATIC_CONST_DEVICE_ATTR Matti Vaittinen
2022-10-03  8:12 ` [PATCH v3 06/10] iio: adxl367: Use IIO_STATIC_CONST_DEVICE_ATTR() Matti Vaittinen
2022-10-03  8:12 ` [PATCH v3 07/10] iio: adxl372: " Matti Vaittinen
2022-10-03  8:13 ` [PATCH v3 08/10] iio: bmc150-accel-core: " Matti Vaittinen
2022-10-03  8:13 ` [PATCH v3 09/10] iio: at91-sama5d2_adc: " Matti Vaittinen
2022-10-03  8:13   ` Matti Vaittinen
2022-10-06  8:35   ` Claudiu.Beznea
2022-10-06  8:35     ` Claudiu.Beznea
2022-10-03  8:13 ` [RFT PATCH v3 10/10] iio: Don't silently expect attribute types Matti Vaittinen
2022-10-03  8:13   ` Matti Vaittinen
2022-10-03  8:43   ` Andy Shevchenko
2022-10-03  8:43     ` Andy Shevchenko
2022-10-03  8:58     ` Matti Vaittinen
2022-10-03  8:58       ` Matti Vaittinen
2022-10-03  9:02       ` Matti Vaittinen
2022-10-03  9:02         ` Matti Vaittinen
2022-10-03  9:39         ` Andy Shevchenko
2022-10-03  9:39           ` Andy Shevchenko
2022-10-03  9:42       ` Andy Shevchenko
2022-10-03  9:42         ` Andy Shevchenko
2022-10-06  8:35   ` Claudiu.Beznea
2022-10-06  8:35     ` Claudiu.Beznea
2022-10-06 12:53     ` Matti Vaittinen
2022-10-06 12:53       ` Matti Vaittinen
2022-10-09 17:38       ` Jonathan Cameron
2022-10-09 17:38         ` Jonathan Cameron
2022-10-10  9:36         ` Matti Vaittinen
2022-10-10  9:36           ` Matti Vaittinen
2022-11-05 14:45           ` Jonathan Cameron
2022-11-05 14:45             ` 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=20221016121332.4240fe60@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=alexandru.ardelean@analog.com \
    --cc=lars@metafoo.de \
    --cc=linmq006@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mazziesaccount@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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.