From: khali@linux-fr.org Date: Thu, 7 Apr 2005 18:21:37 +0000 (-0700) Subject: [PATCH] I2C: Fix oops in eeprom driver X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82e59799aa57d2471333bf9ebbc9b4b2226b9790;p=thirdparty%2Fkernel%2Fstable.git [PATCH] I2C: Fix oops in eeprom driver This fixes an oops in the eeprom driver. It was first reported here: http://bugzilla.kernel.org/show_bug.cgi?id=4347 It was additionally discussed here (while tracking a completely different bug): http://archives.andrew.net.au/lm-sensors/msg30021.html The patch is already in 2.6.12-rc1: http://linux.bkbits.net:8080/linux-2.5/cset@1.2227 The oops happens when one reads data from the sysfs interface file such that (off < 16) and (count < 16 - off). For example "sensors" from lm_sensors 2.9.0 does this, and causes the oops. Signed-off-by: Jean Delvare Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Chris Wright Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c index 31ea1300ec9c7..53dddf09df32e 100644 --- a/drivers/i2c/chips/eeprom.c +++ b/drivers/i2c/chips/eeprom.c @@ -130,7 +130,8 @@ static ssize_t eeprom_read(struct kobject *kobj, char *buf, loff_t off, size_t c /* Hide Vaio security settings to regular users (16 first bytes) */ if (data->nature == VAIO && off < 16 && !capable(CAP_SYS_ADMIN)) { - int in_row1 = 16 - off; + size_t in_row1 = 16 - off; + in_row1 = min(in_row1, count); memset(buf, 0, in_row1); if (count - in_row1 > 0) memcpy(buf + in_row1, &data->data[16], count - in_row1);