Mark Wielaard [Sun, 21 Dec 2014 22:02:12 +0000 (23:02 +0100)]
readelf: Don't try to read macinfo cus sentinel or beyond.
https://bugzilla.redhat.com/show_bug.cgi?id=1170810
Reported-by: Alexander Cherepanov <cherepan@mccme.ru>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 21 Dec 2014 21:55:54 +0000 (22:55 +0100)]
readelf: Add more sanity checks to print_debug_exception_table.
https://bugzilla.redhat.com/show_bug.cgi?id=1170810
Reported-by: Alexander Cherepanov <cherepan@mccme.ru>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 11 Jan 2015 14:00:52 +0000 (15:00 +0100)]
libdw: Prevent infinite recursion when processing DW_TAG_imported_unit.
Invalid DWARF could create cycles with DW_TAG_imported_unit, which would
lead to infinite recursion and stack overflow in libdw_visit_scopes.
Keep track of imported units and error out when a cycle is detected.
Found by afl-fuzz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Alexander Cherepanov [Sun, 28 Dec 2014 16:57:19 +0000 (19:57 +0300)]
libelf: Fix dir traversal vuln in ar extraction.
read_long_names terminates names at the first '/' found but then skips
one character without checking (it's supposed to be '\n'). Hence the
next name could start with any character including '/'. This leads to
a directory traversal vulnerability at the time the contents of the
archive is extracted.
The danger is mitigated by the fact that only one '/' is possible in a
resulting filename and only in the leading position. Hence only files
in the root directory can be written via this vuln and only when ar is
executed as root.
The fix for the vuln is to not skip any characters while looking
for '/'.
Signed-off-by: Alexander Cherepanov <cherepan@mccme.ru>
Mark Wielaard [Fri, 19 Dec 2014 19:53:22 +0000 (20:53 +0100)]
tests: Don't match libfunc symbol on ppc64 in run-deleted.sh testcase.
For PPC64 we need access to the OPD table which we get through the shdrs
but for the deleted-lib we only have phdrs. So we don't have the name of
the function. But since we should find the EH_FRAME through phdrs just
fine, we can unwind into main. Skip the libfunc name check for now till
we find a nice way to enable the lookup without opd:
https://bugzilla.redhat.com/show_bug.cgi?id=1176238
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 19 Dec 2014 17:54:04 +0000 (18:54 +0100)]
tests: vdsosyms should not fail for architectures that don't have a vdso.
Not finding a vdso is not fatal. But there should be no errors trying.
And if the vdso is found, then getting the symbol table shouldn't fail.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 19 Dec 2014 17:33:52 +0000 (18:33 +0100)]
tests: run-deleted.sh should SKIP if arch doesn't support unwinding.
Also relax the special ARM needs DWARF check a little to account for eu-stack
error output.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 19 Dec 2014 17:19:29 +0000 (18:19 +0100)]
libdwfl: Always try find_dynsym last, also on find_symtab ELF errors.
An ELF error during find_symtab might be incomplete shdrs or string table
from ELF images read through elf_from_memory. The phdrs and dynsym should
always be complete.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 19 Dec 2014 14:40:16 +0000 (15:40 +0100)]
libdwfl: Remove p_align sanity check from elf_from_memory.
In commit f15bcd "elf_from_remote_memory should use pagesize, not p_align"
we already relaxed the p_align sanity check to allow alignment of the
segment against the pagesize since that is what the glibc dynamic linker
actually does. But on some architectures the kernel inserts a vdso with
a completely bogus p_align for some PT_LOAD segments. So just drop the
whole sanity check and allow anything since we won't use p_align, but
always already use pagesize anyway.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Ulrich Drepper [Thu, 18 Dec 2014 17:32:39 +0000 (12:32 -0500)]
avoid scary command output
The commands to check for invalid text relocations in the generated DSOs
shouldn't be displayed. They contain an echo which prints the text.
This patch suppresses the commands from being printed.
Mark Wielaard [Thu, 18 Dec 2014 22:41:41 +0000 (23:41 +0100)]
Prepare 0.161 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Dec 2014 22:07:12 +0000 (23:07 +0100)]
tests: Add testfile-macros-0xff.bz2 to EXTRA_DIST.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Dec 2014 08:28:50 +0000 (09:28 +0100)]
libdwfl: Make sure symstrdata->d_buf != NULL in relocate resolve_symbol.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 17 Dec 2014 14:07:49 +0000 (15:07 +0100)]
readelf: Add bounds check before each CFA op that takes an argument.
Some CFA ops don't take any arguments, for those it is valid to be at the
end of the data block.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 21:47:39 +0000 (22:47 +0100)]
libdw: Check diridx is valid under DW_LNE_define_file in dwarf_getsrclines.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 21:19:08 +0000 (22:19 +0100)]
readelf: Print dwarf_errmsg if dwarf_onesrcline or dwarf_linesrc fails.
Don't just crash using the NULL result in print_decoded_line_section.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 19:05:58 +0000 (20:05 +0100)]
libelf: Make sure ar archive long_names len fits in mapped ELF file.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 18:43:21 +0000 (19:43 +0100)]
libelf: Check index_size doesn't overflow in elf_getarsym.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 15:41:19 +0000 (16:41 +0100)]
libdw: Make sure there is enough space to read offset in dwarf_getpubnames.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 15:30:59 +0000 (16:30 +0100)]
readelf: Correct overflow check for length in print_debug_aranges_section.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 15:10:28 +0000 (16:10 +0100)]
readelf,libdw: Correct .debug_line overflow check for unit_length.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 15 Dec 2014 18:43:02 +0000 (19:43 +0100)]
readelf: Warn, don't assert, if loclist or rangelist offset is too big.
We use a couple of bits to keep track of the addr size, dwarf size and
warning given for a loclist or rangelist offset. Normally offset won't
be that big and will fit in 61-bits easily. But if not, don't assert,
but just warn we don't handle such large offsets.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 15 Dec 2014 18:05:43 +0000 (19:05 +0100)]
readelf: Don't assert when addr_size or ref_size is not 4 or 8 in print_ops.
Just report invalid data and continue.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 15 Dec 2014 15:56:49 +0000 (16:56 +0100)]
libdw: dwarf_getpubnames set error to DWARF_E_NO_ENTRY for zero entries.
realloc in get_offsets will return NULL otherwise and dwarf_getpubnames
might think there was no issue and try to use that NULL pointer.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 15 Dec 2014 14:34:59 +0000 (15:34 +0100)]
readelf: Add more bounds checks to print_gdb_index_section.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 15 Dec 2014 13:56:07 +0000 (14:56 +0100)]
libdw: Add bounds checking to dwarf_getpubnames.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 15 Dec 2014 12:40:18 +0000 (13:40 +0100)]
readelf: Make sure there is enough room for reading .debug_line unit_length.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 15 Dec 2014 10:35:46 +0000 (11:35 +0100)]
readelf: Check there is enough room for the DW_LNE_set_address argument
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 15 Dec 2014 10:17:33 +0000 (11:17 +0100)]
libelf: Clear any garbage left in the ar name table.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 09:53:22 +0000 (10:53 +0100)]
libdw: Unroll the first get_sleb128 step to help the compiler optimize.
The common case is a single-byte. So no extra (max len) calculation is
necessary then.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Josh Stone [Mon, 15 Dec 2014 20:18:25 +0000 (12:18 -0800)]
libdw: pre-compute leb128 loop limits
Signed-off-by: Josh Stone <jistone@redhat.com>
Mark Wielaard [Sun, 14 Dec 2014 20:48:23 +0000 (21:48 +0100)]
libdw: Add get_uleb128 and get_sleb128 bounds checking.
Both get_uleb128 and get_sleb128 now take an end pointer to prevent
reading too much data. Adjust all callers to provide the end pointer.
There are still two exceptions. "Raw" dwarf_getabbrevattr and
read_encoded_valued don't have a end pointer associated yet.
They will have to be provided in the future.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 12 Dec 2014 15:43:04 +0000 (16:43 +0100)]
libdw: Make sure all attributes come with a (fake) CU for bound checks.
All attributes now have a reference to a (fake) CU that has startp and
endp set to the data section where the form data comes from. Use that
for bounds checking in __libdw_form_val_len and dwarf_formblock to make
sure data read doesn't overflow any data section. Remove libdwP.h cu_data
and use cu startp and endp directly where appropriate.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Dec 2014 10:04:55 +0000 (11:04 +0100)]
elfcmp: Make sure Elf32_Word difference doesn't wrap around in int compare.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 13 Dec 2014 21:23:45 +0000 (22:23 +0100)]
libdwfl: Make sure elf_getdata_rawchunk size_t doesn't overflow find_dynsym.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 11 Dec 2014 23:22:31 +0000 (00:22 +0100)]
libdw: Make sure end of next cu doesn't overflow section data size.
An invalid or trucated debug info/type section could cause the cu endp
to point beyond the end of section data.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 13 Dec 2014 23:09:29 +0000 (00:09 +0100)]
Guard against 64bit unsigned wrap around in (int) compare functions.
Dwarf_Adrr and Dwarf_Off are 64-bit unsigned, and comparison functions
used in qsort or tfind return int, it is possible for the difference to
be so large that it wraps around. Make sure to just return -1, 0 or 1
in compare_aranges and compare_cukey.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Josh Stone [Mon, 15 Dec 2014 19:05:11 +0000 (11:05 -0800)]
Add config/compile as installed by automake 1.14
Signed-off-by: Josh Stone <jistone@redhat.com>
Mark Wielaard [Thu, 11 Dec 2014 17:26:09 +0000 (18:26 +0100)]
readelf: Check TType base offset and Action table are sane in exception table.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 11 Dec 2014 16:21:22 +0000 (17:21 +0100)]
readelf: Don't print more augmentation characters than there are.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 11 Dec 2014 15:33:30 +0000 (16:33 +0100)]
libelf: Correct ELF64 section offset check in file_read_elf.
The ELF64 case didn't check for overflow and accidentially used the 32bit
Shdr size.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 11 Dec 2014 15:28:57 +0000 (16:28 +0100)]
libelf: Add some ar header sanity checking.
Don't allow entries or size to overflow the parent file size.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 12 Dec 2014 20:51:27 +0000 (21:51 +0100)]
tests: Add an explicit -fasynchronous-unwind-tables for deleted-lib.so.
Some systems don't add a PT_GNU_EH_FRAME segment by default, but the
deleted test depends on it so that it can get at the .eh_frame_hdr table
through the phdrs from the remote memory ELF image. Request one explicitly
with -fasynchronous-unwind-tables.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Josh Stone [Fri, 12 Dec 2014 01:19:23 +0000 (17:19 -0800)]
tests: Test addr2line -i with lexical blocks present
This test is for the fix in commit
aecdf2670c02, but it was hampered by
unlucky sorting of line records. With the new stable sort, the test now
gets the desired line numbers.
Signed-off-by: Josh Stone <jistone@redhat.com>
Josh Stone [Fri, 12 Dec 2014 00:23:46 +0000 (16:23 -0800)]
libdwfl: Search for the last matching address in lines
Now that libdw's srclines use a stable sort, we can reliably choose the
*last* matching line record for a given address, which should be the
innermost where inlines are concerned.
Signed-off-by: Josh Stone <jistone@redhat.com>
Josh Stone [Fri, 12 Dec 2014 00:22:48 +0000 (16:22 -0800)]
libdw: Make srclines use a stable sort
This adds a sequence number to the linked-list entries, so the original
order can break ties in sorting, making this a stable sort.
Signed-off-by: Josh Stone <jistone@redhat.com>
Mark Wielaard [Tue, 9 Dec 2014 12:43:58 +0000 (13:43 +0100)]
libelf: Make sure n * w doesn't overflow in elf_getarsym.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 9 Dec 2014 12:16:23 +0000 (13:16 +0100)]
libdwfl: Check file count overflow in handle_file_note.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 9 Dec 2014 11:58:07 +0000 (12:58 +0100)]
readelf: Check count fits and doesn't overflow fptr in handle_file_note.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 8 Dec 2014 09:11:43 +0000 (10:11 +0100)]
readelf: Report invalid data if action table doesn't follow call site table.
Don't assert.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Josh Stone [Thu, 11 Dec 2014 02:41:43 +0000 (18:41 -0800)]
libdw: save startp/endp boundaries in Dwarf_CU
Rather than looking up section data every time, we can simply save the
range of each CU as pointers in Dwarf_CU.
Signed-off-by: Josh Stone <jistone@redhat.com>
Josh Stone [Thu, 11 Dec 2014 02:33:34 +0000 (18:33 -0800)]
libdw: optimize dwarf_hasattr to just look at abbrev
To just check the presence of an attribute, we only need to look at the
abbreviation data. This optimization avoids reading over die data at all,
except possibly just to get the abbrev code.
Signed-off-by: Josh Stone <jistone@redhat.com>
Josh Stone [Thu, 11 Dec 2014 02:28:04 +0000 (18:28 -0800)]
libdw: unify die->abbrev lookups
Add a new internal function, __libdw_dieabbrev, which deals with checking
a die for an abbrev, and setting it as needed.
Signed-off-by: Josh Stone <jistone@redhat.com>
Josh Stone [Wed, 10 Dec 2014 19:14:40 +0000 (11:14 -0800)]
addr2line: Always prefer linkage_name over plain names
Signed-off-by: Josh Stone <jistone@redhat.com>
Josh Stone [Wed, 10 Dec 2014 19:06:52 +0000 (11:06 -0800)]
addr2line: Iterate scopes for inline's parent function
The function which contains an inline might not be the immediate next
die scope. For instance, there may be a lexical scope in between.
Instead, iterate the remaining scopes until an appropriate tag is found.
Signed-off-by: Josh Stone <jistone@redhat.com>
Mark Wielaard [Sun, 7 Dec 2014 22:40:12 +0000 (23:40 +0100)]
readelf: maximum operations per instruction cannot be zero in .debug_line.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 7 Dec 2014 21:45:28 +0000 (22:45 +0100)]
readelf: DW_OP_call_ref and DW_OP_GNU_implicit_pointer are invalid for CFA.
print_cfa_program might call print_ops with zero offset size. We don't
need (and don't know) the DWARF offset size in that case. DW_OP_call_ref
and DW_OP_GNU_implicit_pointer need to know the offset size because they
reference a DIE. But they are invalid when used from CFA.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 7 Dec 2014 19:48:43 +0000 (20:48 +0100)]
libdwfl: Check actually used ehsize, shentsize and phentsize in relocate.c
In relocate_section we check relocation sections don't overlap any of the
ELF headers. We should check against the actually used ehsize, shentsize
and phentsize. Not the possibly bogus values in the file ehdr itself.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 7 Dec 2014 19:26:56 +0000 (20:26 +0100)]
libdwfl: Never relocate value against section zero (load address).
This really is just a robustify patch in case section zero got the
wrong section flags set. In that case __libdwfl_relocate_value might
call dwfl_offline_section_address which might assert (because it isn't
prepared to handle section zero). elf_nextscn will never see section zero.
So be explicit in dwfl_offline_section_address and immediately assert
when shndx is zero. And handle section zero immediately by not relocating
the value in __libdwfl_relocate_value.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 4 Dec 2014 20:43:44 +0000 (21:43 +0100)]
libdw: Add overflow checking to __libdw_form_val_len.
Pass endp as argument to __libdw_form_val_len and check we don't read
beyond the end of expected data and don't return lengths that would
overflow.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Petr Machata [Tue, 2 Dec 2014 20:22:14 +0000 (21:22 +0100)]
Change calling convention of dwarf_getmacros to allow opcode 0xff
We now require callers to pass DWARF_GETMACROS_START to start the
iteration. 0 is still accepted, but signals to libdw that the
iteration request comes from an old-style caller, and that opcode 0xff
should be rejected when iterating .debug_macro, to avoid confusion.
Signed-off-by: Petr Machata <pmachata@redhat.com>
Mark Wielaard [Thu, 4 Dec 2014 16:01:20 +0000 (17:01 +0100)]
objdump: Add various sanity checks to guard against corrupted data.
Reported-by: Alexander Cherepanov <cherepan@mccme.ru>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 30 Nov 2014 20:03:57 +0000 (21:03 +0100)]
readelf: Fix overflow check in handle_sysv_hash64.
Since all values are 64bit, not 32bit as in other hashes, we need to
explicitly check for overflow.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 29 Nov 2014 19:23:30 +0000 (20:23 +0100)]
libdwfl: Check relocations don't overlap ELF ehdr, shdrs or phdrs.
If either the section that needs the relocation applied, or the
section that the relocations come from overlap one of the ehdrs,
shdrs or phdrs data then refuse to do the relocations. We update
both section data. It isn't illegal for ELF section data to overlap
the header data, but updating the (relocation) data might corrupt
the in-memory libelf headers causing strange corruptions or errors.
Also check offset + size of a relocation doesn't overflow.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 28 Nov 2014 21:22:16 +0000 (22:22 +0100)]
readelf: Don't trash destshdr for STT_SECTION in handle_relocs_rel[a].
We might need the original destshdr for handling other relocations.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 27 Nov 2014 22:53:30 +0000 (23:53 +0100)]
Add configure --disable-textrelcheck option to enable CC=afl-fuzz on 32bit.
Using american fuzzy lop has found a lot of issues. It would be nice to
make using it a bit easier. Our build files make sure that no shared
library uses text relocations, but afl-gcc will insert some on i686.
http://www.akkadia.org/drepper/textrelocs.html
Now CC=afl-gcc ./configure --disable-textrelcheck will allow them so
that afl can instrument the libraries.
Don't try to use or install them except with afl-fuzz. When selinux is
enabled it might prevent loading the libraries with DT_TEXTREL set.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 27 Nov 2014 22:41:57 +0000 (23:41 +0100)]
libdw: Initialize variables in getcfi_gnu_eh_frame.
Some older GCCs are not clever enough to realize that when search_table
is NULL not only are search_table_entries and search_table_encoding not
initialized, they are also not used. Giving "may be used uninitialized"
errors.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 27 Nov 2014 22:19:47 +0000 (23:19 +0100)]
tests: vdsosyms call dwfl_linux_proc_attach.
Older kernels won't let us get at the vdso otherwise.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 26 Nov 2014 23:12:32 +0000 (00:12 +0100)]
readelf: Cast Dwarf_Word length to ptrdiff_t for comparison.
Avoids comparison between signed and unsigned integer expressions warning.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 24 Nov 2014 20:54:42 +0000 (21:54 +0100)]
readelf, libdw: Guard against divide by zero line_range in .debug_line.
For DW_LNS_const_add_pc and special opcodes don't accept line_range
being zero.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 23 Nov 2014 22:21:05 +0000 (23:21 +0100)]
libdw: Always check __libdw_find_attr return value.
__libdw_find_attr will return NULL and might not set code or form.
Only use code or form if the returned address is not NULL.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 23 Nov 2014 22:13:55 +0000 (23:13 +0100)]
libdw: Don't assert in __libdw_getabbrev when seeing bad DWARF.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 23 Nov 2014 20:54:51 +0000 (21:54 +0100)]
libelf: Change signed overflow check to unsigned in elf_getdata_rawchunk.
Arithmetic of signed values that overflow causes undefined behaviour
Change to explicit unsigned arithmetic overflow check.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 23 Nov 2014 17:26:16 +0000 (18:26 +0100)]
readelf: Check length for nexthdr overflow in print_debug_aranges_section.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 23 Nov 2014 14:27:23 +0000 (15:27 +0100)]
libelf: Copy over any leftover data from src to dest in elf_cvt_note.
If any data is left then the data is likely part of the truncated note
name/desc. This probably means the note is corrupted, but it is better
to have the actual data in dest instead of random uninitialized memory.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 21 Nov 2014 22:26:35 +0000 (23:26 +0100)]
readelf: print_attributes (-A) robustify and handle non-gnu attributes.
print_attributes wasn't robust against empty or broken attribute sections.
It also only handled GNU attributes. But the arm backend contains some
none-GNU attributes. The difference is in how to handle the tag arguments.
Adds a new test run-readelf-A.sh for both gnu (ppc32) and non-gnu (arm)
attributes.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 22 Nov 2014 22:08:48 +0000 (23:08 +0100)]
Use elf_getphdrnum instead of accessing ehdr->e_phnum directly.
Using elf_getphdrnum lets us handle ELF files that use more than PN_XNUM
phdrs. And guards against some corrupt files.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 22 Nov 2014 16:33:05 +0000 (17:33 +0100)]
libelf: elf_getphdrnum sanity check the returned phnum result.
The internal __elf_getphdrnum_rdlock might return an inconsistent phnum.
Return a sanitized value, or return an error to users that rely on phnum
to be consistent. That way iterating over all phdrs using elf_getphdr
will return consistent results.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 24 Nov 2014 21:17:51 +0000 (22:17 +0100)]
dwarf.h: Add DW_LANG_C11, DW_LANG_C_plus_plus_11 and DW_LANG_C_plus_plus_14.
The following patch is needed to recognize the new DW_LANG constants
that GCC 5 might emit as implemented by this GCC patch:
https://gcc.gnu.org/ml/gcc-patches/2014-11/msg02852.html
Also added to https://fedorahosted.org/elfutils/wiki/DwarfExtensions
GCC 5 can emit these new DWARFv5 draft language constants. Handle them in
dwarf_aggregate_size and dwarf_getfuncs. Also handle DW_LANG_Go in
dwarf_aggregate_size (lower bound for array is zero for Go).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 26 Nov 2014 16:51:28 +0000 (17:51 +0100)]
dwarf.h: Add DW_AT_noreturn.
DW_AT_noreturn is added by GCC5 for functions that don't return to their
caller. It is set on a DW_TAG_subprogram for the traditional GNU noreturn
attribute, the C11 _Noreturn keyword or C++11 [[noreturn]] attribute. It
is a new DWARF5 extension. This is a constant only addition to dwarf.h.
No other part of elfutils currently depends on this attribute.
Also added to https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 18 Nov 2014 09:07:10 +0000 (10:07 +0100)]
libdwfl: Sanity check the symbol table before use.
Make sure the number of symbols reported and the first global fit the data.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 18 Nov 2014 09:01:48 +0000 (10:01 +0100)]
readelf: Fix sanity check of DW_FORM_block length in print_cfa_program
We were checking the reg nr, not the length of the block.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 18 Nov 2014 08:56:01 +0000 (09:56 +0100)]
libelf: Check for overflow in version_xlate elf_cvt_Verdef and elf_cvt_Verneed.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 17 Nov 2014 22:35:28 +0000 (23:35 +0100)]
readelf: When the version chain ends, stop processing the entries.
The version definition, auxiliary version, version dependency and needed
version sections chain information together through "next" fields. When
the "next" field is zero there are no more information entries. Stop
processing when we see zero instead of repeatedly processing the same
entry (at offset zero from the current one).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 17 Nov 2014 22:15:45 +0000 (23:15 +0100)]
Check elf_strptr didn't fail getting section name.
Since elf_strptr can fail and return NULL we should always check the result
before usage. Debug sections are only handled by section name, so make sure
the name actually exists.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 17 Nov 2014 22:01:34 +0000 (23:01 +0100)]
readelf: Warn if ptr_size is not 4 or 8 bytes.
Just warn and don't call print_cfa_program in that case. Bad things will
happen and the result is mostly bogus.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 16 Nov 2014 23:42:53 +0000 (00:42 +0100)]
libelf: elf_getshdrstrndx cannot use SHN_XINDEX without section headers.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 16 Nov 2014 23:33:36 +0000 (00:33 +0100)]
libelf: Fix handling of (extended) phnum.
If there is no e_phoff e_phnum cannot be trusted. Extended phnum can only
be gotten if we have an actual section table and a shdr for section zero,
Extended phnum can be too large to fit in the file (or a size_t).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 16 Nov 2014 10:40:08 +0000 (11:40 +0100)]
readelf: Robustify print_cfa_program.
Check block len before calling print_ops.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 16 Nov 2014 10:30:51 +0000 (11:30 +0100)]
gelf_getnote: Check padding overflow.
Since ELF notes need to be properly aligned they can include padding.
Make sure the padding itself and the padding calculation doesn't overflow.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 16 Nov 2014 10:19:29 +0000 (11:19 +0100)]
libelf: getdata check 64bit values correctly on 32bit arch.
On 32bit arches size_t is too small to do size and overflow checks
of 64bit ELF files. Use the actual Elf64 types to make sure checks
on 64bit ELF files are done correctly on 32bit arches.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 14 Nov 2014 20:42:47 +0000 (21:42 +0100)]
readelf: Sanity check CIE unit_length and augmentationlen in debug_frame.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 14 Nov 2014 16:05:08 +0000 (17:05 +0100)]
libelf: gelf_getnote check for offset overflow.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 14 Nov 2014 15:58:36 +0000 (16:58 +0100)]
libdwelf: Check the d_buf actually exists in dwelf_elf_gnu_debuglink.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 14 Nov 2014 11:38:12 +0000 (12:38 +0100)]
libdwfl: dwfl_module_getdwarf.c don't use symtab with bogus sh_entsize.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 14 Nov 2014 11:24:28 +0000 (12:24 +0100)]
readelf: Check def == NULL before use in handle_versym.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 10 Nov 2014 13:49:20 +0000 (14:49 +0100)]
libdwfl: find_dynsym don't assume dynamic linker has adjusted DYNAMIC entries.
commit 037505 "Fix resolving ELF symbols for live PIDs with deleted files"
changed find_dynsym to assume the PT_DYNAMIC entries had been adjusted by
the dynamic linker. That is often a correct assumption when the ELF image
comes from remote memory. But we cannot rely on that. In the case of the
vdso image the DYNAMIC segment has not been adjusted for example.
There is no good way to determine whether the DYNAMIC segment has or
hasn't been adjusted already to the load address by the dynamic linker.
So we just try twice. Once without and if the fails again with assuming
adjustments being applied.
Includes a new vdsosyms testcase that fails on i686 before and succeeds
after the fix.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 13 Nov 2014 14:43:02 +0000 (15:43 +0100)]
libelf: Fix unsigned overflow check in elf_getdata.
Mark Wielaard [Sat, 8 Nov 2014 15:18:34 +0000 (16:18 +0100)]
libelf: Use mempcpy not __mempcpy.
We were using mempcpy everywhere else, only __libelf_next_arhdr_wrlock used
__mempcpy.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 11 Nov 2014 13:10:04 +0000 (14:10 +0100)]
libdw: Fix dwarf_getsrclines.c 32bit compile error.
__libdw_getsrclines should have been marked as internal_function in
both libdwP.h and dwarf_getsrclines.c. Do address_size comparison as
uint8_t to avoid signedness warning.
Signed-off-by: Mark Wielaard <mjw@redhat.com>