Skip to content

Commit e151955

Browse files
Sebastian Andrzej Siewiorpetrpavlu
authored andcommitted
cfi: Use RCU while invoking __module_address().
__module_address() can be invoked within a RCU section, there is no requirement to have preemption disabled. The _notrace() variant was introduced in commit 14c4c8e ("cfi: Use rcu_read_{un}lock_sched_notrace"). The recursive case where __cfi_slowpath_diag() could end up calling itself is no longer present, as all that logic is gone since commit 8924560 ("cfi: Switch to -fsanitize=kcfi"). Sami Tolvanen said that KCFI checks don't perform function calls. Elliot Berman verified it with | modprobe -a dummy_stm stm_ftrace stm_p_basic | mkdir -p /sys/kernel/config/stp-policy/dummy_stm.0.my-policy/default | echo function > /sys/kernel/tracing/current_tracer | echo 1 > /sys/kernel/tracing/tracing_on | echo dummy_stm.0 > /sys/class/stm_source/ftrace/stm_source_link Replace the rcu_read_lock_sched_notrace() section around __module_address() with RCU. Cc: Elliot Berman <quic_eberman@quicinc.com> Cc: Kees Cook <kees@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Sami Tolvanen <samitolvanen@google.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: llvm@lists.linux.dev Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Elliot Berman <elliot.berman@oss.qualcomm.com> # sm8650-qrd [1] Link: https://lore.kernel.org/all/20241230185812429-0800.eberman@hu-eberman-lv.qualcomm.com [1] Link: https://lore.kernel.org/r/20250108090457.512198-22-bigeasy@linutronix.de Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
1 parent ccf74e7 commit e151955

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

kernel/cfi.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,11 @@ static bool is_module_cfi_trap(unsigned long addr)
7171
struct module *mod;
7272
bool found = false;
7373

74-
rcu_read_lock_sched_notrace();
75-
74+
guard(rcu)();
7675
mod = __module_address(addr);
7776
if (mod)
7877
found = is_trap(addr, mod->kcfi_traps, mod->kcfi_traps_end);
7978

80-
rcu_read_unlock_sched_notrace();
81-
8279
return found;
8380
}
8481
#else /* CONFIG_MODULES */

0 commit comments

Comments
 (0)