Received: by 10.223.185.116 with SMTP id b49csp6387449wrg; Thu, 8 Mar 2018 06:42:08 -0800 (PST) X-Google-Smtp-Source: AG47ELtc/lm1PwYodzFPfPEN5QVNO9IZfVsSo6TFwsB4nxT2p7i/XqB2IIxK4tN5eR7dQqBpmvcM X-Received: by 10.101.90.75 with SMTP id z11mr20954753pgs.29.1520520127965; Thu, 08 Mar 2018 06:42:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520520127; cv=none; d=google.com; s=arc-20160816; b=X3hTAA8rpImMp9AfJ0hRRdKCm/YhhIKY/9YNALV+yEFxZP70D5TqZOJHWr48fecmOs FLIS6pdW2xwoUrGdNbZ8BHS/oLtf3q512t6gUezxTPw2WZNmmd6ZMxG4fpR7RDv4/mSR a4GwW+Ot6ZRw7yRNTN71zFCLqt8JOoyZxOUR19w1kD5/ZHTk4mxnm5W9MPBvvP/s+I+X 6zT+ejgQYXoBDAbi1OBcCDW1a85xMBlfTwyeMv/zCwvqOu29fOTNYbvE4fpvxnkFWlRS hX0fop4SsQFJIXwT6rVlcdMSxTx65NMFM7lQmY3vkMs8u3KvYzGvS6VZ0bocJt9Zs3zr aPcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=H0nifbRMpGDAXWboFTB/0e238gyjpcDv6PKHLFMaIlc=; b=Q6wmTb7cEruWwZEWRU36GXz16dlO/5z45/DM1BYWLfs6Z0c0PYGnpbUjjZYEppl6eO oRUXSEgEQwITIQxURJz/XY33P3+voZSF/6JjCZUXRh/qkGvWRkbpvZY7A96sQWTqEhlq GoN65p+l0c/Ms2mYFlk6YG5JoZ9Yhaey6DUjyzGjQUsJCUB79uHiIG/fvLYcG5QhqqoI 8uJP+915GazXUny7ZW3zpblUO/mES8Pkw2jNKRLUIONVLkDrrKffMdU8JfC3l5tzkWYm YCrhm6bszWgjaTTcSqhsuQ4V8NFw27sP5qtM0LLavKcFjywSZSp61zfrnnB3r3Axcwyc Uj7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si12930948pgn.157.2018.03.08.06.41.53; Thu, 08 Mar 2018 06:42:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754930AbeCHOkd (ORCPT + 99 others); Thu, 8 Mar 2018 09:40:33 -0500 Received: from terminus.zytor.com ([198.137.202.136]:50199 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751773AbeCHOkb (ORCPT ); Thu, 8 Mar 2018 09:40:31 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w28EeLJJ012834; Thu, 8 Mar 2018 06:40:21 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w28EeKk0012831; Thu, 8 Mar 2018 06:40:20 -0800 Date: Thu, 8 Mar 2018 06:40:20 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Seunghun Han Message-ID: Cc: linux-kernel@vger.kernel.org, kkamagui@gmail.com, tony.luck@intel.com, tglx@linutronix.de, bp@suse.de, hpa@zytor.com, linux-edac@vger.kernel.org, mingo@kernel.org, gregkh@linuxfoundation.org Reply-To: hpa@zytor.com, gregkh@linuxfoundation.org, mingo@kernel.org, linux-edac@vger.kernel.org, tony.luck@intel.com, kkamagui@gmail.com, linux-kernel@vger.kernel.org, bp@suse.de, tglx@linutronix.de In-Reply-To: <20180302202706.9434-1-kkamagui@gmail.com> References: <20180302202706.9434-1-kkamagui@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:ras/urgent] x86/MCE: Serialize sysfs changes Git-Commit-ID: b3b7c4795ccab5be71f080774c45bbbcc75c2aaf X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: b3b7c4795ccab5be71f080774c45bbbcc75c2aaf Gitweb: https://git.kernel.org/tip/b3b7c4795ccab5be71f080774c45bbbcc75c2aaf Author: Seunghun Han AuthorDate: Tue, 6 Mar 2018 15:21:43 +0100 Committer: Thomas Gleixner CommitDate: Thu, 8 Mar 2018 15:36:27 +0100 x86/MCE: Serialize sysfs changes The check_interval file in /sys/devices/system/machinecheck/machinecheck 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 Signed-off-by: Borislav Petkov Signed-off-by: Thomas Gleixner Cc: Greg Kroah-Hartman Cc: Tony Luck Cc: linux-edac Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/20180302202706.9434-1-kkamagui@gmail.com --- arch/x86/kernel/cpu/mcheck/mce.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c index b3323cab9139..466f47301334 100644 --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c @@ -56,6 +56,9 @@ static DEFINE_MUTEX(mce_log_mutex); +/* sysfs synchronization */ +static DEFINE_MUTEX(mce_sysfs_mutex); + #define CREATE_TRACE_POINTS #include @@ -2088,6 +2091,7 @@ static ssize_t set_ignore_ce(struct device *s, if (kstrtou64(buf, 0, &new) < 0) return -EINVAL; + mutex_lock(&mce_sysfs_mutex); if (mca_cfg.ignore_ce ^ !!new) { if (new) { /* disable ce features */ @@ -2100,6 +2104,8 @@ static ssize_t set_ignore_ce(struct device *s, on_each_cpu(mce_enable_ce, (void *)1, 1); } } + mutex_unlock(&mce_sysfs_mutex); + return size; } @@ -2112,6 +2118,7 @@ static ssize_t set_cmci_disabled(struct device *s, if (kstrtou64(buf, 0, &new) < 0) return -EINVAL; + mutex_lock(&mce_sysfs_mutex); if (mca_cfg.cmci_disabled ^ !!new) { if (new) { /* disable cmci */ @@ -2123,6 +2130,8 @@ static ssize_t set_cmci_disabled(struct device *s, on_each_cpu(mce_enable_ce, NULL, 1); } } + mutex_unlock(&mce_sysfs_mutex); + return size; } @@ -2130,8 +2139,19 @@ static ssize_t store_int_with_restart(struct device *s, struct device_attribute *attr, const char *buf, size_t size) { - ssize_t ret = device_store_int(s, attr, buf, size); + unsigned long old_check_interval = check_interval; + ssize_t ret = device_store_ulong(s, attr, buf, size); + + if (check_interval == old_check_interval) + return ret; + + if (check_interval < 1) + check_interval = 1; + + mutex_lock(&mce_sysfs_mutex); mce_restart(); + mutex_unlock(&mce_sysfs_mutex); + return ret; }