[v2,2/4] gdb/dwarf: validate address sizes when reading DWARF headers
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
Commit Message
There is currently very little validation done on the addr_size fields
read from the various DWARF section headers. One could write some DWARF
debug info with strange address sizes (like 0 or 47), and it's not
always clear how GDB will react. Instead of wondering how each site
that uses the address size will behave, I propose to do some early
validation on the address size fields, so that the rest of the code does
not have to worry about unexpected values.
I chose to make the valid values 2, 4 and 8. This is based on the fact
that we have a few sites where we do:
switch (unit->addr_size)
{
case 8:
return bfd_get_signed_64 (unit->abfd, buf);
case 4:
return bfd_get_signed_32 (unit->abfd, buf);
case 2:
return bfd_get_signed_16 (unit->abfd, buf);
default:
abort ();
}
LLVM's getSupportedAddressSizes function lists the same size.
Add the dwarf2_addr_size_is_supported function, and use it at a few
places where we read an address size from a header.
- unit-head.c, where we read unit headers from .debug_info
- read.c, where we read .debug_loclists and .debug_rnglists headers
- aranges.c, where we read .debug_aranges headers. It replaces a more
lax check.
- frame.c, where we read .debug_frame headers
- dwarf_decode_line_header in line-header.c just skips over the address
size, I did not add a check there.
Change-Id: I1b3bd220981347bdf347647183efd1165040875d
---
gdb/dwarf2/aranges.c | 4 ++--
gdb/dwarf2/frame.c | 5 +++++
gdb/dwarf2/read.c | 7 +++++++
gdb/dwarf2/types.h | 8 ++++++++
gdb/dwarf2/unit-head.c | 7 +++++++
5 files changed, 29 insertions(+), 2 deletions(-)
@@ -137,11 +137,11 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
dwarf2_per_cu *const per_cu = per_cu_it->second;
const uint8_t address_size = *addr++;
- if (address_size < 1 || address_size > 8)
+ if (!dwarf2_addr_size_is_supported (address_size))
{
warn->warn
(_("Section .debug_aranges in %ps entry at offset %s "
- "address_size %u is invalid, ignoring .debug_aranges."),
+ "address_size %u is not supported, ignoring .debug_aranges."),
styled_string (file_name_style.style (),
objfile_name (objfile)),
plongest (entry_addr - section->buffer), address_size);
@@ -1770,6 +1770,11 @@ decode_frame_entry_1 (struct gdbarch *gdbarch,
/* FIXME: check that this is the same as from the CU header. */
cie->addr_size = read_1_byte (unit->abfd, buf);
++buf;
+
+ if (!dwarf2_addr_size_is_supported (cie->addr_size))
+ error (_("Unsupported address size in CIE "
+ "(is %u, should be 2, 4 or 8)."), cie->addr_size);
+
cie->segment_size = read_1_byte (unit->abfd, buf);
++buf;
}
@@ -14091,6 +14091,13 @@ read_loclists_rnglists_header (struct loclists_rnglists_header *header,
header->addr_size = read_1_byte (abfd, info_ptr);
info_ptr += 1;
+ if (!dwarf2_addr_size_is_supported (header->addr_size))
+ error (_(DWARF_ERROR_PREFIX
+ "unsupported address size in %s header "
+ "(is %u, should be 2, 4 or 8) [in module %s]"),
+ section->get_name (), header->addr_size,
+ section->get_file_name ());
+
header->segment_collector_size = read_1_byte (abfd, info_ptr);
info_ptr += 1;
@@ -39,4 +39,12 @@ sect_offset_str (sect_offset offset)
return hex_string (to_underlying (offset));
}
+/* Return true if ADDR_SIZE is an address size GDB knows how to handle. */
+
+static inline bool
+dwarf2_addr_size_is_supported (unsigned int addr_size)
+{
+ return addr_size == 2 || addr_size == 4 || addr_size == 8;
+}
+
#endif /* GDB_DWARF2_TYPES_H */
@@ -110,6 +110,13 @@ read_unit_head (struct unit_head *header, const gdb_byte *info_ptr,
header->addr_size = read_1_byte (abfd, info_ptr);
info_ptr += 1;
}
+
+ if (!dwarf2_addr_size_is_supported (header->addr_size))
+ error (_(DWARF_ERROR_PREFIX
+ "unsupported address size in unit header "
+ "(is %u, should be 2, 4 or 8) [in module %s]"),
+ header->addr_size, filename);
+
signed_addr = bfd_get_sign_extend_vma (abfd);
if (signed_addr < 0)
internal_error (_("read_unit_head: dwarf from non elf file"));