lkml.org 
[lkml]   [2021]   [Aug]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH Part1 v5 23/38] x86/head/64: set up a startup %gs for stack protector
On Wed, Aug 25, 2021 at 05:07:26PM +0200, Joerg Roedel wrote:
> On Fri, Aug 20, 2021 at 10:19:18AM -0500, Brijesh Singh wrote:
> > void __head startup_64_setup_env(unsigned long physbase)
> > {
> > + u64 gs_area = (u64)fixup_pointer(startup_gs_area, physbase);
> > +
>
> This breaks as soon as the compiler decides that startup_64_setup_env()
> needs stack protection too.

Good point.

>
> And the startup_gs_area is also not needed, there is initial_gs for
> that.
>
> What you need is something along these lines (untested):
>
> diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
> index d8b3ebd2bb85..3c7c59bc9903 100644
> --- a/arch/x86/kernel/head_64.S
> +++ b/arch/x86/kernel/head_64.S
> @@ -65,6 +65,16 @@ SYM_CODE_START_NOALIGN(startup_64)
> leaq (__end_init_task - FRAME_SIZE)(%rip), %rsp
>
> leaq _text(%rip), %rdi
> +
> + movl $MSR_GS_BASE, %ecx
> + movq initial_gs(%rip), %rax
> + movq $_text, %rdx
> + subq %rdx, %rax
> + addq %rdi, %rax
> + movq %rax, %rdx
> + shrq $32, %rdx
> + wrmsr
> +
> pushq %rsi
> call startup_64_setup_env
> popq %rsi
>
>
> It loads the initial_gs pointer, applies the fixup on it and loads it
> into MSR_GS_BASE.

This seems to do the trick, and is probably closer to what the 32-bit
version would look like. Thanks for the suggestion!

\
 
 \ /
  Last update: 2021-08-25 19:16    [W:0.180 / U:0.912 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site