eeprom: at24: check at24_read/write arguments
authorHeiner Kallweit <hkallweit1@gmail.com>
Fri, 24 Nov 2017 06:47:50 +0000 (07:47 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 5 Dec 2017 10:26:33 +0000 (11:26 +0100)
commit d9bcd462daf34aebb8de9ad7f76de0198bb5a0f0 upstream.

So far we completely rely on the caller to provide valid arguments.
To be on the safe side perform an own sanity check.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/eeprom/at24.c

index e0d018e8bb8e14dd50da5870bf4f74859d56ec1a..372b2060fbba1ebc268d40091d91bdbba880ed30 100644 (file)
@@ -507,6 +507,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
        if (unlikely(!count))
                return count;
 
+       if (off + count > at24->chip.byte_len)
+               return -EINVAL;
+
        /*
         * Read data from chip, protecting against concurrent updates
         * from this host, but not from other I2C masters.
@@ -539,6 +542,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
        if (unlikely(!count))
                return -EINVAL;
 
+       if (off + count > at24->chip.byte_len)
+               return -EINVAL;
+
        /*
         * Write data to chip, protecting against concurrent updates
         * from this host, but not from other I2C masters.