summarylogtreecommitdiffstats
path: root/0124-cfi-Fix-__cfi_slowpath_diag-RCU-usage-with-cpuidle.patch
diff options
context:
space:
mode:
authorBjörn Bidar2022-06-24 20:03:01 +0300
committerBjörn Bidar2022-06-25 16:46:45 +0300
commit657059c03d46120dea746abb196d9d622e21fe5f (patch)
tree2ae07d28cd858ef0cda12e3c8af27932d06c0fbb /0124-cfi-Fix-__cfi_slowpath_diag-RCU-usage-with-cpuidle.patch
parent034adcf2fd3311bba3f58b8575b0be699ab3bd70 (diff)
downloadaur-657059c03d46120dea746abb196d9d622e21fe5f.tar.gz
Update to 5.18.6.p2-1
- New upstream release based on 5.18.5 - Add MGLRU Zen patch - Add linux-5.18.6 patches - Move System.map from -headers into the base package to avoid external modules having wrong bpf symbols when running optimized builds. Fixes #5 - Remove M/m from CPUSUFFIXES_KBUILD and LCPU, fixes build failing when selecting an optimized build architecture that is not genering. Fixes #6. Signed-off-by: Björn Bidar <bjorn.bidar@thaodan.de>
Diffstat (limited to '0124-cfi-Fix-__cfi_slowpath_diag-RCU-usage-with-cpuidle.patch')
-rw-r--r--0124-cfi-Fix-__cfi_slowpath_diag-RCU-usage-with-cpuidle.patch76
1 files changed, 76 insertions, 0 deletions
diff --git a/0124-cfi-Fix-__cfi_slowpath_diag-RCU-usage-with-cpuidle.patch b/0124-cfi-Fix-__cfi_slowpath_diag-RCU-usage-with-cpuidle.patch
new file mode 100644
index 000000000000..e1e9c7eb0481
--- /dev/null
+++ b/0124-cfi-Fix-__cfi_slowpath_diag-RCU-usage-with-cpuidle.patch
@@ -0,0 +1,76 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Sami Tolvanen <samitolvanen@google.com>
+Date: Tue, 31 May 2022 10:59:10 -0700
+Subject: [PATCH] cfi: Fix __cfi_slowpath_diag RCU usage with cpuidle
+
+commit 57cd6d157eb479f0a8e820fd36b7240845c8a937 upstream.
+
+RCU_NONIDLE usage during __cfi_slowpath_diag can result in an invalid
+RCU state in the cpuidle code path:
+
+ WARNING: CPU: 1 PID: 0 at kernel/rcu/tree.c:613 rcu_eqs_enter+0xe4/0x138
+ ...
+ Call trace:
+ rcu_eqs_enter+0xe4/0x138
+ rcu_idle_enter+0xa8/0x100
+ cpuidle_enter_state+0x154/0x3a8
+ cpuidle_enter+0x3c/0x58
+ do_idle.llvm.6590768638138871020+0x1f4/0x2ec
+ cpu_startup_entry+0x28/0x2c
+ secondary_start_kernel+0x1b8/0x220
+ __secondary_switched+0x94/0x98
+
+Instead, call rcu_irq_enter/exit to wake up RCU only when needed and
+disable interrupts for the entire CFI shadow/module check when we do.
+
+Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
+Link: https://lore.kernel.org/r/20220531175910.890307-1-samitolvanen@google.com
+Fixes: cf68fffb66d6 ("add support for Clang CFI")
+Cc: stable@vger.kernel.org
+Signed-off-by: Kees Cook <keescook@chromium.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ kernel/cfi.c | 22 ++++++++++++++++------
+ 1 file changed, 16 insertions(+), 6 deletions(-)
+
+diff --git a/kernel/cfi.c b/kernel/cfi.c
+index 9594cfd1cf2cf7ea7be1a44ad048d3b25b624acc..08102d19ec15a2e402c10ad8d22743caafe47d68 100644
+--- a/kernel/cfi.c
++++ b/kernel/cfi.c
+@@ -281,6 +281,8 @@ static inline cfi_check_fn find_module_check_fn(unsigned long ptr)
+ static inline cfi_check_fn find_check_fn(unsigned long ptr)
+ {
+ cfi_check_fn fn = NULL;
++ unsigned long flags;
++ bool rcu_idle;
+
+ if (is_kernel_text(ptr))
+ return __cfi_check;
+@@ -290,13 +292,21 @@ static inline cfi_check_fn find_check_fn(unsigned long ptr)
+ * the shadow and __module_address use RCU, so we need to wake it
+ * up if necessary.
+ */
+- RCU_NONIDLE({
+- if (IS_ENABLED(CONFIG_CFI_CLANG_SHADOW))
+- fn = find_shadow_check_fn(ptr);
++ rcu_idle = !rcu_is_watching();
++ if (rcu_idle) {
++ local_irq_save(flags);
++ rcu_irq_enter();
++ }
++
++ if (IS_ENABLED(CONFIG_CFI_CLANG_SHADOW))
++ fn = find_shadow_check_fn(ptr);
++ if (!fn)
++ fn = find_module_check_fn(ptr);
+
+- if (!fn)
+- fn = find_module_check_fn(ptr);
+- });
++ if (rcu_idle) {
++ rcu_irq_exit();
++ local_irq_restore(flags);
++ }
+
+ return fn;
+ }