summaryrefslogtreecommitdiff
path: root/libdw
Commit message (Collapse)AuthorAgeFilesLines
* libdw: Fix possibly unbounded stack usage in __libdw_intern_expression.Mark Wielaard2015-05-272-15/+36
| | | | | | | Create a stack allocated array to hold locs. Allocate locs bigger than the array with malloc and free them when done. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* dwarf_begin_elf: new error for compression failureJonathan Lebon2015-05-134-61/+97
| | | | | | | | | | | In order to provide better feedback to users, a distinction is made between finding no dwarf info (E_NO_DWARF) and finding dwarf info but which is compressed and failed to decompress (E_COMPRESSED_ERROR). This can occur for example if elfutils was built without zlib support, or if the compressed section is invalid. Signed-off-by: Jonathan Lebon <jlebon@redhat.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* dwarf_begin_elf: decouple section searching from readingJonathan Lebon2015-05-132-31/+36
| | | | | | | | | | | To help legibility, we separate the section name matching from the actual section reading. This also allows us to remove duplicate code in cases of sections appearing twice or empty section data. There are no changes in functionality. The indentation will be fixed in the next commit, in the interest of keeping this commit easier to read. Signed-off-by: Jonathan Lebon <jlebon@redhat.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: Detect line number overflow in dwarf_getsrclines on 32bit.Mark Wielaard2015-05-122-1/+7
| | | | | | | | | | We do check whether the values we store for the line fit our data representation in add_new_line, but on 32bit systems we would fail to notice line overflowing. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c32 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: dwarf_getaranges check there is enough data before reading.Mark Wielaard2015-05-122-2/+19
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c30 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Link against standalone argp libraryAnthony G. Basile2015-05-042-1/+6
| | | | | | | | | | | | | | argp is not part of POSIX standards and not provided by uClibc or some other standard C libraries. However, it is possible to link against a breakout argp library. One is provided at http://www.lysator.liu.se/~nisse/misc/ This patch tests if libc provides argp otherwise it adds the linker flag -largp where needed in the build system. Signed-off-by: Anthony G. Basile <blueness@gentoo.org> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
* libdw: Undefined behavior in get_sleb128_step.Mark Wielaard2015-04-282-4/+27
| | | | | | | | | | gcc -fsanitize=undefined pointed out that for too big sleb128 values we could shift into the sign bit. So for sleb128 values that have to fit in a (signed) int64_t variable reduce the max number of steps by one. https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: Don't overflow stack with user defined macro attributes array.Mark Wielaard2015-04-222-4/+31
| | | | | | | | | | | | In theory user defined debug macros can have an arbitrary number of arguments. Don't allocate them all on stack. If there are more than 8 (arbitrary number, but no sane macro should have more arguments), then dynamically allocate and free the attributes. Found by gcc -fsanitize=undefined. Which pointed out the nforms could be zero, creating an empty vla (which could cause undefined behavior). Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Do not reject type units in dwarf_getsrcfiles and dwarf_getsrclinesPetr Machata2015-04-035-9/+32
| | | | Signed-off-by: Petr Machata <pmachata@redhat.com>
* Publish known-dwarf.hPetr Machata2015-03-312-2/+7
| | | | | | | | | | | | | - Make the macro names properly scoped (DWARF_ALL_KNOWN_* and DWARF_ONE_KNOWN_*). - Simplify the calling convention: don't keep track of the comment associated with the enumerator, always use the non-_DESC DWARF_ONE_KNOWN_* callback. - Install known-dwarf.h alongside libdw.h and others. Signed-off-by: Petr Machata <pmachata@redhat.com>
* libdw: Add DWARF5/GCC5 DW_LANG_Fortran03 and DW_LANG_Fortran08 support.Mark Wielaard2015-02-163-0/+10
| | | | | | | | | | | GCC5 adds support for the new Fortran 2003 and 2008 standard DWARF5 language codes. Add them to dwarf.h and handle them in dwarf_aggregate_size. http://dwarfstd.org/ShowIssue.php?issue=141121.1 Also documented at https://fedorahosted.org/elfutils/wiki/DwarfExtensions Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: Add support for DWARF5/GCC5 DW_TAG_atomic_type.Mark Wielaard2015-02-164-2/+13
| | | | | | | | | | | GCC5 adds support for the new C11 _Atomic DWARF5 DW_TAG_atomic_type qualifier. Add it to dwarf.h and handle it in dwarf_peel_type. http://dwarfstd.org/ShowIssue.php?issue=131112.1 Also documented at https://fedorahosted.org/elfutils/wiki/DwarfExtensions Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: ensure read_encoded_value's value is setJosh Stone2015-02-112-1/+5
| | | | | | | | | | | | With CFLAGS='-Og -g', F21 gcc hits -Werror=maybe-uninitialized in read_encoded_value at "*result += value". It's fine with -O2/-O0. In particular it seems to care about the __libdw_cfi_read_address_inc calls. By my inspection, the only way those don't set value are for error cases, which will then return immediately. This patch just sets value = 0 to begin with, so gcc is always convinced it's fine. Signed-off-by: Josh Stone <jistone@redhat.com>
* dwarf_ranges: do not request base address attributes if not necessaryPetr Machata2015-02-112-9/+19
| | | | | | | | - Instead of bailing out at iteration start, we remember the base-address-selecting attributes were not seen, and then bail out later if no base address selection entry has been seen. Signed-off-by: Petr Machata <pmachata@redhat.com>
* libdw: Search for the last matching address with dwarf_getsrc_die.Mark Wielaard2015-01-162-25/+27
| | | | | | | | | | 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>
* libdw: Robustify eh_frame_hdr and encoded-values reading.Mark Wielaard2015-01-155-23/+104
| | | | | | | | | 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>
* libdw: Check DW_AT_sibling attribute offset is after current DIE.Mark Wielaard2015-01-152-2/+10
| | | | | | | | | | 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>
* libdw: Check register number in CFI isn't insanely large.Mark Wielaard2015-01-152-1/+15
| | | | | | | | | | 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>
* libdw: Add missing size check to parse_eh_frame_hdr.Mark Wielaard2015-01-152-8/+10
| | | | | | | | | | 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>
* libdw: Handle NULL dbg for call_ref, GNU_implicit_pointer and addr DW_OPs.Mark Wielaard2015-01-152-10/+38
| | | | | | | | | | | | | 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>
* libdw: fix offset for sig8 lookup in dwarf_formref_dieJason P. Leasure2015-01-142-1/+6
| | | | | | | 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>
* libdw: Check sibling attribute offset still falls inside CU data.Mark Wielaard2015-01-122-0/+12
| | | | | | Found with afl-fuzz. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: Prevent infinite recursion when processing DW_TAG_imported_unit.Mark Wielaard2015-01-127-15/+51
| | | | | | | | | | 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>
* avoid scary command outputUlrich Drepper2014-12-182-1/+5
| | | | | | 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.
* libdw: Check diridx is valid under DW_LNE_define_file in dwarf_getsrclines.Mark Wielaard2014-12-172-0/+10
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: Make sure there is enough space to read offset in dwarf_getpubnames.Mark Wielaard2014-12-172-0/+8
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* readelf,libdw: Correct .debug_line overflow check for unit_length.Mark Wielaard2014-12-172-2/+7
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: dwarf_getpubnames set error to DWARF_E_NO_ENTRY for zero entries.Mark Wielaard2014-12-172-2/+2
| | | | | | | 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>
* libdw: Add bounds checking to dwarf_getpubnames.Mark Wielaard2014-12-172-3/+20
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: Unroll the first get_sleb128 step to help the compiler optimize.Mark Wielaard2014-12-172-3/+11
| | | | | | | The common case is a single-byte. So no extra (max len) calculation is necessary then. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: pre-compute leb128 loop limitsJosh Stone2014-12-172-2/+21
| | | | Signed-off-by: Josh Stone <jistone@redhat.com>
* libdw: Add get_uleb128 and get_sleb128 bounds checking.Mark Wielaard2014-12-1721-132/+270
| | | | | | | | | | | 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>
* libdw: Make sure all attributes come with a (fake) CU for bound checks.Mark Wielaard2014-12-1714-54/+139
| | | | | | | | | | 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>
* libdw: Make sure end of next cu doesn't overflow section data size.Mark Wielaard2014-12-162-0/+10
| | | | | | | 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>
* Guard against 64bit unsigned wrap around in (int) compare functions.Mark Wielaard2014-12-162-1/+8
| | | | | | | | | 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>
* libdw: Make srclines use a stable sortJosh Stone2014-12-122-21/+38
| | | | | | | 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>
* libdw: save startp/endp boundaries in Dwarf_CUJosh Stone2014-12-117-11/+25
| | | | | | | 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>
* libdw: optimize dwarf_hasattr to just look at abbrevJosh Stone2014-12-112-4/+42
| | | | | | | | 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>
* libdw: unify die->abbrev lookupsJosh Stone2014-12-116-70/+64
| | | | | | | 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>
* libdw: Add overflow checking to __libdw_form_val_len.Mark Wielaard2014-12-116-31/+76
| | | | | | | | 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>
* Change calling convention of dwarf_getmacros to allow opcode 0xffPetr Machata2014-12-103-85/+123
| | | | | | | | | 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>
* Add configure --disable-textrelcheck option to enable CC=afl-fuzz on 32bit.Mark Wielaard2014-12-042-1/+5
| | | | | | | | | | | | | | | 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>
* libdw: Initialize variables in getcfi_gnu_eh_frame.Mark Wielaard2014-12-032-3/+8
| | | | | | | | | 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>
* readelf, libdw: Guard against divide by zero line_range in .debug_line.Mark Wielaard2014-11-262-0/+11
| | | | | | | For DW_LNS_const_add_pc and special opcodes don't accept line_range being zero. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdw: Always check __libdw_find_attr return value.Mark Wielaard2014-11-264-7/+13
| | | | | | | __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>
* libdw: Don't assert in __libdw_getabbrev when seeing bad DWARF.Mark Wielaard2014-11-262-3/+13
| | | | Signed-off-by: Mark Wielaard <mjw@redhat.com>
* dwarf.h: Add DW_LANG_C11, DW_LANG_C_plus_plus_11 and DW_LANG_C_plus_plus_14.Mark Wielaard2014-11-264-1/+21
| | | | | | | | | | | | | | 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>
* dwarf.h: Add DW_AT_noreturn.Mark Wielaard2014-11-262-0/+7
| | | | | | | | | | | 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>
* libdw: Fix dwarf_getsrclines.c 32bit compile error.Mark Wielaard2014-11-112-1/+8
| | | | | | | | __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>
* Support .debug_macroPetr Machata2014-11-1014-710/+1528
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - This code is based on the following proposal: http://www.dwarfstd.org/ShowIssue.php?issue=110722.1 - dwarf_getmacros serves either of .debug_macinfo or .debug_macro transparently, but if the latter uses opcode 0xff, it bails out with an error. The reason is that in .debug_macro, 0xff is a custom code that can mean anything, while in .debug_macinfo there's fixed semantics associated with 0xff. - dwarf_getmacros_off is a new interface used for requesting iteration through transparently included units. - dwarf_macro_getparamcnt and dwarf_macro_param are new interfaces used for requesting number of parameters of an opcode and individual parameters. dwarf_macro_getsrcfiles is a new interface used for requesting a file part of .debug_line unit associated with macro unit that the opcode comes from. - The existing interfaces dwarf_macro_opcode, dwarf_macro_param1 and dwarf_macro_param2 remain operational for old- as well as new-style Dwarf macro sections, if applicable. - dwarf_getsrclines was made into a light wrapper around a worker function that loads line unit given its offset. The worker also caches loaded units in an offset-keyed search tree, so that we don't end up re-reading units even though they were read in a different domain (e.g. a macro unit request can prime cache for later CU lookup). dwarf_macro_getsrcfiles calls the worker function under covers. Signed-off-by: Petr Machata <pmachata@redhat.com>