Skip to content

Commit 071e43f

Browse files
mugitya03gregkh
authored andcommitted
i2c: rtl9300: Fix out-of-bounds bug in rtl9300_i2c_smbus_xfer
commit 57f312b upstream. 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. 1. commit 39244cc ("i2c: ismt: Fix an out-of-bounds bug in ismt_access()") 2. commit 92fbb6d ("i2c: xgene-slimpro: Fix out-of-bounds bug in xgene_slimpro_i2c_xfer()") Fixes: c366be7 ("i2c: Add driver for the RTL9300 I2C controller") Signed-off-by: Alex Guo <alexguo1023@gmail.com> Cc: <stable@vger.kernel.org> # v6.13+ Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20250810-i2c-rtl9300-multi-byte-v5-1-cd9dca0db722@narfation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d23264c commit 071e43f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/i2c/busses/i2c-rtl9300.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ static int rtl9300_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned s
281281
ret = rtl9300_i2c_reg_addr_set(i2c, command, 1);
282282
if (ret)
283283
goto out_unlock;
284+
if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX) {
285+
ret = -EINVAL;
286+
goto out_unlock;
287+
}
284288
ret = rtl9300_i2c_config_xfer(i2c, chan, addr, data->block[0]);
285289
if (ret)
286290
goto out_unlock;

0 commit comments

Comments
 (0)