From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
Bryam Vargas <hexlabsecurity@proton.me>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] i2c: smbus: make i2c_smbus_read_block_data() safer
Date: Sun, 27 Sep 2026 22:41:14 -0700 [thread overview]
Message-ID: <arn9x7nwovm85HfY@google.com> (raw)
In-Reply-To: <ammWUROtUGeriY8G@google.com>
On Tue, Jul 28, 2026 at 11:00:23PM -0700, Dmitry Torokhov wrote:
> i2c_smbus_read_block_data() is dangerous to use because it may deliver
> up to I2C_SMBUS_BLOCK_MAX (32) bytes, which may be surprising to the
> caller. Callers tend to allocate buffers of sizes big enough to hold
> data from a well-behaving device and do not expect that
> i2c_smbus_read_block_data() may attempt to write more data than
> expected.
>
> To make i2c_smbus_read_block_data() safer to use, change it so that
> it accepts size of the supplied buffer as another argument and ensure
> that it will not copy more data than the size of the buffer. Signal
> oversized responses with -EMSGSIZE.
>
> To allow users to gradually transition to the new API employ some
> macro trickery allowing calling i2c_smbus_read_block_data() with either
> 3 or 4 arguments. When called with 3 arguments it is assumed that
> the buffer size is I2C_SMBUS_BLOCK_MAX bytes. Once everyone is
> transitioned to the 4 argument form the macros should be removed.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>
> v2:
> - dropped incorrect changes to Documentation (Andi)
> - signal oversized responses with -EMSGSIZE (Andi)
Andi, could this be applied or would you like me to change something
else?
Thanks.
--
Dmitry
next prev parent reply other threads:[~2026-09-28 5:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 6:00 [PATCH v2] i2c: smbus: make i2c_smbus_read_block_data() safer Dmitry Torokhov
2026-09-28 5:41 ` Dmitry Torokhov [this message]
2026-09-29 22:46 ` Andi Shyti
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=arn9x7nwovm85HfY@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=andi.shyti@kernel.org \
--cc=hexlabsecurity@proton.me \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.