diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-06-20 13:04:12 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-06-20 13:04:12 -0400 |
commit | 4e183d7add15e8bdd131aa14976e26ca3d71a889 (patch) | |
tree | 345a510fb2c18ffd75cc526d48535430cdbfd2d0 | |
parent | 33688abb2802ff3a230bd2441f765477b94cc89e (diff) | |
parent | 2744d2fde00dc8bcc3679eb72c81a63058e90faa (diff) |
Merge tag 'hwmon-for-linus-v4.7-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck:
"Two stability fixes plus a security fix for the dell-smm driver"
* tag 'hwmon-for-linus-v4.7-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
hwmon: (dell-smm) Disallow fan_type() calls on broken machines
hwmon: (dell-smm) Restrict fan control and serial number to CAP_SYS_ADMIN by default
hwmon: (dell-smm) Fail in ioctl I8K_BIOS_VERSION when bios version is not a number
-rw-r--r-- | drivers/hwmon/dell-smm-hwmon.c | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index c43318d3416e..4bbc58714868 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/uaccess.h> | 35 | #include <linux/uaccess.h> |
36 | #include <linux/io.h> | 36 | #include <linux/io.h> |
37 | #include <linux/sched.h> | 37 | #include <linux/sched.h> |
38 | #include <linux/ctype.h> | ||
38 | 39 | ||
39 | #include <linux/i8k.h> | 40 | #include <linux/i8k.h> |
40 | 41 | ||
@@ -66,11 +67,13 @@ | |||
66 | 67 | ||
67 | static DEFINE_MUTEX(i8k_mutex); | 68 | static DEFINE_MUTEX(i8k_mutex); |
68 | static char bios_version[4]; | 69 | static char bios_version[4]; |
70 | static char bios_machineid[16]; | ||
69 | static struct device *i8k_hwmon_dev; | 71 | static struct device *i8k_hwmon_dev; |
70 | static u32 i8k_hwmon_flags; | 72 | static u32 i8k_hwmon_flags; |
71 | static uint i8k_fan_mult = I8K_FAN_MULT; | 73 | static uint i8k_fan_mult = I8K_FAN_MULT; |
72 | static uint i8k_pwm_mult; | 74 | static uint i8k_pwm_mult; |
73 | static uint i8k_fan_max = I8K_FAN_HIGH; | 75 | static uint i8k_fan_max = I8K_FAN_HIGH; |
76 | static bool disallow_fan_type_call; | ||
74 | 77 | ||
75 | #define I8K_HWMON_HAVE_TEMP1 (1 << 0) | 78 | #define I8K_HWMON_HAVE_TEMP1 (1 << 0) |
76 | #define I8K_HWMON_HAVE_TEMP2 (1 << 1) | 79 | #define I8K_HWMON_HAVE_TEMP2 (1 << 1) |
@@ -94,13 +97,13 @@ module_param(ignore_dmi, bool, 0); | |||
94 | MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match"); | 97 | MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match"); |
95 | 98 | ||
96 | #if IS_ENABLED(CONFIG_I8K) | 99 | #if IS_ENABLED(CONFIG_I8K) |
97 | static bool restricted; | 100 | static bool restricted = true; |
98 | module_param(restricted, bool, 0); | 101 | module_param(restricted, bool, 0); |
99 | MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set"); | 102 | MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)"); |
100 | 103 | ||
101 | static bool power_status; | 104 | static bool power_status; |
102 | module_param(power_status, bool, 0600); | 105 | module_param(power_status, bool, 0600); |
103 | MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k"); | 106 | MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)"); |
104 | #endif | 107 | #endif |
105 | 108 | ||
106 | static uint fan_mult; | 109 | static uint fan_mult; |
@@ -239,6 +242,9 @@ static int i8k_get_fan_type(int fan) | |||
239 | { | 242 | { |
240 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, }; | 243 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, }; |
241 | 244 | ||
245 | if (disallow_fan_type_call) | ||
246 | return -EINVAL; | ||
247 | |||
242 | regs.ebx = fan & 0xff; | 248 | regs.ebx = fan & 0xff; |
243 | return i8k_smm(®s) ? : regs.eax & 0xff; | 249 | return i8k_smm(®s) ? : regs.eax & 0xff; |
244 | } | 250 | } |
@@ -387,14 +393,20 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) | |||
387 | 393 | ||
388 | switch (cmd) { | 394 | switch (cmd) { |
389 | case I8K_BIOS_VERSION: | 395 | case I8K_BIOS_VERSION: |
396 | if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) || | ||
397 | !isdigit(bios_version[2])) | ||
398 | return -EINVAL; | ||
399 | |||
390 | val = (bios_version[0] << 16) | | 400 | val = (bios_version[0] << 16) | |
391 | (bios_version[1] << 8) | bios_version[2]; | 401 | (bios_version[1] << 8) | bios_version[2]; |
392 | break; | 402 | break; |
393 | 403 | ||
394 | case I8K_MACHINE_ID: | 404 | case I8K_MACHINE_ID: |
395 | memset(buff, 0, 16); | 405 | if (restricted && !capable(CAP_SYS_ADMIN)) |
396 | strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), | 406 | return -EPERM; |
397 | sizeof(buff)); | 407 | |
408 | memset(buff, 0, sizeof(buff)); | ||
409 | strlcpy(buff, bios_machineid, sizeof(buff)); | ||
398 | break; | 410 | break; |
399 | 411 | ||
400 | case I8K_FN_STATUS: | 412 | case I8K_FN_STATUS: |
@@ -511,7 +523,7 @@ static int i8k_proc_show(struct seq_file *seq, void *offset) | |||
511 | seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", | 523 | seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", |
512 | I8K_PROC_FMT, | 524 | I8K_PROC_FMT, |
513 | bios_version, | 525 | bios_version, |
514 | i8k_get_dmi_data(DMI_PRODUCT_SERIAL), | 526 | (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid, |
515 | cpu_temp, | 527 | cpu_temp, |
516 | left_fan, right_fan, left_speed, right_speed, | 528 | left_fan, right_fan, left_speed, right_speed, |
517 | ac_power, fn_key); | 529 | ac_power, fn_key); |
@@ -718,6 +730,9 @@ static struct attribute *i8k_attrs[] = { | |||
718 | static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, | 730 | static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, |
719 | int index) | 731 | int index) |
720 | { | 732 | { |
733 | if (disallow_fan_type_call && | ||
734 | (index == 9 || index == 12)) | ||
735 | return 0; | ||
721 | if (index >= 0 && index <= 1 && | 736 | if (index >= 0 && index <= 1 && |
722 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) | 737 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) |
723 | return 0; | 738 | return 0; |
@@ -929,12 +944,14 @@ static struct dmi_system_id i8k_dmi_table[] __initdata = { | |||
929 | 944 | ||
930 | MODULE_DEVICE_TABLE(dmi, i8k_dmi_table); | 945 | MODULE_DEVICE_TABLE(dmi, i8k_dmi_table); |
931 | 946 | ||
932 | static struct dmi_system_id i8k_blacklist_dmi_table[] __initdata = { | 947 | /* |
948 | * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed | ||
949 | * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist | ||
950 | * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call. | ||
951 | * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121 | ||
952 | */ | ||
953 | static struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initdata = { | ||
933 | { | 954 | { |
934 | /* | ||
935 | * CPU fan speed going up and down on Dell Studio XPS 8000 | ||
936 | * for unknown reasons. | ||
937 | */ | ||
938 | .ident = "Dell Studio XPS 8000", | 955 | .ident = "Dell Studio XPS 8000", |
939 | .matches = { | 956 | .matches = { |
940 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | 957 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
@@ -942,16 +959,19 @@ static struct dmi_system_id i8k_blacklist_dmi_table[] __initdata = { | |||
942 | }, | 959 | }, |
943 | }, | 960 | }, |
944 | { | 961 | { |
945 | /* | ||
946 | * CPU fan speed going up and down on Dell Studio XPS 8100 | ||
947 | * for unknown reasons. | ||
948 | */ | ||
949 | .ident = "Dell Studio XPS 8100", | 962 | .ident = "Dell Studio XPS 8100", |
950 | .matches = { | 963 | .matches = { |
951 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | 964 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
952 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"), | 965 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"), |
953 | }, | 966 | }, |
954 | }, | 967 | }, |
968 | { | ||
969 | .ident = "Dell Inspiron 580", | ||
970 | .matches = { | ||
971 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | ||
972 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "), | ||
973 | }, | ||
974 | }, | ||
955 | { } | 975 | { } |
956 | }; | 976 | }; |
957 | 977 | ||
@@ -966,8 +986,7 @@ static int __init i8k_probe(void) | |||
966 | /* | 986 | /* |
967 | * Get DMI information | 987 | * Get DMI information |
968 | */ | 988 | */ |
969 | if (!dmi_check_system(i8k_dmi_table) || | 989 | if (!dmi_check_system(i8k_dmi_table)) { |
970 | dmi_check_system(i8k_blacklist_dmi_table)) { | ||
971 | if (!ignore_dmi && !force) | 990 | if (!ignore_dmi && !force) |
972 | return -ENODEV; | 991 | return -ENODEV; |
973 | 992 | ||
@@ -978,8 +997,13 @@ static int __init i8k_probe(void) | |||
978 | i8k_get_dmi_data(DMI_BIOS_VERSION)); | 997 | i8k_get_dmi_data(DMI_BIOS_VERSION)); |
979 | } | 998 | } |
980 | 999 | ||
1000 | if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) | ||
1001 | disallow_fan_type_call = true; | ||
1002 | |||
981 | strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), | 1003 | strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), |
982 | sizeof(bios_version)); | 1004 | sizeof(bios_version)); |
1005 | strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), | ||
1006 | sizeof(bios_machineid)); | ||
983 | 1007 | ||
984 | /* | 1008 | /* |
985 | * Get SMM Dell signature | 1009 | * Get SMM Dell signature |