[arch-commits] Commit in linux-hardened/trunk (5 files)
Jan Steffens
heftig at archlinux.org
Sat May 9 19:59:29 UTC 2020
Date: Saturday, May 9, 2020 @ 19:59:26
Author: heftig
Revision: 382975
5.6.11.a-3: more GCC 10 fixes
Added:
linux-hardened/trunk/0003-Makefile-disallow-data-races-on-gcc-10-as-well.patch
linux-hardened/trunk/0004-x86-Fix-early-boot-crash-on-gcc-10-next-try.patch
Modified:
linux-hardened/trunk/0001-gcc-plugins-drop-support-for-GCC-4.7.patch
linux-hardened/trunk/0002-gcc-common.h-Update-for-GCC-10.patch
linux-hardened/trunk/PKGBUILD
-----------------------------------------------------------+
0001-gcc-plugins-drop-support-for-GCC-4.7.patch | 2
0002-gcc-common.h-Update-for-GCC-10.patch | 2
0003-Makefile-disallow-data-races-on-gcc-10-as-well.patch | 32 ++
0004-x86-Fix-early-boot-crash-on-gcc-10-next-try.patch | 131 ++++++++++++
PKGBUILD | 10
5 files changed, 172 insertions(+), 5 deletions(-)
Modified: 0001-gcc-plugins-drop-support-for-GCC-4.7.patch
===================================================================
--- 0001-gcc-plugins-drop-support-for-GCC-4.7.patch 2020-05-09 19:59:23 UTC (rev 382974)
+++ 0001-gcc-plugins-drop-support-for-GCC-4.7.patch 2020-05-09 19:59:26 UTC (rev 382975)
@@ -1,7 +1,7 @@
From dba68a9d4df76d49d32245e4236713a43fb321da Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy at kernel.org>
Date: Sun, 29 Mar 2020 20:08:32 +0900
-Subject: [PATCH 1/2] gcc-plugins: drop support for GCC <= 4.7
+Subject: [PATCH 1/4] gcc-plugins: drop support for GCC <= 4.7
Nobody was opposed to raising minimum GCC version to 4.8 [1]
So, we will drop GCC <= 4.7 support sooner or later.
Modified: 0002-gcc-common.h-Update-for-GCC-10.patch
===================================================================
--- 0002-gcc-common.h-Update-for-GCC-10.patch 2020-05-09 19:59:23 UTC (rev 382974)
+++ 0002-gcc-common.h-Update-for-GCC-10.patch 2020-05-09 19:59:26 UTC (rev 382975)
@@ -2,7 +2,7 @@
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?=
<frederic.pierret at qubes-os.org>
Date: Tue, 7 Apr 2020 13:32:59 +0200
-Subject: [PATCH 2/2] gcc-common.h: Update for GCC 10
+Subject: [PATCH 2/4] gcc-common.h: Update for GCC 10
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Added: 0003-Makefile-disallow-data-races-on-gcc-10-as-well.patch
===================================================================
--- 0003-Makefile-disallow-data-races-on-gcc-10-as-well.patch (rev 0)
+++ 0003-Makefile-disallow-data-races-on-gcc-10-as-well.patch 2020-05-09 19:59:26 UTC (rev 382975)
@@ -0,0 +1,32 @@
+From af805f5f1d2e61dd2cf907d9635f0abc66fe1197 Mon Sep 17 00:00:00 2001
+From: Sergei Trofimovich <slyfox at gentoo.org>
+Date: Tue, 17 Mar 2020 00:07:18 +0000
+Subject: [PATCH 3/4] Makefile: disallow data races on gcc-10 as well
+
+gcc-10 will rename --param=allow-store-data-races=0
+to -fno-allow-store-data-races.
+
+The flag change happened at https://gcc.gnu.org/PR92046.
+
+Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org>
+Acked-by: Jiri Kosina <jkosina at suse.cz>
+Signed-off-by: Masahiro Yamada <masahiroy at kernel.org>
+---
+ Makefile | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/Makefile b/Makefile
+index 5dedd6f9ad75..6899bfc9dc7b 100644
+--- a/Makefile
++++ b/Makefile
+@@ -714,6 +714,7 @@ endif
+
+ # Tell gcc to never replace conditional load with a non-conditional one
+ KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
++KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)
+
+ include scripts/Makefile.kcov
+ include scripts/Makefile.gcc-plugins
+--
+2.26.2
+
Added: 0004-x86-Fix-early-boot-crash-on-gcc-10-next-try.patch
===================================================================
--- 0004-x86-Fix-early-boot-crash-on-gcc-10-next-try.patch (rev 0)
+++ 0004-x86-Fix-early-boot-crash-on-gcc-10-next-try.patch 2020-05-09 19:59:26 UTC (rev 382975)
@@ -0,0 +1,131 @@
+From 309b6eca2e2605accf7a3b02b47b5c2732dbe543 Mon Sep 17 00:00:00 2001
+From: Borislav Petkov <bp at suse.de>
+Date: Wed, 22 Apr 2020 18:11:30 +0200
+Subject: [PATCH 4/4] x86: Fix early boot crash on gcc-10, next try
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+... or the odyssey of trying to disable the stack protector for the
+function which generates the stack canary value.
+
+The whole story started with Sergei reporting a boot crash with a kernel
+built with gcc-10:
+
+ Kernel panic — not syncing: stack-protector: Kernel stack is corrupted in: start_secondary
+ CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.6.0-rc5—00235—gfffb08b37df9 #139
+ Hardware name: Gigabyte Technology Co., Ltd. To be filled by O.E.M./H77M—D3H, BIOS F12 11/14/2013
+ Call Trace:
+ dump_stack
+ panic
+ ? start_secondary
+ __stack_chk_fail
+ start_secondary
+ secondary_startup_64
+ -—-[ end Kernel panic — not syncing: stack—protector: Kernel stack is corrupted in: start_secondary
+
+This happens because gcc-10 tail-call optimizes the last function call
+in start_secondary() - cpu_startup_entry() - and thus emits a stack
+canary check which fails because the canary value changes after the
+boot_init_stack_canary() call.
+
+To fix that, the initial attempt was to mark the one function which
+generates the stack canary with:
+
+ __attribute__((optimize("-fno-stack-protector"))) ... start_secondary(void *unused)
+
+however, using the optimize attribute doesn't work cumulatively
+as the attribute does not add to but rather replaces previously
+supplied optimization options - roughly all -fxxx options.
+
+The key one among them being -fno-omit-frame-pointer and thus leading to
+not present frame pointer - frame pointer which the kernel needs.
+
+The next attempt to prevent compilers from tail-call optimizing
+the last function call cpu_startup_entry(), shy of carving out
+start_secondary() into a separate compilation unit and building it with
+-fno-stack-protector, is this one.
+
+The current solution is short and sweet, and reportedly, is supported by
+both compilers so let's see how far we'll get this time.
+
+Reported-by: Sergei Trofimovich <slyfox at gentoo.org>
+Signed-off-by: Borislav Petkov <bp at suse.de>
+Reviewed-by: Nick Desaulniers <ndesaulniers at google.com>
+Reviewed-by: Kees Cook <keescook at chromium.org>
+Link: https://lkml.kernel.org/r/20200314164451.346497-1-slyfox@gentoo.org
+---
+ arch/x86/include/asm/stackprotector.h | 7 ++++++-
+ arch/x86/kernel/smpboot.c | 8 ++++++++
+ arch/x86/xen/smp_pv.c | 1 +
+ include/linux/compiler.h | 6 ++++++
+ 4 files changed, 21 insertions(+), 1 deletion(-)
+
+diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
+index 91e29b6a86a5..9804a7957f4e 100644
+--- a/arch/x86/include/asm/stackprotector.h
++++ b/arch/x86/include/asm/stackprotector.h
+@@ -55,8 +55,13 @@
+ /*
+ * Initialize the stackprotector canary value.
+ *
+- * NOTE: this must only be called from functions that never return,
++ * NOTE: this must only be called from functions that never return
+ * and it must always be inlined.
++ *
++ * In addition, it should be called from a compilation unit for which
++ * stack protector is disabled. Alternatively, the caller should not end
++ * with a function call which gets tail-call optimized as that would
++ * lead to checking a modified canary value.
+ */
+ static __always_inline void boot_init_stack_canary(void)
+ {
+diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
+index 69881b2d446c..9674321ce3a3 100644
+--- a/arch/x86/kernel/smpboot.c
++++ b/arch/x86/kernel/smpboot.c
+@@ -262,6 +262,14 @@ static void notrace start_secondary(void *unused)
+
+ wmb();
+ cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
++
++ /*
++ * Prevent tail call to cpu_startup_entry() because the stack protector
++ * guard has been changed a couple of function calls up, in
++ * boot_init_stack_canary() and must not be checked before tail calling
++ * another function.
++ */
++ prevent_tail_call_optimization();
+ }
+
+ /**
+diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c
+index 802ee5bba66c..0cebe5db691d 100644
+--- a/arch/x86/xen/smp_pv.c
++++ b/arch/x86/xen/smp_pv.c
+@@ -92,6 +92,7 @@ asmlinkage __visible void cpu_bringup_and_idle(void)
+ cpu_bringup();
+ boot_init_stack_canary();
+ cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
++ prevent_tail_call_optimization();
+ }
+
+ void xen_smp_intr_free_pv(unsigned int cpu)
+diff --git a/include/linux/compiler.h b/include/linux/compiler.h
+index 034b0a644efc..732754d96039 100644
+--- a/include/linux/compiler.h
++++ b/include/linux/compiler.h
+@@ -356,4 +356,10 @@ static inline void *offset_to_ptr(const int *off)
+ /* &a[0] degrades to a pointer: a different type from an array */
+ #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
+
++/*
++ * This is needed in functions which generate the stack canary, see
++ * arch/x86/kernel/smpboot.c::start_secondary() for an example.
++ */
++#define prevent_tail_call_optimization() asm("")
++
+ #endif /* __LINUX_COMPILER_H */
+--
+2.26.2
+
Modified: PKGBUILD
===================================================================
--- PKGBUILD 2020-05-09 19:59:23 UTC (rev 382974)
+++ PKGBUILD 2020-05-09 19:59:26 UTC (rev 382975)
@@ -5,7 +5,7 @@
pkgbase=linux-hardened
pkgver=5.6.11.a
-pkgrel=2
+pkgrel=3
pkgdesc='Security-Hardened Linux'
url='https://github.com/anthraxx/linux-hardened'
arch=(x86_64)
@@ -22,6 +22,8 @@
config # the main kernel config file
0001-gcc-plugins-drop-support-for-GCC-4.7.patch
0002-gcc-common.h-Update-for-GCC-10.patch
+ 0003-Makefile-disallow-data-races-on-gcc-10-as-well.patch
+ 0004-x86-Fix-early-boot-crash-on-gcc-10-next-try.patch
sphinx-workaround.patch
)
validpgpkeys=(
@@ -35,8 +37,10 @@
'a3eb5f89cff627b3bd9232edf50ff28a9522134e9529017b82412cb19ce3ccac'
'SKIP'
'93ba919836378a3a4df05e78011281a6e4430afe89a0e54dac48e2ad15355fa4'
- 'f52774d05b2ab6886df95434a31a6070799b7bcc5d48ca9c93d499d40dd9622d'
- '40c9da5e310ba66c99aeb4c472c6549d8b98cb13ea66835df0291a113113b0c5'
+ '118531186e7069b006d48fdfb2dbd9f28ee6d01cbfaacb007d8f44e8e76a57e1'
+ 'd2ee933dd10dee475746a7e9081bca3ebdae8c6fb631f458d8f0d4987c9a0845'
+ 'b604f4041c94d12abc0a0ad9e15ab54a7712c424d7740d6dffff8e0a001ae862'
+ '09dbf84dff332fd9c2cde9eca97ce70e73ff7b90c08f22b169c6b69a633c56b0'
'8cb21e0b3411327b627a9dd15b8eb773295a0d2782b1a41b2a8839d1b2f5778c')
export KBUILD_BUILD_HOST=archlinux
More information about the arch-commits
mailing list