Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp66923ybx; Mon, 4 Nov 2019 15:58:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxwBVNpY6qIYxV+NlfJdus/v9QZ1tbDl8aix0KvZoMWiV921PkRqaXSb/cjnSidLDq1bJF8 X-Received: by 2002:a17:906:594f:: with SMTP id g15mr11913496ejr.197.1572911933546; Mon, 04 Nov 2019 15:58:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572911933; cv=none; d=google.com; s=arc-20160816; b=F8h6e6eSPqsRX9/vgNqnQCIaK0U9m74Y2nAp0CX6fl60Kt85mCnmTWsCAPltj0KKfD +fBOsvxN0lrDbj31N8LfhxwL8Y/jSodpPhAwjIa98Jlm8twsb/gO43SKbsIUPD7soulg eUgM2RevuKkc6FNFZM4DXk1TsFKhldmpjToTA/6L34JcZWOuFGy46eVOMA3fZsyV15T2 A0nqBH5WLDRglBiZVzbG78mbZDOxLjTmQJNyW2l3C/slUqVN1eoJmx9RFB9IKJlK4yD2 XchK2syPQe34MIKN09yZ/rGSFKBS8sKxTIsHVpKWb9N5DXwoBuqLYm8ClHOAamFs1MaP Injw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=aDIcPV7bm+AUCE501J8cjQ6mg61TmiBFwVsQ1+r0bJw=; b=ZvtKGU6Xim0iVhCIcGv/uOmXWiFOhokiRxHSVl1bLDlI60AdkHFbsaYZ3ALHE9ceZU zY0dCWKytYW3P3cGqAly45E+OdwCd45lCvCt3QWABaBNvSPh/vT8LMWpXbLaBIoWBo2C zBe986vXJo7rxNIHWox19dwftG/WLojhiL/KcQNLnapa8iSL6DgLpZuHCTM2yBZjPN84 1qRaag4fqKLkCpMmB02FyJmKMpPdUlvSbp1vuuaoe4gdFLftPiTsqF9Ip98YdMif7oP8 M/4W+mw58Urt4zxvbBKkUTsWjak2BrTClZsFU4kwCLIlXmfYykfpOwltnuJty7M2+V8h D49w== 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 f8si8294256ede.120.2019.11.04.15.58.29; Mon, 04 Nov 2019 15:58:53 -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 S1729945AbfKDX4Y (ORCPT + 99 others); Mon, 4 Nov 2019 18:56:24 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:39263 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729862AbfKDX4X (ORCPT ); Mon, 4 Nov 2019 18:56:23 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iRmCk-0001NK-1x; Tue, 05 Nov 2019 00:56:14 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id A2A191C0105; Tue, 5 Nov 2019 00:56:13 +0100 (CET) Date: Mon, 04 Nov 2019 23:56:13 -0000 From: "tip-bot2 for Thomas Gleixner" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/dumpstack/64: Don't evaluate exception stacks before setup Cc: Cyrill Gorcunov , Thomas Gleixner , Josh Poimboeuf , stable@vger.kernel.org, Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <157291177324.29376.14563915167890708264.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following commit has been merged into the x86/urgent branch of tip: Commit-ID: e361362b08cab1098b64b0e5fd8c879f086b3f46 Gitweb: https://git.kernel.org/tip/e361362b08cab1098b64b0e5fd8c879f086b3f46 Author: Thomas Gleixner AuthorDate: Wed, 23 Oct 2019 20:05:49 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 05 Nov 2019 00:51:35 +01:00 x86/dumpstack/64: Don't evaluate exception stacks before setup Cyrill reported the following crash: BUG: unable to handle page fault for address: 0000000000001ff0 #PF: supervisor read access in kernel mode RIP: 0010:get_stack_info+0xb3/0x148 It turns out that if the stack tracer is invoked before the exception stack mappings are initialized in_exception_stack() can erroneously classify an invalid address as an address inside of an exception stack: begin = this_cpu_read(cea_exception_stacks); <- 0 end = begin + sizeof(exception stacks); i.e. any address between 0 and end will be considered as exception stack address and the subsequent code will then try to derefence the resulting stack frame at a non mapped address. end = begin + (unsigned long)ep->size; ==> end = 0x2000 regs = (struct pt_regs *)end - 1; ==> regs = 0x2000 - sizeof(struct pt_regs *) = 0x1ff0 info->next_sp = (unsigned long *)regs->sp; ==> Crashes due to accessing 0x1ff0 Prevent this by checking the validity of the cea_exception_stack base address and bailing out if it is zero. Fixes: afcd21dad88b ("x86/dumpstack/64: Use cpu_entry_area instead of orig_ist") Reported-by: Cyrill Gorcunov Signed-off-by: Thomas Gleixner Tested-by: Cyrill Gorcunov Acked-by: Josh Poimboeuf Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1910231950590.1852@nanos.tec.linutronix.de --- arch/x86/kernel/dumpstack_64.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c index 753b8cf..87b9789 100644 --- a/arch/x86/kernel/dumpstack_64.c +++ b/arch/x86/kernel/dumpstack_64.c @@ -94,6 +94,13 @@ static bool in_exception_stack(unsigned long *stack, struct stack_info *info) BUILD_BUG_ON(N_EXCEPTION_STACKS != 6); begin = (unsigned long)__this_cpu_read(cea_exception_stacks); + /* + * Handle the case where stack trace is collected _before_ + * cea_exception_stacks had been initialized. + */ + if (!begin) + return false; + end = begin + sizeof(struct cea_exception_stacks); /* Bail if @stack is outside the exception stack area. */ if (stk < begin || stk >= end)