Skip to content

Commit a10a0f3

Browse files
M-Vaittinenjic23
authored andcommitted
iio: bmc150-accel-core: 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") Link: https://lore.kernel.org/r/cf8a56658fc38db8bed64f456d898f5ad5a2814f.1664782676.git.mazziesaccount@gmail.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 5e23b33 commit a10a0f3

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/iio/accel/bmc150-accel-core.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,17 +925,30 @@ static const struct iio_chan_spec_ext_info bmc150_accel_ext_info[] = {
925925
{ }
926926
};
927927

928-
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
929-
static IIO_CONST_ATTR(hwfifo_watermark_max,
930-
__stringify(BMC150_ACCEL_FIFO_LENGTH));
928+
static ssize_t hwfifo_watermark_min_show(struct device *dev,
929+
struct device_attribute *attr,
930+
char *buf)
931+
{
932+
return sysfs_emit(buf, "%s\n", "1");
933+
}
934+
935+
static ssize_t hwfifo_watermark_max_show(struct device *dev,
936+
struct device_attribute *attr,
937+
char *buf)
938+
{
939+
return sysfs_emit(buf, "%s\n", __stringify(BMC150_ACCEL_FIFO_LENGTH));
940+
}
941+
942+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
943+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
931944
static IIO_DEVICE_ATTR(hwfifo_enabled, S_IRUGO,
932945
bmc150_accel_get_fifo_state, NULL, 0);
933946
static IIO_DEVICE_ATTR(hwfifo_watermark, S_IRUGO,
934947
bmc150_accel_get_fifo_watermark, NULL, 0);
935948

936949
static const struct attribute *bmc150_accel_fifo_attributes[] = {
937-
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
938-
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
950+
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
951+
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
939952
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
940953
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
941954
NULL,

0 commit comments

Comments
 (0)