Received: by 10.223.185.116 with SMTP id b49csp4173165wrg; Mon, 19 Feb 2018 12:32:00 -0800 (PST) X-Google-Smtp-Source: AH8x227Sfp7ZFdb6Hxfejlzv5WCmWvo8ZaDy2XqsD7wXpAM60N0hI0ZWpWjVVlFcfQbNIJeyRrkV X-Received: by 2002:a17:902:e83:: with SMTP id 3-v6mr15166618plx.158.1519072319955; Mon, 19 Feb 2018 12:31:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519072319; cv=none; d=google.com; s=arc-20160816; b=gkihWrTPom5rS6/8gXUSGdpZjkJyQHDMOXRMfL1UhiYciAYfie/c0o28N+QwCeWShP xskXAVP9h3+Hn/Io0lMYz52yjFP11ULn8Wvoicx2bkCe/5RoPgtycDC7UyCZv/MV5kBG txB3IWAF3t7qwjE4D16t7lI0QXEcSNZrOcMqb6dxtEoFuIawajjiisoZK2Z1ouJ/4/iA I+pg/hsPp2FhLEsDajqf3CkiAbWa4RNQJ0bmDe1H8E0V0aXqDNcvcZ7bRh71LQdQKy8K mlBY8MHrz0+LdGGzP+FuedViNnlYn79Bd5kFYpp8vsjFeYrQ962/eaH5N9gt8iS+fICt 60JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=snfFdfEmtMKvLIrxUrpfmjqwOQCJNOqzPPj8i4RMgMU=; b=pUtZYD979MxzAk4XorUmIqCSEAJzj5AzAbRJo3EyJpCnof0IwE17+rxHodSM0rXAfz 8gqjQoLqhwc9FCgs3cVIUOp2hWGhlQlGwtr6T7jALylBudyQ6aHJuRnf9Y1GXvwFpGA7 XvPSecXM/0j18WL3zq1qf+dbLEjv+Re89Kb6K9FGpVVTHHe1z22P783XM2dJh5mETxpJ 7Vqh+eTvEGDJU04oahVuSfoQondVgbfRZqKzdd4mQR5alcQ61bv0HxhOtj/4fWGz7GZO ZoVTBnaxvltmdGPmue20++1u7pjNk39mzKf7qFtALZ0fJgslIMBk6/Rh83+YlGcJGh7h pbSA== 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 n10-v6si5012664pls.112.2018.02.19.12.31.45; Mon, 19 Feb 2018 12:31:59 -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 S932360AbeBSU2x (ORCPT + 99 others); Mon, 19 Feb 2018 15:28:53 -0500 Received: from mail.skyhub.de ([5.9.137.197]:37736 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932188AbeBSU2w (ORCPT ); Mon, 19 Feb 2018 15:28:52 -0500 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TIH-gRj1Uhd9; Mon, 19 Feb 2018 21:28:50 +0100 (CET) Received: from pd.tnic (p200300EC2BC81D00F5823ED58EA92312.dip0.t-ipconnect.de [IPv6:2003:ec:2bc8:1d00:f582:3ed5:8ea9:2312]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 2F2E71EC08BF; Mon, 19 Feb 2018 21:28:50 +0100 (CET) From: Borislav Petkov To: X86 ML Cc: Peter Zijlstra , Josh Poimboeuf , Andy Lutomirski , LKML Subject: [PATCH 1/5] x86/dumpstack: Unify show_regs() Date: Mon, 19 Feb 2018 21:28:22 +0100 Message-Id: <20180219202826.19797-2-bp@alien8.de> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20180219202826.19797-1-bp@alien8.de> References: <20180219202826.19797-1-bp@alien8.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov The 32-bit version uses KERN_EMERG and commit b0f4c4b32c8e ("bugs, x86: Fix printk levels for panic, softlockups and stack dumps") changed the 64-bit version to KERN_DEFAULT. The same justification in that commit that those messages do not belong in the terminal, holds true for 32-bit also, so make it so. Make code_bytes static, while at it. Signed-off-by: Borislav Petkov --- arch/x86/include/asm/stacktrace.h | 2 -- arch/x86/kernel/dumpstack.c | 49 ++++++++++++++++++++++++++++++++++++++- arch/x86/kernel/dumpstack_32.c | 42 --------------------------------- arch/x86/kernel/dumpstack_64.c | 42 --------------------------------- 4 files changed, 48 insertions(+), 87 deletions(-) diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h index f73706878772..133d9425fced 100644 --- a/arch/x86/include/asm/stacktrace.h +++ b/arch/x86/include/asm/stacktrace.h @@ -87,8 +87,6 @@ get_stack_pointer(struct task_struct *task, struct pt_regs *regs) void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, unsigned long *stack, char *log_lvl); -extern unsigned int code_bytes; - /* The form of the top of the frame on the stack */ struct stack_frame { struct stack_frame *next_frame; diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index a2d8a3908670..18fa9d74c182 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -24,7 +24,7 @@ int panic_on_unrecovered_nmi; int panic_on_io_nmi; -unsigned int code_bytes = 64; +static unsigned int code_bytes = 64; static int die_counter; bool in_task_stack(unsigned long *stack, struct task_struct *task, @@ -375,3 +375,50 @@ static int __init code_bytes_setup(char *s) return 1; } __setup("code_bytes=", code_bytes_setup); + +void show_regs(struct pt_regs *regs) +{ + bool all = true; + int i; + + show_regs_print_info(KERN_DEFAULT); + + if (IS_ENABLED(CONFIG_X86_32)) + all = !user_mode(regs); + + __show_regs(regs, all); + + /* + * When in-kernel, we also print out the stack and code at the + * time of the fault.. + */ + if (!user_mode(regs)) { + unsigned int code_prologue = code_bytes * 43 / 64; + unsigned int code_len = code_bytes; + unsigned char c; + u8 *ip; + + show_trace_log_lvl(current, regs, NULL, KERN_DEFAULT); + + printk(KERN_DEFAULT "Code: "); + + ip = (u8 *)regs->ip - code_prologue; + if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { + /* try starting at IP */ + ip = (u8 *)regs->ip; + code_len = code_len - code_prologue + 1; + } + for (i = 0; i < code_len; i++, ip++) { + if (ip < (u8 *)PAGE_OFFSET || + probe_kernel_address(ip, c)) { + pr_cont(" Bad RIP value."); + break; + } + if (ip == (u8 *)regs->ip) + pr_cont("<%02x> ", c); + else + pr_cont("%02x ", c); + } + } + pr_cont("\n"); +} diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c index 04170f63e3a1..cd53f3030e40 100644 --- a/arch/x86/kernel/dumpstack_32.c +++ b/arch/x86/kernel/dumpstack_32.c @@ -127,45 +127,3 @@ int get_stack_info(unsigned long *stack, struct task_struct *task, info->type = STACK_TYPE_UNKNOWN; return -EINVAL; } - -void show_regs(struct pt_regs *regs) -{ - int i; - - show_regs_print_info(KERN_EMERG); - __show_regs(regs, !user_mode(regs)); - - /* - * When in-kernel, we also print out the stack and code at the - * time of the fault.. - */ - if (!user_mode(regs)) { - unsigned int code_prologue = code_bytes * 43 / 64; - unsigned int code_len = code_bytes; - unsigned char c; - u8 *ip; - - show_trace_log_lvl(current, regs, NULL, KERN_EMERG); - - pr_emerg("Code:"); - - ip = (u8 *)regs->ip - code_prologue; - if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { - /* try starting at IP */ - ip = (u8 *)regs->ip; - code_len = code_len - code_prologue + 1; - } - for (i = 0; i < code_len; i++, ip++) { - if (ip < (u8 *)PAGE_OFFSET || - probe_kernel_address(ip, c)) { - pr_cont(" Bad EIP value."); - break; - } - if (ip == (u8 *)regs->ip) - pr_cont(" <%02x>", c); - else - pr_cont(" %02x", c); - } - } - pr_cont("\n"); -} diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c index 563e28d14f2c..5cdb9e84da57 100644 --- a/arch/x86/kernel/dumpstack_64.c +++ b/arch/x86/kernel/dumpstack_64.c @@ -149,45 +149,3 @@ int get_stack_info(unsigned long *stack, struct task_struct *task, info->type = STACK_TYPE_UNKNOWN; return -EINVAL; } - -void show_regs(struct pt_regs *regs) -{ - int i; - - show_regs_print_info(KERN_DEFAULT); - __show_regs(regs, 1); - - /* - * When in-kernel, we also print out the stack and code at the - * time of the fault.. - */ - if (!user_mode(regs)) { - unsigned int code_prologue = code_bytes * 43 / 64; - unsigned int code_len = code_bytes; - unsigned char c; - u8 *ip; - - show_trace_log_lvl(current, regs, NULL, KERN_DEFAULT); - - printk(KERN_DEFAULT "Code: "); - - ip = (u8 *)regs->ip - code_prologue; - if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { - /* try starting at IP */ - ip = (u8 *)regs->ip; - code_len = code_len - code_prologue + 1; - } - for (i = 0; i < code_len; i++, ip++) { - if (ip < (u8 *)PAGE_OFFSET || - probe_kernel_address(ip, c)) { - pr_cont(" Bad RIP value."); - break; - } - if (ip == (u8 *)regs->ip) - pr_cont("<%02x> ", c); - else - pr_cont("%02x ", c); - } - } - pr_cont("\n"); -} -- 2.13.0