mm: add generic function_nocfi macro
authorSami Tolvanen <samitolvanen@google.com>
Thu, 8 Apr 2021 18:28:28 +0000 (11:28 -0700)
committerKees Cook <keescook@chromium.org>
Thu, 8 Apr 2021 23:04:21 +0000 (16:04 -0700)
commit5caf968262df0ec7a3377fb67d4a6bfa979cb028
treeda8b0f692f2d79604ef9c9731e1b1ed0fe640251
parentff301ceb5299551c3650d0e07ba879b766da4cc0
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: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210408182843.1754385-4-samitolvanen@google.com
include/linux/mm.h