Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1246899ybl; Wed, 18 Dec 2019 15:13:21 -0800 (PST) X-Google-Smtp-Source: APXvYqwlXlRhurlMBFOEYvBmo8EvHnufpGSdVORbHAGYrhJl+NvRcdPzhpqSO4Pckehyt4rG2a2t X-Received: by 2002:a05:6830:1e37:: with SMTP id t23mr5385360otr.16.1576710801282; Wed, 18 Dec 2019 15:13:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576710801; cv=none; d=google.com; s=arc-20160816; b=bn/I0vPA9rS4ziCPIzqROB4RRqDJDRWWQ9i5k16FniWiENuFw4U9HOGJp1ZhDSkm20 mtdLfUOgsz9aYanPwlZ7ciU+jIuNJzJ6ASBLn45V423HJfAHxLibma6Tgldogt278Kj4 a2uPbUIOws3sGD7v8zuCZTlAA1g0pmgMpOMf1WAVXxJMOcxGiPvTOt+VMbAMAiePEnfr IciDEjx6sikWooLWTW783VmBW8/3dqj0TtwDEr+PtXXo1TvYqCtB5GT3eLfdsBbSH4S4 bUPBFH/0jj7zYrq1l10/qSoWFU633cpoyiOmUxZCa2VldiqP3bB2NxOAxNi3d+XFJRqf 5tgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=O7cRpxVyt8uxMLcyDyuXxaiEb45NcHrYdQjrFEEd8is=; b=KOYrAEHihegkYRtJOfP0w5eu6noqVCmJmu3c7UpzeUDHj0Kigh9uMzDba/DCcVe/2C aVeg5rNslWmygfnoS4zOjC2gvDEyPMqXRVnEl6/25QzTa3kIobHPCXPfwTyEaeHjHukx NUJxH3ep4nSoTKeFzIQ9a8LefUaOzAoxyLE76bBke9yRXU8FP/15bqU1YfOIFhyCh1YT 3NJPHOz/L2UT7TZk4DlPo/KsWhNx+6GEnmWh4Cs+LDrUUBoRCMGoWNo0zN2dm1o2opYK HYQWsK5XWrSpeX9td6lVzjLhrcfQ/WY1Bk1zLVBcpmDcfI9vUM6CcPKo+dq1JR983NLY My5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cvPGswJD; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si2177216otj.148.2019.12.18.15.13.09; Wed, 18 Dec 2019 15:13:21 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=cvPGswJD; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbfLRXMU (ORCPT + 99 others); Wed, 18 Dec 2019 18:12:20 -0500 Received: from mail-wr1-f73.google.com ([209.85.221.73]:45152 "EHLO mail-wr1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726741AbfLRXMT (ORCPT ); Wed, 18 Dec 2019 18:12:19 -0500 Received: by mail-wr1-f73.google.com with SMTP id d8so1496603wrq.12 for ; Wed, 18 Dec 2019 15:12:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=O7cRpxVyt8uxMLcyDyuXxaiEb45NcHrYdQjrFEEd8is=; b=cvPGswJDDCWWZrQ9HPqf9ZoStjXiGuTN61KVqKFRTF/ugxQS/hxj7FlWuHb/7dRR/0 Bw8AMJKfchRCkhA0FflSqoIW/fbUNTuZABELRviUTxuBYe6qdHxF/ZHNaJ1i/9h4EQhz +o/JTPG67rwkv6AoO/pTlylX9MEI0+7oQmhsNGQCvoxs3UsrO/e9ReQdV2REYnEYqxbx yrPb4MLABG4L4OQVFX+asx6Fcsk8NMZEEc1QJGhnMWuxUrtnHK5bDH58u13ocqlmGjXv mXmUY/npxI6D8qYLlsz783loophJ8C3MgwePm7yq/tfmeGrwhIm5W6NJXEPeLfZrglOA 8tag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=O7cRpxVyt8uxMLcyDyuXxaiEb45NcHrYdQjrFEEd8is=; b=J8NHnNSKe9qf6IqcMaVdFPZINIq8Snc4A0w7GkudQOPb72PwfkmsVFGLOYpOHn12JM yMk46R3h4cxvrsNKwd59o1iFfGvNeuc0m33tgtgQ0Qp6vkpBwWpF87NiXcIq2oUWE9q8 61IJNrdM7uxTqaYkjR2juoXcsx1ZMFAypMTjBg4SQLXmOcZBZj3/CNDF7kxQ6o0ps2j7 AtNrFpye0rrruPyVN03P30zvTi4tHltivke5MsrXIl/G2FCkbTsP9Wzx08vykFnYOhy2 Q9pCmRIxgE1LdOwl/DraqKtmcw6XHaHRlhrs88rZRRZND0FC+n9GgRVuYlrLu/BCOMgx aYkw== X-Gm-Message-State: APjAAAU7wUlk3jHiigcG47XLAuy3SwLYnXD57pe+0jzxXMsrWspW6fQm Z5JbVkhYIyuiox4qYjs2PwgWGP2udw== X-Received: by 2002:adf:81c2:: with SMTP id 60mr5454204wra.8.1576710735282; Wed, 18 Dec 2019 15:12:15 -0800 (PST) Date: Thu, 19 Dec 2019 00:11:49 +0100 In-Reply-To: <20191218231150.12139-1-jannh@google.com> Message-Id: <20191218231150.12139-3-jannh@google.com> Mime-Version: 1.0 References: <20191218231150.12139-1-jannh@google.com> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog Subject: [PATCH v7 3/4] x86/dumpstack: Introduce die_addr() for die() with #GP fault address From: Jann Horn To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, jannh@google.com Cc: linux-kernel@vger.kernel.org, Andrey Konovalov , Andy Lutomirski , Sean Christopherson 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 Split __die() into __die_header() and __die_body(). This allows inserting extra information below the header line that initiates the bug report. Introduce a new function die_addr() that behaves like die(), but is for faults only and uses __die_header()+__die_body() so that a future commit can print extra information after the header line. Signed-off-by: Jann Horn --- Notes: v3: new patch v4-v6: no changes v7: - introduce die_addr() instead of open-coding __die_header() and __die_body() calls in traps.c (Borislav) - make __die_header() and __die_body() static - rewrite commit message arch/x86/include/asm/kdebug.h | 1 + arch/x86/kernel/dumpstack.c | 24 +++++++++++++++++++++++- arch/x86/kernel/traps.c | 5 ++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kdebug.h b/arch/x86/include/asm/kdebug.h index 75f1e35e7c15..247ab14c6309 100644 --- a/arch/x86/include/asm/kdebug.h +++ b/arch/x86/include/asm/kdebug.h @@ -33,6 +33,7 @@ enum show_regs_mode { }; extern void die(const char *, struct pt_regs *,long); +void die_addr(const char *str, struct pt_regs *regs, long err, long gp_addr); extern int __must_check __die(const char *, struct pt_regs *, long); extern void show_stack_regs(struct pt_regs *regs); extern void __show_regs(struct pt_regs *regs, enum show_regs_mode); diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index e07424e19274..8995bf10c97c 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -365,7 +365,7 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr) } NOKPROBE_SYMBOL(oops_end); -int __die(const char *str, struct pt_regs *regs, long err) +static void __die_header(const char *str, struct pt_regs *regs, long err) { const char *pr = ""; @@ -384,7 +384,11 @@ int __die(const char *str, struct pt_regs *regs, long err) IS_ENABLED(CONFIG_KASAN) ? " KASAN" : "", IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION) ? (boot_cpu_has(X86_FEATURE_PTI) ? " PTI" : " NOPTI") : ""); +} +NOKPROBE_SYMBOL(__die_header); +static int __die_body(const char *str, struct pt_regs *regs, long err) +{ show_regs(regs); print_modules(); @@ -394,6 +398,13 @@ int __die(const char *str, struct pt_regs *regs, long err) return 0; } +NOKPROBE_SYMBOL(__die_body); + +int __die(const char *str, struct pt_regs *regs, long err) +{ + __die_header(str, regs, err); + return __die_body(str, regs, err); +} NOKPROBE_SYMBOL(__die); /* @@ -410,6 +421,17 @@ void die(const char *str, struct pt_regs *regs, long err) oops_end(flags, regs, sig); } +void die_addr(const char *str, struct pt_regs *regs, long err, long gp_addr) +{ + unsigned long flags = oops_begin(); + int sig = SIGSEGV; + + __die_header(str, regs, err); + if (__die_body(str, regs, err)) + sig = 0; + oops_end(flags, regs, sig); +} + void show_regs(struct pt_regs *regs) { show_regs_print_info(KERN_DEFAULT); diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index c8b4ae6aed5b..4c691bb9e0d9 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -621,7 +621,10 @@ do_general_protection(struct pt_regs *regs, long error_code) "maybe for address", gp_addr); - die(desc, regs, error_code); + if (hint != GP_NON_CANONICAL) + gp_addr = 0; + + die_addr(desc, regs, error_code, gp_addr); return; } -- 2.24.1.735.g03f4e72817-goog