objtool: Update Retpoline validation

commit 9bb2ec608a209018080ca262f771e6a9ff203b6f upstream.

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>
[cascardo: conflict fixup at arch/x86/xen/xen-head.S]
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Peter Zijlstra
2022-06-14 23:15:59 +02:00
committed by Greg Kroah-Hartman
parent 55bba093fd
commit 28aa3fa0b2
4 changed files with 22 additions and 6 deletions

View File

@@ -75,6 +75,12 @@
.popsection .popsection
.endm .endm
/*
* (ab)use RETPOLINE_SAFE on RET to annotate away 'bare' RET instructions
* vs RETBleed validation.
*/
#define ANNOTATE_UNRET_SAFE ANNOTATE_RETPOLINE_SAFE
/* /*
* JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple * JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple
* indirect jmp/call which may be susceptible to the Spectre variant 2 * indirect jmp/call which may be susceptible to the Spectre variant 2

View File

@@ -66,6 +66,7 @@ SYM_FUNC_START(sme_encrypt_execute)
pop %rbp pop %rbp
/* Offset to __x86_return_thunk would be wrong here */ /* Offset to __x86_return_thunk would be wrong here */
ANNOTATE_UNRET_SAFE
ret ret
int3 int3
SYM_FUNC_END(sme_encrypt_execute) SYM_FUNC_END(sme_encrypt_execute)
@@ -154,6 +155,7 @@ SYM_FUNC_START(__enc_copy)
pop %r15 pop %r15
/* Offset to __x86_return_thunk would be wrong here */ /* Offset to __x86_return_thunk would be wrong here */
ANNOTATE_UNRET_SAFE
ret ret
int3 int3
.L__enc_copy_end: .L__enc_copy_end:

View File

@@ -70,6 +70,7 @@ SYM_CODE_START(hypercall_page)
.rept (PAGE_SIZE / 32) .rept (PAGE_SIZE / 32)
UNWIND_HINT_FUNC UNWIND_HINT_FUNC
.skip 31, 0x90 .skip 31, 0x90
ANNOTATE_UNRET_SAFE
RET RET
.endr .endr

View File

@@ -1799,8 +1799,9 @@ static int read_retpoline_hints(struct objtool_file *file)
} }
if (insn->type != INSN_JUMP_DYNAMIC && if (insn->type != INSN_JUMP_DYNAMIC &&
insn->type != INSN_CALL_DYNAMIC) { insn->type != INSN_CALL_DYNAMIC &&
WARN_FUNC("retpoline_safe hint not an indirect jump/call", insn->type != INSN_RETURN) {
WARN_FUNC("retpoline_safe hint not an indirect jump/call/ret",
insn->sec, insn->offset); insn->sec, insn->offset);
return -1; return -1;
} }
@@ -3051,7 +3052,8 @@ static int validate_retpoline(struct objtool_file *file)
for_each_insn(file, insn) { for_each_insn(file, insn) {
if (insn->type != INSN_JUMP_DYNAMIC && if (insn->type != INSN_JUMP_DYNAMIC &&
insn->type != INSN_CALL_DYNAMIC) insn->type != INSN_CALL_DYNAMIC &&
insn->type != INSN_RETURN)
continue; continue;
if (insn->retpoline_safe) if (insn->retpoline_safe)
@@ -3066,9 +3068,14 @@ static int validate_retpoline(struct objtool_file *file)
if (!strcmp(insn->sec->name, ".init.text") && !module) if (!strcmp(insn->sec->name, ".init.text") && !module)
continue; continue;
WARN_FUNC("indirect %s found in RETPOLINE build", if (insn->type == INSN_RETURN) {
insn->sec, insn->offset, WARN_FUNC("'naked' return found in RETPOLINE build",
insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call"); insn->sec, insn->offset);
} else {
WARN_FUNC("indirect %s found in RETPOLINE build",
insn->sec, insn->offset,
insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call");
}
warnings++; warnings++;
} }