Patch "iio: cros_ec: fix an use-after-free in cros_ec_sensors_push_data()" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    iio: cros_ec: fix an use-after-free in cros_ec_sensors_push_data()

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     iio-cros_ec-fix-an-use-after-free-in-cros_ec_sensors.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 0de7a380026dc67c494104cd8e64a70ae58efa9e
Author: Tzung-Bi Shih <tzungbi@xxxxxxxxxx>
Date:   Tue Aug 29 11:06:22 2023 +0800

    iio: cros_ec: fix an use-after-free in cros_ec_sensors_push_data()
    
    [ Upstream commit 7771c8c80d62ad065637ef74ed2962983f6c5f6d ]
    
    cros_ec_sensors_push_data() reads `indio_dev->active_scan_mask` and
    calls iio_push_to_buffers_with_timestamp() without making sure the
    `indio_dev` stays in buffer mode.  There is a race if `indio_dev` exits
    buffer mode right before cros_ec_sensors_push_data() accesses them.
    
    An use-after-free on `indio_dev->active_scan_mask` was observed.  The
    call trace:
    [...]
     _find_next_bit
     cros_ec_sensors_push_data
     cros_ec_sensorhub_event
     blocking_notifier_call_chain
     cros_ec_irq_thread
    
    It was caused by a race condition: one thread just freed
    `active_scan_mask` at [1]; while another thread tried to access the
    memory at [2].
    
    Fix it by calling iio_device_claim_buffer_mode() to ensure the
    `indio_dev` can't exit buffer mode during cros_ec_sensors_push_data().
    
    [1]: https://elixir.bootlin.com/linux/v6.5/source/drivers/iio/industrialio-buffer.c#L1189
    [2]: https://elixir.bootlin.com/linux/v6.5/source/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c#L198
    
    Cc: stable@xxxxxxxxxxxxxxx
    Fixes: aa984f1ba4a4 ("iio: cros_ec: Register to cros_ec_sensorhub when EC supports FIFO")
    Signed-off-by: Tzung-Bi Shih <tzungbi@xxxxxxxxxx>
    Reviewed-by: Guenter Roeck <groeck@xxxxxxxxxxxx>
    Reviewed-by: Stephen Boyd <swboyd@xxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20230829030622.1571852-1-tzungbi@xxxxxxxxxx
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index d98f7e4d202c1..1ddce991fb3f4 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -190,8 +190,11 @@ int cros_ec_sensors_push_data(struct iio_dev *indio_dev,
 	/*
 	 * Ignore samples if the buffer is not set: it is needed if the ODR is
 	 * set but the buffer is not enabled yet.
+	 *
+	 * Note: iio_device_claim_buffer_mode() returns -EBUSY if the buffer
+	 * is not enabled.
 	 */
-	if (!iio_buffer_enabled(indio_dev))
+	if (iio_device_claim_buffer_mode(indio_dev) < 0)
 		return 0;
 
 	out = (s16 *)st->samples;
@@ -210,6 +213,7 @@ int cros_ec_sensors_push_data(struct iio_dev *indio_dev,
 	iio_push_to_buffers_with_timestamp(indio_dev, st->samples,
 					   timestamp + delta);
 
+	iio_device_release_buffer_mode(indio_dev);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cros_ec_sensors_push_data);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux