History

cfi: Switch to -fsanitize=kcfi

Switch from Clang's original forward-edge control-flow integrity implementation to -fsanitize=kcfi, which is better suited for the kernel, as it doesn't require LTO, doesn't use a jump table that requires altering function references, and won't break cross-module function address equality.

Sami Tolvanen committed 4 years ago

Commit 89245601 parent 92efda89 files · +133 −176Browse files

Showing the changes to scripts (1 of 9 files). Show all

Unified · Split

scripts/module.lds.S+4−19
@@ -3,20 +3,10 @@ · 2 unmodified lines
33 * Archs are free to supply their own linker scripts. ld will
44 * combine them automatically.
55 */
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−
156 SECTIONS {
167 /DISCARD/ : {
178 *(.discard)
189 *(.discard.*)
19− SANITIZER_DISCARDS
2010 }
2111
2212 __ksymtab 0 : { *(SORT(___ksymtab+*)) }
@@ -33,6 +23,10 @@ SECTIONS { · 10 unmodified lines
3323
3424 __patchable_function_entries : { *(__patchable_function_entries) }
3525
26+#ifdef CONFIG_ARCH_USES_CFI_TRAPS
27+ __kcfi_traps : { KEEP(*(.kcfi_traps)) }
28+#endif
29+
3630 #ifdef CONFIG_LTO_CLANG
3731 /*
3832 * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and
@@ -53,15 +47,6 @@ SECTIONS { · 14 unmodified lines
5347 *(.rodata .rodata.[0-9a-zA-Z_]*)
5448 *(.rodata..L*)
5549 }
56−
57− /*
58− * With CONFIG_CFI_CLANG, we assume __cfi_check is at the beginning
59− * of the .text section, and is aligned to PAGE_SIZE.
60− */
61− .text : ALIGN_CFI {
62− *(.text.__cfi_check)
63− *(.text .text.[0-9a-zA-Z_]* .text..L.cfi*)
64− }
6550 #endif
6651 }
6752

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t