Skip to contentSkip to conversation

hwmon: Do not accept invalid name attributes

PATCH In review Guenter Roeck 2 participants 3 messages Mar 2, 2014 – Mar 3, 2014 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v2 1/1 hwmon: Do not accept invalid name attributes

hwmon name attributes must not include '-', as specified in Documentation/hwmon/sysfs-interface. Also filter out spaces, tabs, wildcards, and newline characters.

---
v2: In addition to '-', filter out zero length names as well as names

    containing '*', ' ', '\t', and '\n'.
 drivers/hwmon/hwmon.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/hwmon/hwmon.c +5 -0
index e176a43..a26c385 100644
@@ -22,6 +22,7 @@
 #include <linux/gfp.h>
 #include <linux/spinlock.h>
 #include <linux/pci.h>
+#include <linux/string.h>
 
 #define HWMON_ID_PREFIX "hwmon"
 #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
@@ -99,6 +100,10 @@ hwmon_device_register_with_groups(struct device *dev, const char *name,
 	struct hwmon_device *hwdev;
 	int err, id;
 
+	/* Do not accept invalid characters in hwmon name attribute */
+	if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
+		return ERR_PTR(-EINVAL);
+
 	id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
 	if (id < 0)
 		return ERR_PTR(id);
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Tested-by Reviewed-by on v2 1/1
#1 lore raw
Quoted 25 lines · Guenter Roeck

hwmon name attributes must not include '-', as specified in Documentation/hwmon/sysfs-interface. Also filter out spaces, tabs, wildcards, and newline characters.

---
v2: In addition to '-', filter out zero length names as well as names

    containing '*', ' ', '\t', and '\n'.
 drivers/hwmon/hwmon.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/hwmon/hwmon.c +1 -0
index e176a43..a26c385 100644
@@ -22,6 +22,7 @@
 #include <linux/gfp.h>
 #include <linux/spinlock.h>
 #include <linux/pci.h>
+#include <linux/string.h>
 
 #define HWMON_ID_PREFIX "hwmon"
 #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"

drivers/hwmon/hwmon.c hwmon_device_register_with_groups(struct device *dev, const char *name, · line 109

Quoted 10 lines
drivers/hwmon/hwmon.c +4 -0
@@ -99,6 +100,10 @@ hwmon_device_register_with_groups(struct device *dev, const char *name,
 	struct hwmon_device *hwdev;
 	int err, id;
 
+	/* Do not accept invalid characters in hwmon name attribute */
+	if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
+		return ERR_PTR(-EINVAL);
+
 	id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
 	if (id < 0)
 		return ERR_PTR(id);
Signature · 7 lines
Jean Delvare
SUSE L3 Support

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#2 lore raw
In reply to Guenter Roeck
Quoted 29 lines · Jean Delvare
Quoted 28 lines · Guenter Roeck

hwmon name attributes must not include '-', as specified in Documentation/hwmon/sysfs-interface. Also filter out spaces, tabs, wildcards, and newline characters.

---
v2: In addition to '-', filter out zero length names as well as names

    containing '*', ' ', '\t', and '\n'.
 drivers/hwmon/hwmon.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/hwmon/hwmon.c +1 -0
index e176a43..a26c385 100644
@@ -22,6 +22,7 @@
 #include <linux/gfp.h>
 #include <linux/spinlock.h>
 #include <linux/pci.h>
+#include <linux/string.h>
 
 #define HWMON_ID_PREFIX "hwmon"
 #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
@@ -99,6 +100,10 @@ hwmon_device_register_with_groups(struct device *dev, const char *name,
 	struct hwmon_device *hwdev;
 	int err, id;
 
Quoted 11 lines

drivers/hwmon/hwmon.c hwmon_device_register_with_groups(struct device *dev, const char *name, · line 109

Quoted 7 lines
drivers/hwmon/hwmon.c +4 -0
+	/* Do not accept invalid characters in hwmon name attribute */
+	if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
+		return ERR_PTR(-EINVAL);
+
 	id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
 	if (id < 0)
 		return ERR_PTR(id);

Thanks!

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors