mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Kees Cook <keescook@chromium.org>,
	x86@kernel.org, Joan Bruguera <joanbrugueram@gmail.com>,
	linux-kernel@vger.kernel.org, Juergen Gross <jgross@suse.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	xen-devel <xen-devel@lists.xenproject.org>,
	Jan Beulich <jbeulich@suse.com>,
	Roger Pau Monne <roger.pau@citrix.com>,
	mark.rutland@arm.com
Subject: Re: [RFC][PATCH 2/6] x86/power: Inline write_cr[04]()
Date: Fri, 13 Jan 2023 18:17:32 +0100	[thread overview]
Message-ID: <Y8GSLDhgMlE96P6+@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <Y8FZvLq+MeQ7A+lI@gmail.com>

On Fri, Jan 13, 2023 at 02:16:44PM +0100, Ingo Molnar wrote:
> 
> * Peter Zijlstra <peterz@infradead.org> wrote:
> 
> > Since we can't do CALL/RET until GS is restored and CR[04] pinning is
> > of dubious value in this code path, simply write the stored values.
> > 
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> >  arch/x86/power/cpu.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > --- a/arch/x86/power/cpu.c
> > +++ b/arch/x86/power/cpu.c
> > @@ -208,11 +208,11 @@ static void notrace __restore_processor_
> >  #else
> >  /* CONFIG X86_64 */
> >  	native_wrmsrl(MSR_EFER, ctxt->efer);
> > -	native_write_cr4(ctxt->cr4);
> > +	asm volatile("mov %0,%%cr4": "+r" (ctxt->cr4) : : "memory");
> 
> >  #endif
> >  	native_write_cr3(ctxt->cr3);
> >  	native_write_cr2(ctxt->cr2);
> > -	native_write_cr0(ctxt->cr0);
> > +	asm volatile("mov %0,%%cr0": "+r" (ctxt->cr0) : : "memory");
> 
> Yeah, so CR pinning protects against are easily accessible 'gadget' 
> functions that exploits can call to disable HW protection features in the 
> CR register.
> 
> __restore_processor_state() might be such a gadget if an exploit can pass 
> in a well-prepared 'struct saved_context' on the stack.

Given the extent of saved_context, I think it's a total loss. Best we
can do is something like the last patch here that dis-allows indirect
calls of this function entirely (on appropriate builds/hardware).

> Can we set up cr0/cr4 after we have a proper GS, or is that a 
> chicken-and-egg scenario?

Can be done, but given the state we're in, I'd rather have the simplest
possible rules, calling out to functions with dodgy CR[04] is
'suboptimal' as well.

If people really worry about this I suppose we can call the full
native_write_cr4() later to double check the value in the context or
something.

  reply	other threads:[~2023-01-13 17:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12 14:31 [RFC][PATCH 0/6] x86: Fix suspend vs retbleed=stuff Peter Zijlstra
2023-01-12 14:31 ` [RFC][PATCH 1/6] x86/power: De-paravirt restore_processor_state() Peter Zijlstra
2023-01-13  8:14   ` Juergen Gross
2023-01-12 14:31 ` [RFC][PATCH 2/6] x86/power: Inline write_cr[04]() Peter Zijlstra
2023-01-12 21:51   ` Kees Cook
2023-01-13 13:16   ` Ingo Molnar
2023-01-13 17:17     ` Peter Zijlstra [this message]
2023-01-12 14:31 ` [RFC][PATCH 3/6] x86/callthunk: No callthunk for restore_processor_state() Peter Zijlstra
2023-01-12 14:31 ` [RFC][PATCH 4/6] x86/power: Sprinkle some noinstr Peter Zijlstra
2023-01-12 14:31 ` [RFC][PATCH 5/6] PM / hibernate: Add minimal noinstr annotations Peter Zijlstra
2023-01-12 14:31 ` [RFC][PATCH 6/6] x86/power: Seal restore_processor_state() Peter Zijlstra
2023-01-13  7:39 ` [RFC][PATCH 0/6] x86: Fix suspend vs retbleed=stuff Joan Bruguera
2023-01-13  9:17   ` Peter Zijlstra
2023-01-13 12:59     ` Peter Zijlstra

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=Y8GSLDhgMlE96P6+@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=joanbrugueram@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=rafael@kernel.org \
    --cc=roger.pau@citrix.com \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.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®