diff options
| author | Andrii Nakryiko <[email protected]> | 2021-11-24 00:23:18 +0000 |
|---|---|---|
| committer | Daniel Borkmann <[email protected]> | 2021-11-25 23:15:03 +0000 |
| commit | 593835377f24ca1bb98008ec1dc3baefe491ad6e (patch) | |
| tree | fa57f0773226c642232f84063ffc07d93250cf94 /tools/lib/bpf/linker.c | |
| parent | libbpf: Fix glob_syms memory leak in bpf_linker (diff) | |
| download | kernel-593835377f24ca1bb98008ec1dc3baefe491ad6e.tar.gz kernel-593835377f24ca1bb98008ec1dc3baefe491ad6e.zip | |
libbpf: Fix using invalidated memory in bpf_linker
add_dst_sec() can invalidate bpf_linker's section index making
dst_symtab pointer pointing into unallocated memory. Reinitialize
dst_symtab pointer on each iteration to make sure it's always valid.
Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
Signed-off-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/lib/bpf/linker.c')
| -rw-r--r-- | tools/lib/bpf/linker.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 3e1b2a15fdc7..9aa016fb55aa 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -2000,7 +2000,7 @@ add_sym: static int linker_append_elf_relos(struct bpf_linker *linker, struct src_obj *obj) { struct src_sec *src_symtab = &obj->secs[obj->symtab_sec_idx]; - struct dst_sec *dst_symtab = &linker->secs[linker->symtab_sec_idx]; + struct dst_sec *dst_symtab; int i, err; for (i = 1; i < obj->sec_cnt; i++) { @@ -2033,6 +2033,9 @@ static int linker_append_elf_relos(struct bpf_linker *linker, struct src_obj *ob return -1; } + /* add_dst_sec() above could have invalidated linker->secs */ + dst_symtab = &linker->secs[linker->symtab_sec_idx]; + /* shdr->sh_link points to SYMTAB */ dst_sec->shdr->sh_link = linker->symtab_sec_idx; |
