Re: [GIT PULL] x86/asm changes for v5.6
From: Borislav Petkov
Date: Fri Jan 31 2020 - 09:27:38 EST
+ Josh.
On Thu, Jan 30, 2020 at 10:02:54AM -0800, Linus Torvalds wrote:
> Maybe with the exception that a short conditional jump inside the
> alternative code itself is fine.
>
> Because a branch-over inside the alternative sequence (or a loop -
> think inline cmpxchg loop or whatever) would be fine, since it's
> unaffected by code placement.
Perhaps something like the below as a start.
The build becomes really noisy if the error case is hit because aborting
in handle_group_alt() really messes up objtool processing but that is
perhaps ok as the idea is to *see* that something's wrong.
---
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 4768d91c6d68..b4dfd625842d 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -756,7 +771,9 @@ static int handle_group_alt(struct objtool_file *file,
last_new_insn = NULL;
insn = *new_insn;
sec_for_each_insn_from(file, insn) {
- if (insn->offset >= special_alt->new_off + special_alt->new_len)
+ unsigned long new_offset = special_alt->new_off + special_alt->new_len;
+
+ if (insn->offset >= new_offset)
break;
last_new_insn = insn;
@@ -765,8 +787,12 @@ static int handle_group_alt(struct objtool_file *file,
insn->func = orig_insn->func;
if (insn->type != INSN_JUMP_CONDITIONAL &&
- insn->type != INSN_JUMP_UNCONDITIONAL)
+ insn->type != INSN_JUMP_UNCONDITIONAL) {
continue;
+ } else {
+ if (insn->offset > 0 && insn->offset + insn->len < new_offset)
+ ERROR("Subsequent JMP instructions are not alternatives-patched. Stopping.");
+ }
if (!insn->immediate)
continue;
diff --git a/tools/objtool/warn.h b/tools/objtool/warn.h
index cbb0a02b7480..652c7adc7650 100644
--- a/tools/objtool/warn.h
+++ b/tools/objtool/warn.h
@@ -40,6 +40,14 @@ static inline char *offstr(struct section *sec, unsigned long offset)
return str;
}
+#define ERROR(format, ...) \
+({ \
+ fprintf(stderr, \
+ "%s: error: objtool: " format "\n", \
+ objname, ##__VA_ARGS__); \
+ abort(); \
+})
+
#define WARN(format, ...) \
fprintf(stderr, \
"%s: warning: objtool: " format "\n", \
--
Regards/Gruss,
Boris.
SUSE Software Solutions Germany GmbH, GF: Felix ImendÃrffer, HRB 36809, AG NÃrnberg