Skip to contentSkip to conversation

objtool, retpolines: Integrate objtool with retpoline support more closely

tip:x86/pti New David Woodhouse 3 participants 4 messages Feb 21, 2018 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Makefile

Quoted 12 lines · tip-bot for Peter Zijlstra
Makefile +0 -0
@@ -489,6 +489,11 @@ KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
  KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)

 endif

Makefile +5 -0
+ifneq ($(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register),)
+  CC_HAS_RETPOLINE := 1
+endif
+export CC_HAS_RETPOLINE
+

That isn't the same as the check in arch/x86/Makefile.

#2 lore raw
Quoted 15 lines · David Woodhouse

Makefile

Quoted 12 lines · tip-bot for Peter Zijlstra
Makefile +0 -0
@@ -489,6 +489,11 @@ KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
  KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)

 endif

Makefile +5 -0
+ifneq ($(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register),)
+  CC_HAS_RETPOLINE := 1
+endif
+export CC_HAS_RETPOLINE
+

That isn't the same as the check in arch/x86/Makefile.

That's because this crossed with the llvm cruft, right? I'll have a look.

#3 lore raw
Quoted 2 lines · Peter Zijlstra

That's because this crossed with the llvm cruft, right? I'll have a look.

Best I could come up with that seems to work is something like the below. Ingo, can you backmerge or stuff on top as appropriate?

---
 Makefile               |  8 ++++----
 arch/x86/Makefile      | 10 +++-------
 scripts/Makefile.build |  2 +-
 3 files changed, 8 insertions(+), 12 deletions(-)
Makefile +4 -4
index e1a155a50fdc..3aa0a115eafb 100644
@@ -489,10 +489,10 @@ KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
 KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
 endif
 
-ifneq ($(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register),)
-  CC_HAS_RETPOLINE := 1
-endif
-export CC_HAS_RETPOLINE
+RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
+RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
+RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
+export RETPOLINE_CFLAGS
 
 ifeq ($(config-targets),1)
 # ===========================================================================
arch/x86/Makefile +3 -7
index dbc7d0ed2eaa..498c1b812300 100644
@@ -232,13 +232,9 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
 
 # Avoid indirect branches in kernel to deal with Spectre
 ifdef CONFIG_RETPOLINE
-    RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
-    RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
-
-    RETPOLINE_CFLAGS += $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
-    ifneq ($(RETPOLINE_CFLAGS),)
-        KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE
-    endif
+ifneq ($(RETPOLINE_CFLAGS),)
+  KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE
+endif
 endif
 
 archscripts: scripts_basic
scripts/Makefile.build +1 -1
index 07e5802e324b..4f2b25d43ec9 100644
@@ -267,7 +267,7 @@ else
 objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable)
 endif
 ifdef CONFIG_RETPOLINE
-ifdef CC_HAS_RETPOLINE
+ifneq ($(RETPOLINE_CFLAGS),)
   objtool_args += --retpoline
 endif
 endif
#4 lore raw

PATCH v2 1/1 objtool, retpolines: Integrate objtool with retpoline support more closely

Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Peter Zijlstra

That's because this crossed with the llvm cruft, right? I'll have a look.

Best I could come up with that seems to work is something like the below. Ingo, can you backmerge or stuff on top as appropriate?

I backmerged/reordered and made the v2 patch below out of it.

Does this look good to everyone?

Thanks,

Ingo

=======================>

Quoted 1 line

From d5028ba8ee5a18c9d0bb926d883c28b370f89009 Mon Sep 17 00:00:00 2001

From: Peter Zijlstra <[email protected]>
Date: Tue, 6 Feb 2018 09:46:13 +0100
Subject: [PATCH] objtool, retpolines: Integrate objtool with retpoline support more closely

Disable retpoline validation in objtool if your compiler sucks, and otherwise select the validation stuff for CONFIG_RETPOLINE=y (most builds would already have it set due to ORC).

Cc Andy Lutomirski <[email protected]>
Cc Arjan van de Ven <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dan Williams <[email protected]>
Cc Dave Hansen <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 Makefile               |  5 +++++
 arch/x86/Kconfig       |  1 +
 arch/x86/Makefile      | 10 +++-------
 scripts/Makefile.build |  2 ++
 4 files changed, 11 insertions(+), 7 deletions(-)
Makefile +5 -0
index 79ad2bfa24b6..3dfce4d2f25d 100644
@@ -489,6 +489,11 @@ KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
 KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
 endif
 
+RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
+RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
+RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
+export RETPOLINE_CFLAGS
+
 ifeq ($(config-targets),1)
 # ===========================================================================
 # *config targets only - make sure prerequisites are updated, and descend
arch/x86/Kconfig +1 -0
index 63bf349b2b24..c1aed6c0e413 100644
@@ -436,6 +436,7 @@ config GOLDFISH
 config RETPOLINE
 	bool "Avoid speculative indirect branches in kernel"
 	default y
+	select STACK_VALIDATION if HAVE_STACK_VALIDATION
 	help
 	  Compile kernel with the retpoline compiler options to guard against
 	  kernel-to-user data leaks by avoiding speculative indirect
arch/x86/Makefile +3 -7
index dbc7d0ed2eaa..498c1b812300 100644
@@ -232,13 +232,9 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
 
 # Avoid indirect branches in kernel to deal with Spectre
 ifdef CONFIG_RETPOLINE
-    RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
-    RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
-
-    RETPOLINE_CFLAGS += $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
-    ifneq ($(RETPOLINE_CFLAGS),)
-        KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE
-    endif
+ifneq ($(RETPOLINE_CFLAGS),)
+  KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE
+endif
 endif
 
 archscripts: scripts_basic
scripts/Makefile.build +2 -0
index ce0fc4dd68c6..4f2b25d43ec9 100644
@@ -267,8 +267,10 @@ else
 objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable)
 endif
 ifdef CONFIG_RETPOLINE
+ifneq ($(RETPOLINE_CFLAGS),)
   objtool_args += --retpoline
 endif
+endif
 
 
 ifdef CONFIG_MODVERSIONS