Since variable sized jump_label support is somewhat 'inspired', ensure
objtool validates the tricky bits. Specifically it is important that
the displacement for the 2 byte jump is limited to a single byte --
since this is the hardest part of the whole scheme and relies on
somewhat dodgy GAS tricks.

Signed-off-by: Peter Zijlstra (Intel) <pet...@infradead.org>
Cc: Josh Poimboeuf <jpoim...@redhat.com>
Cc: "H.J. Lu" <hjl.to...@gmail.com>
---
 tools/objtool/check.c |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -817,8 +817,32 @@ static int handle_jump_alt(struct objtoo
                           struct instruction *orig_insn,
                           struct instruction **new_insn)
 {
-       if (orig_insn->type == INSN_NOP)
+       if ((orig_insn->len != 2) && (orig_insn->len != 5)) {
+               WARN_FUNC("jump_label: unsupported INSN length: %d",
+                               orig_insn->sec, orig_insn->offset, 
orig_insn->len);
+               return -1;
+       }
+
+       if (orig_insn->type == INSN_NOP) {
+               long disp;
+
+               if (orig_insn->len == 2) {
+                       if (special_alt->orig_sec != special_alt->new_sec) {
+                               WARN_FUNC("jump_label: JMP8 crossing sections",
+                                               orig_insn->sec, 
orig_insn->offset);
+                               return -1;
+                       }
+
+                       disp = special_alt->new_off - (special_alt->orig_off + 
2);
+                       if ((disp >> 31) != (disp >> 7)) {
+                               WARN_FUNC("jump_label: JMP8 displacement not a 
byte",
+                                               orig_insn->sec, 
orig_insn->offset);
+                               return -1;
+                       }
+               }
+
                return 0;
+       }
 
        if (orig_insn->type != INSN_JUMP_UNCONDITIONAL) {
                WARN_FUNC("unsupported instruction at jump label",


Reply via email to