提交 88af262c 编写于 作者: P Peter Zijlstra 提交者: Zheng Zengkai

objtool: Fix .symtab_shndx handling for elf_create_undef_symbol()

stable inclusion
from stable-v5.10.133
commit a0319253825ebd8c5b19e31902c4f35f85e93285
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5PTAS
CVE: CVE-2022-29900,CVE-2022-23816,CVE-2022-29901

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a0319253825ebd8c5b19e31902c4f35f85e93285

--------------------------------

commit 584fd3b3 upstream.

When an ELF object uses extended symbol section indexes (IOW it has a
.symtab_shndx section), these must be kept in sync with the regular
symbol table (.symtab).

So for every new symbol we emit, make sure to also emit a
.symtab_shndx value to keep the arrays of equal size.

Note: since we're writing an UNDEF symbol, most GElf_Sym fields will
be 0 and we can repurpose one (st_size) to host the 0 for the xshndx
value.

Fixes: 2f2f7e47 ("objtool: Add elf_create_undef_symbol()")
Reported-by: NNick Desaulniers <ndesaulniers@google.com>
Suggested-by: NFangrui Song <maskray@google.com>
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: NNick Desaulniers <ndesaulniers@google.com>
Link: https://lkml.kernel.org/r/YL3q1qFO9QIRL/BA@hirez.programming.kicks-ass.netSigned-off-by: NBen Hutchings <ben@decadent.org.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NLin Yujun <linyujun809@huawei.com>
Reviewed-by: NZhang Jianhua <chris.zjh@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 0ead9b45
...@@ -768,7 +768,7 @@ static int elf_add_string(struct elf *elf, struct section *strtab, char *str) ...@@ -768,7 +768,7 @@ static int elf_add_string(struct elf *elf, struct section *strtab, char *str)
struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name) struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
{ {
struct section *symtab; struct section *symtab, *symtab_shndx;
struct symbol *sym; struct symbol *sym;
Elf_Data *data; Elf_Data *data;
Elf_Scn *s; Elf_Scn *s;
...@@ -819,6 +819,29 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name) ...@@ -819,6 +819,29 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
symtab->len += data->d_size; symtab->len += data->d_size;
symtab->changed = true; symtab->changed = true;
symtab_shndx = find_section_by_name(elf, ".symtab_shndx");
if (symtab_shndx) {
s = elf_getscn(elf->elf, symtab_shndx->idx);
if (!s) {
WARN_ELF("elf_getscn");
return NULL;
}
data = elf_newdata(s);
if (!data) {
WARN_ELF("elf_newdata");
return NULL;
}
data->d_buf = &sym->sym.st_size; /* conveniently 0 */
data->d_size = sizeof(Elf32_Word);
data->d_align = 4;
data->d_type = ELF_T_WORD;
symtab_shndx->len += 4;
symtab_shndx->changed = true;
}
sym->sec = find_section_by_index(elf, 0); sym->sec = find_section_by_index(elf, 0);
elf_add_symbol(elf, sym); elf_add_symbol(elf, sym);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册