History

cfi: Drop __CFI_ADDRESSABLE

The __CFI_ADDRESSABLE macro is used for init_module and cleanup_module to ensure we have the address of the CFI jump table, and with CONFIG_X86_KERNEL_IBT to ensure LTO won't optimize away the symbols. As __CFI_ADDRESSABLE is no longer necessary with -fsanitize=kcfi, add a more flexible version of the __ADDRESSABLE macro and always ensure these symbols won't be dropped.

Sami Tolvanen committed 4 years ago

Commit 92efda81 parent 9fca7113 files · +6 −24Browse files

Unified · Split

3 files
  1. include/linux/cfi.h +0 −20
  2. include/linux/compiler.h +4 −2
  3. include/linux/module.h +2 −2
include/linux/cfi.h+0−20
@@ -13,26 +13,6 @@ typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag); · 12 unmodified lines
1313 /* Compiler-generated function in each module, and the kernel */
1414 extern void __cfi_check(uint64_t id, void *ptr, void *diag);
1515
16−/*
17− * Force the compiler to generate a CFI jump table entry for a function
18− * and store the jump table address to __cfi_jt_<function>.
19− */
20−#define __CFI_ADDRESSABLE(fn, __attr) \
21− const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn
22−
23−#else /* !CONFIG_CFI_CLANG */
24−
25−#ifdef CONFIG_X86_KERNEL_IBT
26−
27−#define __CFI_ADDRESSABLE(fn, __attr) \
28− const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn
29−
30−#endif /* CONFIG_X86_KERNEL_IBT */
31−
3216 #endif /* CONFIG_CFI_CLANG */
3317
34−#ifndef __CFI_ADDRESSABLE
35−#define __CFI_ADDRESSABLE(fn, __attr)
36−#endif
37−
3818 #endif /* _LINUX_CFI_H */
include/linux/compiler.h+4−2
@@ -221,9 +221,11 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, · 220 unmodified lines
221221 * otherwise, or eliminated entirely due to lack of references that are
222222 * visible to the compiler.
223223 */
224−#define __ADDRESSABLE(sym) \
225− static void * __section(".discard.addressable") __used \
224+#define ___ADDRESSABLE(sym, __attrs) \
225+ static void * __used __attrs \
226226 __UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)&sym;
227+#define __ADDRESSABLE(sym) \
228+ ___ADDRESSABLE(sym, __section(".discard.addressable"))
227229
228230 /**
229231 * offset_to_ptr - convert a relative memory offset to an absolute pointer
include/linux/module.h+2−2
@@ -132,7 +132,7 @@ extern void cleanup_module(void); · 131 unmodified lines
132132 { return initfn; } \
133133 int init_module(void) __copy(initfn) \
134134 __attribute__((alias(#initfn))); \
135− __CFI_ADDRESSABLE(init_module, __initdata);
135+ ___ADDRESSABLE(init_module, __initdata);
136136
137137 /* This is only required if you want to be unloadable. */
138138 #define module_exit(exitfn) \
@@ -140,7 +140,7 @@ extern void cleanup_module(void); · 1 unmodified line
140140 { return exitfn; } \
141141 void cleanup_module(void) __copy(exitfn) \
142142 __attribute__((alias(#exitfn))); \
143− __CFI_ADDRESSABLE(cleanup_module, __exitdata);
143+ ___ADDRESSABLE(cleanup_module, __exitdata);
144144
145145 #endif
146146

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