Mark Wielaard [Mon, 26 Jan 2015 15:34:57 +0000 (16:34 +0100)]
libdwfl: Clear symtab result on error before using find_dynsym fallback.
find_dynsym could succeed after find_symtab failed but had already set up
symdata, syments and first_global. find_dynsym would not set or clear
first_global since all syms in dynsym are global. Causing lots of failing
lookups when calling __libdwfl_addrsym if first_global was some huge
bogus value.
Reported-by: Hanno Böck <hanno@hboeck.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 22 Jan 2015 11:49:29 +0000 (12:49 +0100)]
libelf: Make sure string returned by elf_strptr is NUL terminated.
The result of elf_strptr is often used directly to print or strcmp
the string. If the section data was truncated or corrupted that could
lead to invalid memory reads possibly crashing the application.
https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c24
Reported-by: Alexander Cherepanov <cherepan@mccme.ru>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 21 Jan 2015 22:56:43 +0000 (23:56 +0100)]
libelf: elf_strptr should use datalist when data has been added to section.
elf_strptr always used the rawdata when available. But when data has been
added to the section it should find the correct buffer in the datalist.
Adds a large testcase that checks various ways of adding and extracting
strings from a section.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 20 Jan 2015 20:55:55 +0000 (21:55 +0100)]
libelf: Fix elf_newdata when raw ELF file/image data is available.
When ELF data for a section has been read by elf_rawdata, data_read
and rawdata_base are set, but data_list_rear will not be set until the
data will be converted (by elf_getdata). elf_newdata would overwrite
the existing data in that case. Both elf_getdata and elf_update rely
on the fact that when data_list_rear is set they don't have to look
at the raw data anymore. So make sure we update the data list properly
before adding any new data and raw data is available in elf_newdata.
Add newdata test that calls elf_newdata before and after elf_rawdata
and elf_getdata and checks the new size and contents of the section.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 20 Jan 2015 13:52:41 +0000 (14:52 +0100)]
libelf: elf_strptr should fetch the shdr for the section if not yet known.
elf_strptr might be called before the shdrs are read in. In that case it
needs to explicitly call __elf[32|64]_getshdr_rdlock to check the section
type and size. The new strptr testcase triggers this corner case and crashes
before the fix.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 27 Jan 2015 14:55:41 +0000 (15:55 +0100)]
s/Really, not guarantee/Really, no guarantee/g
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 27 Jan 2015 12:07:17 +0000 (13:07 +0100)]
libebl.h: Add comment from README that this is completely UNSUPPORTED.
Make it really, really clear that the libebl interface is NOT source and
NOT abi compatible and we will break any users.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 15 Jan 2015 12:39:06 +0000 (13:39 +0100)]
tests: Make deleted and vdsosyms testcases work with "restricted ptrace".
Some systems might have "restricted ptrace" that doesn't allow process
inspection of arbitrary processes. Change the deleted testcase to
explicitly allow any other process to inspect it using the PR_SET_PTRACER
prctl set to PR_SET_PTRACER_ANY. Change the vdsosyms testcase to inspect
the process itself which should always be allowed.
Reported-by: Anatol Pomozov <anatol.pomozov@gmail.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 24 Dec 2014 12:17:23 +0000 (13:17 +0100)]
libdw: Search for the last matching address with dwarf_getsrc_die.
In commit 7d9b5a dwfl_module_getsrc was changed so that it returns the last
line record <= addr, rather than returning immediately on a match. This
changes dwarf_getsrc_die to do the same. And it adds a new test that checks
this by comparing against the same results from eu-addr2line (which uses
dwfl_module_getsrc) using dwarf_addrdie and dwarf_getsrc_die instead.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 27 Dec 2014 15:16:29 +0000 (16:16 +0100)]
libdwfl: dwfl_module_getsrc should never match end_sequence line.
The line with end_sequence set has an address outside the current line
sequence. An end_sequence line has no other useful information except
marking the address as out of range.
Two tests, addrscopes and funcscopes, depended on matching the end_sequence
line. But that was because they included the high_pc address in the scope.
However the high_pc attributes has as address the first location past the
range associated with a given DIE. Adjust the tests to use high_pc - 1 as
end of the scope.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 7 Jan 2015 22:39:28 +0000 (23:39 +0100)]
libdw: Robustify eh_frame_hdr and encoded-values reading.
Sanity check and keep track of binary_search_table data buffer length.
Add bounds check to encoded value reading. Also fix a bug when reading
the eh_frame header data from an other endian ELF image. Add a testcase
that would fail the new sanity checks because of the endian bug.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 4 Jan 2015 23:12:53 +0000 (00:12 +0100)]
libdwfl: Handle seeing CU EOF marker without any other (real) CU.
intern_cu (and __libdwfl_nextcu) didn't correctly handle immediately seeing
the CU EOF marker. In that case the *nextp pointer (first_cu) returned by
intern_cu is -1. And less_layzy will immediately destroy the found CU node.
So don't use the *found result after calling less_lazy.
Found by afl-fuzz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 4 Jan 2015 23:03:03 +0000 (00:03 +0100)]
libdw: Check DW_AT_sibling attribute offset is after current DIE.
The sibling attribute should point after this DIE in the CU.
Otherwise various algorithms might loop or go into infinite recursion
walking the DIE tree.
Found by afl-fuzz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 4 Jan 2015 15:08:22 +0000 (16:08 +0100)]
libdw: Check register number in CFI isn't insanely large.
Some cfi.c array size allocation calculations might overflow when trying
to accommodate insanely large number of registers. Don't allow register
numbers larger than INT32_MAX / sizeof (dwarf_frame_register).
Found by afl-fuzz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 3 Jan 2015 23:35:25 +0000 (00:35 +0100)]
elfcmp: Add some NULL and zero checks.
https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c17
Reported-by: Alexander Cherepanov <cherepan@mccme.ru>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 2 Jan 2015 23:27:58 +0000 (00:27 +0100)]
libdw: Add missing size check to parse_eh_frame_hdr.
afl-fuzz showed that when parse_eh_frame_hdr was called from
getcfi_scn_eh_frame invalid data could be read because of a missing size
check. That check was there when parse_eh_frame_hdr was called from
getcfi_gnu_eh_frame. Move the size check into parse_eh_frame. And add
an extra check to make sure d_buf is not NULL.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 2 Jan 2015 23:09:45 +0000 (00:09 +0100)]
libdw: Handle NULL dbg for call_ref, GNU_implicit_pointer and addr DW_OPs.
afl-fuzz pointed out that __libdw_intern_expression didn't handle CFI
containing DW_OP_call_ref, DW_OP_implicit_pointer or DW_OP_addr. Because
in that case the Dwarf dbg is NULL. Both DW_OP_call_ref and
DW_OP_implicit_pointer cannot be used in CFI. That is just an error.
But DW_OP_addr can be. Without a Dwarf dbg we'll need to read the address
argument directly. Don't use __libdw_read_address_inc which might do a
relocation of the value read. But in practice the relocation hook isn't
implemented anyway.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 30 Dec 2014 23:51:45 +0000 (00:51 +0100)]
libelf: gelf_getphdr should check phdr index is valid.
elf_getphdrnum does checks the phdrnum makes sense. But gelf_getphdr
checked the given index against the "raw" e_phnum or internal
__elf_getphdrnum_rdlock result without checking. Extract the checking
code into a new internal __elf_getphdrnum_chk_rdlock function and
use that.
Found by afl-fuzz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 30 Dec 2014 23:40:02 +0000 (00:40 +0100)]
backends: Check sh_entsize is not zero in ppc_symbol.c (find_dyn_got).
Found with afl-fuzz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 28 Dec 2014 23:53:27 +0000 (00:53 +0100)]
elflint: Add various low-level checks.
elflint could crash or hang because it didn't check some low level issues.
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 [Wed, 14 Jan 2015 20:38:16 +0000 (21:38 +0100)]
tests: Add testfile-debug-types test case.
Test for regression fixed in commit
7c713822:
"libdw: fix offset for sig8 lookup in dwarf_formref_die"
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Jason P. Leasure [Wed, 14 Jan 2015 14:26:55 +0000 (09:26 -0500)]
libdw: fix offset for sig8 lookup in dwarf_formref_die
The type_offset of a type unit header is relative to the beginning
of the type unit header.
Signed-off-by: Jason P. Leasure <jpleasu@super.org>
Mark Wielaard [Sat, 27 Dec 2014 11:13:50 +0000 (12:13 +0100)]
libdw: Check sibling attribute offset still falls inside CU data.
Found with afl-fuzz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 26 Dec 2014 21:57:00 +0000 (22:57 +0100)]
strings: Produce error when section data falls outside file.
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 [Fri, 26 Dec 2014 18:36:31 +0000 (19:36 +0100)]
nm: Guard against divide by zero in error check.
Also add section index number in error message.
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 [Fri, 26 Dec 2014 15:20:39 +0000 (16:20 +0100)]
nm: Handle/Skip /SYM64/ index entries.
Add a testcase to show eu-nm now handles archives with 64-bit symbol table.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 26 Dec 2014 15:12:52 +0000 (16:12 +0100)]
nm: Stop processing ar members on first invalid offset.
Otherwise we will keep looping on that same invalid entry.
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 [Thu, 25 Dec 2014 21:50:21 +0000 (22:50 +0100)]
libelf: ar_size cannot be negative. Fix max ar size.
Elf_Arhdr ar_size is loff_t, which is signed. Make sure it isn't negative.
When the parent start_offset is non-zero maxsize should include it to
compensate for ar offset.
Found with afl-fuzz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
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>