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.

module: ensure __cfi_check alignment

CONFIG_CFI_CLANG_SHADOW assumes the __cfi_check() function is page
aligned and at the beginning of the .text section. While Clang would
normally align the function correctly, it fails to do so for modules
with no executable code.

This change ensures the correct __cfi_check() location and
alignment. It also discards the .eh_frame section, which Clang can
generate with certain sanitizers, such as CFI.

Link: https://bugs.llvm.org/show_bug.cgi?id=46293
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Jessica Yu <jeyu@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210408182843.1754385-5-samitolvanen@google.com

authored by

Sami Tolvanen and committed by
Kees Cook
28aad1c2 5caf9682

+18 -1
+18 -1
scripts/module.lds.S
··· 3 3 * Archs are free to supply their own linker scripts. ld will 4 4 * combine them automatically. 5 5 */ 6 + #ifdef CONFIG_CFI_CLANG 7 + # include <asm/page.h> 8 + # define ALIGN_CFI ALIGN(PAGE_SIZE) 9 + # define SANITIZER_DISCARDS *(.eh_frame) 10 + #else 11 + # define ALIGN_CFI 12 + # define SANITIZER_DISCARDS 13 + #endif 14 + 6 15 SECTIONS { 7 16 /DISCARD/ : { 8 17 *(.discard) 9 18 *(.discard.*) 19 + SANITIZER_DISCARDS 10 20 } 11 21 12 22 __ksymtab 0 : { *(SORT(___ksymtab+*)) } ··· 51 41 *(.rodata..L*) 52 42 } 53 43 54 - .text : { *(.text .text.[0-9a-zA-Z_]*) } 44 + /* 45 + * With CONFIG_CFI_CLANG, we assume __cfi_check is at the beginning 46 + * of the .text section, and is aligned to PAGE_SIZE. 47 + */ 48 + .text : ALIGN_CFI { 49 + *(.text.__cfi_check) 50 + *(.text .text.[0-9a-zA-Z_]* .text..L.cfi*) 51 + } 55 52 #endif 56 53 } 57 54