Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Sami Tolvanen and committed by
Kees Cook
5caf9682 ff301ceb

+10
+10
include/linux/mm.h
··· 125 125 #endif 126 126 127 127 /* 128 + * With CONFIG_CFI_CLANG, the compiler replaces function addresses in 129 + * instrumented C code with jump table addresses. Architectures that 130 + * support CFI can define this macro to return the actual function address 131 + * when needed. 132 + */ 133 + #ifndef function_nocfi 134 + #define function_nocfi(x) (x) 135 + #endif 136 + 137 + /* 128 138 * To prevent common memory management code establishing 129 139 * a zero page mapping on a read fault. 130 140 * This macro should be defined within <asm/pgtable.h>.