Commit 1f9a1b74 authored by Josh Poimboeuf's avatar Josh Poimboeuf

objtool: Fix retpoline detection in asm code

The JMP_NOSPEC macro branches to __x86_retpoline_*() rather than the
__x86_indirect_thunk_*() wrappers used by C code.  Detect jumps to
__x86_retpoline_*() as retpoline dynamic jumps.

Presumably this doesn't trigger a user-visible bug.  I only found it
when testing vmlinux.o validation.

Fixes: 39b73533 ("objtool: Detect jumps to retpoline thunks")
Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/31f5833e2e4f01e3d755889ac77e3661e906c09f.1611263461.git.jpoimboe@redhat.com
parent 6f567c93
...@@ -48,7 +48,7 @@ bool arch_support_alt_relocation(struct special_alt *special_alt, ...@@ -48,7 +48,7 @@ bool arch_support_alt_relocation(struct special_alt *special_alt,
* replacement group. * replacement group.
*/ */
return insn->offset == special_alt->new_off && return insn->offset == special_alt->new_off &&
(insn->type == INSN_CALL || is_static_jump(insn)); (insn->type == INSN_CALL || is_jump(insn));
} }
/* /*
......
...@@ -785,7 +785,8 @@ static int add_jump_destinations(struct objtool_file *file) ...@@ -785,7 +785,8 @@ static int add_jump_destinations(struct objtool_file *file)
dest_sec = reloc->sym->sec; dest_sec = reloc->sym->sec;
dest_off = reloc->sym->sym.st_value + dest_off = reloc->sym->sym.st_value +
arch_dest_reloc_offset(reloc->addend); arch_dest_reloc_offset(reloc->addend);
} else if (strstr(reloc->sym->name, "_indirect_thunk_")) { } else if (!strncmp(reloc->sym->name, "__x86_indirect_thunk_", 21) ||
!strncmp(reloc->sym->name, "__x86_retpoline_", 16)) {
/* /*
* Retpoline jumps are really dynamic jumps in * Retpoline jumps are really dynamic jumps in
* disguise, so convert them accordingly. * disguise, so convert them accordingly.
......
...@@ -68,6 +68,17 @@ static inline bool is_static_jump(struct instruction *insn) ...@@ -68,6 +68,17 @@ static inline bool is_static_jump(struct instruction *insn)
insn->type == INSN_JUMP_UNCONDITIONAL; insn->type == INSN_JUMP_UNCONDITIONAL;
} }
static inline bool is_dynamic_jump(struct instruction *insn)
{
return insn->type == INSN_JUMP_DYNAMIC ||
insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL;
}
static inline bool is_jump(struct instruction *insn)
{
return is_static_jump(insn) || is_dynamic_jump(insn);
}
struct instruction *find_insn(struct objtool_file *file, struct instruction *find_insn(struct objtool_file *file,
struct section *sec, unsigned long offset); struct section *sec, unsigned long offset);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment