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.
Showing the changes to scripts (1 of 9 files). Show all
Unified · Split
| @@ -3,20 +3,10 @@ · 2 unmodified lines | ||
| 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 | − | |
| 15 | 6 | SECTIONS { |
| 16 | 7 | /DISCARD/ : { |
| 17 | 8 | *(.discard) |
| 18 | 9 | *(.discard.*) |
| 19 | − SANITIZER_DISCARDS | |
| 20 | 10 | } |
| 21 | 11 | |
| 22 | 12 | __ksymtab 0 : { *(SORT(___ksymtab+*)) } |
| @@ -33,6 +23,10 @@ SECTIONS { · 10 unmodified lines | ||
| 33 | 23 | |
| 34 | 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 | 30 | #ifdef CONFIG_LTO_CLANG |
| 37 | 31 | /* |
| 38 | 32 | * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and |
| @@ -53,15 +47,6 @@ SECTIONS { · 14 unmodified lines | ||
| 53 | 47 | *(.rodata .rodata.[0-9a-zA-Z_]*) |
| 54 | 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 | 50 | #endif |
| 66 | 51 | } |
| 67 | 52 | |