hardening: Enable i386 FORTIFY_SOURCE on Clang 16+
Subsystems (3)
Kees Cook
maintainerv2 cover hardening: Enable i386 FORTIFY_SOURCE on Clang 16+
Hi,
This drops -ffreestanding for i386 unconditionally for GCC, and on Clang version 16 and later. FORTIFY_SOURCE depends on the libcall optimizations made without -ffreestanding on Clang. On GCC, there is no expected differences. With that done, it's possible to gain Clang FORTIFY_SOURCE coverage on i386 again, though only for Clang 16+.
-Kees
v1: https://lore.kernel.org/lkml/[email protected]/
v2: drop -ffreestanding (Nathan)
Kees Cook (2):
x86/build: Remove -ffreestanding on i386 with GCC
hardening: Enable i386 FORTIFY_SOURCE on Clang 16+
arch/x86/Makefile | 2 ++ security/Kconfig.hardening | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
Kees Cook
maintainerPATCH v2 1/2 x86/build: Remove -ffreestanding on i386 with GCC
The use of -ffreestanding is a leftover that is only needed for certain versions of Clang. Adjust this to be Clang-only. A later patch will make this a versioned check.
---
Cc: Nathan Chancellor <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
--- arch/x86/Makefile | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/Makefile +2 -0
@@ -137,8 +137,10 @@ ifeq ($(CONFIG_X86_32),y) include $(srctree)/arch/x86/Makefile_32.cpu KBUILD_CFLAGS += $(cflags-y) + ifeq ($(CONFIG_CC_IS_CLANG),y) # temporary until string.h is fixed KBUILD_CFLAGS += -ffreestanding + endif ifeq ($(CONFIG_STACKPROTECTOR),y) ifeq ($(CONFIG_SMP),y)
Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] x86/build: Remove -ffreestanding on i386 with GCC
Quoted 23 lines · Kees Cook
The use of -ffreestanding is a leftover that is only needed for certain versions of Clang. Adjust this to be Clang-only. A later patch will make this a versioned check.
Signed-off-by Kees Cook <[email protected]>---
Cc: Nathan Chancellor <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>--- arch/x86/Makefile | 2 ++ 1 file changed, 2 insertions(+)arch/x86/Makefile +0
-0
arch/x86/Makefile ifeq ($(CONFIG_X86_32),y) · line 143
Quoted 7 lines
arch/x86/Makefile +2
-0@@ -137,8 +137,10 @@ ifeq ($(CONFIG_X86_32),y) include $(srctree)/arch/x86/Makefile_32.cpu KBUILD_CFLAGS += $(cflags-y) + ifeq ($(CONFIG_CC_IS_CLANG),y) # temporary until string.h is fixed KBUILD_CFLAGS += -ffreestanding + endif
Ingo
Re: [PATCH v2 1/2] x86/build: Remove -ffreestanding on i386 with GCC
In reply to Kees CookQuoted 5 lines · Kees Cook
The use of -ffreestanding is a leftover that is only needed for certain versions of Clang. Adjust this to be Clang-only. A later patch will make this a versioned check.
Signed-off-by Kees Cook <[email protected]>
This could also adjust the comment but it is probably not that big of a deal since the "temporary" is already pretty stale.
Quoted 31 lines
---
Cc: Nathan Chancellor <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>--- arch/x86/Makefile | 2 ++ 1 file changed, 2 insertions(+)arch/x86/Makefile +2
-0@@ -137,8 +137,10 @@ ifeq ($(CONFIG_X86_32),y) include $(srctree)/arch/x86/Makefile_32.cpu KBUILD_CFLAGS += $(cflags-y) + ifeq ($(CONFIG_CC_IS_CLANG),y) # temporary until string.h is fixed KBUILD_CFLAGS += -ffreestanding + endif ifeq ($(CONFIG_STACKPROTECTOR),y) ifeq ($(CONFIG_SMP),y)Signature · 1 line
2.34.1
Kees Cook
maintainerRe: [PATCH v2 1/2] x86/build: Remove -ffreestanding on i386 with GCC
Quoted 9 lines · Nathan Chancellor
Quoted 5 lines · Kees Cook
The use of -ffreestanding is a leftover that is only needed for certain versions of Clang. Adjust this to be Clang-only. A later patch will make this a versioned check.
Signed-off-by Kees Cook <[email protected]>This could also adjust the comment but it is probably not that big of a deal since the "temporary" is already pretty stale.
Ah yeah, good call. I'll fix that up locally.
Quoted 2 lines
Reviewed-by Nathan Chancellor <[email protected]>
Thanks!
-Kees
Signature · 1 line
Kees Cook
Kees Cook
maintainerPATCH v2 2/2 hardening: Enable i386 FORTIFY_SOURCE on Clang 16+
In reply to Kees CookThe i386 regparm bug exposed with FORTIFY_SOURCE with Clang was fixed in Clang 16[1].
--- arch/x86/Makefile | 2 +- security/Kconfig.hardening | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/Makefile +1 -1
@@ -137,7 +137,7 @@ ifeq ($(CONFIG_X86_32),y) include $(srctree)/arch/x86/Makefile_32.cpu KBUILD_CFLAGS += $(cflags-y) - ifeq ($(CONFIG_CC_IS_CLANG),y) + ifneq ($(call clang-min-version, 160000),y) # temporary until string.h is fixed KBUILD_CFLAGS += -ffreestanding endif
security/Kconfig.hardening +1 -1
@@ -286,7 +286,7 @@ config FORTIFY_SOURCE bool "Harden common str/mem functions against buffer overflows" depends on ARCH_HAS_FORTIFY_SOURCE # https://github.com/llvm/llvm-project/issues/53645 - depends on !CC_IS_CLANG || !X86_32 + depends on !X86_32 || !CC_IS_CLANG || CLANG_VERSION >= 160000 help Detect overflows of buffers in common string and memory functions where the compiler can determine and validate the buffer sizes.
Signature · 1 line
2.34.1
Quoted 5 lines · Kees Cook
The i386 regparm bug exposed with
FORTIFY_SOURCEwith Clang was fixed in Clang 16[1].
Quoted 34 lines
--- arch/x86/Makefile | 2 +- security/Kconfig.hardening | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/x86/Makefile +1
-1@@ -137,7 +137,7 @@ ifeq ($(CONFIG_X86_32),y) include $(srctree)/arch/x86/Makefile_32.cpu KBUILD_CFLAGS += $(cflags-y) - ifeq ($(CONFIG_CC_IS_CLANG),y) + ifneq ($(call clang-min-version, 160000),y) # temporary until string.h is fixed KBUILD_CFLAGS += -ffreestanding endifsecurity/Kconfig.hardening +1
-1@@ -286,7 +286,7 @@ config FORTIFY_SOURCE bool "Harden common str/mem functions against buffer overflows" depends on ARCH_HAS_FORTIFY_SOURCE # https://github.com/llvm/llvm-project/issues/53645 - depends on !CC_IS_CLANG || !X86_32 + depends on !X86_32 || !CC_IS_CLANG || CLANG_VERSION >= 160000 help Detect overflows of buffers in common string and memory functions where the compiler can determine and validate the buffer sizes.Signature · 1 line
2.34.1