mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xin Li <xin@zytor.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>, linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
	peterz@infradead.org
Subject: Re: [PATCH v1 1/1] x86/fred: Clear the WFE bit in missing-ENDBRANCH #CP
Date: Wed, 11 Sep 2024 16:44:05 -0700	[thread overview]
Message-ID: <9efbfb57-d454-4bad-bdb8-e3000b6ba0ce@zytor.com> (raw)
In-Reply-To: <04674df0-a026-42d1-aacf-293f3018329f@citrix.com>

On 9/11/2024 4:35 PM, Andrew Cooper wrote:
> On 12/09/2024 12:19 am, Xin Li (Intel) wrote:
>> The WFE, i.e., WAIT_FOR_ENDBRANCH, bit in the augmented CS of FRED
>> stack frame is set to 1 in missing-ENDBRANCH #CP exceptions.
>>
>> The CPU will generate another missing-ENDBRANCH #CP if the WFE bit
>> is left as 1, because the indirect branch tracker will be set in
>> the WAIT_FOR_ENDBRANCH state upon completion of the following ERETS
>> instruction and the CPU will restart from the IP that just caused a
>> previous missing-ENDBRANCH #CP.
>>
>> Clear the WFE bit to avoid dead looping in missing-ENDBRANCH #CP.
>>
>> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
> 
> Ah - good.  Finally some evidence that this hole in CET has been plugged
> by FRED.
> 
> However, I'd suggest describing it differently.

Yep, it's a much better story including historical issues with IDT.

I will use it as the comment above ibt_clear_fred_wfe() in the next
iteration, but keep the change log.  Is it okay?

> 
> 
> By definition, all missing-ENDBRANCH #CPs are a result of WFE && !ENDBR.
> 
> But, in original CET under IDT delivery, any transfer for
> interrupt/exception/etc that does not change privilege will clobber the
> WFE state because MSR_{U,S}_CET.WFE is intentionally set by microcode so
> as to expect to find an ENDBR at the interrupt/exception/syscall entrypoint.
> 
> In practice, this means interrupts and exceptions hitting the kernel, or
> user interrupts, loose the WFE state of the interrupted context.  And
> yes, this means that a well timed interrupt (to the precise instruction
> boundary) will let an attacker sneak a bad function pointer past the
> CET-IBT enforcement.
> 
> In FRED, the WFE state of the interrupted context (even if it is the
> same privilege) is preserved and restored, in order to close this hole.
> 
> Therefore, the intentional #CP selfchecks need to clear WFE when they
> are deemed to have succeeded, now that FRED is causing the state not to
> get lost.
> 
> ~Andrew


  reply	other threads:[~2024-09-11 23:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-11 23:19 Xin Li (Intel)
2024-09-11 23:35 ` Andrew Cooper
2024-09-11 23:44   ` Xin Li [this message]
2024-09-15 18:17   ` Xin Li
2024-09-16  9:16     ` Andrew Cooper
2024-09-12  0:22 ` Dave Hansen
2024-09-12  8:53   ` Xin Li
2024-09-12 13:13     ` Andrew Cooper
2024-09-12  7:57 ` Peter Zijlstra
2024-09-12  8:25   ` Xin Li

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=9efbfb57-d454-4bad-bdb8-e3000b6ba0ce@zytor.com \
    --to=xin@zytor.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --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

all inboxes | Powered by JetHome®