Skip to content

Commit 648cd48

Browse files
committed
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. Tested-by: Jean Delvare <[email protected]> Reviewed-by: Jean Delvare <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 768821a commit 648cd48

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/hwmon/hwmon.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/gfp.h>
2323
#include <linux/spinlock.h>
2424
#include <linux/pci.h>
25+
#include <linux/string.h>
2526

2627
#define HWMON_ID_PREFIX "hwmon"
2728
#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
@@ -99,6 +100,10 @@ hwmon_device_register_with_groups(struct device *dev, const char *name,
99100
struct hwmon_device *hwdev;
100101
int err, id;
101102

103+
/* Do not accept invalid characters in hwmon name attribute */
104+
if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
105+
return ERR_PTR(-EINVAL);
106+
102107
id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
103108
if (id < 0)
104109
return ERR_PTR(id);

0 commit comments

Comments
 (0)