Skip to content

Commit 768895f

Browse files
committed
Merge tag 'objtool-urgent-2021-06-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull objtool fixes from Ingo Molnar: "Two objtool fixes: - fix a bug that corrupts the code by mistakenly rewriting conditional jumps - fix another bug generating an incorrect ELF symbol table during retpoline rewriting" * tag 'objtool-urgent-2021-06-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: objtool: Only rewrite unconditional retpoline thunk calls objtool: Fix .symtab_shndx handling for elf_create_undef_symbol()
2 parents ad347ab + 2d49b72 commit 768895f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

tools/objtool/arch/x86/decode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ int arch_rewrite_retpolines(struct objtool_file *file)
747747

748748
list_for_each_entry(insn, &file->retpoline_call_list, call_node) {
749749

750+
if (insn->type != INSN_JUMP_DYNAMIC &&
751+
insn->type != INSN_CALL_DYNAMIC)
752+
continue;
753+
750754
if (!strcmp(insn->sec->name, ".text.__x86.indirect_thunk"))
751755
continue;
752756

tools/objtool/elf.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ static int elf_add_string(struct elf *elf, struct section *strtab, char *str)
717717

718718
struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
719719
{
720-
struct section *symtab;
720+
struct section *symtab, *symtab_shndx;
721721
struct symbol *sym;
722722
Elf_Data *data;
723723
Elf_Scn *s;
@@ -769,6 +769,29 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
769769
symtab->len += data->d_size;
770770
symtab->changed = true;
771771

772+
symtab_shndx = find_section_by_name(elf, ".symtab_shndx");
773+
if (symtab_shndx) {
774+
s = elf_getscn(elf->elf, symtab_shndx->idx);
775+
if (!s) {
776+
WARN_ELF("elf_getscn");
777+
return NULL;
778+
}
779+
780+
data = elf_newdata(s);
781+
if (!data) {
782+
WARN_ELF("elf_newdata");
783+
return NULL;
784+
}
785+
786+
data->d_buf = &sym->sym.st_size; /* conveniently 0 */
787+
data->d_size = sizeof(Elf32_Word);
788+
data->d_align = 4;
789+
data->d_type = ELF_T_WORD;
790+
791+
symtab_shndx->len += 4;
792+
symtab_shndx->changed = true;
793+
}
794+
772795
sym->sec = find_section_by_index(elf, 0);
773796

774797
elf_add_symbol(elf, sym);

0 commit comments

Comments
 (0)