Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754660AbcCBQzX (ORCPT ); Wed, 2 Mar 2016 11:55:23 -0500 Received: from mail.skyhub.de ([78.46.96.112]:41632 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752106AbcCBQzW (ORCPT ); Wed, 2 Mar 2016 11:55:22 -0500 Date: Wed, 2 Mar 2016 17:55:16 +0100 From: Borislav Petkov To: Mika =?utf-8?B?UGVudHRpbMOk?= Cc: "H. Peter Anvin" , X86 ML , LKML , Tom Lendacky Subject: Re: [RFC PATCH] x86: Make sure verify_cpu has a good stack Message-ID: <20160302165516.GC8362@pd.tnic> References: <1456917606-4979-1-git-send-email-bp@alien8.de> <56D70CE2.1050500@nextfour.com> <20160302161532.GK16954@pd.tnic> <56D716F7.3080407@nextfour.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <56D716F7.3080407@nextfour.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1402 Lines: 56 On Wed, Mar 02, 2016 at 06:38:15PM +0200, Mika Penttilä wrote: > I actually looked at it a while too... > > The > movq stack_start - __START_KERNEL_map, %rsp > > turns into (objdump disassembly) > > mov 0x0,%rsp > > with relocation > 0000000000000004 R_X86_64_32S stack_start+0x0000000080000000 > > Now stack_start is at ffffffff81ef3380, so the relocation gives 1ef3380 which would be correct, so why the > second subq ? > > You may explain :) Here it is :-) $ readelf -a vmlinux | grep stack_start 70526: ffffffff81cbabf8 0 NOTYPE GLOBAL DEFAULT 14 stack_start 0xffffffff81cbabf8 - __START_KERNEL_map = 0xffffffff81cbabf8 - 0xffffffff80000000 = 0x1cbabf8 (gdb) x/x 0x1cbabf8 0x1cbabf8: 0xffffffff81c03ff8 (You don't need gdb for that - you can hexdump or objdump vmlinux). Now stack_start is: GLOBAL(stack_start) .quad init_thread_union+THREAD_SIZE-8 which is $ readelf -a vmlinux | grep init_thread_union 82491: ffffffff81c00000 16384 OBJECT GLOBAL DEFAULT 14 init_thread_union so init_thread_union+THREAD_SIZE-8 = 0xffffffff81c00000 + 4*4096-8 = 0xffffffff81c03ff8 So you have to subtract __START_KERNEL_map again because it has there a virtual address and we haven't enabled paging yet: 0xffffffff81c03ff8 - 0xffffffff80000000 = 0x1c03ff8. Makes sense? -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply.