提交 3690914e 编写于 作者: P Peter Zijlstra 提交者: Zheng Zengkai

objtool: Extract elf_symbol_add()

stable inclusion
from stable-v5.10.133
commit b69e1b4b689faa1af25a0a76cd1ef8c612770608
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=b69e1b4b689faa1af25a0a76cd1ef8c612770608

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

commit 9a7827b7 upstream.

Create a common helper to add symbols.
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: NBorislav Petkov <bp@suse.de>
Signed-off-by: NIngo Molnar <mingo@kernel.org>
Reviewed-by: NMiroslav Benes <mbenes@suse.cz>
Link: https://lkml.kernel.org/r/20210326151300.003468981@infradead.org
[bwh: Backported to 5.10: rb_add() parameter order is different]
Signed-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>
上级 2988ebf0
...@@ -341,12 +341,39 @@ static int read_sections(struct elf *elf) ...@@ -341,12 +341,39 @@ static int read_sections(struct elf *elf)
return 0; return 0;
} }
static void elf_add_symbol(struct elf *elf, struct symbol *sym)
{
struct list_head *entry;
struct rb_node *pnode;
sym->type = GELF_ST_TYPE(sym->sym.st_info);
sym->bind = GELF_ST_BIND(sym->sym.st_info);
sym->offset = sym->sym.st_value;
sym->len = sym->sym.st_size;
rb_add(&sym->sec->symbol_tree, &sym->node, symbol_to_offset);
pnode = rb_prev(&sym->node);
if (pnode)
entry = &rb_entry(pnode, struct symbol, node)->list;
else
entry = &sym->sec->symbol_list;
list_add(&sym->list, entry);
elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx);
elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
/*
* Don't store empty STT_NOTYPE symbols in the rbtree. They
* can exist within a function, confusing the sorting.
*/
if (!sym->len)
rb_erase(&sym->node, &sym->sec->symbol_tree);
}
static int read_symbols(struct elf *elf) static int read_symbols(struct elf *elf)
{ {
struct section *symtab, *symtab_shndx, *sec; struct section *symtab, *symtab_shndx, *sec;
struct symbol *sym, *pfunc; struct symbol *sym, *pfunc;
struct list_head *entry;
struct rb_node *pnode;
int symbols_nr, i; int symbols_nr, i;
char *coldstr; char *coldstr;
Elf_Data *shndx_data = NULL; Elf_Data *shndx_data = NULL;
...@@ -391,9 +418,6 @@ static int read_symbols(struct elf *elf) ...@@ -391,9 +418,6 @@ static int read_symbols(struct elf *elf)
goto err; goto err;
} }
sym->type = GELF_ST_TYPE(sym->sym.st_info);
sym->bind = GELF_ST_BIND(sym->sym.st_info);
if ((sym->sym.st_shndx > SHN_UNDEF && if ((sym->sym.st_shndx > SHN_UNDEF &&
sym->sym.st_shndx < SHN_LORESERVE) || sym->sym.st_shndx < SHN_LORESERVE) ||
(shndx_data && sym->sym.st_shndx == SHN_XINDEX)) { (shndx_data && sym->sym.st_shndx == SHN_XINDEX)) {
...@@ -406,32 +430,14 @@ static int read_symbols(struct elf *elf) ...@@ -406,32 +430,14 @@ static int read_symbols(struct elf *elf)
sym->name); sym->name);
goto err; goto err;
} }
if (sym->type == STT_SECTION) { if (GELF_ST_TYPE(sym->sym.st_info) == STT_SECTION) {
sym->name = sym->sec->name; sym->name = sym->sec->name;
sym->sec->sym = sym; sym->sec->sym = sym;
} }
} else } else
sym->sec = find_section_by_index(elf, 0); sym->sec = find_section_by_index(elf, 0);
sym->offset = sym->sym.st_value; elf_add_symbol(elf, sym);
sym->len = sym->sym.st_size;
rb_add(&sym->sec->symbol_tree, &sym->node, symbol_to_offset);
pnode = rb_prev(&sym->node);
if (pnode)
entry = &rb_entry(pnode, struct symbol, node)->list;
else
entry = &sym->sec->symbol_list;
list_add(&sym->list, entry);
elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx);
elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
/*
* Don't store empty STT_NOTYPE symbols in the rbtree. They
* can exist within a function, confusing the sorting.
*/
if (!sym->len)
rb_erase(&sym->node, &sym->sec->symbol_tree);
} }
if (stats) if (stats)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册