Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4208417ybv; Tue, 25 Feb 2020 15:30:38 -0800 (PST) X-Google-Smtp-Source: APXvYqxP7IPbM7FG4UZbXeONtPnbcVGHXGzHt8fxQhHBhOguPEBs+UOBV57kK+8CmXAxPHJVJ18N X-Received: by 2002:a9d:6ad6:: with SMTP id m22mr853903otq.7.1582673438358; Tue, 25 Feb 2020 15:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582673438; cv=none; d=google.com; s=arc-20160816; b=XgAqjJFias94dk95ahwIsdsEQMQ355OqRsp2wgLOMHHLYUyzTS19mz8nOK1PEhFfGI MiVdNbKtEgpkXCmDKL19Fr3umMYaWLc57vyXAEbA1ksKzvVQ7Tjuo6FUCGTfhiXkDosR Ii5wcNG0J8nZhlyz+4Xd+IqZrzn/+M6WhElMYX4/g6GgMKc9w757gejMRzohqU/jesn2 FveVzSw4kc8r+2umFqpBU/rVXQRa7aYO2Y/MoIJbFmG8nMu/70g4RYTCdofcGPT5x5ls i7/Wt0sr1tbj9N2Ckm1c131Gci3Vs/kCFyQDVoHW3qzfh5M7EyD7uDSnqtxKH1QZ7Mro 661Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id; bh=4cW1sH+EQ+PMijw5F8QrBM7as/XHfwLWWwFz8pN6mck=; b=cKwBc6AioCFbDvyYtMFB6DzsA006xtxI86W8kRkluOX9+yt1R5YY1WIyuzgJutiUkw R6q0HcRkFiUmPlWtpl0Xr4+fx3nkM4iY5poF6m5uAEAJfh267vxQsKPxgk7/SROfJsFq zww+WnnKzDQdLzpPDx+GuTVfbCwz0zx76lnslLP0KaBfBPPu/eW6m4Z7irnxs8twT+II p6iTqqDEc+9nyxwJQX8FWJU9wi6tYfUMArG4r/wr7bgTmr3CaG6/3UVmlNKNcVkXAF1k Ajz1kLwLXT169tv149OM9yMVGi2+ZOSgpijiqG+AvzOxnsNE66pB+Ejj1Fpk6gHPEvVr XGnA== 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 i15si148178oik.46.2020.02.25.15.30.26; Tue, 25 Feb 2020 15:30:38 -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 S1729832AbgBYX0E (ORCPT + 99 others); Tue, 25 Feb 2020 18:26:04 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:55602 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729740AbgBYX0A (ORCPT ); Tue, 25 Feb 2020 18:26:00 -0500 Received: from p5de0bf0b.dip0.t-ipconnect.de ([93.224.191.11] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1j6jZw-0004W2-J0; Wed, 26 Feb 2020 00:25:29 +0100 Received: from nanos.tec.linutronix.de (localhost [IPv6:::1]) by nanos.tec.linutronix.de (Postfix) with ESMTP id 160EA1039F7; Wed, 26 Feb 2020 00:25:28 +0100 (CET) Message-Id: <20200225220216.315548935@linutronix.de> User-Agent: quilt/0.65 Date: Tue, 25 Feb 2020 22:36:38 +0100 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Steven Rostedt , Brian Gerst , Juergen Gross , Paolo Bonzini , Arnd Bergmann , Andy Lutomirski Subject: [patch 02/10] x86/mce: Disable tracing and kprobes on do_machine_check() References: <20200225213636.689276920@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Lutomirski do_machine_check() can be raised in almost any context including the most fragile ones. Prevent kprobes and tracing. Signed-off-by: Andy Lutomirski Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/traps.h | 3 --- arch/x86/kernel/cpu/mce/core.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) --- a/arch/x86/include/asm/traps.h +++ b/arch/x86/include/asm/traps.h @@ -88,9 +88,6 @@ dotraplinkage void do_page_fault(struct dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code); dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code); dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code); -#ifdef CONFIG_X86_MCE -dotraplinkage void do_machine_check(struct pt_regs *regs, long error_code); -#endif dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code); #ifdef CONFIG_X86_32 dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code); --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -1213,8 +1213,14 @@ static void __mc_scan_banks(struct mce * * On Intel systems this is entered on all CPUs in parallel through * MCE broadcast. However some CPUs might be broken beyond repair, * so be always careful when synchronizing with others. + * + * Tracing and kprobes are disabled: if we interrupted a kernel context + * with IF=1, we need to minimize stack usage. There are also recursion + * issues: if the machine check was due to a failure of the memory + * backing the user stack, tracing that reads the user stack will cause + * potentially infinite recursion. */ -void do_machine_check(struct pt_regs *regs, long error_code) +void notrace do_machine_check(struct pt_regs *regs, long error_code) { DECLARE_BITMAP(valid_banks, MAX_NR_BANKS); DECLARE_BITMAP(toclear, MAX_NR_BANKS); @@ -1360,6 +1366,7 @@ void do_machine_check(struct pt_regs *re ist_exit(regs); } EXPORT_SYMBOL_GPL(do_machine_check); +NOKPROBE_SYMBOL(do_machine_check); #ifndef CONFIG_MEMORY_FAILURE int memory_failure(unsigned long pfn, int flags) @@ -1892,10 +1899,11 @@ static void unexpected_machine_check(str void (*machine_check_vector)(struct pt_regs *, long error_code) = unexpected_machine_check; -dotraplinkage void do_mce(struct pt_regs *regs, long error_code) +dotraplinkage notrace void do_mce(struct pt_regs *regs, long error_code) { machine_check_vector(regs, error_code); } +NOKPROBE_SYMBOL(do_mce); /* * Called for each booted CPU to set up machine checks.