linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] eeprom: at24: check at24_read/write arguments
@ 2017-11-24  6:47 Heiner Kallweit
  2017-11-27 12:33 ` Bartosz Golaszewski
  2017-11-29 14:58 ` Bartosz Golaszewski
  0 siblings, 2 replies; 6+ messages in thread
From: Heiner Kallweit @ 2017-11-24  6:47 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-i2c@vger.kernel.org

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>
---
 drivers/misc/eeprom/at24.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 00d602be7..52cbaeb6f 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -569,6 +569,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;
+
 	client = at24_translate_offset(at24, &off);
 
 	ret = pm_runtime_get_sync(&client->dev);
@@ -614,6 +617,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;
+
 	client = at24_translate_offset(at24, &off);
 
 	ret = pm_runtime_get_sync(&client->dev);
-- 
2.15.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-12-02 22:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-24  6:47 [PATCH] eeprom: at24: check at24_read/write arguments Heiner Kallweit
2017-11-27 12:33 ` Bartosz Golaszewski
2017-11-27 19:40   ` Heiner Kallweit
2017-11-27 19:44     ` Bartosz Golaszewski
2017-12-02 22:36     ` Wolfram Sang
2017-11-29 14:58 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).