]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
objtool: Explicitly avoid self modifying code in .altinstr_replacement
authorPeter Zijlstra <peterz@infradead.org>
Tue, 26 Oct 2021 12:01:34 +0000 (14:01 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 28 Oct 2021 21:25:25 +0000 (23:25 +0200)
Assume ALTERNATIVE()s know what they're doing and do not change, or
cause to change, instructions in .altinstr_replacement sections.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Borislav Petkov <bp@suse.de>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Tested-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/r/20211026120309.722511775@infradead.org
tools/objtool/check.c

index fdbc6d2c5597102519b2cb989b87b23f0e83627c..8ab6f24f875396d87de4b82c74fe6a825bf2839f 100644 (file)
@@ -993,18 +993,27 @@ static void remove_insn_ops(struct instruction *insn)
        }
 }
 
-static void add_call_dest(struct objtool_file *file, struct instruction *insn,
-                         struct symbol *dest, bool sibling)
+static void annotate_call_site(struct objtool_file *file,
+                              struct instruction *insn, bool sibling)
 {
        struct reloc *reloc = insn_reloc(file, insn);
+       struct symbol *sym = insn->call_dest;
 
-       insn->call_dest = dest;
-       if (!dest)
+       if (!sym)
+               sym = reloc->sym;
+
+       /*
+        * Alternative replacement code is just template code which is
+        * sometimes copied to the original instruction. For now, don't
+        * annotate it. (In the future we might consider annotating the
+        * original instruction if/when it ever makes sense to do so.)
+        */
+       if (!strcmp(insn->sec->name, ".altinstr_replacement"))
                return;
 
-       if (insn->call_dest->static_call_tramp) {
-               list_add_tail(&insn->call_node,
-                             &file->static_call_list);
+       if (sym->static_call_tramp) {
+               list_add_tail(&insn->call_node, &file->static_call_list);
+               return;
        }
 
        /*
@@ -1012,7 +1021,7 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
         * so they need a little help, NOP out any KCOV calls from noinstr
         * text.
         */
-       if (insn->sec->noinstr && insn->call_dest->kcov) {
+       if (insn->sec->noinstr && sym->kcov) {
                if (reloc) {
                        reloc->type = R_NONE;
                        elf_write_reloc(file->elf, reloc);
@@ -1024,9 +1033,10 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
                                       : arch_nop_insn(insn->len));
 
                insn->type = sibling ? INSN_RETURN : INSN_NOP;
+               return;
        }
 
-       if (mcount && insn->call_dest->fentry) {
+       if (mcount && sym->fentry) {
                if (sibling)
                        WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
 
@@ -1041,9 +1051,17 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
 
                insn->type = INSN_NOP;
 
-               list_add_tail(&insn->mcount_loc_node,
-                             &file->mcount_loc_list);
+               list_add_tail(&insn->mcount_loc_node, &file->mcount_loc_list);
+               return;
        }
+}
+
+static void add_call_dest(struct objtool_file *file, struct instruction *insn,
+                         struct symbol *dest, bool sibling)
+{
+       insn->call_dest = dest;
+       if (!dest)
+               return;
 
        /*
         * Whatever stack impact regular CALLs have, should be undone
@@ -1053,6 +1071,8 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
         * are converted to JUMP, see read_intra_function_calls().
         */
        remove_insn_ops(insn);
+
+       annotate_call_site(file, insn, sibling);
 }
 
 /*