Re: [PATCH 02/10] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer()

From: Andy Shevchenko

Date: Thu Nov 19 2026 - 12:22:32 EST


On Thu, Nov 19, 2026 at 03:30:35PM +0000, Lee Jones wrote:
> The ADXL313 32-entry FIFO plus one sample held in the output filter can
> yield up to 33 3-axis samples (ADXL313_FIFO_SIZE + 1). Because of
> missing parentheses in ADXL313_NUM_AXIS * ADXL313_FIFO_SIZE + 1,
> fifo_buf is sized at 97 16-bit elements instead of 99, overflowing the
> buffer by four bytes whenever all 33 entries are read.
>
> In addition, adxl313_get_samples() returns the 6-bit FIFO_STATUS entries
> field (0..63) without bounds checking, allowing a malfunctioning or
> spoofed bus device to overflow fifo_buf on the heap in
> adxl313_fifo_transfer().
>
> Parenthesise (ADXL313_FIFO_SIZE + 1) when sizing fifo_buf and reject
> entry counts exceeding ADXL313_FIFO_SIZE + 1 in adxl313_get_samples().

...

> - return FIELD_GET(ADXL313_REG_FIFO_STATUS_ENTRIES_MSK, regval);
> + /* 32 FIFO entries plus 1 entry at the output filter */
> + ret = FIELD_GET(ADXL313_REG_FIFO_STATUS_ENTRIES_MSK, regval);
> + if (ret > ADXL313_FIFO_SIZE + 1)
> + return -EINVAL;

ERANGE? EIO? EPROTO? (I think from the listed the first suits better, but maybe
in errno.h a better one is lurking.)

> + return ret;

--
With Best Regards,
Andy Shevchenko