Skip to contentSkip to conversation

USB: cxacru: fix an bounds check warning

PATCH New Dan Carpenter 1 participant 1 message Jan 30, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: cxacru: fix an bounds check warning

This is a privileged operation so it doesn't matter much. We use "tmp" as an offset into an array. If it were invalid we could read out of bounds and trigger an oops if the memory is not mapped. Plus it makes static checkers complain.

---
This changes the behavior a little bit because in the original we could give slightly invalid "len" values and the function would still work...

Please review it extra carefully to make sure it doesn't break userspace.

drivers/usb/atm/cxacru.c +2 -0
index 1173f9c..0a866e9 100644
@@ -476,6 +476,8 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
 			return -EINVAL;
 		if (index < 0 || index > 0x7f)
 			return -EINVAL;
+		if (tmp < 0 || tmp > len - pos)
+			return -EINVAL;
 		pos += tmp;
 
 		/* skip trailing newline */