Skip to content

Commit 9bb2ec6

Browse files
Peter Zijlstrasuryasaimadhu
authored andcommitted
objtool: Update Retpoline validation
Update retpoline validation with the new CONFIG_RETPOLINE requirement of not having bare naked RET instructions. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Borislav Petkov <bp@suse.de>
1 parent bf5835b commit 9bb2ec6

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

arch/x86/include/asm/nospec-branch.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
.popsection
7676
.endm
7777

78+
/*
79+
* (ab)use RETPOLINE_SAFE on RET to annotate away 'bare' RET instructions
80+
* vs RETBleed validation.
81+
*/
82+
#define ANNOTATE_UNRET_SAFE ANNOTATE_RETPOLINE_SAFE
83+
7884
/*
7985
* JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple
8086
* indirect jmp/call which may be susceptible to the Spectre variant 2

arch/x86/mm/mem_encrypt_boot.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ SYM_FUNC_START(sme_encrypt_execute)
6666
pop %rbp
6767

6868
/* Offset to __x86_return_thunk would be wrong here */
69+
ANNOTATE_UNRET_SAFE
6970
ret
7071
int3
7172
SYM_FUNC_END(sme_encrypt_execute)
@@ -154,6 +155,7 @@ SYM_FUNC_START(__enc_copy)
154155
pop %r15
155156

156157
/* Offset to __x86_return_thunk would be wrong here */
158+
ANNOTATE_UNRET_SAFE
157159
ret
158160
int3
159161
.L__enc_copy_end:

arch/x86/xen/xen-head.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SYM_CODE_START(hypercall_page)
2626
.rept (PAGE_SIZE / 32)
2727
UNWIND_HINT_FUNC
2828
ANNOTATE_NOENDBR
29+
ANNOTATE_UNRET_SAFE
2930
ret
3031
/*
3132
* Xen will write the hypercall page, and sort out ENDBR.

tools/objtool/check.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,8 +2115,9 @@ static int read_retpoline_hints(struct objtool_file *file)
21152115
}
21162116

21172117
if (insn->type != INSN_JUMP_DYNAMIC &&
2118-
insn->type != INSN_CALL_DYNAMIC) {
2119-
WARN_FUNC("retpoline_safe hint not an indirect jump/call",
2118+
insn->type != INSN_CALL_DYNAMIC &&
2119+
insn->type != INSN_RETURN) {
2120+
WARN_FUNC("retpoline_safe hint not an indirect jump/call/ret",
21202121
insn->sec, insn->offset);
21212122
return -1;
21222123
}
@@ -3526,7 +3527,8 @@ static int validate_retpoline(struct objtool_file *file)
35263527

35273528
for_each_insn(file, insn) {
35283529
if (insn->type != INSN_JUMP_DYNAMIC &&
3529-
insn->type != INSN_CALL_DYNAMIC)
3530+
insn->type != INSN_CALL_DYNAMIC &&
3531+
insn->type != INSN_RETURN)
35303532
continue;
35313533

35323534
if (insn->retpoline_safe)
@@ -3541,9 +3543,14 @@ static int validate_retpoline(struct objtool_file *file)
35413543
if (!strcmp(insn->sec->name, ".init.text") && !opts.module)
35423544
continue;
35433545

3544-
WARN_FUNC("indirect %s found in RETPOLINE build",
3545-
insn->sec, insn->offset,
3546-
insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call");
3546+
if (insn->type == INSN_RETURN) {
3547+
WARN_FUNC("'naked' return found in RETPOLINE build",
3548+
insn->sec, insn->offset);
3549+
} else {
3550+
WARN_FUNC("indirect %s found in RETPOLINE build",
3551+
insn->sec, insn->offset,
3552+
insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call");
3553+
}
35473554

35483555
warnings++;
35493556
}

0 commit comments

Comments
 (0)