Re: [RFC PATCH] x86: Make sure verify_cpu has a good stack

From: Borislav Petkov
Date: Wed Mar 02 2016 - 11:55:26 EST


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.