mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alexandru Chirvasitu <achirvasub@gmail.com>,
	Ingo Molnar <mingo@kernel.org>, Andy Lutomirski <luto@kernel.org>,
	kernel list <linux-kernel@vger.kernel.org>,
	Borislav Petkov <bp@alien8.de>, Brian Gerst <brgerst@gmail.com>,
	Denys Vlasenko <dvlasenk@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH] x86-32: fix kexec with stack canary (CONFIG_CC_STACKPROTECTOR)
Date: Wed, 27 Dec 2017 20:58:08 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1712272054160.2431@nanos> (raw)
In-Reply-To: <alpine.LFD.2.21.1712271143180.8572@i7.lan>

On Wed, 27 Dec 2017, Linus Torvalds wrote:
> From: Linus Torvalds <torvalds@linux-foundation.org>
> Date: Wed, 27 Dec 2017 11:41:30 -0800
> Subject: [PATCH] x86-32: fix kexec with stack canary (CONFIG_CC_STACKPROTECTOR)
> 
> Commit e802a51ede91 ("x86/idt: Consolidate IDT invalidation") cleaned up
> and unified the IDT invalidation that existed in a couple of places.  It
> changed no actual real code.
> 
> Despite not changing any actual real code, it _did_ change code
> generation: by implementing the common idt_invalidate() function in
> archx86/kernel/idt.c, it made the use of the function in
> arch/x86/kernel/machine_kexec_32.c be a real function call rather than
> an (accidental) inlining of the function.

Duh. I just got around reading that thread. Yes, that was definitely not
intended and the situation before my change was not really obvious ...

> That, in turn, exposed two issues:
> 
>  - in load_segments(), we had incorrectly reset all the segment
>    registers, which then made the stack canary load (which gcc does
>    using offset of %gs) cause a trap.  Instead of %gs pointing to the
>    stack canary, it will be the normal zero-based kernel segment, and
>    the stack canary load will take a page fault at address 0x14.
> 
>  - to make this even harder to debug, we had invalidated the GDT just
>    before calling idt_invalidate(), which meant that the fault happened
>    with an invalid GDT, which in turn causes a triple fault and
>    immediate reboot.

Nice detective work.

> Fix this by
> 
>  (a) not reloading the special segments in load_segments(). We currently
>      don't do any percpu accesses (which would require %fs on x86-32) in
>      this area, but there's no reason to think that we might not want to
>      do them, and like %gs, it's pointless to break it.
> 
>  (b) doing idt_invalidate() before invalidating the GDT, to keep things
>      at least _slightly_ more debuggable for a bit longer. Without a
>      IDT, traps will not work. Without a GDT, traps also will not work,
>      but neither will any segment loads etc. So in a very real sense,
>      the GDT is even more core than the IDT.
> 
> Reported-and-tested-by: Alexandru Chirvasitu <achirvasub@gmail.com>
> Fixes: e802a51ede91 ("x86/idt: Consolidate IDT invalidation")
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Peter Anvin <hpa@zytor.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> ---
> 
> I wrote "Reported-and-tested-by: Alexandru" because while this isn't 
> exactly the same patch as anything Alexandru tested, it's pretty close, 
> and I'm pretty sure this version will fix his issues too.
> 
> I decided to try to just do the minimal changes: the GDT invalidation last 
> (because of the debugging) and _only_ removing the resetting of fs/gs 
> rather than removing load_segments() entirely.
> 
> I think making idt_invalidate() be inline would be a good thing as well, 
> and I do think that all those "phys_to_virt(0)" things are garbage, but I 
> also think they are independent issues, so I didn't touch any of that. 

I've put that on the list of stuff to look at once my actual time waster is
done.

> I'm assuming I'll get this patch back through the x86 tree, and will not 
> be applying it to my own git tree unless the x86 people ask me to.

I'll pick it up.

Thanks,

	tglx

  reply	other threads:[~2017-12-27 19:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-27 19:48 Linus Torvalds
2017-12-27 19:58 ` Thomas Gleixner [this message]
2017-12-27 23:06 ` [tip:x86/urgent] x86-32: Fix " tip-bot for Linus Torvalds
2017-12-28 22:47 ` [PATCH] x86-32: fix " Eric W. Biederman
2017-12-28 23:23   ` hpa
2017-12-29  0:30     ` Eric W. Biederman

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=alpine.DEB.2.20.1712272054160.2431@nanos \
    --to=tglx@linutronix.de \
    --cc=achirvasub@gmail.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®