Skip to contentSkip to conversation

i2c: i801: Fix out-of-bounds bug in i801_block_transaction _byte_by_byte

PATCH In review Alex Guo 2 participants 2 messages Jun 15, 2025 – Jun 16, 2025

Subsystems (2)
lore
Share & tools
lore

Alex Guo

author
#0 lore raw

PATCH 1/1 i2c: i801: Fix out-of-bounds bug in i801_block_transaction _byte_by_byte

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()")

---
 drivers/i2c/busses/i2c-i801.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-i801.c +2 -0
index 7503418be39a..aed4473fb9ba 100644
@@ -678,6 +678,8 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
 		return -EOPNOTSUPP;
 
 	len = data->block[0];
+	if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
+		return -EINVAL;
 
 	if (read_write == I2C_SMBUS_WRITE) {
 		iowrite8(len, SMBHSTDAT0(priv));
Signature · 1 line
2.34.1
#1 lore raw

Hi Alex,

Quoted 4 lines · Alex Guo

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.

The same check is already present in i801_smbus_block_transaction() and i801_i2c_block_transaction(), which are the only 2 functions calling i801_block_transaction_byte_by_byte(). So the out-of-bounds bug you describe does not exist.

Signature · 2 lines
Jean Delvare
SUSE L3 Support