Skip to content

Commit ab0ee36

Browse files
M-Vaittinenjic23
authored andcommitted
iio: adxl372: Fix unsafe buffer attributes
The iio_triggered_buffer_setup_ext() was changed by commit 15097c7 ("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 <[email protected]> Fixes: 15097c7 ("iio: buffer: wrap all buffer attributes into iio_dev_attr") Cc: <[email protected]> Link: https://lore.kernel.org/r/19158499623cdf7f9c5efae1f13c9f1a918ff75f.1664782676.git.mazziesaccount@gmail.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 54246b9 commit ab0ee36

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/iio/accel/adxl372.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -998,17 +998,30 @@ static ssize_t adxl372_get_fifo_watermark(struct device *dev,
998998
return sprintf(buf, "%d\n", st->watermark);
999999
}
10001000

1001-
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
1002-
static IIO_CONST_ATTR(hwfifo_watermark_max,
1003-
__stringify(ADXL372_FIFO_SIZE));
1001+
static ssize_t hwfifo_watermark_min_show(struct device *dev,
1002+
struct device_attribute *attr,
1003+
char *buf)
1004+
{
1005+
return sysfs_emit(buf, "%s\n", "1");
1006+
}
1007+
1008+
static ssize_t hwfifo_watermark_max_show(struct device *dev,
1009+
struct device_attribute *attr,
1010+
char *buf)
1011+
{
1012+
return sysfs_emit(buf, "%s\n", __stringify(ADXL372_FIFO_SIZE));
1013+
}
1014+
1015+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
1016+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
10041017
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
10051018
adxl372_get_fifo_watermark, NULL, 0);
10061019
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
10071020
adxl372_get_fifo_enabled, NULL, 0);
10081021

10091022
static const struct attribute *adxl372_fifo_attributes[] = {
1010-
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
1011-
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
1023+
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
1024+
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
10121025
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
10131026
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
10141027
NULL,

0 commit comments

Comments
 (0)