UPSTREAM: cfi: Use rcu_read_{un}lock_sched_notrace

If rcu_read_lock_sched tracing is enabled, the tracing subsystem can
perform a jump which needs to be checked by CFI. For example, stm_ftrace
source is enabled as a module and hooks into enabled ftrace events. This
can cause an recursive loop where find_shadow_check_fn ->
rcu_read_lock_sched -> (call to stm_ftrace generates cfi slowpath) ->
find_shadow_check_fn -> rcu_read_lock_sched -> ...

To avoid the recursion, either the ftrace codes needs to be marked with
__no_cfi or CFI should not trace. Use the "_notrace" in CFI to avoid
tracing so that CFI can guard ftrace.

Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Cc: stable@vger.kernel.org
Fixes: cf68fffb66d6 ("add support for Clang CFI")
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210811155914.19550-1-quic_eberman@quicinc.com

Bug: 194223154
Change-Id: I7d112496c7f503f95ba69390f6454623cf6dfed2
(cherry picked from commit 14c4c8e41511aa8fba7fb239b20b6539b5bce201)
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
This commit is contained in:
Elliot Berman
2021-08-11 08:59:14 -07:00
committed by Steve Muckle
parent 580b7fa7d9
commit 5cd4b1ce23

View File

@@ -251,9 +251,9 @@ static inline cfi_check_fn __find_shadow_check_fn(unsigned long ptr)
{ {
cfi_check_fn fn; cfi_check_fn fn;
rcu_read_lock_sched(); rcu_read_lock_sched_notrace();
fn = ptr_to_check_fn(rcu_dereference_sched(cfi_shadow), ptr); fn = ptr_to_check_fn(rcu_dereference_sched(cfi_shadow), ptr);
rcu_read_unlock_sched(); rcu_read_unlock_sched_notrace();
return fn; return fn;
} }
@@ -272,11 +272,11 @@ static inline cfi_check_fn __find_module_check_fn(unsigned long ptr)
cfi_check_fn fn = NULL; cfi_check_fn fn = NULL;
struct module *mod; struct module *mod;
rcu_read_lock_sched(); rcu_read_lock_sched_notrace();
mod = __module_address(ptr); mod = __module_address(ptr);
if (mod) if (mod)
fn = mod->cfi_check; fn = mod->cfi_check;
rcu_read_unlock_sched(); rcu_read_unlock_sched_notrace();
return fn; return fn;
} }