Skip to contentSkip to conversation

iio: adis_buffer: Fix out-of-bounds memory access

PATCH In review Lars-Peter Clausen 2 participants 2 messages Nov 27, 2015 – Nov 29, 2015

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

PATCH 1/1 iio: adis_buffer: Fix out-of-bounds memory access

The SPI tx and rx buffers are both supposed to be scan_bytes amount of bytes large and a common allocation is used to allocate both buffers. This puts the beginning of the tx buffer scan_bytes bytes after the rx buffer. The initialization of the tx buffer pointer is done adding scan_bytes to the beginning of the rx buffer, but since the rx buffer is of type __be16 this will actually add two times as much and the tx buffer ends up pointing after the allocated buffer.

Fix this by using scan_count, which is scan_bytes / 2, instead of scan_bytes when initializing the tx buffer pointer.

Fixes aacff892cbd5 ("staging:iio:adis: Preallocate transfer message")

---
Apologies if you got this twice, forgot the mailinglist on the first try.

---
 drivers/iio/imu/adis_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +1 -1
index cb32b59..36607d5 100644
@@ -43,7 +43,7 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,
 		return -ENOMEM;
 
 	rx = adis->buffer;
-	tx = rx + indio_dev->scan_bytes;
+	tx = rx + scan_count;
 
 	spi_message_init(&adis->msg);
 
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 8 lines · Lars-Peter Clausen

The SPI tx and rx buffers are both supposed to be scan_bytes amount of bytes large and a common allocation is used to allocate both buffers. This puts the beginning of the tx buffer scan_bytes bytes after the rx buffer. The initialization of the tx buffer pointer is done adding scan_bytes to the beginning of the rx buffer, but since the rx buffer is of type __be16 this will actually add two times as much and the tx buffer ends up pointing after the allocated buffer.

Quoted 5 lines

Fix this by using scan_count, which is scan_bytes / 2, instead of scan_bytes when initializing the tx buffer pointer.

Fixes aacff892cbd5 ("staging:iio:adis: Preallocate transfer message")

Applied to my local fixes branch - will push out once Greg has caught up with last pull request - don't want to muddy the waters!

Jonathan

Quoted 20 lines

---
Apologies if you got this twice, forgot the mailinglist on the first try.

---
 drivers/iio/imu/adis_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +1 -1
index cb32b59..36607d5 100644
@@ -43,7 +43,7 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,
 		return -ENOMEM;
 
 	rx = adis->buffer;
-	tx = rx + indio_dev->scan_bytes;
+	tx = rx + scan_count;
 
 	spi_message_init(&adis->msg);