Skip to contentSkip to conversation

x86/build: Unilaterally disable -fcf-protection

PATCH In review Andrew Cooper 3 participants 5 messages May 12, 2020 – May 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/build: Unilaterally disable -fcf-protection

See comment for details. Works around a GCC-9 bug which breaks the build on Ubuntu.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Jason Andryuk <[email protected]>
CC: Stefan Bader <[email protected]>

Sorry for messing you around with how to fix this. I'd neglected to consider the CONFIG_LIVEPATCH interaction. With that extra observation, there is no point having the extra complexity given that the result with CET-IBT and Retpoline still isn't usable.

---
 xen/arch/x86/arch.mk         | 9 +++++++++
 xen/arch/x86/boot/build32.mk | 1 +
 2 files changed, 10 insertions(+)
xen/arch/x86/arch.mk +9 -0
index 2a51553edb..93e30e4bea 100644
@@ -67,6 +67,15 @@ CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch=thunk-extern
 CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch-register
 CFLAGS-$(CONFIG_INDIRECT_THUNK) += -fno-jump-tables
 
+# Xen doesn't support CET-IBT yet.  At a minimum, logic is required to
+# enable it for supervisor use, but the Livepatch functionality needs
+# to learn not to overwrite ENDBR64 instructions.
+#
+# Furthermore, Ubuntu enables -fcf-protection by default, along with a
+# buggy version of GCC-9 which objects to it in combination with
+# -mindirect-branch=thunk-extern (Fixed in GCC 10, 9.4).
+$(call cc-option-add,CFLAGS,CC,-fcf-protection=none)
+
 # If supported by the compiler, reduce stack alignment to 8 bytes. But allow
 # this to be overridden elsewhere.
 $(call cc-option-add,CFLAGS-stack-boundary,CC,-mpreferred-stack-boundary=3)
xen/arch/x86/boot/build32.mk +1 -0
index 48c7407c00..5a00755512 100644
@@ -3,6 +3,7 @@ CFLAGS =
 include $(XEN_ROOT)/Config.mk
 
 $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
+$(call cc-option-add,CFLAGS,CC,-fcf-protection=none)
 
 CFLAGS += -Werror -fno-asynchronous-unwind-tables -fno-builtin -g0 -msoft-float
 CFLAGS += -I$(XEN_ROOT)/xen/include
Signature · 1 line
2.11.0
Tested-by Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Andrew Cooper

See comment for details. Works around a GCC-9 bug which breaks the build on Ubuntu.

xen/arch/x86/arch.mk CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch=thunk-extern · line 72

Quoted 11 lines
xen/arch/x86/arch.mk +3 -0
index 2a51553edb..93e30e4bea 100644
@@ -67,6 +67,15 @@ CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch=thunk-extern
 CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch-register
 CFLAGS-$(CONFIG_INDIRECT_THUNK) += -fno-jump-tables
 
+# Xen doesn't support CET-IBT yet.  At a minimum, logic is required to
+# enable it for supervisor use, but the Livepatch functionality needs
+# to learn not to overwrite ENDBR64 instructions.

Is the problem that existing functions start with ENDBR64, but the livepatch overwrites with a "real" instruction?

Regards,
Jason

#2 lore raw
Quoted 19 lines · Jason Andryuk

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

Quoted 5 lines · Andrew Cooper

See comment for details. Works around a GCC-9 bug which breaks the build on Ubuntu.

Quoted 8 lines
xen/arch/x86/arch.mk +0 -0
index 2a51553edb..93e30e4bea 100644
@@ -67,6 +67,15 @@ CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch=thunk-extern
 CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch-register
 CFLAGS-$(CONFIG_INDIRECT_THUNK) += -fno-jump-tables
 
Quoted 5 lines

xen/arch/x86/arch.mk CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch=thunk-extern · line 72

Quoted 3 lines
xen/arch/x86/arch.mk +3 -0
+# Xen doesn't support CET-IBT yet.  At a minimum, logic is required to
+# enable it for supervisor use, but the Livepatch functionality needs
+# to learn not to overwrite ENDBR64 instructions.

Is the problem that existing functions start with ENDBR64, but the livepatch overwrites with a "real" instruction?

We livepatch by creating a new complete copy of the function, and putting jmp new at the head of the old one.

This means we don't need to patch every callsite and track every function pointer to the old function, and we can fully revert by replacing the 5 bytes which became jmp new.

With CET-IBT in the mix, livepatch will have to learn to spot an ENDBR64 instruction and leave it intact, patching instead the next 5 bytes, so an old function pointer still lands on the ENDBR64 instruction.

~Andrew

#3 lore raw
Quoted 14 lines · Andrew Cooper
Quoted 8 lines · Jason Andryuk

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

xen/arch/x86/arch.mk CFLAGS-$(CONFIG_INDIRECT_THUNK) += -mindirect-branch=thunk-extern · line 72

Quoted 3 lines · Andrew Cooper
xen/arch/x86/arch.mk +3 -0
+# Xen doesn't support CET-IBT yet.  At a minimum, logic is required to
+# enable it for supervisor use, but the Livepatch functionality needs
+# to learn not to overwrite ENDBR64 instructions.

Is the problem that existing functions start with ENDBR64, but the livepatch overwrites with a "real" instruction?

We livepatch by creating a new complete copy of the function, and putting jmp new at the head of the old one.

Quoted 7 lines

This means we don't need to patch every callsite and track every function pointer to the old function, and we can fully revert by replacing the 5 bytes which became jmp new.

With CET-IBT in the mix, livepatch will have to learn to spot an ENDBR64 instruction and leave it intact, patching instead the next 5 bytes, so an old function pointer still lands on the ENDBR64 instruction.

Ah, okay. Thanks for the explanation.

-Jason