Skip to content

Commit 7631376

Browse files
jpoimboegregkh
authored andcommitted
objtool: Fix retpoline detection in asm code
[ Upstream commit 1f9a1b7 ] 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: 39b7353 ("objtool: Detect jumps to retpoline thunks") Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Link: https://lore.kernel.org/r/31f5833e2e4f01e3d755889ac77e3661e906c09f.1611263461.git.jpoimboe@redhat.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9e06f36 commit 7631376

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎tools/objtool/arch/x86/special.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool arch_support_alt_relocation(struct special_alt *special_alt,
4848
* replacement group.
4949
*/
5050
return insn->offset == special_alt->new_off &&
51-
(insn->type == INSN_CALL || is_static_jump(insn));
51+
(insn->type == INSN_CALL || is_jump(insn));
5252
}
5353

5454
/*

‎tools/objtool/check.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ static int add_jump_destinations(struct objtool_file *file)
789789
dest_sec = reloc->sym->sec;
790790
dest_off = reloc->sym->sym.st_value +
791791
arch_dest_reloc_offset(reloc->addend);
792-
} else if (strstr(reloc->sym->name, "_indirect_thunk_")) {
792+
} else if (!strncmp(reloc->sym->name, "__x86_indirect_thunk_", 21) ||
793+
!strncmp(reloc->sym->name, "__x86_retpoline_", 16)) {
793794
/*
794795
* Retpoline jumps are really dynamic jumps in
795796
* disguise, so convert them accordingly.

‎tools/objtool/check.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ static inline bool is_static_jump(struct instruction *insn)
5454
insn->type == INSN_JUMP_UNCONDITIONAL;
5555
}
5656

57+
static inline bool is_dynamic_jump(struct instruction *insn)
58+
{
59+
return insn->type == INSN_JUMP_DYNAMIC ||
60+
insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL;
61+
}
62+
63+
static inline bool is_jump(struct instruction *insn)
64+
{
65+
return is_static_jump(insn) || is_dynamic_jump(insn);
66+
}
67+
5768
struct instruction *find_insn(struct objtool_file *file,
5869
struct section *sec, unsigned long offset);
5970

0 commit comments

Comments
 (0)