Skip to content

Commit 03f16cd

Browse files
jpoimboePeter Zijlstra
authored andcommitted
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. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Link: https://lkml.kernel.org/r/939bf3d85604b2a126412bf11af6e3bd3b872bcb.1650300597.git.jpoimboe@redhat.com
1 parent c2bdd61 commit 03f16cd

File tree

17 files changed

+73
-57
lines changed

17 files changed

+73
-57
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ install: sub_make_done :=
13021302
# ---------------------------------------------------------------------------
13031303
# Tools
13041304

1305-
ifdef CONFIG_STACK_VALIDATION
1305+
ifdef CONFIG_OBJTOOL
13061306
prepare: tools/objtool
13071307
endif
13081308

arch/Kconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,11 +1028,14 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
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
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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ config X86
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
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
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
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
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
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
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
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ choice
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
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 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
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 @@ static __always_inline bool arch_static_branch(struct static_key * const key, co
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
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)
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
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,
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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 @@
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct unwind_hint {
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 {
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 {
179179
.endm
180180
#endif
181181

182-
#endif /* CONFIG_STACK_VALIDATION */
182+
#endif /* CONFIG_OBJTOOL */
183183

184184
#endif /* _LINUX_OBJTOOL_H */

kernel/trace/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ config FTRACE_MCOUNT_USE_OBJTOOL
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

0 commit comments

Comments
 (0)