From: Conor Dooley <conor.dooley@microchip.com>
To: Alex Guo <alexguo1023@gmail.com>
Cc: <daire.mcnamara@microchip.com>, <andi.shyti@kernel.org>,
<linux-riscv@lists.infradead.org>, <linux-i2c@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] i2c: busses: Fix out-of-bounds bug in mchp_corei2c_smbus_xfer
Date: Thu, 19 Jun 2025 08:33:10 +0100 [thread overview]
Message-ID: <20250619-jubilant-nag-c50bdebdac0c@wendy> (raw)
In-Reply-To: <20250615234919.525431-1-alexguo1023@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1470 bytes --]
On Sun, Jun 15, 2025 at 07:49:19PM -0400, Alex Guo wrote:
> The data->block[0] variable comes from user. Without proper check,
> the variable may be very large to cause an out-of-bounds bug.
>
> Fix this bug by checking the value of data->block[0] first.
>
> Similar commit:
> 1. commit 39244cc7548 ("i2c: ismt: Fix an out-of-bounds bug in
> ismt_access()")
> 2. commit 92fbb6d1296 ("i2c: xgene-slimpro: Fix out-of-bounds
> bug in xgene_slimpro_i2c_xfer()")
>
> Signed-off-by: Alex Guo <alexguo1023@gmail.com>
> ---
> drivers/i2c/busses/i2c-microchip-corei2c.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-microchip-corei2c.c b/drivers/i2c/busses/i2c-microchip-corei2c.c
> index 492bf4c34722..a79d4d327f20 100644
> --- a/drivers/i2c/busses/i2c-microchip-corei2c.c
> +++ b/drivers/i2c/busses/i2c-microchip-corei2c.c
> @@ -492,6 +492,8 @@ static int mchp_corei2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned
> if (read_write == I2C_SMBUS_WRITE) {
> int data_len;
>
> + if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
> + return -EINVAL;
Seems reasonable, but I'd like to see a blank line here after the
return. Maybe Andi can do it on application?
Acked-by: Conor Dooley <conor.dooley@microchip.com>
> data_len = data->block[0];
> msgs[CORE_I2C_SMBUS_MSG_WR].len = data_len + 2;
> for (int i = 0; i <= data_len; i++)
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-06-19 7:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-15 23:49 [PATCH] i2c: busses: Fix out-of-bounds bug in mchp_corei2c_smbus_xfer Alex Guo
2025-06-19 7:33 ` Conor Dooley [this message]
2025-06-28 20:09 ` Wolfram Sang
2025-07-15 21:58 ` 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=20250619-jubilant-nag-c50bdebdac0c@wendy \
--to=conor.dooley@microchip.com \
--cc=alexguo1023@gmail.com \
--cc=andi.shyti@kernel.org \
--cc=daire.mcnamara@microchip.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
/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