]> Git Repo - linux.git/commitdiff
eeprom: ee1004: limit i2c reads to I2C_SMBUS_BLOCK_MAX
authorJonas Malaco <[email protected]>
Thu, 3 Feb 2022 16:49:52 +0000 (13:49 -0300)
committerGreg Kroah-Hartman <[email protected]>
Fri, 4 Feb 2022 15:27:44 +0000 (16:27 +0100)
Commit effa453168a7 ("i2c: i801: Don't silently correct invalid transfer
size") revealed that ee1004_eeprom_read() did not properly limit how
many bytes to read at once.

In particular, i2c_smbus_read_i2c_block_data_or_emulated() takes the
length to read as an u8.  If count == 256 after taking into account the
offset and page boundary, the cast to u8 overflows.  And this is common
when user space tries to read the entire EEPROM at once.

To fix it, limit each read to I2C_SMBUS_BLOCK_MAX (32) bytes, already
the maximum length i2c_smbus_read_i2c_block_data_or_emulated() allows.

Fixes: effa453168a7 ("i2c: i801: Don't silently correct invalid transfer size")
Cc: [email protected]
Reviewed-by: Heiner Kallweit <[email protected]>
Signed-off-by: Jonas Malaco <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
drivers/misc/eeprom/ee1004.c

index bb9c4512c968c8b3435b65cc46b713f3c75e216b..9fbfe784d71015aeaee46adaa57c2ecfaf96e077 100644 (file)
@@ -114,6 +114,9 @@ static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,
        if (offset + count > EE1004_PAGE_SIZE)
                count = EE1004_PAGE_SIZE - offset;
 
+       if (count > I2C_SMBUS_BLOCK_MAX)
+               count = I2C_SMBUS_BLOCK_MAX;
+
        return i2c_smbus_read_i2c_block_data_or_emulated(client, offset, count, buf);
 }
 
This page took 0.056575 seconds and 4 git commands to generate.