All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/ibt: Fix CC_HAS_IBT check for clang
@ 2022-03-11 19:56 Nathan Chancellor
  2022-03-12 12:20 ` Peter Zijlstra
  2022-03-12 12:37 ` [tip: x86/core] " tip-bot2 for Nathan Chancellor
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2022-03-11 19:56 UTC (permalink / raw)
  To: Peter Zijlstra, x86
  Cc: Nick Desaulniers, linux-kernel, llvm, Nathan Chancellor

Commit 41c5ef31ad71 ("x86/ibt: Base IBT bits") added a check for a crash
in clang. However, this check does not work for two reasons.

The first reason is that '-pg' is missing from the check, which is
required for '-mfentry' to do anything.

The second reason is that cc-option only uses /dev/null as the input
file, which does not show a problem:

$ clang --version | head -1
Ubuntu clang version 12.0.1-8build1

$ clang -fcf-protection=branch -mfentry -pg -c -x c /dev/null -o /dev/null

$ echo $?
0

$ echo "void a(void) {}" | clang -fcf-protection=branch -mfentry -pg -c -x c - -o /dev/null
...

$ echo $?
139

Use this test instead so that the check works for older versions of
clang.

Fixes: 41c5ef31ad71 ("x86/ibt: Base IBT bits")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 arch/x86/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 4ca7bfe927b3..870e0d10452d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1867,7 +1867,7 @@ config CC_HAS_IBT
 	# Clang/LLVM >= 14
 	# fentry check to work around https://reviews.llvm.org/D111108
 	def_bool ((CC_IS_GCC && $(cc-option, -fcf-protection=branch -mindirect-branch-register)) || \
-		  (CC_IS_CLANG && $(cc-option, -fcf-protection=branch -mfentry))) && \
+		  (CC_IS_CLANG && $(success,echo "void a(void) {}" | $(CC) -Werror $(CLANG_FLAGS) -fcf-protection=branch -mfentry -pg -x c - -c -o /dev/null))) && \
 		  $(as-instr,endbr64)
 
 config X86_KERNEL_IBT

base-commit: 9e1db76f44de4d9439e48c9ef61e5d457395202b
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/ibt: Fix CC_HAS_IBT check for clang
  2022-03-11 19:56 [PATCH] x86/ibt: Fix CC_HAS_IBT check for clang Nathan Chancellor
@ 2022-03-12 12:20 ` Peter Zijlstra
  2022-03-12 12:37 ` [tip: x86/core] " tip-bot2 for Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2022-03-12 12:20 UTC (permalink / raw)
  To: Nathan Chancellor; +Cc: x86, Nick Desaulniers, linux-kernel, llvm

On Fri, Mar 11, 2022 at 12:56:42PM -0700, Nathan Chancellor wrote:
> Commit 41c5ef31ad71 ("x86/ibt: Base IBT bits") added a check for a crash
> in clang. However, this check does not work for two reasons.
> 
> The first reason is that '-pg' is missing from the check, which is
> required for '-mfentry' to do anything.
> 
> The second reason is that cc-option only uses /dev/null as the input
> file, which does not show a problem:
> 
> $ clang --version | head -1
> Ubuntu clang version 12.0.1-8build1
> 
> $ clang -fcf-protection=branch -mfentry -pg -c -x c /dev/null -o /dev/null
> 
> $ echo $?
> 0
> 
> $ echo "void a(void) {}" | clang -fcf-protection=branch -mfentry -pg -c -x c - -o /dev/null
> ...
> 
> $ echo $?
> 139
> 
> Use this test instead so that the check works for older versions of
> clang.
> 
> Fixes: 41c5ef31ad71 ("x86/ibt: Base IBT bits")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Urgh... not pretty, but that's what we gotta live with I suppose.

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: x86/core] x86/ibt: Fix CC_HAS_IBT check for clang
  2022-03-11 19:56 [PATCH] x86/ibt: Fix CC_HAS_IBT check for clang Nathan Chancellor
  2022-03-12 12:20 ` Peter Zijlstra
@ 2022-03-12 12:37 ` tip-bot2 for Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Nathan Chancellor @ 2022-03-12 12:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Nathan Chancellor, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the x86/core branch of tip:

Commit-ID:     f8afc9d88e65d189653f363eacc1f3131216ef7c
Gitweb:        https://git.kernel.org/tip/f8afc9d88e65d189653f363eacc1f3131216ef7c
Author:        Nathan Chancellor <nathan@kernel.org>
AuthorDate:    Fri, 11 Mar 2022 12:56:42 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Sat, 12 Mar 2022 13:22:13 +01:00

x86/ibt: Fix CC_HAS_IBT check for clang

Commit 41c5ef31ad71 ("x86/ibt: Base IBT bits") added a check for a crash
in clang. However, this check does not work for two reasons.

The first reason is that '-pg' is missing from the check, which is
required for '-mfentry' to do anything.

The second reason is that cc-option only uses /dev/null as the input
file, which does not show a problem:

$ clang --version | head -1
Ubuntu clang version 12.0.1-8build1

$ clang -fcf-protection=branch -mfentry -pg -c -x c /dev/null -o /dev/null

$ echo $?
0

$ echo "void a(void) {}" | clang -fcf-protection=branch -mfentry -pg -c -x c - -o /dev/null
...

$ echo $?
139

Use this test instead so that the check works for older versions of
clang.

Fixes: 41c5ef31ad71 ("x86/ibt: Base IBT bits")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220311195642.2033108-1-nathan@kernel.org
---
 arch/x86/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 4ca7bfe..870e0d1 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1867,7 +1867,7 @@ config CC_HAS_IBT
 	# Clang/LLVM >= 14
 	# fentry check to work around https://reviews.llvm.org/D111108
 	def_bool ((CC_IS_GCC && $(cc-option, -fcf-protection=branch -mindirect-branch-register)) || \
-		  (CC_IS_CLANG && $(cc-option, -fcf-protection=branch -mfentry))) && \
+		  (CC_IS_CLANG && $(success,echo "void a(void) {}" | $(CC) -Werror $(CLANG_FLAGS) -fcf-protection=branch -mfentry -pg -x c - -c -o /dev/null))) && \
 		  $(as-instr,endbr64)
 
 config X86_KERNEL_IBT

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-12 12:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11 19:56 [PATCH] x86/ibt: Fix CC_HAS_IBT check for clang Nathan Chancellor
2022-03-12 12:20 ` Peter Zijlstra
2022-03-12 12:37 ` [tip: x86/core] " tip-bot2 for Nathan Chancellor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.