From d0c4e7802dae311d71059d0e2114150a5e09acf1 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 11 Jun 2020 13:27:50 +0930 Subject: asan: readelf: process_mips_specific buffer overflow DT_MIPS_OPTIONS is not a regular array as assumed by readelf. This patch corrects that assumption, and to do so easily, makes various internal (host byte order) structs the same size as external (target byte order) structs. include/ * elf/mips.h (Elf32_RegInfo): Use fixed width integer types. (Elf64_Internal_RegInfo, Elf_Internal_Options): Likewise. binutils/ * readelf.c (process_mips_specific): Assert size of internal types match size of external types, and simplify allocation of internal buffer. Catch possible integer overflow when sanity checking option size. Don't assume options are a regular array. Sanity check reginfo option against option size. Use PRI macros when printing. --- include/ChangeLog | 5 +++++ include/elf/mips.h | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/ChangeLog b/include/ChangeLog index f6200db..3c27652 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,8 @@ +2020-06-11 Alan Modra + + * elf/mips.h (Elf32_RegInfo): Use fixed width integer types. + (Elf64_Internal_RegInfo, Elf_Internal_Options): Likewise. + 2020-06-06 Alan Modra * elf/ppc64.h (elf_ppc64_reloc_type): Rename diff --git a/include/elf/mips.h b/include/elf/mips.h index d116b03..cc08ebd 100644 --- a/include/elf/mips.h +++ b/include/elf/mips.h @@ -560,11 +560,11 @@ typedef union typedef struct { /* Mask of general purpose registers used. */ - unsigned long ri_gprmask; + uint32_t ri_gprmask; /* Mask of co-processor registers used. */ - unsigned long ri_cprmask[4]; + uint32_t ri_cprmask[4]; /* GP register value for this object file. */ - long ri_gp_value; + uint32_t ri_gp_value; } Elf32_RegInfo; /* The external version of the Elf_RegInfo structure. */ @@ -1008,9 +1008,9 @@ typedef struct /* Size of option descriptor, including header. */ unsigned char size; /* Section index of affected section, or 0 for global option. */ - unsigned short section; + uint16_t section; /* Information specific to this kind of option. */ - unsigned long info; + uint32_t info; } Elf_Internal_Options; /* MIPS ELF option header swapping routines. */ @@ -1074,13 +1074,13 @@ typedef struct typedef struct { /* Mask of general purpose registers used. */ - unsigned long ri_gprmask; + uint32_t ri_gprmask; /* Padding. */ - unsigned long ri_pad; + uint32_t ri_pad; /* Mask of co-processor registers used. */ - unsigned long ri_cprmask[4]; + uint32_t ri_cprmask[4]; /* GP register value for this object file. */ - bfd_vma ri_gp_value; + uint64_t ri_gp_value; } Elf64_Internal_RegInfo; /* ABI Flags structure version 0. */ -- cgit v1.1