Skip to content

Commit 52d9bb9

Browse files
hkallweitgregkh
authored andcommitted
eeprom: at24: check at24_read/write arguments
commit d9bcd46 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>
1 parent 656155d commit 52d9bb9

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎drivers/misc/eeprom/at24.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
507507
if (unlikely(!count))
508508
return count;
509509

510+
if (off + count > at24->chip.byte_len)
511+
return -EINVAL;
512+
510513
/*
511514
* Read data from chip, protecting against concurrent updates
512515
* 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)
539542
if (unlikely(!count))
540543
return -EINVAL;
541544

545+
if (off + count > at24->chip.byte_len)
546+
return -EINVAL;
547+
542548
/*
543549
* Write data to chip, protecting against concurrent updates
544550
* from this host, but not from other I2C masters.

0 commit comments

Comments
 (0)