From: sashiko-bot@kernel.org
To: "Chris Morgan" <macroalpha82@gmail.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org
Subject: Re: [PATCH V7 08/11] iio: imu: inv_icm42607: Add Accelerometer for icm42607
Date: Fri, 15 May 2026 13:34:26 +0000 [thread overview]
Message-ID: <20260515133428.0BE29C2BCF5@smtp.kernel.org> (raw)
In-Reply-To: <20260515130018.237378-9-macroalpha82@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Reversed bounds check in FIFO parser causes valid packets to be dropped and out-of-bounds reads
- [High] Unprotected lockless access to shared FIFO state leads to data races and corruption
- [High] Missing packet bounds check in `inv_icm42607_buffer_fifo_read` allows out-of-bounds memory access
- [High] Unsupported TEMP-only scan mask causes silent data drops and userspace deadlock
- [Medium] Reserved array elements exposed as zeroed sampling frequencies in userspace
--
commit 7b72703c452d419fa91a97227176f51c49a6b7cb
Author: Chris Morgan <macromorgan@hotmail.com>
iio: imu: inv_icm42607: Add Accelerometer for icm42607
This commit adds accelerometer sensor support to the icm42607 driver. It
introduces device configuration, power management, timestamp handling, and data
parsing from the hardware FIFO. It also exposes available sampling frequencies
and scales to userspace.
> diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c
> new file mode 100644
> index 0000000000000..b354a84fd2ed4
> --- /dev/null
> +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c
[ ... ]
> +static const unsigned long inv_icm42607_accel_scan_masks[] = {
> + INV_ICM42607_SCAN_MASK_ACCEL_3AXIS,
> + INV_ICM42607_SCAN_MASK_TEMP,
> + INV_ICM42607_SCAN_MASK_ACCEL_3AXIS | INV_ICM42607_SCAN_MASK_TEMP,
> + 0
> +};
Does offering INV_ICM42607_SCAN_MASK_TEMP by itself cause issues? If userspace
requests only the temperature channel, inv_icm42607_accel_update_scan_mode()
enables only the TEMP sensor. If the hardware generates packets without ACCEL
or GYRO headers, inv_icm42607_fifo_decode_packet() returns -EINVAL.
Even if it generates an ACCEL packet, inv_icm42607_accel_parse_fifo() explicitly
discards packets lacking accelerometer data. Would this cause the TEMP data to be
silently dropped, potentially leaving userspace applications deadlocked waiting
for data?
[ ... ]
> +static int inv_icm42607_accel_read_avail(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + const int **vals,
> + int *type, int *length, long mask)
> +{
> + if (chan->type != IIO_ACCEL)
> + return -EINVAL;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SCALE:
> + *vals = (const int *)inv_icm42607_accel_scale_nano;
> + *type = IIO_VAL_INT_PLUS_NANO;
> + *length = ARRAY_SIZE(inv_icm42607_accel_scale_nano) * 2;
> + return IIO_AVAIL_LIST;
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *vals = (const int *)inv_icm42607_accel_odr;
> + *type = IIO_VAL_INT_PLUS_MICRO;
> + *length = ARRAY_SIZE(inv_icm42607_accel_odr) * 2;
> + return IIO_AVAIL_LIST;
Can this expose uninitialized array elements to userspace? Because
inv_icm42607_accel_odr has indices 0-5 reserved and implicitly initialized to
zero, passing the full ARRAY_SIZE() could expose those 0.000000 sampling
frequencies as available to userspace.
[ ... ]
> + /* parse all fifo packets */
> + for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) {
> + size = inv_icm42607_fifo_decode_packet(&st->fifo.data[i],
> + &accel, &gyro, &temp, ×tamp, &odr);
> + /* quit if error or FIFO is empty */
> + if (size <= 0)
> + return size;
> +
> + /* If the packet size could cause us to overflow, return. */
> + if (i + size <= st->fifo.count)
> + return -EIO;
Is this condition reversed? If i + size <= st->fifo.count, the packet fits
within the valid buffer limit, but the parser returns -EIO and valid packets
are dropped. Conversely, if the packet exceeds the buffer boundaries
(i + size > st->fifo.count), it evaluates to false, allowing the parser to
read out-of-bounds kernel memory.
> +
> + /* skip packet if no accel data or data is invalid */
> + if (accel == NULL || !inv_icm42607_fifo_is_data_valid(accel))
> + continue;
[ ... ]
> diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_buffer.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_buffer.c
> index 74e5213d92671..4371f428cc3f8 100644
> --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_buffer.c
> +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_buffer.c
[ ... ]
> @@ -440,7 +460,7 @@ int inv_icm42607_buffer_fifo_read(struct inv_icm42607_state *st,
> /* compute number of samples for each sensor */
> for (i = 0; i < st->fifo.count; i += size) {
> size = inv_icm42607_fifo_decode_packet(&st->fifo.data[i],
> - &accel, &gyro, &temp, ×tamp);
> + &accel, &gyro, &temp, ×tamp, &odr);
> /* Make sure the size is at least 1 valid packet. */
> if (size < INV_ICM42607_FIFO_1SENSOR_PACKET_SIZE)
> break;
Could this code access memory out-of-bounds? If the hardware returns a
partial packet at the very end of the st->fifo.data array, the loop does not
verify that i + size <= st->fifo.count before passing the decoded pointers.
inv_icm42607_fifo_decode_packet() could then yield pointers that point
outside the populated bounds, which inv_icm42607_fifo_is_data_valid() would
subsequently dereference.
[ ... ]
> int inv_icm42607_buffer_hwfifo_flush(struct inv_icm42607_state *st,
> unsigned int count)
> {
> + struct inv_icm42607_sensor_state *accel_st = iio_priv(st->indio_accel);
> + struct inv_sensors_timestamp *ts;
> + s64 accel_ts;
> int ret;
>
> + accel_ts = iio_get_time_ns(st->indio_accel);
> +
> ret = inv_icm42607_buffer_fifo_read(st, count);
> + if (ret)
> + return ret;
>
> - return ret;
> + if (st->fifo.nb.total == 0)
> + return 0;
> +
> + if (st->fifo.nb.accel > 0) {
> + ts = &accel_st->ts;
> + inv_sensors_timestamp_interrupt(ts, st->fifo.nb.accel, accel_ts);
> + ret = inv_icm42607_accel_parse_fifo(st->indio_accel);
Can a data race happen here? inv_icm42607_buffer_fifo_read() properly
acquires and releases st->lock, but then inv_icm42607_accel_parse_fifo() is
called without holding the lock. A concurrent flush operation could acquire
the lock, overwrite st->fifo.data, and reset st->fifo.count while the
original thread is mid-parse, leading to memory corruption and out-of-bounds
reads.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260515130018.237378-1-macroalpha82@gmail.com?part=8
next prev parent reply other threads:[~2026-05-15 13:34 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 13:00 [PATCH V7 00/11] Add Invensense ICM42607 Chris Morgan
2026-05-15 13:00 ` [PATCH V7 01/11] dt-bindings: iio: imu: icm42600: Add mount-matrix to icm42600 Chris Morgan
2026-05-15 13:00 ` [PATCH V7 02/11] dt-bindings: iio: imu: icm42600: Add icm42607 binding Chris Morgan
2026-05-15 13:00 ` [PATCH V7 03/11] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver Chris Morgan
2026-05-15 13:23 ` sashiko-bot
2026-05-15 18:31 ` Jonathan Cameron
2026-05-15 13:00 ` [PATCH V7 04/11] iio: imu: inv_icm42607: Add I2C and SPI For icm42607 Chris Morgan
2026-05-15 13:45 ` sashiko-bot
2026-05-15 18:43 ` Jonathan Cameron
2026-05-15 13:00 ` [PATCH V7 05/11] iio: imu: inv_icm42607: Add PM support for icm42607 Chris Morgan
2026-05-15 13:36 ` sashiko-bot
2026-05-15 13:00 ` [PATCH V7 06/11] iio: imu: inv_icm42607: Add Buffer " Chris Morgan
2026-05-15 13:35 ` sashiko-bot
2026-05-15 13:00 ` [PATCH V7 07/11] iio: imu: inv_icm42607: Add Temp Support in icm42607 Chris Morgan
2026-05-15 13:00 ` [PATCH V7 08/11] iio: imu: inv_icm42607: Add Accelerometer for icm42607 Chris Morgan
2026-05-15 13:34 ` sashiko-bot [this message]
2026-05-15 13:00 ` [PATCH V7 09/11] iio: imu: inv_icm42607: Add Wake on Movement to icm42607 Chris Morgan
2026-05-15 13:42 ` sashiko-bot
2026-05-15 13:00 ` [PATCH V7 10/11] iio: imu: inv_icm42607: Add Gyroscope " Chris Morgan
2026-05-15 13:37 ` sashiko-bot
2026-05-15 13:00 ` [PATCH V7 11/11] arm64: dts: rockchip: Add icm42607p IMU for RG-DS Chris Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260515133428.0BE29C2BCF5@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=macroalpha82@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox