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
3 * Archs are free to supply their own linker scripts. ld will3 * Archs are free to supply their own linker scripts. ld will
4 * combine them automatically.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
15SECTIONS {6SECTIONS {
16 /DISCARD/ : {7 /DISCARD/ : {
17 *(.discard)8 *(.discard)
18 *(.discard.*)9 *(.discard.*)
19 SANITIZER_DISCARDS
20 }10 }
21 11
22 __ksymtab 0 : { *(SORT(___ksymtab+*)) }12 __ksymtab 0 : { *(SORT(___ksymtab+*)) }
@@ -33,6 +23,10 @@ SECTIONS { · 10 unmodified lines
33 23
34 __patchable_function_entries : { *(__patchable_function_entries) }24 __patchable_function_entries : { *(__patchable_function_entries) }
35 25
26#ifdef CONFIG_ARCH_USES_CFI_TRAPS
27 __kcfi_traps : { KEEP(*(.kcfi_traps)) }
28#endif
29
36#ifdef CONFIG_LTO_CLANG30#ifdef CONFIG_LTO_CLANG
37 /*31 /*
38 * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and32 * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and
@@ -53,15 +47,6 @@ SECTIONS { · 14 unmodified lines
53 *(.rodata .rodata.[0-9a-zA-Z_]*)47 *(.rodata .rodata.[0-9a-zA-Z_]*)
54 *(.rodata..L*)48 *(.rodata..L*)
55 }49 }
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 }
65#endif50#endif
66}51}
67 52

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