Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

objtool: Move ANNOTATE* macros to annotate.h

In preparation for using the objtool annotation macros in higher-level
objtool.h macros like UNWIND_HINT, move them to their own file.

Acked-by: Petr Mladek <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

+110 -89
+109
include/linux/annotate.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_ANNOTATE_H 3 + #define _LINUX_ANNOTATE_H 4 + 5 + #include <linux/objtool_types.h> 6 + 7 + #ifdef CONFIG_OBJTOOL 8 + 9 + #ifndef __ASSEMBLY__ 10 + 11 + #define __ASM_ANNOTATE(label, type) \ 12 + ".pushsection .discard.annotate_insn,\"M\",@progbits,8\n\t" \ 13 + ".long " __stringify(label) " - .\n\t" \ 14 + ".long " __stringify(type) "\n\t" \ 15 + ".popsection\n\t" 16 + 17 + #define ASM_ANNOTATE(type) \ 18 + "911:\n\t" \ 19 + __ASM_ANNOTATE(911b, type) 20 + 21 + #else /* __ASSEMBLY__ */ 22 + 23 + .macro ANNOTATE type:req 24 + .Lhere_\@: 25 + .pushsection .discard.annotate_insn,"M",@progbits,8 26 + .long .Lhere_\@ - . 27 + .long \type 28 + .popsection 29 + .endm 30 + 31 + #endif /* __ASSEMBLY__ */ 32 + 33 + #else /* !CONFIG_OBJTOOL */ 34 + #ifndef __ASSEMBLY__ 35 + #define __ASM_ANNOTATE(label, type) "" 36 + #define ASM_ANNOTATE(type) 37 + #else /* __ASSEMBLY__ */ 38 + .macro ANNOTATE type:req 39 + .endm 40 + #endif /* __ASSEMBLY__ */ 41 + #endif /* !CONFIG_OBJTOOL */ 42 + 43 + #ifndef __ASSEMBLY__ 44 + 45 + /* 46 + * Annotate away the various 'relocation to !ENDBR` complaints; knowing that 47 + * these relocations will never be used for indirect calls. 48 + */ 49 + #define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) 50 + #define ANNOTATE_NOENDBR_SYM(sym) asm(__ASM_ANNOTATE(sym, ANNOTYPE_NOENDBR)) 51 + 52 + /* 53 + * This should be used immediately before an indirect jump/call. It tells 54 + * objtool the subsequent indirect jump/call is vouched safe for retpoline 55 + * builds. 56 + */ 57 + #define ANNOTATE_RETPOLINE_SAFE ASM_ANNOTATE(ANNOTYPE_RETPOLINE_SAFE) 58 + /* 59 + * See linux/instrumentation.h 60 + */ 61 + #define ANNOTATE_INSTR_BEGIN(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_BEGIN) 62 + #define ANNOTATE_INSTR_END(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_END) 63 + /* 64 + * objtool annotation to ignore the alternatives and only consider the original 65 + * instruction(s). 66 + */ 67 + #define ANNOTATE_IGNORE_ALTERNATIVE ASM_ANNOTATE(ANNOTYPE_IGNORE_ALTS) 68 + /* 69 + * This macro indicates that the following intra-function call is valid. 70 + * Any non-annotated intra-function call will cause objtool to issue a warning. 71 + */ 72 + #define ANNOTATE_INTRA_FUNCTION_CALL ASM_ANNOTATE(ANNOTYPE_INTRA_FUNCTION_CALL) 73 + /* 74 + * Use objtool to validate the entry requirement that all code paths do 75 + * VALIDATE_UNRET_END before RET. 76 + * 77 + * NOTE: The macro must be used at the beginning of a global symbol, otherwise 78 + * it will be ignored. 79 + */ 80 + #define ANNOTATE_UNRET_BEGIN ASM_ANNOTATE(ANNOTYPE_UNRET_BEGIN) 81 + /* 82 + * This should be used to refer to an instruction that is considered 83 + * terminating, like a noreturn CALL or UD2 when we know they are not -- eg 84 + * WARN using UD2. 85 + */ 86 + #define ANNOTATE_REACHABLE(label) __ASM_ANNOTATE(label, ANNOTYPE_REACHABLE) 87 + /* 88 + * This should not be used; it annotates away CFI violations. There are a few 89 + * valid use cases like kexec handover to the next kernel image, and there is 90 + * no security concern there. 91 + * 92 + * There are also a few real issues annotated away, like EFI because we can't 93 + * control the EFI code. 94 + */ 95 + #define ANNOTATE_NOCFI_SYM(sym) asm(__ASM_ANNOTATE(sym, ANNOTYPE_NOCFI)) 96 + 97 + #else /* __ASSEMBLY__ */ 98 + #define ANNOTATE_NOENDBR ANNOTATE type=ANNOTYPE_NOENDBR 99 + #define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=ANNOTYPE_RETPOLINE_SAFE 100 + /* ANNOTATE_INSTR_BEGIN ANNOTATE type=ANNOTYPE_INSTR_BEGIN */ 101 + /* ANNOTATE_INSTR_END ANNOTATE type=ANNOTYPE_INSTR_END */ 102 + #define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=ANNOTYPE_IGNORE_ALTS 103 + #define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=ANNOTYPE_INTRA_FUNCTION_CALL 104 + #define ANNOTATE_UNRET_BEGIN ANNOTATE type=ANNOTYPE_UNRET_BEGIN 105 + #define ANNOTATE_REACHABLE ANNOTATE type=ANNOTYPE_REACHABLE 106 + #define ANNOTATE_NOCFI_SYM ANNOTATE type=ANNOTYPE_NOCFI 107 + #endif /* __ASSEMBLY__ */ 108 + 109 + #endif /* _LINUX_ANNOTATE_H */
+1 -89
include/linux/objtool.h
··· 3 3 #define _LINUX_OBJTOOL_H 4 4 5 5 #include <linux/objtool_types.h> 6 + #include <linux/annotate.h> 6 7 7 8 #ifdef CONFIG_OBJTOOL 8 - 9 - #include <asm/asm.h> 10 9 11 10 #ifndef __ASSEMBLY__ 12 11 ··· 51 52 ".popsection\n\t" 52 53 53 54 #define __ASM_BREF(label) label ## b 54 - 55 - #define __ASM_ANNOTATE(label, type) \ 56 - ".pushsection .discard.annotate_insn,\"M\",@progbits,8\n\t" \ 57 - ".long " __stringify(label) " - .\n\t" \ 58 - ".long " __stringify(type) "\n\t" \ 59 - ".popsection\n\t" 60 - 61 - #define ASM_ANNOTATE(type) \ 62 - "911:\n\t" \ 63 - __ASM_ANNOTATE(911b, type) 64 55 65 56 #else /* __ASSEMBLY__ */ 66 57 ··· 100 111 #endif 101 112 .endm 102 113 103 - .macro ANNOTATE type:req 104 - .Lhere_\@: 105 - .pushsection .discard.annotate_insn,"M",@progbits,8 106 - .long .Lhere_\@ - . 107 - .long \type 108 - .popsection 109 - .endm 110 - 111 114 #endif /* __ASSEMBLY__ */ 112 115 113 116 #else /* !CONFIG_OBJTOOL */ ··· 109 128 #define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t" 110 129 #define STACK_FRAME_NON_STANDARD(func) 111 130 #define STACK_FRAME_NON_STANDARD_FP(func) 112 - #define __ASM_ANNOTATE(label, type) "" 113 - #define ASM_ANNOTATE(type) 114 131 #else 115 132 .macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=0 116 133 .endm 117 134 .macro STACK_FRAME_NON_STANDARD func:req 118 135 .endm 119 - .macro ANNOTATE type:req 120 - .endm 121 136 #endif 122 137 123 138 #endif /* CONFIG_OBJTOOL */ 124 - 125 - #ifndef __ASSEMBLY__ 126 - /* 127 - * Annotate away the various 'relocation to !ENDBR` complaints; knowing that 128 - * these relocations will never be used for indirect calls. 129 - */ 130 - #define ANNOTATE_NOENDBR ASM_ANNOTATE(ANNOTYPE_NOENDBR) 131 - #define ANNOTATE_NOENDBR_SYM(sym) asm(__ASM_ANNOTATE(sym, ANNOTYPE_NOENDBR)) 132 - 133 - /* 134 - * This should be used immediately before an indirect jump/call. It tells 135 - * objtool the subsequent indirect jump/call is vouched safe for retpoline 136 - * builds. 137 - */ 138 - #define ANNOTATE_RETPOLINE_SAFE ASM_ANNOTATE(ANNOTYPE_RETPOLINE_SAFE) 139 - /* 140 - * See linux/instrumentation.h 141 - */ 142 - #define ANNOTATE_INSTR_BEGIN(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_BEGIN) 143 - #define ANNOTATE_INSTR_END(label) __ASM_ANNOTATE(label, ANNOTYPE_INSTR_END) 144 - /* 145 - * objtool annotation to ignore the alternatives and only consider the original 146 - * instruction(s). 147 - */ 148 - #define ANNOTATE_IGNORE_ALTERNATIVE ASM_ANNOTATE(ANNOTYPE_IGNORE_ALTS) 149 - /* 150 - * This macro indicates that the following intra-function call is valid. 151 - * Any non-annotated intra-function call will cause objtool to issue a warning. 152 - */ 153 - #define ANNOTATE_INTRA_FUNCTION_CALL ASM_ANNOTATE(ANNOTYPE_INTRA_FUNCTION_CALL) 154 - /* 155 - * Use objtool to validate the entry requirement that all code paths do 156 - * VALIDATE_UNRET_END before RET. 157 - * 158 - * NOTE: The macro must be used at the beginning of a global symbol, otherwise 159 - * it will be ignored. 160 - */ 161 - #define ANNOTATE_UNRET_BEGIN ASM_ANNOTATE(ANNOTYPE_UNRET_BEGIN) 162 - /* 163 - * This should be used to refer to an instruction that is considered 164 - * terminating, like a noreturn CALL or UD2 when we know they are not -- eg 165 - * WARN using UD2. 166 - */ 167 - #define ANNOTATE_REACHABLE(label) __ASM_ANNOTATE(label, ANNOTYPE_REACHABLE) 168 - /* 169 - * This should not be used; it annotates away CFI violations. There are a few 170 - * valid use cases like kexec handover to the next kernel image, and there is 171 - * no security concern there. 172 - * 173 - * There are also a few real issues annotated away, like EFI because we can't 174 - * control the EFI code. 175 - */ 176 - #define ANNOTATE_NOCFI_SYM(sym) asm(__ASM_ANNOTATE(sym, ANNOTYPE_NOCFI)) 177 - 178 - #else 179 - #define ANNOTATE_NOENDBR ANNOTATE type=ANNOTYPE_NOENDBR 180 - #define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=ANNOTYPE_RETPOLINE_SAFE 181 - /* ANNOTATE_INSTR_BEGIN ANNOTATE type=ANNOTYPE_INSTR_BEGIN */ 182 - /* ANNOTATE_INSTR_END ANNOTATE type=ANNOTYPE_INSTR_END */ 183 - #define ANNOTATE_IGNORE_ALTERNATIVE ANNOTATE type=ANNOTYPE_IGNORE_ALTS 184 - #define ANNOTATE_INTRA_FUNCTION_CALL ANNOTATE type=ANNOTYPE_INTRA_FUNCTION_CALL 185 - #define ANNOTATE_UNRET_BEGIN ANNOTATE type=ANNOTYPE_UNRET_BEGIN 186 - #define ANNOTATE_REACHABLE ANNOTATE type=ANNOTYPE_REACHABLE 187 - #define ANNOTATE_NOCFI_SYM ANNOTATE type=ANNOTYPE_NOCFI 188 - #endif 189 139 190 140 #if defined(CONFIG_NOINSTR_VALIDATION) && \ 191 141 (defined(CONFIG_MITIGATION_UNRET_ENTRY) || defined(CONFIG_MITIGATION_SRSO))