Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3061065imm; Sun, 1 Jul 2018 11:19:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI7TBZkr/mKVDhnI5a+y3r0noj9fNJUU19yxc8TvQLeJuw1200MqYU39HGoq5OMxAmJkJtY X-Received: by 2002:a17:902:7e08:: with SMTP id b8-v6mr22922437plm.230.1530469172548; Sun, 01 Jul 2018 11:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530469172; cv=none; d=google.com; s=arc-20160816; b=Ttv37sbyEae7mbRbhMr4iwj/ysn/OMcMGygxG4Nn9YvS5iwpOV8p+PLIJ0SUDI9Do3 FhRP3x6q5ZD/DC73gkYSGTHRiJ6D7EVs9Fu1oMFRE9vRjk4qYLDh9vfT5V1HrMRCJ3DE ElQ3MBtLic+p2NhIyAFQMl+cjjSl7pG3n6ZaeTv6l/r4XUWeC0pt5Z7gzar6qkzvGp9o Ee5qdQB65GFGo67aAE3hDKb4qV9vuCpWf78QnlLozMS2b9dJklSjcrANkaeMxv+YeGE7 G9GLlF6ZnFZFmZm+GpsAEH976t8VNzsFoQP82Z3BcjNqptFzxBx2O3YmZ3eIIuY9p4dM Fu9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=GGOukO4Xmi4Js/9LQrsi00WzPQ28R5b1f79txLv05nk=; b=vqT6yTfNfaFQPLtEXh/wZo/nI2saQ2FhwOJ/2n5F+fSqVHX0CnYs8F9dBVnj3+TLX1 qC3yAbTkIegLNOXJ9PApfY7kC52QlEvucFK3MWUHf/3gYWsiTzjMNFwAB0DEvbaUV8a8 PwBMBrz6Pb5I5MgWYhRmg04BD4e5rvAwTA5MiofIHoIcFoz25zJ5vCUjAjANVo9lMBOe advS9vn22aPYQ0bj5AwG4TQAmeErtmLsPqCYFGpXMNwuahW0cpUQkmFRmohctiao5ZAd MW7/DYLgiw93+Wk/s5O26SOrLUGKaGBgqDWFcmHpgxaxYzvvVNKmuZ/R1HUNqKQmgPjb Fv6Q== 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 v4-v6si11850411pgf.488.2018.07.01.11.19.18; Sun, 01 Jul 2018 11:19:32 -0700 (PDT) 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 S1753618AbeGASR7 (ORCPT + 99 others); Sun, 1 Jul 2018 14:17:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33748 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965263AbeGAQZx (ORCPT ); Sun, 1 Jul 2018 12:25:53 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 009A8ACD; Sun, 1 Jul 2018 16:25:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tony Luck , Borislav Petkov , Thomas Gleixner Subject: [PATCH 4.9 005/101] x86/mce: Do not overwrite MCi_STATUS in mce_no_way_out() Date: Sun, 1 Jul 2018 18:20:51 +0200 Message-Id: <20180701160757.356266184@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Borislav Petkov commit 1f74c8a64798e2c488f86efc97e308b85fb7d7aa upstream. mce_no_way_out() does a quick check during #MC to see whether some of the MCEs logged would require the kernel to panic immediately. And it passes a struct mce where MCi_STATUS gets written. However, after having saved a valid status value, the next iteration of the loop which goes over the MCA banks on the CPU, overwrites the valid status value because we're using struct mce as storage instead of a temporary variable. Which leads to MCE records with an empty status value: mce: [Hardware Error]: CPU 0: Machine Check Exception: 6 Bank 0: 0000000000000000 mce: [Hardware Error]: RIP 10: {trigger_mce+0x7/0x10} In order to prevent the loss of the status register value, return immediately when severity is a panic one so that we can panic immediately with the first fatal MCE logged. This is also the intention of this function and not to noodle over the banks while a fatal MCE is already logged. Tony: read the rest of the MCA bank to populate the struct mce fully. Suggested-by: Tony Luck Signed-off-by: Borislav Petkov Signed-off-by: Thomas Gleixner Cc: Link: https://lkml.kernel.org/r/20180622095428.626-8-bp@alien8.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/mcheck/mce.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c @@ -738,23 +738,25 @@ EXPORT_SYMBOL_GPL(machine_check_poll); static int mce_no_way_out(struct mce *m, char **msg, unsigned long *validp, struct pt_regs *regs) { - int i, ret = 0; char *tmp; + int i; for (i = 0; i < mca_cfg.banks; i++) { m->status = mce_rdmsrl(msr_ops.status(i)); - if (m->status & MCI_STATUS_VAL) { - __set_bit(i, validp); - if (quirk_no_way_out) - quirk_no_way_out(i, m, regs); - } + if (!(m->status & MCI_STATUS_VAL)) + continue; + + __set_bit(i, validp); + if (quirk_no_way_out) + quirk_no_way_out(i, m, regs); if (mce_severity(m, mca_cfg.tolerant, &tmp, true) >= MCE_PANIC_SEVERITY) { + mce_read_aux(m, i); *msg = tmp; - ret = 1; + return 1; } } - return ret; + return 0; } /*