From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751899AbeCIKQK (ORCPT ); Fri, 9 Mar 2018 05:16:10 -0500 Received: from mail.skyhub.de ([5.9.137.197]:49900 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751729AbeCIKQG (ORCPT ); Fri, 9 Mar 2018 05:16:06 -0500 Date: Fri, 9 Mar 2018 11:15:52 +0100 From: Borislav Petkov To: Linus Torvalds Cc: Josh Poimboeuf , X86 ML , Andy Lutomirski , Peter Zijlstra , LKML Subject: Re: [PATCH 5/9] x86/dumpstack: Improve opcodes dumping in the Code: section Message-ID: <20180309101551.GA10753@pd.tnic> References: <20180306094920.16917-1-bp@alien8.de> <20180306094920.16917-6-bp@alien8.de> <20180307101314.GC23662@pd.tnic> <20180307132535.g7c2jro5n7okavbh@treble> <20180308101628.GA21166@pd.tnic> <20180308223632.GA15694@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 08, 2018 at 03:20:58PM -0800, Linus Torvalds wrote: > Yes, so the reason the prologue is more important is that there's > really two cases for the "Code:" line: Yap, I had a hunch it must be about some of those but thanks for taking the time and writing it down! I've tried to summarize the reasoning and slap it as a comment above it so that it is clear why we do it this way: --- diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index c3aa0e29513e..7a21098c9128 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -71,6 +71,25 @@ static void printk_stack_address(unsigned long address, int reliable, printk("%s %s%pB\n", log_lvl, reliable ? "" : "? ", (void *)address); } +/* + * The are a couple of reasons for the 2/3rd prologue, courtesy of Linus: + * + * In case where we don't have the exact kernel image (which, if we did, we can + * simply disassemble and navigate to the RIP), the purpose of the bigger + * prologue is to have more context and to be able to correlate the code from + * the different toolchains better. + * + * In addition, it helps in recreating the register allocation of the failing + * kernel and thus make sense of the register dump. + * + * What is more, the additional complication of a variable length insn arch like + * x86 warrants having longer byte sequence before rIP so that the disassembler + * can "sync" up properly and find instruction boundaries when decoding the + * opcode bytes. + * + * Thus, the 2/3rds prologue and 64 byte OPCODE_BUFSIZE is just a random + * guesstimate in attempt to achieve all of the above. + */ void show_opcodes(u8 *rip, const char *loglvl) { #define OPCODE_BUFSIZE 64 -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.