Re: [PATCH 02/10] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer()
From: Jonathan Cameron
Date: Sat Nov 21 2026 - 17:32:11 EST
On Thu, 19 Nov 2026 19:22:17 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:
> 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.)
EIO would be my preference given it's a sign of corrupt message or broken
hardware. I can tweak whilst applying if everyone is fine with that.
>
> > + return ret;
>