patch "iio: triggered-buffer: prevent possible freeing of wrong buffer" added to char-misc-linus
Subsystems (2)
This is a note to let you know that I've just added the patch titled
iio: triggered-buffer: prevent possible freeing of wrong buffer
to my char-misc git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
in the char-misc-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From bce61476dc82f114e24e9c2e11fb064781ec563c Mon Sep 17 00:00:00 2001
From: David Lechner <[email protected]>
Date: Tue, 31 Oct 2023 16:05:19 -0500
Subject: iio: triggered-buffer: prevent possible freeing of wrong buffer
Commit ee708e6baacd ("iio: buffer: introduce support for attaching more IIO buffers") introduced support for multiple buffers per indio_dev but left indio_dev->buffer for a few legacy use cases.
In the case of the triggered buffer, iio_triggered_buffer_cleanup() still assumes that indio_dev->buffer points to the buffer allocated by iio_triggered_buffer_setup_ext(). However, since iio_triggered_buffer_setup_ext() now calls iio_device_attach_buffer() to attach the buffer, indio_dev->buffer will only point to the buffer allocated by iio_device_attach_buffer() if it the first buffer attached.
This adds a check to make sure that no other buffer has been attached yet to ensure that indio_dev->buffer will be assigned when iio_device_attach_buffer() is called.
As per discussion in the review thread, we may want to deal with multiple triggers per device, but this is a fix for the issue in the meantime and any such support would be unlikely to be suitable for a backport.
--- drivers/iio/buffer/industrialio-triggered-buffer.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/iio/buffer/industrialio-triggered-buffer.c +10 -0
@@ -46,6 +46,16 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,struct iio_buffer *buffer;int ret; +/* +* iio_triggered_buffer_cleanup() assumes that the buffer allocated here +* is assigned to indio_dev->buffer but this is only the case if this +* function is the first caller to iio_device_attach_buffer(). If +* indio_dev->buffer is already set then we can't proceed otherwise the +* cleanup function will try to free a buffer that was not allocated here. +*/ +if (indio_dev->buffer) +return -EADDRINUSE ; + buffer =iio_kfifo_allocate ();if (!buffer) { ret = -ENOMEM ;
Signature · 1 line
2.43.0