[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d616ffac-9747-55f8-0478-dd747dba381a@metafoo.de>
Date: Sun, 28 Feb 2021 09:29:01 +0100
From: Lars-Peter Clausen <lars@...afoo.de>
To: Alexandru Ardelean <alexandru.ardelean@...log.com>,
linux-kernel@...r.kernel.org, linux-iio@...r.kernel.org
Cc: Michael.Hennerich@...log.com, jic23@...nel.org, nuno.sa@...log.com,
dragos.bogdan@...log.com
Subject: Re: [PATCH v6 19/24] iio: buffer: introduce support for attaching
more IIO buffers
On 2/15/21 11:40 AM, Alexandru Ardelean wrote:
> static ssize_t iio_show_scan_index(struct device *dev,
> struct device_attribute *attr,
> char *buf)
> @@ -1451,11 +1465,13 @@ static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer)
> iio_free_chan_devattr_list(&buffer->buffer_attr_list);
> }
>
> -int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
> +int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
> {
> [...]
> +error_unwind_sysfs_and_mask:
> + for (; unwind_idx >= 0; unwind_idx--) {
> + buffer = iio_dev_opaque->attached_buffers[unwind_idx];
> + __iio_buffer_free_sysfs_and_mask(buffer);
> + }
> + kfree(iio_dev_opaque->attached_buffers);
> + return ret;
> }
>
> -void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
> +void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev)
> {
> [...]
> + for (i = iio_dev_opaque->attached_buffers_cnt - 1; i >= 0; i--) {
> + buffer = iio_dev_opaque->attached_buffers[i];
> + __iio_buffer_free_sysfs_and_mask(buffer);
> + }
> +
> + kfree(iio_dev_opaque->attached_buffers);
> }
> [...]
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 1d500ea246af..f7f785431106 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1583,7 +1583,7 @@ static void iio_dev_release(struct device *device)
> iio_device_unregister_eventset(indio_dev);
> iio_device_unregister_sysfs(indio_dev);
>
> - iio_buffer_put(indio_dev->buffer);
> + iio_buffers_put(indio_dev);
We do call kfree(iio_dev_opaque->attached_buffers) before we get here. I
think we need to keep the array around, otherwise we end of up with a
use after free.
Powered by blists - more mailing lists