misc/at24: avoid infinite loop on write()
authorVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Mon, 28 Oct 2013 17:05:15 +0000 (19:05 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 29 Oct 2013 23:24:33 +0000 (16:24 -0700)
This change fixes a problem of infinite zero byte write() without
an error status, if there is an attempt to write a file bigger than
EEPROM size over sysfs interface.

Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Cc: Wolfram Sang <w.sang@pengutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/eeprom/at24.c

index 5d4fd69d04ca05f1b189e458fdbacd4e54e3a0b7..94b8a33243192d4217c54442424bc91e1dbd936c 100644 (file)
@@ -428,6 +428,9 @@ static ssize_t at24_bin_write(struct file *filp, struct kobject *kobj,
 {
        struct at24_data *at24;
 
+       if (unlikely(off >= attr->size))
+               return -EFBIG;
+
        at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));
        return at24_write(at24, buf, off, count);
 }