Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rodrigo Alencar via B4 Relay"
	<devnull+rodrigo.alencar.analog.com@kernel.org>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v5 01/13] iio: core: validate file offset in iio_debugfs_write_reg()
Date: Sun, 17 May 2026 19:04:43 +0000	[thread overview]
Message-ID: <20260517190444.A10C4C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260517-ad9910-iio-driver-v5-1-31599c88314a@analog.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The `*ppos != 0` check introduces a functional regression for sequential writes, masking the true bug which is the inappropriate use of `simple_write_to_buffer()`.
- [High] Unpatched uninitialized stack memory reads in other IIO drivers caused by the identical anti-pattern.
--

commit 7c5ddbc34738b9e84e226b9906348d61e3569bf4
Author: Rodrigo Alencar <rodrigo.alencar@analog.com>

iio: core: validate file offset in iio_debugfs_write_reg()

This patch adds a check to ensure that the file offset is zero in
iio_debugfs_write_reg() before calling simple_write_to_buffer(). This is
intended to prevent leaving the start of the buffer uninitialized if a write
occurs at a non-zero offset.

> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index bd6f4f9f45330..e587aca79b8e7 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -419,7 +419,7 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
>  	char buf[80];
>  	int ret;
>  
> -	if (count >= sizeof(buf))
> +	if (count >= sizeof(buf) || *ppos != 0)

Does this cause a functional regression for sequential writes?

If a user writes multiple commands to the same open file descriptor, for
example using (echo "cmd1"; echo "cmd2") > direct_reg_access, the first
write advances the file position. This means *ppos will be non-zero on the
second write, causing it to fail with -EINVAL.

Before simple_write_to_buffer() was introduced, the code used
copy_from_user() and ignored *ppos, correctly treating every write() call
as a distinct command starting at the beginning of the buffer.

Since simple_write_to_buffer() is designed for stateful linear memory buffers
rather than stateless command endpoints using local stack arrays, would it be
better to revert the use of simple_write_to_buffer() entirely and use
copy_from_user() or strndup_user() to parse each write independently?

Additionally, does this leave a similar pattern unpatched in other IIO
drivers?

While this patch addresses the issue in iio_debugfs_write_reg(), the same
pattern of using simple_write_to_buffer() into a local stack array still
exists in other locations:

1. iio_backend_debugfs_write_reg() in drivers/iio/industrialio-backend.c
2. ad3552r_hs_write_data_source() in drivers/iio/dac/ad3552r-hs.c

Both functions use simple_write_to_buffer() into uninitialized local stack
arrays without checking *ppos.

Furthermore, ad9467_chan_test_mode_write() in drivers/iio/adc/ad9467.c
uses the same pattern. While the buffer is zero-initialized there,
sequential writes will still be functionally broken.

>  		return -EINVAL;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260517-ad9910-iio-driver-v5-0-31599c88314a@analog.com?part=1

  reply	other threads:[~2026-05-17 19:04 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-17 18:37 [PATCH v5 00/13] AD9910 Direct Digital Synthesizer Rodrigo Alencar via B4 Relay
2026-05-17 18:37 ` [PATCH v5 01/13] iio: core: validate file offset in iio_debugfs_write_reg() Rodrigo Alencar via B4 Relay
2026-05-17 19:04   ` sashiko-bot [this message]
2026-05-18 10:43   ` Rodrigo Alencar
2026-05-17 18:37 ` [PATCH v5 02/13] iio: core: support 64-bit register through debugfs Rodrigo Alencar via B4 Relay
2026-05-17 18:56   ` sashiko-bot
2026-05-18 13:56   ` Rodrigo Alencar
2026-05-17 18:37 ` [PATCH v5 03/13] iio: core: add hierarchical channel relationships Rodrigo Alencar via B4 Relay
2026-05-17 18:56   ` sashiko-bot
2026-05-18 14:26     ` Rodrigo Alencar
2026-05-17 18:37 ` [PATCH v5 04/13] Documentation: ABI: testing: add parent entry for iio channels Rodrigo Alencar via B4 Relay
2026-05-17 18:45   ` sashiko-bot
2026-05-17 18:37 ` [PATCH v5 05/13] dt-bindings: iio: frequency: add ad9910 Rodrigo Alencar via B4 Relay
2026-05-17 18:44   ` sashiko-bot
2026-05-18  7:52   ` Krzysztof Kozlowski
2026-05-18 10:03     ` Rodrigo Alencar
2026-05-17 18:37 ` [PATCH v5 06/13] iio: frequency: ad9910: initial driver implementation Rodrigo Alencar via B4 Relay
2026-05-17 19:20   ` sashiko-bot
2026-05-18 11:45   ` Rodrigo Alencar
2026-05-17 18:37 ` [PATCH v5 07/13] iio: frequency: ad9910: add basic parallel port support Rodrigo Alencar via B4 Relay
2026-05-17 18:37 ` [PATCH v5 08/13] iio: frequency: ad9910: add digital ramp generator support Rodrigo Alencar via B4 Relay
2026-05-17 18:37 ` [PATCH v5 09/13] iio: frequency: ad9910: add RAM mode support Rodrigo Alencar via B4 Relay
2026-05-17 19:19   ` sashiko-bot
2026-05-18 13:50   ` Rodrigo Alencar
2026-05-17 18:37 ` [PATCH v5 10/13] iio: frequency: ad9910: add output shift keying support Rodrigo Alencar via B4 Relay
2026-05-17 18:37 ` [PATCH v5 11/13] iio: frequency: ad9910: show channel priority in debugfs Rodrigo Alencar via B4 Relay
2026-05-17 18:37 ` [PATCH v5 12/13] Documentation: ABI: testing: add docs for ad9910 sysfs entries Rodrigo Alencar via B4 Relay
2026-05-17 19:00   ` sashiko-bot
2026-05-17 18:37 ` [PATCH v5 13/13] docs: iio: add documentation for ad9910 driver Rodrigo Alencar via B4 Relay
2026-05-17 19:00   ` sashiko-bot

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=20260517190444.A10C4C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=devnull+rodrigo.alencar.analog.com@kernel.org \
    --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