Commit 5caf9682 authored by Sami Tolvanen's avatar Sami Tolvanen Committed by Kees Cook

mm: add generic function_nocfi macro

With CONFIG_CFI_CLANG, the compiler replaces function addresses
in instrumented C code with jump table addresses. This means that
__pa_symbol(function) returns the physical address of the jump table
entry instead of the actual function, which may not work as the jump
table code will immediately jump to a virtual address that may not be
mapped.

To avoid this address space confusion, this change adds a generic
definition for function_nocfi(), which architectures that support CFI
can override. The typical implementation of would use inline assembly
to take the function address, which avoids compiler instrumentation.
Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210408182843.1754385-4-samitolvanen@google.com
parent ff301ceb
......@@ -124,6 +124,16 @@ extern int mmap_rnd_compat_bits __read_mostly;
#define lm_alias(x) __va(__pa_symbol(x))
#endif
/*
* With CONFIG_CFI_CLANG, the compiler replaces function addresses in
* instrumented C code with jump table addresses. Architectures that
* support CFI can define this macro to return the actual function address
* when needed.
*/
#ifndef function_nocfi
#define function_nocfi(x) (x)
#endif
/*
* To prevent common memory management code establishing
* a zero page mapping on a read fault.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment