History

objtool: Add CONFIG_OBJTOOL

Now that stack validation is an optional feature of objtool, add CONFIG_OBJTOOL and replace most usages of CONFIG_STACK_VALIDATION with it. CONFIG_STACK_VALIDATION can now be considered to be frame-pointer specific. CONFIG_UNWINDER_ORC is already inherently valid for live patching, so no need to "validate" it.

Josh Poimboeuf committed 4 years ago

Commit 03f16cd1 parent c2bdd6117 files · +73 −57Browse files

Unified · Split

17 files
  1. Makefile +1 −1
  2. arch/Kconfig +6 −2
  3. arch/x86/Kconfig +11 −7
  4. arch/x86/Kconfig.debug +1 −1
  5. arch/x86/include/asm/jump_label.h +3 −3
  6. arch/x86/kernel/alternative.c +3 −3
  7. include/linux/compiler.h +3 −3
  8. include/linux/instrumentation.h +3 −3
  9. include/linux/objtool.h +3 −3
  10. kernel/trace/Kconfig +1 −0
  11. lib/Kconfig.debug +11 −9
  12. lib/Kconfig.kcsan +2 −1
  13. lib/Kconfig.ubsan +1 −1
  14. scripts/Makefile.build +2 −2
  15. scripts/link-vmlinux.sh +18 −14
  16. scripts/package/builddeb +1 −1
  17. tools/include/linux/objtool.h +3 −3
Makefile+1−1
@@ -1302,7 +1302,7 @@ install: sub_make_done := · 1301 unmodified lines
13021302 # ---------------------------------------------------------------------------
13031303 # Tools
13041304
1305−ifdef CONFIG_STACK_VALIDATION
1305+ifdef CONFIG_OBJTOOL
13061306 prepare: tools/objtool
13071307 endif
13081308
arch/Kconfig+6−2
@@ -1028,11 +1028,14 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT · 1027 unmodified lines
10281028 depends on MMU
10291029 select ARCH_HAS_ELF_RANDOMIZE
10301030
1031+config HAVE_OBJTOOL
1032+ bool
1033+
10311034 config HAVE_STACK_VALIDATION
10321035 bool
10331036 help
1034− Architecture supports the 'objtool check' host tool command, which
1035− performs compile-time stack metadata validation.
1037+ Architecture supports objtool compile-time frame pointer rule
1038+ validation.
10361039
10371040 config HAVE_RELIABLE_STACKTRACE
10381041 bool
@@ -1302,6 +1305,7 @@ config HAVE_STATIC_CALL · 263 unmodified lines
13021305 config HAVE_STATIC_CALL_INLINE
13031306 bool
13041307 depends on HAVE_STATIC_CALL
1308+ select OBJTOOL
13051309
13061310 config HAVE_PREEMPT_DYNAMIC
13071311 bool
arch/x86/Kconfig+11−7
@@ -188,7 +188,7 @@ config X86 · 187 unmodified lines
188188 select HAVE_CONTEXT_TRACKING if X86_64
189189 select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING
190190 select HAVE_C_RECORDMCOUNT
191− select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION
191+ select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL
192192 select HAVE_BUILDTIME_MCOUNT_SORT
193193 select HAVE_DEBUG_KMEMLEAK
194194 select HAVE_DMA_CONTIGUOUS
@@ -231,6 +231,7 @@ config X86 · 36 unmodified lines
231231 select HAVE_MOVE_PMD
232232 select HAVE_MOVE_PUD
233233 select HAVE_NMI
234+ select HAVE_OBJTOOL if X86_64
234235 select HAVE_OPTPROBES
235236 select HAVE_PCSPKR_PLATFORM
236237 select HAVE_PERF_EVENTS
@@ -239,17 +240,17 @@ config X86 · 2 unmodified lines
239240 select HAVE_PCI
240241 select HAVE_PERF_REGS
241242 select HAVE_PERF_USER_STACK_DUMP
242− select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT
243+ select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT
243244 select HAVE_POSIX_CPU_TIMERS_TASK_WORK
244245 select HAVE_REGS_AND_STACK_ACCESS_API
245− select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION
246+ select HAVE_RELIABLE_STACKTRACE if UNWINDER_ORC || STACK_VALIDATION
246247 select HAVE_FUNCTION_ARG_ACCESS_API
247248 select HAVE_SETUP_PER_CPU_AREA
248249 select HAVE_SOFTIRQ_ON_OWN_STACK
249250 select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR
250− select HAVE_STACK_VALIDATION if X86_64
251+ select HAVE_STACK_VALIDATION if HAVE_OBJTOOL
251252 select HAVE_STATIC_CALL
252− select HAVE_STATIC_CALL_INLINE if HAVE_STACK_VALIDATION
253+ select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL
253254 select HAVE_PREEMPT_DYNAMIC_CALL
254255 select HAVE_RSEQ
255256 select HAVE_SYSCALL_TRACEPOINTS
@@ -268,7 +269,6 @@ config X86 · 12 unmodified lines
268269 select RTC_MC146818_LIB
269270 select SPARSE_IRQ
270271 select SRCU
271− select STACK_VALIDATION if HAVE_STACK_VALIDATION && (HAVE_STATIC_CALL_INLINE || RETPOLINE)
272272 select SYSCTL_EXCEPTION_TRACE
273273 select THREAD_INFO_IN_TASK
274274 select TRACE_IRQFLAGS_SUPPORT
@@ -459,6 +459,7 @@ config GOLDFISH · 184 unmodified lines
459459
460460 config RETPOLINE
461461 bool "Avoid speculative indirect branches in kernel"
462+ select OBJTOOL if HAVE_OBJTOOL
462463 default y
463464 help
464465 Compile kernel with the retpoline compiler options to guard against
@@ -472,6 +473,7 @@ config CC_HAS_SLS · 7 unmodified lines
472473 config SLS
473474 bool "Mitigate Straight-Line-Speculation"
474475 depends on CC_HAS_SLS && X86_64
476+ select OBJTOOL if HAVE_OBJTOOL
475477 default n
476478 help
477479 Compile the kernel with straight-line-speculation options to guard
@@ -1819,6 +1821,7 @@ config ARCH_RANDOM · 1341 unmodified lines
18191821 config X86_SMAP
18201822 def_bool y
18211823 prompt "Supervisor Mode Access Prevention" if EXPERT
1824+ select OBJTOOL if HAVE_OBJTOOL
18221825 help
18231826 Supervisor Mode Access Prevention (SMAP) is a security
18241827 feature in newer Intel processors. There is a small
@@ -1855,9 +1858,10 @@ config CC_HAS_IBT · 30 unmodified lines
18551858 config X86_KERNEL_IBT
18561859 prompt "Indirect Branch Tracking"
18571860 bool
1858− depends on X86_64 && CC_HAS_IBT && STACK_VALIDATION
1861+ depends on X86_64 && CC_HAS_IBT && HAVE_OBJTOOL
18591862 # https://github.com/llvm/llvm-project/commit/9d7001eba9c4cb311e03cd8cdc231f9e579f2d0f
18601863 depends on !LD_IS_LLD || LLD_VERSION >= 140000
1864+ select OBJTOOL
18611865 help
18621866 Build the kernel with support for Indirect Branch Tracking, a
18631867 hardware support course-grain forward-edge Control Flow Integrity
arch/x86/Kconfig.debug+1−1
@@ -237,7 +237,7 @@ choice · 236 unmodified lines
237237 config UNWINDER_ORC
238238 bool "ORC unwinder"
239239 depends on X86_64
240− select STACK_VALIDATION
240+ select OBJTOOL
241241 help
242242 This option enables the ORC (Oops Rewind Capability) unwinder for
243243 unwinding kernel stack traces. It uses a custom data format which is
arch/x86/include/asm/jump_label.h+3−3
@@ -20,7 +20,7 @@ · 19 unmodified lines
2020 _ASM_PTR "%c0 + %c1 - .\n\t" \
2121 ".popsection \n\t"
2222
23−#ifdef CONFIG_STACK_VALIDATION
23+#ifdef CONFIG_OBJTOOL
2424
2525 static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
2626 {
@@ -34,7 +34,7 @@ l_yes: · 7 unmodified lines
3434 return true;
3535 }
3636
37−#else
37+#else /* !CONFIG_OBJTOOL */
3838
3939 static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
4040 {
@@ -48,7 +48,7 @@ l_yes: · 7 unmodified lines
4848 return true;
4949 }
5050
51−#endif /* STACK_VALIDATION */
51+#endif /* CONFIG_OBJTOOL */
5252
5353 static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
5454 {
arch/x86/kernel/alternative.c+3−3
@@ -338,7 +338,7 @@ next: · 337 unmodified lines
338338 }
339339 }
340340
341−#if defined(CONFIG_RETPOLINE) && defined(CONFIG_STACK_VALIDATION)
341+#if defined(CONFIG_RETPOLINE) && defined(CONFIG_OBJTOOL)
342342
343343 /*
344344 * CALL/JMP *%\reg
@@ -507,11 +507,11 @@ void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) · 162 unmodified lines
507507 }
508508 }
509509
510−#else /* !RETPOLINES || !CONFIG_STACK_VALIDATION */
510+#else /* !CONFIG_RETPOLINE || !CONFIG_OBJTOOL */
511511
512512 void __init_or_module noinline apply_retpolines(s32 *start, s32 *end) { }
513513
514−#endif /* CONFIG_RETPOLINE && CONFIG_STACK_VALIDATION */
514+#endif /* CONFIG_RETPOLINE && CONFIG_OBJTOOL */
515515
516516 #ifdef CONFIG_X86_KERNEL_IBT
517517
include/linux/compiler.h+3−3
@@ -109,7 +109,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, · 108 unmodified lines
109109 #endif
110110
111111 /* Unreachable code */
112−#ifdef CONFIG_STACK_VALIDATION
112+#ifdef CONFIG_OBJTOOL
113113 /*
114114 * These macros help objtool understand GCC code flow for unreachable code.
115115 * The __COUNTER__ based labels are a hack to make each instance of the macros
@@ -128,10 +128,10 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, · 12 unmodified lines
128128 /* Annotate a C jump table to allow objtool to follow the code flow */
129129 #define __annotate_jump_table __section(".rodata..c_jump_table")
130130
131−#else
131+#else /* !CONFIG_OBJTOOL */
132132 #define annotate_unreachable()
133133 #define __annotate_jump_table
134−#endif
134+#endif /* CONFIG_OBJTOOL */
135135
136136 #ifndef unreachable
137137 # define unreachable() do { \
include/linux/instrumentation.h+3−3
@@ -2,7 +2,7 @@ · 1 unmodified line
22 #ifndef __LINUX_INSTRUMENTATION_H
33 #define __LINUX_INSTRUMENTATION_H
44
5−#if defined(CONFIG_DEBUG_ENTRY) && defined(CONFIG_STACK_VALIDATION)
5+#ifdef CONFIG_VMLINUX_VALIDATION
66
77 #include <linux/stringify.h>
88
@@ -53,9 +53,9 @@ · 44 unmodified lines
5353 ".popsection\n\t" : : "i" (c)); \
5454 })
5555 #define instrumentation_end() __instrumentation_end(__COUNTER__)
56−#else
56+#else /* !CONFIG_VMLINUX_VALIDATION */
5757 # define instrumentation_begin() do { } while(0)
5858 # define instrumentation_end() do { } while(0)
59−#endif
59+#endif /* CONFIG_VMLINUX_VALIDATION */
6060
6161 #endif /* __LINUX_INSTRUMENTATION_H */
include/linux/objtool.h+3−3
@@ -38,7 +38,7 @@ struct unwind_hint { · 37 unmodified lines
3838 #define UNWIND_HINT_TYPE_REGS_PARTIAL 2
3939 #define UNWIND_HINT_TYPE_FUNC 3
4040
41−#ifdef CONFIG_STACK_VALIDATION
41+#ifdef CONFIG_OBJTOOL
4242
4343 #ifndef __ASSEMBLY__
4444
@@ -157,7 +157,7 @@ struct unwind_hint { · 112 unmodified lines
157157
158158 #endif /* __ASSEMBLY__ */
159159
160−#else /* !CONFIG_STACK_VALIDATION */
160+#else /* !CONFIG_OBJTOOL */
161161
162162 #ifndef __ASSEMBLY__
163163
@@ -179,6 +179,6 @@ struct unwind_hint { · 15 unmodified lines
179179 .endm
180180 #endif
181181
182−#endif /* CONFIG_STACK_VALIDATION */
182+#endif /* CONFIG_OBJTOOL */
183183
184184 #endif /* _LINUX_OBJTOOL_H */
kernel/trace/Kconfig+1−0
@@ -728,6 +728,7 @@ config FTRACE_MCOUNT_USE_OBJTOOL · 727 unmodified lines
728728 depends on !FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY
729729 depends on !FTRACE_MCOUNT_USE_CC
730730 depends on FTRACE_MCOUNT_RECORD
731+ select OBJTOOL
731732
732733 config FTRACE_MCOUNT_USE_RECORDMCOUNT
733734 def_bool y
lib/Kconfig.debug+11−9
@@ -485,24 +485,25 @@ config FRAME_POINTER · 484 unmodified lines
485485 larger and slower, but it gives very useful debugging information
486486 in case of kernel bugs. (precise oopses/stacktraces/warnings)
487487
488+config OBJTOOL
489+ bool
490+
488491 config STACK_VALIDATION
489492 bool "Compile-time stack metadata validation"
490− depends on HAVE_STACK_VALIDATION
493+ depends on HAVE_STACK_VALIDATION && UNWINDER_FRAME_POINTER
494+ select OBJTOOL
491495 default n
492496 help
493− Add compile-time checks to validate stack metadata, including frame
494− pointers (if CONFIG_FRAME_POINTER is enabled). This helps ensure
495− that runtime stack traces are more reliable.
496−
497− This is also a prerequisite for generation of ORC unwind data, which
498− is needed for CONFIG_UNWINDER_ORC.
497+ Validate frame pointer rules at compile-time. This helps ensure that
498+ runtime stack traces are more reliable.
499499
500500 For more information, see
501501 tools/objtool/Documentation/stack-validation.txt.
502502
503503 config VMLINUX_VALIDATION
504504 bool
505− depends on STACK_VALIDATION && DEBUG_ENTRY
505+ depends on HAVE_OBJTOOL && DEBUG_ENTRY
506+ select OBJTOOL
506507 default y
507508
508509 config VMLINUX_MAP
@@ -2035,10 +2036,11 @@ config KCOV · 1526 unmodified lines
20352036 bool "Code coverage for fuzzing"
20362037 depends on ARCH_HAS_KCOV
20372038 depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS
2038− depends on !ARCH_WANTS_NO_INSTR || STACK_VALIDATION || \
2039+ depends on !ARCH_WANTS_NO_INSTR || HAVE_OBJTOOL || \
20392040 GCC_VERSION >= 120000 || CLANG_VERSION >= 130000
20402041 select DEBUG_FS
20412042 select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC
2043+ select OBJTOOL if HAVE_OBJTOOL
20422044 help
20432045 KCOV exposes kernel code coverage information in a form suitable
20442046 for coverage-guided fuzzing (randomized testing).
lib/Kconfig.kcsan+2−1
@@ -187,7 +187,8 @@ config KCSAN_WEAK_MEMORY · 186 unmodified lines
187187 # We can either let objtool nop __tsan_func_{entry,exit}() and builtin
188188 # atomics instrumentation in .noinstr.text, or use a compiler that can
189189 # implement __no_kcsan to really remove all instrumentation.
190− depends on STACK_VALIDATION || CC_IS_GCC || CLANG_VERSION >= 140000
190+ depends on HAVE_OBJTOOL || CC_IS_GCC || CLANG_VERSION >= 140000
191+ select OBJTOOL if HAVE_OBJTOOL
191192 help
192193 Enable support for modeling a subset of weak memory, which allows
193194 detecting a subset of data races due to missing memory barriers.
lib/Kconfig.ubsan+1−1
@@ -94,7 +94,7 @@ config UBSAN_UNREACHABLE · 93 unmodified lines
9494 bool "Perform checking for unreachable code"
9595 # objtool already handles unreachable checking and gets angry about
9696 # seeing UBSan instrumentation located in unreachable places.
97− depends on !STACK_VALIDATION
97+ depends on !(OBJTOOL && (STACK_VALIDATION || UNWINDER_ORC || X86_SMAP))
9898 depends on $(cc-option,-fsanitize=unreachable)
9999 help
100100 This option enables -fsanitize=unreachable which checks for control
scripts/Makefile.build+2−2
@@ -222,7 +222,7 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), · 221 unmodified lines
222222 $(sub_cmd_record_mcount))
223223 endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
224224
225−ifdef CONFIG_STACK_VALIDATION
225+ifdef CONFIG_OBJTOOL
226226
227227 objtool := $(objtree)/tools/objtool/objtool
228228
@@ -241,7 +241,7 @@ objtool_args = \ · 12 unmodified lines
241241 cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
242242 cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
243243
244−endif # CONFIG_STACK_VALIDATION
244+endif # CONFIG_OBJTOOL
245245
246246 ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
247247
scripts/link-vmlinux.sh+18−14
@@ -108,8 +108,11 @@ objtool_link() · 107 unmodified lines
108108 local objtoolcmd;
109109 local objtoolopt;
110110
111− if is_enabled CONFIG_STACK_VALIDATION && \
112− ( is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT ); then
111+ if ! is_enabled CONFIG_OBJTOOL; then
112+ return;
113+ fi
114+
115+ if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then
113116
114117 # Don't perform vmlinux validation unless explicitly requested,
115118 # but run objtool on vmlinux.o now that we have an object file.
@@ -126,10 +129,23 @@ objtool_link() · 10 unmodified lines
126129 objtoolopt="${objtoolopt} --orc"
127130 fi
128131
132+ if is_enabled CONFIG_RETPOLINE; then
133+ objtoolopt="${objtoolopt} --retpoline"
134+ fi
135+
136+ if is_enabled CONFIG_SLS; then
137+ objtoolopt="${objtoolopt} --sls"
138+ fi
139+
129140 if is_enabled CONFIG_STACK_VALIDATION; then
130141 objtoolopt="${objtoolopt} --stackval"
131142 fi
132143
144+ if is_enabled CONFIG_X86_SMAP; then
145+ objtoolopt="${objtoolopt} --uaccess"
146+ fi
147+
148+
133149 objtoolopt="${objtoolopt} --lto"
134150 fi
135151
@@ -139,18 +155,6 @@ objtool_link() · 3 unmodified lines
139155
140156 if [ -n "${objtoolopt}" ]; then
141157
142− if is_enabled CONFIG_RETPOLINE; then
143− objtoolopt="${objtoolopt} --retpoline"
144− fi
145−
146− if is_enabled CONFIG_SLS; then
147− objtoolopt="${objtoolopt} --sls"
148− fi
149−
150− if is_enabled CONFIG_X86_SMAP; then
151− objtoolopt="${objtoolopt} --uaccess"
152− fi
153−
154158 if ! is_enabled CONFIG_FRAME_POINTER; then
155159 objtoolopt="${objtoolopt} --no-fp"
156160 fi
scripts/package/builddeb+1−1
@@ -67,7 +67,7 @@ deploy_kernel_headers () { · 66 unmodified lines
6767 ) > debian/hdrsrcfiles
6868
6969 {
70− if is_enabled CONFIG_STACK_VALIDATION; then
70+ if is_enabled CONFIG_OBJTOOL; then
7171 echo tools/objtool/objtool
7272 fi
7373
tools/include/linux/objtool.h+3−3
@@ -38,7 +38,7 @@ struct unwind_hint { · 37 unmodified lines
3838 #define UNWIND_HINT_TYPE_REGS_PARTIAL 2
3939 #define UNWIND_HINT_TYPE_FUNC 3
4040
41−#ifdef CONFIG_STACK_VALIDATION
41+#ifdef CONFIG_OBJTOOL
4242
4343 #ifndef __ASSEMBLY__
4444
@@ -157,7 +157,7 @@ struct unwind_hint { · 112 unmodified lines
157157
158158 #endif /* __ASSEMBLY__ */
159159
160−#else /* !CONFIG_STACK_VALIDATION */
160+#else /* !CONFIG_OBJTOOL */
161161
162162 #ifndef __ASSEMBLY__
163163
@@ -179,6 +179,6 @@ struct unwind_hint { · 15 unmodified lines
179179 .endm
180180 #endif
181181
182−#endif /* CONFIG_STACK_VALIDATION */
182+#endif /* CONFIG_OBJTOOL */
183183
184184 #endif /* _LINUX_OBJTOOL_H */