Skip to content

Commit 57cd6d1

Browse files
samitolvanenkees
authored andcommitted
cfi: Fix __cfi_slowpath_diag RCU usage with cpuidle
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Fixes: cf68fff ("add support for Clang CFI") Cc: [email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent b13bacc commit 57cd6d1

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

kernel/cfi.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ static inline cfi_check_fn find_module_check_fn(unsigned long ptr)
281281
static inline cfi_check_fn find_check_fn(unsigned long ptr)
282282
{
283283
cfi_check_fn fn = NULL;
284+
unsigned long flags;
285+
bool rcu_idle;
284286

285287
if (is_kernel_text(ptr))
286288
return __cfi_check;
@@ -290,13 +292,21 @@ static inline cfi_check_fn find_check_fn(unsigned long ptr)
290292
* the shadow and __module_address use RCU, so we need to wake it
291293
* up if necessary.
292294
*/
293-
RCU_NONIDLE({
294-
if (IS_ENABLED(CONFIG_CFI_CLANG_SHADOW))
295-
fn = find_shadow_check_fn(ptr);
295+
rcu_idle = !rcu_is_watching();
296+
if (rcu_idle) {
297+
local_irq_save(flags);
298+
rcu_irq_enter();
299+
}
300+
301+
if (IS_ENABLED(CONFIG_CFI_CLANG_SHADOW))
302+
fn = find_shadow_check_fn(ptr);
303+
if (!fn)
304+
fn = find_module_check_fn(ptr);
296305

297-
if (!fn)
298-
fn = find_module_check_fn(ptr);
299-
});
306+
if (rcu_idle) {
307+
rcu_irq_exit();
308+
local_irq_restore(flags);
309+
}
300310

301311
return fn;
302312
}

0 commit comments

Comments
 (0)