Skip to content

Commit d590faf

Browse files
larsclausenjic23
authored andcommitted
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: aacff89 ("staging:iio:adis: Preallocate transfer message") Signed-off-by: Lars-Peter Clausen <[email protected]> Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 9225c0b commit d590faf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/iio/imu/adis_buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,
4343
return -ENOMEM;
4444

4545
rx = adis->buffer;
46-
tx = rx + indio_dev->scan_bytes;
46+
tx = rx + scan_count;
4747

4848
spi_message_init(&adis->msg);
4949

0 commit comments

Comments
 (0)