]> xenbits.xensource.com Git - xen.git/commitdiff
x86/spec-ctrl: Protect against Speculative Code Store Bypass
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 11 Mar 2021 14:39:11 +0000 (14:39 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 8 Jun 2021 18:16:38 +0000 (19:16 +0100)
Modern x86 processors have far-better-than-architecturally-guaranteed self
modifying code detection.  Typically, when a write hits an instruction in
flight, a Machine Clear occurs to flush stale content in the frontend and
backend.

For self modifying code, before a write which hits an instruction in flight
retires, the frontend can speculatively decode and execute the old instruction
stream.  Speculation of this form can suffer from type confusion in registers,
and potentially leak data.

Furthermore, updates are typically byte-wise, rather than atomic.  Depending
on timing, speculation can race ahead multiple times between individual
writes, and execute the transiently-malformed instruction stream.

Xen has stubs which are used in certain cases for emulation purposes.  Inhibit
speculation between updating the stub and executing it.

This is XSA-375 / CVE-2021-0089.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
(cherry picked from commit 45f59ed8865318bb0356954bad067f329677ce9e)

xen/arch/x86/pv/emul-priv-op.c
xen/arch/x86/x86_emulate/x86_emulate.c

index 755f00db336dec16cdda812e0d8a5238f939e557..fdba01ce965879b656603536a429e8e2509f79ff 100644 (file)
@@ -101,6 +101,8 @@ static io_emul_stub_t *io_emul_stub_setup(struct priv_op_ctxt *ctxt, u8 opcode,
     BUILD_BUG_ON(STUB_BUF_SIZE / 2 < MAX(9, /* Default emul stub */
                                          5 + IOEMUL_QUIRK_STUB_BYTES));
 
+    asm volatile ( "lfence" ::: "memory" ); /* SCSB */
+
     /* Handy function-typed pointer to the stub. */
     return (void *)stub_va;
 }
index 1f0c208fc5773a4c7f424eac5ae367f032ff3c22..19594ab45d9d7991aef31406e6f020f1d22eb685 100644 (file)
@@ -1008,6 +1008,7 @@ static inline int mkec(uint8_t e, int32_t ec, ...)
 # define invoke_stub(pre, post, constraints...) do {                    \
     stub_exn.info = (union stub_exception_token) { .raw = ~0 };         \
     stub_exn.line = __LINE__; /* Utility outweighs livepatching cost */ \
+    asm volatile ( "lfence" ::: "memory" ); /* SCSB */                  \
     asm volatile ( pre "\n\tINDIRECT_CALL %[stub]\n\t" post "\n"        \
                    ".Lret%=:\n\t"                                       \
                    ".pushsection .fixup,\"ax\"\n"                       \