Skip to contentSkip to conversation

platform/chrome: cros_ec_sensorhub: Off by one in cros_sensorhub_send_sample()

PATCH Applied Dan Carpenter 3 participants 3 messages Apr 7, 2020 – Apr 13, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/chrome: cros_ec_sensorhub: Off by one in cros_sensorhub_send_sample()

The sensorhub->push_data[] array has sensorhub->sensor_num elements.
It's allocated in cros_ec_sensorhub_ring_add(). So the > should be >to prevent a read one element beyond the end of the array.

Fixes 145d59baff59 ("platform/chrome: cros_ec_sensorhub: Add FIFO support")
---
 drivers/platform/chrome/cros_ec_sensorhub_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +1 -1
index 230e6cf3da2f..85e8ba782f0c 100644
@@ -40,7 +40,7 @@ cros_sensorhub_send_sample(struct cros_ec_sensorhub *sensorhub,
 	int id = sample->sensor_id;
 	struct iio_dev *indio_dev;
 
-	if (id > sensorhub->sensor_num)
+	if (id >= sensorhub->sensor_num)
 		return -EINVAL;
 
 	cb = sensorhub->push_data[id].push_data_cb;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

The sensorhub->push_data[] array has sensorhub->sensor_num elements.
It's allocated in cros_ec_sensorhub_ring_add(). So the > should be >> to prevent a read one element beyond the end of the array.

Fixes 145d59baff59 ("platform/chrome: cros_ec_sensorhub: Add FIFO support")
Quoted 20 lines
---
 drivers/platform/chrome/cros_ec_sensorhub_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +1 -2
index 230e6cf3da2f..85e8ba782f0c 100644
@@ -40,7 +40,7 @@ cros_sensorhub_send_sample(struct cros_ec_sensorhub *sensorhub,
        int id = sample->sensor_id;
        struct iio_dev *indio_dev;
 
-       if (id > sensorhub->sensor_num)
+       if (id >= sensorhub->sensor_num)
                return -EINVAL;
 
        cb = sensorhub->push_data[id].push_data_cb;
--

2.25.1

#2 lore raw
In reply to Dan Carpenter

Hi Dan,

Thank you for your patch.

Quoted 6 lines · Dan Carpenter

The sensorhub->push_data[] array has sensorhub->sensor_num elements.
It's allocated in cros_ec_sensorhub_ring_add(). So the > should be >> to prevent a read one element beyond the end of the array.

Fixes 145d59baff59 ("platform/chrome: cros_ec_sensorhub: Add FIFO support")

---

Applied as a fix for 5.7

Quoted 17 lines
 drivers/platform/chrome/cros_ec_sensorhub_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +1 -1
index 230e6cf3da2f..85e8ba782f0c 100644
@@ -40,7 +40,7 @@ cros_sensorhub_send_sample(struct cros_ec_sensorhub *sensorhub,
 	int id = sample->sensor_id;
 	struct iio_dev *indio_dev;
 
-	if (id > sensorhub->sensor_num)
+	if (id >= sensorhub->sensor_num)
 		return -EINVAL;
 
 	cb = sensorhub->push_data[id].push_data_cb;