diff options
author | Alan Modra <amodra@gmail.com> | 2022-08-05 19:40:23 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-08-05 20:48:29 +0930 |
commit | 37c59664adcb87bdf3279a5919940785057fe565 (patch) | |
tree | 811409b12b93bc339a6cafbf3ae53353cfe08308 /bfd/elf.c | |
parent | dfbc689c699b3a15f11e8eb09cb05629f60b36b3 (diff) | |
download | gdb-37c59664adcb87bdf3279a5919940785057fe565.zip gdb-37c59664adcb87bdf3279a5919940785057fe565.tar.gz gdb-37c59664adcb87bdf3279a5919940785057fe565.tar.bz2 |
asan: ppc64_elf_get_synthetic_symtab heap buffer overflow
Fuzzed input files with sizes of .dynamic not a multiple of dynamic
tag size can result in reading past the end of the buffer with the
current simple checks. Fix that, and use the same check in other
files that process input object .dynamic section. (There is no need
for buffer overflow checks in the linker's generated .dynamic
section.)
* elf32-ppc.c (ppc_elf_get_synthetic_symtab): Sanity check
.dynamic content buffer reads.
* elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Likewise.
* elf64-ia64-vms.c (elf64_vms_link_add_object_symbols): Likewise.
* elf.c (_bfd_elf_print_private_bfd_data): Simplify .dynamic
buffer sanity checks.
* elflink.c (elf_link_add_object_symbols): Avoid possible UB
subtracting sizeof_dyn from pointer.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 11 |
1 files changed, 3 insertions, 8 deletions
@@ -1721,14 +1721,9 @@ _bfd_elf_print_private_bfd_data (bfd *abfd, void *farg) extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in; - extdyn = dynbuf; - /* PR 17512: file: 6f427532. */ - if (s->size < extdynsize) - goto error_return; - extdynend = extdyn + s->size; - /* PR 17512: file: id:000006,sig:06,src:000000,op:flip4,pos:5664. - Fix range check. */ - for (; extdyn <= (extdynend - extdynsize); extdyn += extdynsize) + for (extdyn = dynbuf, extdynend = dynbuf + s->size; + (size_t) (extdynend - extdyn) >= extdynsize; + extdyn += extdynsize) { Elf_Internal_Dyn dyn; const char *name = ""; |