Skip to content

Commit b3b7c47

Browse files
kkamaguiKAGA-KOKO
authored andcommitted
x86/MCE: Serialize sysfs changes
The check_interval file in /sys/devices/system/machinecheck/machinecheck<cpu number> directory is a global timer value for MCE polling. If it is changed by one CPU, mce_restart() broadcasts the event to other CPUs to delete and restart the MCE polling timer and __mcheck_cpu_init_timer() reinitializes the mce_timer variable. If more than one CPU writes a specific value to the check_interval file concurrently, mce_timer is not protected from such concurrent accesses and all kinds of explosions happen. Since only root can write to those sysfs variables, the issue is not a big deal security-wise. However, concurrent writes to these configuration variables is void of reason so the proper thing to do is to serialize the access with a mutex. Boris: - Make store_int_with_restart() use device_store_ulong() to filter out negative intervals - Limit min interval to 1 second - Correct locking - Massage commit message Signed-off-by: Seunghun Han <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Tony Luck <[email protected]> Cc: linux-edac <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected]
1 parent fa94d0c commit b3b7c47

File tree

1 file changed

+21
-1
lines changed
  • arch/x86/kernel/cpu/mcheck

1 file changed

+21
-1
lines changed

arch/x86/kernel/cpu/mcheck/mce.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656

5757
static DEFINE_MUTEX(mce_log_mutex);
5858

59+
/* sysfs synchronization */
60+
static DEFINE_MUTEX(mce_sysfs_mutex);
61+
5962
#define CREATE_TRACE_POINTS
6063
#include <trace/events/mce.h>
6164

@@ -2088,6 +2091,7 @@ static ssize_t set_ignore_ce(struct device *s,
20882091
if (kstrtou64(buf, 0, &new) < 0)
20892092
return -EINVAL;
20902093

2094+
mutex_lock(&mce_sysfs_mutex);
20912095
if (mca_cfg.ignore_ce ^ !!new) {
20922096
if (new) {
20932097
/* disable ce features */
@@ -2100,6 +2104,8 @@ static ssize_t set_ignore_ce(struct device *s,
21002104
on_each_cpu(mce_enable_ce, (void *)1, 1);
21012105
}
21022106
}
2107+
mutex_unlock(&mce_sysfs_mutex);
2108+
21032109
return size;
21042110
}
21052111

@@ -2112,6 +2118,7 @@ static ssize_t set_cmci_disabled(struct device *s,
21122118
if (kstrtou64(buf, 0, &new) < 0)
21132119
return -EINVAL;
21142120

2121+
mutex_lock(&mce_sysfs_mutex);
21152122
if (mca_cfg.cmci_disabled ^ !!new) {
21162123
if (new) {
21172124
/* disable cmci */
@@ -2123,15 +2130,28 @@ static ssize_t set_cmci_disabled(struct device *s,
21232130
on_each_cpu(mce_enable_ce, NULL, 1);
21242131
}
21252132
}
2133+
mutex_unlock(&mce_sysfs_mutex);
2134+
21262135
return size;
21272136
}
21282137

21292138
static ssize_t store_int_with_restart(struct device *s,
21302139
struct device_attribute *attr,
21312140
const char *buf, size_t size)
21322141
{
2133-
ssize_t ret = device_store_int(s, attr, buf, size);
2142+
unsigned long old_check_interval = check_interval;
2143+
ssize_t ret = device_store_ulong(s, attr, buf, size);
2144+
2145+
if (check_interval == old_check_interval)
2146+
return ret;
2147+
2148+
if (check_interval < 1)
2149+
check_interval = 1;
2150+
2151+
mutex_lock(&mce_sysfs_mutex);
21342152
mce_restart();
2153+
mutex_unlock(&mce_sysfs_mutex);
2154+
21352155
return ret;
21362156
}
21372157

0 commit comments

Comments
 (0)