Skip to content

Commit 5e23b33

Browse files
M-Vaittinenjic23
authored andcommitted
iio: adxl367: Fix unsafe buffer attributes
The devm_iio_kfifo_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/2e2d9ec34fb1df8ab8e2749199822db8cc91d302.1664782676.git.mazziesaccount@gmail.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent ab0ee36 commit 5e23b33

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/iio/accel/adxl367.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,17 +1185,30 @@ static ssize_t adxl367_get_fifo_watermark(struct device *dev,
11851185
return sysfs_emit(buf, "%d\n", fifo_watermark);
11861186
}
11871187

1188-
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
1189-
static IIO_CONST_ATTR(hwfifo_watermark_max,
1190-
__stringify(ADXL367_FIFO_MAX_WATERMARK));
1188+
static ssize_t hwfifo_watermark_min_show(struct device *dev,
1189+
struct device_attribute *attr,
1190+
char *buf)
1191+
{
1192+
return sysfs_emit(buf, "%s\n", "1");
1193+
}
1194+
1195+
static ssize_t hwfifo_watermark_max_show(struct device *dev,
1196+
struct device_attribute *attr,
1197+
char *buf)
1198+
{
1199+
return sysfs_emit(buf, "%s\n", __stringify(ADXL367_FIFO_MAX_WATERMARK));
1200+
}
1201+
1202+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
1203+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
11911204
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
11921205
adxl367_get_fifo_watermark, NULL, 0);
11931206
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
11941207
adxl367_get_fifo_enabled, NULL, 0);
11951208

11961209
static const struct attribute *adxl367_fifo_attributes[] = {
1197-
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
1198-
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
1210+
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
1211+
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
11991212
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
12001213
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
12011214
NULL,

0 commit comments

Comments
 (0)