Received: by 10.223.185.116 with SMTP id b49csp4171987wrg; Mon, 19 Feb 2018 12:30:31 -0800 (PST) X-Google-Smtp-Source: AH8x2240YIxqswMsQuUjjGQiP/LOKnuUG6xkVAJDBokHPNtRlBvWutUIavzcZZ6Ol6qTX0NqoaFh X-Received: by 2002:a17:902:aa98:: with SMTP id d24-v6mr5345855plr.369.1519072231356; Mon, 19 Feb 2018 12:30:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519072231; cv=none; d=google.com; s=arc-20160816; b=cDuQ2MJ5blqZY6DSGvskGa0Nfga9EvrH8uP3xmPvdc1LR71DynYCPyeH+e7e2dYq8O BaNBzNWn1HtmygeqhzDXx53HXxYgbTk3ov7e38qB/urWG7zkcXwFF6Jjtug8iylhVgD/ m9kIPkqFNlkKGNWdsy9V5Zift1/M1Wz4a1k7MC6MvY5mmeXNByQ+pZA1/yWwwEVrOEtg Aftp0QQ1Xj6Ff7imd+stKghoayvDanR2k04m7bjDnQyJf2M/DT6fOwHBSEzxzwvpqplO h4SecsWE4L0JF4xlaMCyd6eLFiq9BdpipZcIBlxJoL+R3vdnu6ulNdOC9AJIm+0IRW+L lA0g== 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=YftyqiHe9d/U2tqkv5JDsfYwlqdkUpty+RTOAod4l7g=; b=tU7YeffBzo8+2DSkoF2R2pBllfWP92nKXiXE/89U0IBZOv5D4HUoTkpxnrFcL/h046 /oWpyEJbIbSfEd10d1F7QljFGl0S1K1XH199kL5n66sV7Cgo56L2/PFf51aSDJYVpqgX zalNjW2DMT1TyLiWpaVSkcaueqUgup/uKqXqdo8N3NrFJM1miWOsC+UnTD9hxUpOZJuz 1+ecsOL6kYvg0Wr+bhg2L2Y6Q/8OEaBlcmNtBia9B1XMvyF8oRBzkfhaE0oa0SBZlREQ G+1bU3Y5LboukzyvuxGVfOlIG8WTIVm2FtkIlLayEZ1Am981ivMVHPmsuscrs6FTzd0v miWQ== 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 126si6966041pfd.48.2018.02.19.12.30.17; Mon, 19 Feb 2018 12:30:31 -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 S932374AbeBSU2z (ORCPT + 99 others); Mon, 19 Feb 2018 15:28:55 -0500 Received: from mail.skyhub.de ([5.9.137.197]:37748 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932143AbeBSU2w (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 EFL3FC6UEb_4; Mon, 19 Feb 2018 21:28:51 +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 C8DA11EC08BF; 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 2/5] x86/dumpstack: Carve out Code: dumping into a function Date: Mon, 19 Feb 2018 21:28:23 +0100 Message-Id: <20180219202826.19797-3-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 No functionality change, carve it out into a separate function for later changes. Signed-off-by: Borislav Petkov --- arch/x86/kernel/dumpstack.c | 57 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 18fa9d74c182..954b1dd1c04a 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -376,10 +376,38 @@ static int __init code_bytes_setup(char *s) } __setup("code_bytes=", code_bytes_setup); +static void show_opcodes(u8 *rip) +{ + unsigned int code_prologue = code_bytes * 43 / 64; + unsigned int code_len = code_bytes; + unsigned char c; + u8 *ip; + int i; + + printk(KERN_DEFAULT "Code: "); + + ip = (u8 *)rip - code_prologue; + if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { + /* try starting at IP */ + ip = (u8 *)rip; + 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 *)rip) + pr_cont("<%02x> ", c); + else + pr_cont("%02x ", c); + } + pr_cont("\n"); +} + void show_regs(struct pt_regs *regs) { bool all = true; - int i; show_regs_print_info(KERN_DEFAULT); @@ -393,32 +421,7 @@ void show_regs(struct pt_regs *regs) * 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); - } + show_opcodes((u8 *)regs->ip); } - pr_cont("\n"); } -- 2.13.0