Skip to contentSkip to conversation

drivers: fsi: Fix FSI core size checking user interfaces

PATCH Applied Eddie James 3 participants 3 messages Feb 21, 2017 – Feb 22, 2017 FSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: fsi: Fix FSI core size checking user interfaces

From: "Edward A. James" <[email protected]>

Some potential for integer overflow and not checking signed offsets.

---
 drivers/fsi/fsi-core.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/fsi/fsi-core.c +4 -10
index d63a892..e13774f 100644
@@ -90,10 +90,7 @@ static int fsi_slave_write(struct fsi_slave *slave, uint32_t addr,
 int fsi_device_read(struct fsi_device *dev, uint32_t addr, void *val,
 		size_t size)
 {
-	if (addr > dev->size)
-		return -EINVAL;
-
-	if (addr + size > dev->size)
+	if (addr > dev->size || size > dev->size || addr > dev->size - size)
 		return -EINVAL;
 
 	return fsi_slave_read(dev->slave, dev->addr + addr, val, size);
@@ -103,10 +100,7 @@ EXPORT_SYMBOL_GPL(fsi_device_read);
 int fsi_device_write(struct fsi_device *dev, uint32_t addr, const void *val,
 		size_t size)
 {
-	if (addr > dev->size)
-		return -EINVAL;
-
-	if (addr + size > dev->size)
+	if (addr > dev->size || size > dev->size || addr > dev->size - size)
 		return -EINVAL;
 
 	return fsi_slave_write(dev->slave, dev->addr + addr, val, size);
@@ -328,7 +322,7 @@ static ssize_t fsi_slave_sysfs_raw_read(struct file *file,
 	if (count != 4 || off & 0x3)
 		return -EINVAL;
 
-	if (off > 0xffffffff)
+	if (off > 0xfffffffc || off < 0)
 		return -EINVAL;
 
 	rc = fsi_slave_read(slave, off, buf, 4);
@@ -346,7 +340,7 @@ static ssize_t fsi_slave_sysfs_raw_write(struct file *file,
 	if (count != 4 || off & 0x3)
 		return -EINVAL;
 
-	if (off > 0xffffffff)
+	if (off > 0xfffffffc || off < 0)
 		return -EINVAL;
 
 	rc = fsi_slave_write(slave, off, buf, 4);
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw

Hi Eddie,

Quoted 1 line

Some potential for integer overflow and not checking signed offsets.

[...]

drivers/fsi/fsi-core.c static int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, · line 94

Quoted 9 lines

int fsi_device_read(struct fsi_device *dev, uint32_t addr, void *val,

drivers/fsi/fsi-core.c +1 -4
 		size_t size)
 {
-	if (addr > dev->size)
-		return -EINVAL;
-
-	if (addr + size > dev->size)
+	if (addr > dev->size || size > dev->size || addr > dev->size - size)
 		return -EINVAL;

I liked the split conditional statements, but that's only personal preference. Regardless, LGTM.

Cheers,

Jeremy

Applied
#2 lore raw
Quoted 16 lines · Jeremy Kerr

Hi Eddie,

Quoted 1 line

Some potential for integer overflow and not checking signed offsets.

[...]

drivers/fsi/fsi-core.c static int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, · line 94

Quoted 9 lines

int fsi_device_read(struct fsi_device *dev, uint32_t addr, void *val,
size_t size)
{

drivers/fsi/fsi-core.c +1 -4
-     if (addr > dev->size)
-             return -EINVAL;
-
-     if (addr + size > dev->size)
+     if (addr > dev->size || size > dev->size || addr > dev->size - size)
              return -EINVAL;
Quoted 2 lines

I liked the split conditional statements, but that's only personal preference. Regardless, LGTM.

My personal preference is also to split them out. It makes them easier to read, and there's less noise in the diff if the conditions need to be updated.

I applied this as-is to dev-4.7 for now.

Quoted 1 line

Thanks for the review Jeremy.

Cheers,

Joel