diff options
Diffstat (limited to 'tools/lib')
| -rw-r--r-- | tools/lib/bpf/libbpf.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 16485ab05fc1..8334a5a9d5d7 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
| @@ -195,6 +195,7 @@ struct bpf_object { | |||
| 195 | Elf *elf; | 195 | Elf *elf; |
| 196 | GElf_Ehdr ehdr; | 196 | GElf_Ehdr ehdr; |
| 197 | Elf_Data *symbols; | 197 | Elf_Data *symbols; |
| 198 | size_t strtabidx; | ||
| 198 | struct { | 199 | struct { |
| 199 | GElf_Shdr shdr; | 200 | GElf_Shdr shdr; |
| 200 | Elf_Data *data; | 201 | Elf_Data *data; |
| @@ -547,7 +548,7 @@ bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx) | |||
| 547 | continue; | 548 | continue; |
| 548 | 549 | ||
| 549 | map_name = elf_strptr(obj->efile.elf, | 550 | map_name = elf_strptr(obj->efile.elf, |
| 550 | obj->efile.ehdr.e_shstrndx, | 551 | obj->efile.strtabidx, |
| 551 | sym.st_name); | 552 | sym.st_name); |
| 552 | map_idx = sym.st_value / sizeof(struct bpf_map_def); | 553 | map_idx = sym.st_value / sizeof(struct bpf_map_def); |
| 553 | if (map_idx >= obj->nr_maps) { | 554 | if (map_idx >= obj->nr_maps) { |
| @@ -630,8 +631,10 @@ static int bpf_object__elf_collect(struct bpf_object *obj) | |||
| 630 | pr_warning("bpf: multiple SYMTAB in %s\n", | 631 | pr_warning("bpf: multiple SYMTAB in %s\n", |
| 631 | obj->path); | 632 | obj->path); |
| 632 | err = -LIBBPF_ERRNO__FORMAT; | 633 | err = -LIBBPF_ERRNO__FORMAT; |
| 633 | } else | 634 | } else { |
| 634 | obj->efile.symbols = data; | 635 | obj->efile.symbols = data; |
| 636 | obj->efile.strtabidx = sh.sh_link; | ||
| 637 | } | ||
| 635 | } else if ((sh.sh_type == SHT_PROGBITS) && | 638 | } else if ((sh.sh_type == SHT_PROGBITS) && |
| 636 | (sh.sh_flags & SHF_EXECINSTR) && | 639 | (sh.sh_flags & SHF_EXECINSTR) && |
| 637 | (data->d_size > 0)) { | 640 | (data->d_size > 0)) { |
| @@ -667,6 +670,10 @@ static int bpf_object__elf_collect(struct bpf_object *obj) | |||
| 667 | goto out; | 670 | goto out; |
| 668 | } | 671 | } |
| 669 | 672 | ||
| 673 | if (!obj->efile.strtabidx || obj->efile.strtabidx >= idx) { | ||
| 674 | pr_warning("Corrupted ELF file: index of strtab invalid\n"); | ||
| 675 | return LIBBPF_ERRNO__FORMAT; | ||
| 676 | } | ||
| 670 | if (maps_shndx >= 0) | 677 | if (maps_shndx >= 0) |
| 671 | err = bpf_object__init_maps_name(obj, maps_shndx); | 678 | err = bpf_object__init_maps_name(obj, maps_shndx); |
| 672 | out: | 679 | out: |
