Commit a845c7cf authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Ingo Molnar

objtool: Improve retpoline alternative handling

Currently objtool requires all retpolines to be:

  a) patched in with alternatives; and

  b) annotated with ANNOTATE_NOSPEC_ALTERNATIVE.

If you forget to do both of the above, objtool segfaults trying to
dereference a NULL 'insn->call_dest' pointer.

Avoid that situation and print a more helpful error message:

  quirks.o: warning: objtool: efi_delete_dummy_variable()+0x99: unsupported intra-function call
  quirks.o: warning: objtool: If this is a retpoline, please patch it in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE.

Future improvements can be made to make objtool smarter with respect to
retpolines, but this is a good incremental improvement for now.
Reported-and-tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/819e50b6d9c2e1a22e34c1a636c0b2057cc8c6e5.1517284349.git.jpoimboe@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 7e86548e
...@@ -543,18 +543,14 @@ static int add_call_destinations(struct objtool_file *file) ...@@ -543,18 +543,14 @@ static int add_call_destinations(struct objtool_file *file)
dest_off = insn->offset + insn->len + insn->immediate; dest_off = insn->offset + insn->len + insn->immediate;
insn->call_dest = find_symbol_by_offset(insn->sec, insn->call_dest = find_symbol_by_offset(insn->sec,
dest_off); dest_off);
/*
* FIXME: Thanks to retpolines, it's now considered if (!insn->call_dest && !insn->ignore) {
* normal for a function to call within itself. So WARN_FUNC("unsupported intra-function call",
* disable this warning for now. insn->sec, insn->offset);
*/ WARN("If this is a retpoline, please patch it in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE.");
#if 0
if (!insn->call_dest) {
WARN_FUNC("can't find call dest symbol at offset 0x%lx",
insn->sec, insn->offset, dest_off);
return -1; return -1;
} }
#endif
} else if (rela->sym->type == STT_SECTION) { } else if (rela->sym->type == STT_SECTION) {
insn->call_dest = find_symbol_by_offset(rela->sym->sec, insn->call_dest = find_symbol_by_offset(rela->sym->sec,
rela->addend+4); rela->addend+4);
...@@ -648,6 +644,8 @@ static int handle_group_alt(struct objtool_file *file, ...@@ -648,6 +644,8 @@ static int handle_group_alt(struct objtool_file *file,
last_new_insn = insn; last_new_insn = insn;
insn->ignore = orig_insn->ignore_alts;
if (insn->type != INSN_JUMP_CONDITIONAL && if (insn->type != INSN_JUMP_CONDITIONAL &&
insn->type != INSN_JUMP_UNCONDITIONAL) insn->type != INSN_JUMP_UNCONDITIONAL)
continue; continue;
...@@ -729,10 +727,6 @@ static int add_special_section_alts(struct objtool_file *file) ...@@ -729,10 +727,6 @@ static int add_special_section_alts(struct objtool_file *file)
goto out; goto out;
} }
/* Ignore retpoline alternatives. */
if (orig_insn->ignore_alts)
continue;
new_insn = NULL; new_insn = NULL;
if (!special_alt->group || special_alt->new_len) { if (!special_alt->group || special_alt->new_len) {
new_insn = find_insn(file, special_alt->new_sec, new_insn = find_insn(file, special_alt->new_sec,
...@@ -1089,11 +1083,11 @@ static int decode_sections(struct objtool_file *file) ...@@ -1089,11 +1083,11 @@ static int decode_sections(struct objtool_file *file)
if (ret) if (ret)
return ret; return ret;
ret = add_call_destinations(file); ret = add_special_section_alts(file);
if (ret) if (ret)
return ret; return ret;
ret = add_special_section_alts(file); ret = add_call_destinations(file);
if (ret) if (ret)
return ret; return ret;
...@@ -1720,10 +1714,12 @@ static int validate_branch(struct objtool_file *file, struct instruction *first, ...@@ -1720,10 +1714,12 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
insn->visited = true; insn->visited = true;
list_for_each_entry(alt, &insn->alts, list) { if (!insn->ignore_alts) {
ret = validate_branch(file, alt->insn, state); list_for_each_entry(alt, &insn->alts, list) {
if (ret) ret = validate_branch(file, alt->insn, state);
return 1; if (ret)
return 1;
}
} }
switch (insn->type) { switch (insn->type) {
......
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