Skip to content

Commit

Permalink
objtool: Allow UNWIND_HINT to suppress dodgy stack modifications
Browse files Browse the repository at this point in the history
rewind_stack_do_exit()
	UNWIND_HINT_FUNC
	/* Prevent any naive code from trying to unwind to our caller. */

	xorl	%ebp, %ebp
	movq	PER_CPU_VAR(cpu_current_top_of_stack), %rax
	leaq	-PTREGS_SIZE(%rax), %rsp
	UNWIND_HINT_REGS

	call	do_exit

Does unspeakable things to the stack, which objtool currently fails to
detect due to a limitation in instruction decoding. This will be
rectified after which the above will result in:

arch/x86/entry/entry_64.o: warning: objtool: .text+0xab: unsupported stack register modification

Allow the UNWIND_HINT on the next instruction to suppress this, it
will overwrite the state anyway.

Suggested-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Tested-by: Nick Desaulniers <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Mar 6, 2021
1 parent a38fd87 commit d54dba4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tools/objtool/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -1959,8 +1959,9 @@ static void restore_reg(struct cfi_state *cfi, unsigned char reg)
* 41 5d pop %r13
* c3 retq
*/
static int update_cfi_state(struct instruction *insn, struct cfi_state *cfi,
struct stack_op *op)
static int update_cfi_state(struct instruction *insn,
struct instruction *next_insn,
struct cfi_state *cfi, struct stack_op *op)
{
struct cfi_reg *cfa = &cfi->cfa;
struct cfi_reg *regs = cfi->regs;
Expand Down Expand Up @@ -2161,7 +2162,7 @@ static int update_cfi_state(struct instruction *insn, struct cfi_state *cfi,
break;
}

if (op->dest.reg == cfi->cfa.base) {
if (op->dest.reg == cfi->cfa.base && !(next_insn && next_insn->hint)) {
WARN_FUNC("unsupported stack register modification",
insn->sec, insn->offset);
return -1;
Expand Down Expand Up @@ -2433,13 +2434,15 @@ static int propagate_alt_cfi(struct objtool_file *file, struct instruction *insn
return 0;
}

static int handle_insn_ops(struct instruction *insn, struct insn_state *state)
static int handle_insn_ops(struct instruction *insn,
struct instruction *next_insn,
struct insn_state *state)
{
struct stack_op *op;

list_for_each_entry(op, &insn->stack_ops, list) {

if (update_cfi_state(insn, &state->cfi, op))
if (update_cfi_state(insn, next_insn, &state->cfi, op))
return 1;

if (op->dest.type == OP_DEST_PUSHF) {
Expand Down Expand Up @@ -2719,7 +2722,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
return 0;
}

if (handle_insn_ops(insn, &state))
if (handle_insn_ops(insn, next_insn, &state))
return 1;

switch (insn->type) {
Expand Down

0 comments on commit d54dba4

Please sign in to comment.