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
13/* Compiler-generated function in each module, and the kernel */13/* Compiler-generated function in each module, and the kernel */
14extern void __cfi_check(uint64_t id, void *ptr, void *diag);14extern void __cfi_check(uint64_t id, void *ptr, void *diag);
15 15
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
32#endif /* CONFIG_CFI_CLANG */16#endif /* CONFIG_CFI_CLANG */
33 17
34#ifndef __CFI_ADDRESSABLE
35#define __CFI_ADDRESSABLE(fn, __attr)
36#endif
37
38#endif /* _LINUX_CFI_H */18#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
221 * otherwise, or eliminated entirely due to lack of references that are221 * otherwise, or eliminated entirely due to lack of references that are
222 * visible to the compiler.222 * visible to the compiler.
223 */223 */
224#define __ADDRESSABLE(sym) \224#define ___ADDRESSABLE(sym, __attrs) \
225 static void * __section(".discard.addressable") __used \225 static void * __used __attrs \
226 __UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)&sym;226 __UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)&sym;
227#define __ADDRESSABLE(sym) \
228 ___ADDRESSABLE(sym, __section(".discard.addressable"))
227 229
228/**230/**
229 * offset_to_ptr - convert a relative memory offset to an absolute pointer231 * 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
132 { return initfn; } \132 { return initfn; } \
133 int init_module(void) __copy(initfn) \133 int init_module(void) __copy(initfn) \
134 __attribute__((alias(#initfn))); \134 __attribute__((alias(#initfn))); \
135 __CFI_ADDRESSABLE(init_module, __initdata);135 ___ADDRESSABLE(init_module, __initdata);
136 136
137/* This is only required if you want to be unloadable. */137/* This is only required if you want to be unloadable. */
138#define module_exit(exitfn) \138#define module_exit(exitfn) \
@@ -140,7 +140,7 @@ extern void cleanup_module(void); · 1 unmodified line
140 { return exitfn; } \140 { return exitfn; } \
141 void cleanup_module(void) __copy(exitfn) \141 void cleanup_module(void) __copy(exitfn) \
142 __attribute__((alias(#exitfn))); \142 __attribute__((alias(#exitfn))); \
143 __CFI_ADDRESSABLE(cleanup_module, __exitdata);143 ___ADDRESSABLE(cleanup_module, __exitdata);
144 144
145#endif145#endif
146 146

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