From: Jonathan Cameron <jic23@kernel.org>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>
Cc: linux-iio@vger.kernel.org, "Gyeyoung Baek" <gye976@gmail.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: chemical: mhz19b: bound receive buffer copy
Date: Sun, 12 Apr 2026 16:12:12 +0100 [thread overview]
Message-ID: <20260412161212.0f0e24c1@jic23-huawei> (raw)
In-Reply-To: <20260322134807.16217-1-pengpeng@iscas.ac.cn>
On Sun, 22 Mar 2026 21:48:07 +0800
Pengpeng Hou <pengpeng@iscas.ac.cn> wrote:
> `mhz19b_receive_buf()` appends bytes to the fixed 9-byte command buffer
> without first checking that the new chunk fits in the remaining space.
> A single receive callback can therefore write past the end of `st->buf`
> before the driver sees that the command is complete.
>
> Drop overlong chunks and reset the partial command state before the
> copy.
This 'before the copy' part of this implies the copy still happens.
I don't think that is true.
>
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> ---
> drivers/iio/chemical/mhz19b.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/iio/chemical/mhz19b.c b/drivers/iio/chemical/mhz19b.c
> index 3c64154918b1..fbd7f14483b3 100644
> --- a/drivers/iio/chemical/mhz19b.c
> +++ b/drivers/iio/chemical/mhz19b.c
> @@ -240,6 +240,12 @@ static size_t mhz19b_receive_buf(struct serdev_device *serdev,
> {
> struct iio_dev *indio_dev = dev_get_drvdata(&serdev->dev);
> struct mhz19b_state *st = iio_priv(indio_dev);
> + size_t remaining = sizeof(st->buf) - st->buf_idx;
> +
> + if (unlikely(len > remaining)) {
> + st->buf_idx = 0;
> + return len;
Given this doesn't complete we will see a timeout error if this is hit?
That is rather misleading. I think I'd at least print a message in this
path to provide a hint of what happened.
Jonathan
> + }
>
> memcpy(st->buf + st->buf_idx, data, len);
> st->buf_idx += len;
prev parent reply other threads:[~2026-04-12 15:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-22 3:19 [PATCH] " Pengpeng Hou
2026-03-22 11:52 ` Gyeyoung Baek
2026-03-22 13:48 ` [PATCH v2] " Pengpeng Hou
2026-03-22 14:34 ` David Lechner
2026-04-12 15:12 ` Jonathan Cameron [this message]
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=20260412161212.0f0e24c1@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gye976@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=pengpeng@iscas.ac.cn \
/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
all inboxes | Powered by JetHome®