Skip to content

Commit 2dbbca9

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool, xen: Fix INSN_SYSCALL / INSN_SYSRET semantics
Objtool uses an arbitrary rule for INSN_SYSCALL and INSN_SYSRET that almost works by accident: if it's in a function, control flow continues after the instruction, otherwise it terminates. That behavior should instead be based on the semantics of the underlying instruction. Change INSN_SYSCALL to always preserve control flow and INSN_SYSRET to always terminate it. The changed semantic for INSN_SYSCALL requires a tweak to the !CONFIG_IA32_EMULATION version of xen_entry_SYSCALL_compat(). In Xen, SYSCALL is a hypercall which usually returns. But in this case it's a hypercall to IRET which doesn't return. Add UD2 to tell objtool to terminate control flow, and to prevent undefined behavior at runtime. Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Juergen Gross <jgross@suse.com> # for the Xen part Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/r/19453dfe9a0431b7f016e9dc16d031cad3812a50.1744095216.git.jpoimboe@kernel.org
1 parent 9f9cc01 commit 2dbbca9

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

arch/x86/xen/xen-asm.S

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ SYM_CODE_END(xen_early_idt_handler_array)
226226
push %rax
227227
mov $__HYPERVISOR_iret, %eax
228228
syscall /* Do the IRET. */
229-
#ifdef CONFIG_MITIGATION_SLS
230-
int3
231-
#endif
229+
ud2 /* The SYSCALL should never return. */
232230
.endm
233231

234232
SYM_CODE_START(xen_iret)

tools/objtool/check.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,14 +3685,19 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
36853685
break;
36863686

36873687
case INSN_SYSCALL:
3688+
if (func && (!next_insn || !next_insn->hint)) {
3689+
WARN_INSN(insn, "unsupported instruction in callable function");
3690+
return 1;
3691+
}
3692+
3693+
break;
3694+
36883695
case INSN_SYSRET:
3689-
if (func) {
3690-
if (!next_insn || !next_insn->hint) {
3691-
WARN_INSN(insn, "unsupported instruction in callable function");
3692-
return 1;
3693-
}
3694-
break;
3696+
if (func && (!next_insn || !next_insn->hint)) {
3697+
WARN_INSN(insn, "unsupported instruction in callable function");
3698+
return 1;
36953699
}
3700+
36963701
return 0;
36973702

36983703
case INSN_STAC:
@@ -3888,9 +3893,9 @@ static int validate_unret(struct objtool_file *file, struct instruction *insn)
38883893
return 1;
38893894

38903895
case INSN_SYSCALL:
3896+
break;
3897+
38913898
case INSN_SYSRET:
3892-
if (insn_func(insn))
3893-
break;
38943899
return 0;
38953900

38963901
case INSN_NOP:

0 commit comments

Comments
 (0)