public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: "Mika Penttilä" <mika.penttila@nextfour.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>, X86 ML <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Tom Lendacky <thomas.lendacky@amd.com>
Subject: Re: [RFC PATCH] x86: Make sure verify_cpu has a good stack
Date: Wed, 2 Mar 2016 17:55:16 +0100	[thread overview]
Message-ID: <20160302165516.GC8362@pd.tnic> (raw)
In-Reply-To: <56D716F7.3080407@nextfour.com>

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.

  reply	other threads:[~2016-03-02 16:55 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-02 11:20 [RFC PATCH] x86: Make sure verify_cpu has a good stack Borislav Petkov
2016-03-02 15:55 ` Mika Penttilä
2016-03-02 16:15   ` Borislav Petkov
2016-03-02 16:38     ` Mika Penttilä
2016-03-02 16:55       ` Borislav Petkov [this message]
2016-03-02 17:44         ` Mika Penttilä
2016-03-02 16:22 ` Brian Gerst
2016-03-02 16:25   ` Borislav Petkov
2016-03-02 17:53     ` H. Peter Anvin
2016-03-02 18:15       ` Borislav Petkov
2016-03-02 18:25         ` H. Peter Anvin
2016-03-02 18:39         ` H. Peter Anvin
2016-03-02 19:50           ` Borislav Petkov
2016-03-02 20:46             ` Borislav Petkov
2016-03-02 21:35             ` H. Peter Anvin
2016-03-02 21:46               ` Borislav Petkov
2016-03-02 21:54                 ` H. Peter Anvin
2016-03-02 22:09                   ` Borislav Petkov
2016-03-02 22:11                     ` H. Peter Anvin
2016-03-02 22:28                       ` Borislav Petkov
2016-03-02 22:32                         ` H. Peter Anvin
2016-03-02 22:40                           ` Borislav Petkov
2016-03-03  0:13                           ` Yinghai Lu
2016-03-03  1:00                             ` Yinghai Lu
2016-03-03  2:50                               ` Yinghai Lu
2016-03-03 12:28                           ` Borislav Petkov
2016-03-03 15:26                             ` H. Peter Anvin
2016-03-03 16:29                               ` Borislav Petkov
2016-03-03 20:22                                 ` H. Peter Anvin
2016-03-03 20:54                                   ` Borislav Petkov
2016-03-03 21:22                                     ` H. Peter Anvin
2016-03-03 21:38                                       ` Borislav Petkov
2016-03-04  1:18                             ` Yinghai Lu
2016-03-04  2:25                             ` Yinghai Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160302165516.GC8362@pd.tnic \
    --to=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.penttila@nextfour.com \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox