diff options
author | Sami Tolvanen <samitolvanen@google.com> | 2021-04-08 11:28:28 -0700 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2021-04-08 16:04:21 -0700 |
commit | 5caf968262df0ec7a3377fb67d4a6bfa979cb028 (patch) | |
tree | da8b0f692f2d79604ef9c9731e1b1ed0fe640251 /include | |
parent | ff301ceb5299551c3650d0e07ba879b766da4cc0 (diff) | |
download | linux-stable-5caf968262df0ec7a3377fb67d4a6bfa979cb028.tar.gz linux-stable-5caf968262df0ec7a3377fb67d4a6bfa979cb028.tar.bz2 linux-stable-5caf968262df0ec7a3377fb67d4a6bfa979cb028.zip |
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
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/mm.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h index 8ba434287387..22cce9c7dd05 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -125,6 +125,16 @@ extern int mmap_rnd_compat_bits __read_mostly; #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. * This macro should be defined within <asm/pgtable.h>. |