summaryrefslogtreecommitdiff
path: root/libdwfl
Commit message (Collapse)AuthorAgeFilesLines
* debuginfod: Make sure there is only one typedef for debuginfod_clientMark Wielaard2023-02-062-0/+8
| | | | | | | | | | | | Both debuginfod.h and libdwfl.h have a simple typedef for struct debuginfod_client. Some compilers pedantically warn when including both headers that such typedefs are only officially supported in C11. So guard them with _ELFUTILS_DEBUGINFOD_CLIENT_TYPEDEF to make them happy. https://sourceware.org/bugzilla/show_bug.cgi?id=30077 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: add check for elf_memory return valueAleksei Vetrov2023-01-261-0/+4
| | | | | | | elf_memory call in __libdw_open_elf_memory can return NULL. It was not checked and led to the null pointer dereference. Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
* Fix typos from codespellSam James2023-01-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | debuginfod/ChangeLog: * debuginfod-client.c: Typo simultaniously. doc/ChangeLog: * debuginfod.8: Typo succesfully. lib/ChangeLog: * dynamicsizehash_concurrent.c: Typo modul. * system.h: Typo dependend. libdwfl/ChangeLog: * open.c: Typo non-existant. src/ChangeLog: * nm.c: Typo Covert. * strings.c: Likewise. tests/ChangeLog: * elfstrmerge.c: Typo outselves. * run-debuginfod-extraction.sh: Typo accidentially. * run-debuginfod-fd-prefetch-caches.sh: Likewise. Signed-off-by: Sam James <sam@gentoo.org>
* libdwfl: Don't undef _Mark Wielaard2022-12-225-4/+7
| | | | | | | A couple of files undefined _, which is defined in lib/eu-config.h as gettext helper macro. This seems unnecessary and arbitrary. Signed-off-by: Mark Wielaard <mark@klomp.org>
* Do not use relative include paths in library files.Mark Wielaard2022-12-2021-26/+48
| | | | | | | | | Rely on include dirs being set up correctly. Setup libdw AM_CPPFLAGS to include libebl directory. In libdwfl note that debuginfod.h is a generated file in the builddir. Only include it in the one file debuginfod-client.c that really needs it. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Read no more than required in dwfl_segment_report_moduleGavin Li2022-12-132-25/+8
| | | | | | | | | | | | | | | Since read_portion and the standard dwfl_elf_phdr_memory_callback functions make sure to read at least minread bytes there is no need for dwfl_segment_report_module to check and adjust the data to the actual buffer size read. Reading beyond the end of the expected data size (if the buffer read is much larger) actually causes issues when passing the data to elfXX_xlatetom() because it is possible that src->d_size is not a multiple of recsize (for ELF_T_DYN, recsize is 16 while the minimum required alignment is 8), causing elfXX_xlatetom() to return ELF_E_INVALID_DATA. Signed-off-by: Gavin Li <gavin@matician.com> Signed-off-by: Mark Wielaard <mark@klomp.org>
* lib{asm,cpu,dw,dwfl,dwelf}: Move platform depended include into system.hYonggang Luo2022-10-2818-31/+21
| | | | Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
* libelf/libdwfl: Remove LIB_SYSTEM_H define in lib{elf,dwfl}_crc32.cYonggang Luo2022-10-272-1/+4
| | | | | | | | | | | | | rationale: https://sourceware.org/bugzilla/show_bug.cgi?id=21001 If we don't remove this macro, when try #include <system.h> in libdw/memory-access.h wont' take effect because "#define LIB_SYSTEM_H 1" The compile error: ./../libdw/memory-access.h:390:12: error: implicit declaration of function ‘bswap_32’ [-Werror=implicit-function-declaration] Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
* Strip __ prefix from __BYTE_ORDER __LITTLE_ENDIAN and __BIG_ENDIANYonggang Luo2022-10-172-1/+6
| | | | | | | | __BYTE_ORDER, __LITTLE_ENDIAN and __BIG_ENDIAN are defined by the gcc/clang preprocessor. BYTE_ORDER, LITTLE_ENDIAN and BIG_ENDIAN are defined in <endian.h>. Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
* Move the #include <libintl.h> into eu-config.hYonggang Luo2022-10-162-2/+0
| | | | | | | | | | So we do not need include in each file. And indeed the macro #define _(Str) dgettext ("elfutils", Str) access libintl function dgettext, so it's make more sense #include <libintl.h> in file eu-config.h Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
* libdwfl: add dwfl_report_offline_memoryAleksei Vetrov2022-10-165-4/+75
| | | | | | | | | | | | | This method allows to read and report ELF from memory instead of opening a file. That way arbitrary memory can be worked with, e.g. when coming from a stream without the need to persist. Another useful application is for fuzzing, because fuzzers might be able to track accesses to the memory and change the fuzzer input to cover more edge cases through more targeted input. Hence, add a new function along with a test case. Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
* libdwfl: Add new function dwfl_frame_regDi Chen2022-07-316-29/+56
| | | | | | | | | | | | | | Dwfl has most of the infrastructure to keep the full unwind state, including the state of unwound registers per frame using Dwfl_Thread_Callbacks. But there is no public API to access the state, except for the PC (dwfl_frame_pc). This commit adds a new function dwfl_frame_reg to get the value of the DWARF register number in the given frame. https://sourceware.org/bugzilla/show_bug.cgi?id=28579 Signed-off-by: Di Chen <dichen@redhat.com>
* libdwfl: Rewrite reading of ar_size in elf_begin_randMark Wielaard2022-07-292-10/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With GCC 12.1.1, glibc 2.35, -fsanitize=undefined and -D_FORTIFY_SOURCE=3 we get the following error message: In file included from /usr/include/ar.h:22, from ../libelf/libelfP.h:33, from core-file.c:31: In function ‘pread’, inlined from ‘pread_retry’ at ../lib/system.h:188:21, inlined from ‘elf_begin_rand’ at core-file.c:86:16, inlined from ‘core_file_read_eagerly’ at core-file.c:205:15: /usr/include/bits/unistd.h:74:10: error: ‘__pread_alias’ writing 58 or more bytes into a region of size 10 overflows the destination [-Werror=stringop-overflow=] 74 | return __glibc_fortify (pread, __nbytes, sizeof (char), | ^~~~~~~~~~~~~~~ /usr/include/ar.h: In function ‘core_file_read_eagerly’: /usr/include/ar.h:41:10: note: destination object ‘ar_size’ of size 10 41 | char ar_size[10]; /* File size, in ASCII decimal. */ | ^~~~~~~ /usr/include/bits/unistd.h:50:16: note: in a call to function ‘__pread_alias’ declared with attribute ‘access (write_only, 2, 3)’ 50 | extern ssize_t __REDIRECT (__pread_alias, | ^~~~~~~~~~ cc1: all warnings being treated as errors The warning disappears when dropping either -fsanitize=undefined or when using -D_FORTIFY_SOURCE=2. It looks like a false positive. But I haven't figured out how/why it happens. The code is a little tricky to proof correct though. The ar_size field is a not-zero terminated string ASCII decimal, right-padded with spaces. Which is then converted with strtoll. Relying on the fact that the struct ar_hdr is zero initialized, so there will be a zero byte after the ar_size field. Rewrite the code to just use a zero byte terminated char array. Which is much easier to reason about. As a bonus the error disappears. Signed-off-by: Mark Wielaard <mark@klomp.org>
* dwfl_get_debuginfod_client: add dummy parameter for --disable-libdebuginfodShahab Vahedi2022-07-182-1/+6
| | | | | | | | | | | | | | | | | | | | | Since the stub version of "dwfl_get_debuginfod_client" doesn't name its parameter, building elfuitls fails on a system with gcc 10.2.1: ----------------------------------------------------------------------------- $ ./configure ... --disable-libdebuginfod $ make Making all in libdwfl CC debuginfod-client.o /src/libdwfl/debuginfod-client.c: In function 'dwfl_get_debuginfod_client': /src/libdwfl/debuginfod-client.c:145:29: error: parameter name omitted 145 | dwfl_get_debuginfod_client (Dwfl *) | ^~~~~~ make[2]: *** [Makefile:707: debuginfod-client.o] Error 1 ----------------------------------------------------------------------------- This fixes the issue by providing a name for the unused parameter. Signed-off-by: Shahab Vahedi <shahab@synopsys.com>
* Move dwfl_get_debuginfod_client to ELFUTILS_0.188Mark Wielaard2022-07-132-2/+10
| | | | | | | 0.187 was already released, so add new function to 0.188. Also add NEWS entry and INTUSE. Signed-off-by: Mark Wielaard <mark@klomp.org>
* Introduce public dwfl_get_debuginfod_client APIMilian Wolff2022-07-135-9/+35
| | | | | | | | | | | | | | | | | Dwfl can use debuginfod internally, which was so far totally opaque to the outside. While the functionality is great for users of the dwfl API, the long wait times induced by downloading of data over debuginfod lead to complaints by endusers. To offer them a bit more insight into the internal ongoings, one can now use e.g. `debuginfod_set_progressfn` on the handle returned by `dwfl_get_debuginfod_client` to report download progress. Rename get_client to dwfl_get_debuginfod_client and make it public. Unconditionally compile debuginfod-client.c and stub the new public function and always return NULL when debuginfod integration was disabled. Signed-off-by: Milian Wolff <mail@milianw.de>
* libdwfl: Update docs and nonnull attributes for dwfl_module_addrinfoMark Wielaard2022-05-272-16/+21
| | | | | | | | Make clear that both the offset and sym arguments cannot be NULL. https://bugzilla.redhat.com/show_bug.cgi?id=1986555 Signed-off-by: Mark Wielaard <mark@klomp.org>
* debuginfod, libdwfl: Initialize libcurl and dlopen debuginfod-client lazilyMark Wielaard2022-04-252-3/+18
| | | | | | | | | | | | | We used to go out of our way to initialize libcurl early before any other thread/code was running. But this meant that we might pay startup cost, which under FIPS is significant, even for code that never uses libdebuginfod or TLS libcurl connections. Although curl_global_init itself isn't thread-safe we can use pthread_once to make sure we don't race against ourselves. This still means we might race against any application code that might use libcurl. But we can assume they will have called curl_global_init before calling dwfl_begin or debuginfod_begin. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Use memcpy to assign image header field valuesMark Wielaard2022-03-182-6/+23
| | | | | | | | The values in the kernel image header aren't properly aligned. Use memcpy and the LE16, LE32 macros to assign and check the values. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Close ar members when they cannot be processed.Mark Wielaard2022-03-182-2/+11
| | | | | | | | | | When reporting ar members they should be closed when they cannot be processed. A comment in offline.c said that process_file called elf_end if it returned NULL. But this is incorrect. And other places that call process_file do call elf_end explicitly when it returns NULL. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Declare possible zero sized arrays only when non-zeroMark Wielaard2022-01-062-2/+7
| | | | | | | | | | The gcc undefined sanitizer complains when seeing a zero sized array declaration. Move the declaration to the point in the code where we know they aren't zero sized. https://sourceware.org/bugzilla/show_bug.cgi?id=28720 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Handle unaligned Dyns in dwfl_segment_report_moduleMark Wielaard2022-01-062-0/+17
| | | | | | | | | | | The xlate functions only handle correctly aligned buffers. But they do handle src == dest. So if the source buffer isn't aligned correctly just copy it first into the destination (which is already correctly aligned). https://sourceware.org/bugzilla/show_bug.cgi?id=28720 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Fix overflow check in link_map.c read_addrsMark Wielaard2022-01-062-1/+6
| | | | | | | | | The buffer_available overflow check wasn't complete. Also check nb isn't too big. https://sourceware.org/bugzilla/show_bug.cgi?id=28720 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Calculate addr to read by hand in link_map.c read_addrs.Mark Wielaard2022-01-042-6/+9
| | | | | | | | | | The gcc undefined sanitizer doesn't like the trick we use to calculate the (possibly) unaligned addresses to read. So calculate them by hand as unsigned char pointers. https://sourceware.org/bugzilla/show_bug.cgi?id=28720 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Call xlatetom on aligned buffers in dwfl_link_map_reportMark Wielaard2022-01-042-1/+23
| | | | | | | | | | Make sure that when calling xlatetom for Phdrs and Dyns in dwfl_link_map_report the input buffer is correctly aligned by calling memcpy and setting in.d_buf to out.d_buf. https://sourceware.org/bugzilla/show_bug.cgi?id=28720 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure dwfl_elf_phdr_memory_callback returns at least minreadMark Wielaard2022-01-042-1/+10
| | | | | | | | | | | The callers of dwfl_elf_phdr_memory_callback assume at least minread bytes are read and available. Make sure to check start is smaller than elf->maximum_size before reading more. Return false if end - start is smaller than minread. Found by afl-fuzz. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Always clean up build_id.memoryMark Wielaard2021-12-212-14/+18
| | | | | | | | | | | There was a small memory leak if an error was detected in some places in dwfl_segment_report_module after the build_id.memory was alredy allocated. Fix this by moving initialization of struct elf_build_id early and always free the memory, if not NULL, at exit. https://sourceware.org/bugzilla/show_bug.cgi?id=28685 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Handle unaligned Nhdr in dwfl_segment_report_moduleMark Wielaard2021-12-202-0/+17
| | | | | | | | | | | The xlate functions only handle correctly aligned buffers. But they do handle src == dest. So if the source buffer isn't aligned correctly just copy it first into the destination (which is already correctly aligned). https://sourceware.org/bugzilla/show_bug.cgi?id=28715 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Handle unaligned Phdr in dwfl_segment_report_moduleMark Wielaard2021-12-202-0/+18
| | | | | | | | | The xlate functions only handle correctly aligned buffers. But they do handle src == dest. So if the source buffer isn't aligned correctly just copy it first into the destination (which is already correctly aligned). Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Handle unaligned Ehdr in dwfl_segment_report_moduleMark Wielaard2021-12-192-0/+19
| | | | | | | | | The xlate functions only handle correctly aligned buffers. But they do handle src == dest. So if the source buffer isn't aligned correctly just copy it first into the destination (which is already correctly aligned). Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Rewrite GElf_Nhdr reading in dwfl_segment_report_moduleMark Wielaard2021-12-192-35/+49
| | | | | | | | Make sure that the notes filesz is not too big. Rewrite reading of the notes to check for overflow at every step. Also limit the size of the buildid bytes. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure dyn_filesz has a sane sizeMark Wielaard2021-12-192-0/+9
| | | | | | | In dwfl_segment_report_module dyn_filesz should be able to hold at least one Elf_Dyn element, and not be larger than possible. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure that ph_buffer_size has room for at least one phdrMark Wielaard2021-12-192-1/+11
| | | | | | | dwfl_segment_report_module might otherwise try to handle half a phdr taking the other half from after the buffer. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure the note len increases each iterationMark Wielaard2021-12-182-1/+6
| | | | | | | | In dwfl_segment_report_module we have an overflow check when reading notes, but we could still not make any progress if the number of bytes read (len) didn't increase at all. Check len > last_len. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make dwfl_segment_report_module aware of maximum Elf sizeMark Wielaard2021-12-184-2/+13
| | | | | | | | | | | At the end of dwfl_segment_report_module we might try to read in the whole contents described by a core file. To do this we first allocate a zeroed block of memory that is as big as possible. The core file however may describe much more loaded data than is actually available in the Elf image. So pass the maximum size so we can limit the amount of memory we reserve. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure note data is properly aligned.Mark Wielaard2021-12-182-1/+9
| | | | | | | | | | | In dwfl_segment_report_module the note data might not be properly aligned. Check that it is before accessing the data directly. Otherwise convert data so it is properly aligned. Also fix NOTE_ALIGN4 and NOTE_ALIGN8 to work correctly with long types. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure there is at least one phdrMark Wielaard2021-12-182-0/+9
| | | | | | The buffer read in needs to contain room for at least one Phdr. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure there is at least one dynamic entryMark Wielaard2021-12-182-0/+10
| | | | | | | The buffer read in needs to contain room for at least one Elf32_Dyn or Elf64_Dyn entry. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Add overflow check while iterating in dwfl_segment_report_moduleMark Wielaard2021-12-162-1/+10
| | | | | | | | | | While iterating the notes we could overflow the len variable if the note name or description was too big. Fix this by adding an (unsigned) overflow check. https://sourceware.org/bugzilla/show_bug.cgi?id=28654 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure phent is sane and there is at least one phdrMark Wielaard2021-12-162-2/+20
| | | | | | | | | | dwfl_link_map_report can only handle program headers that are the correct (32 or 64 bit) size. The buffer read in needs to contain room for at least one Phdr. https://sourceware.org/bugzilla/show_bug.cgi?id=28660 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Don't allocate more than SIZE_MAX in dwfl_segment_report_module.Mark Wielaard2021-12-122-0/+8
| | | | | | | | | | | | | | | | | | | | | | The code in dwfl_segment_report_module tries to allocate and fill in memory as described in a core file. Normally all memory in filled in through the (phdrs) memory_callback or the read_eagerly callback. If the last callback doesn't work we try to calloc file_trimmed_end bytes and then try to fill in the parts of memory we can from the core file at the correct offsets. file_trimmed_end is a GElf_Off which is an unsigned 64bit type. On 32bit systems this means when cast to a size_t to do an allocation might allocate truncated (much smaller) value. So make sure to not allocate more than SIZE_MAX bytes. It would be nice to have a better way to limit the amount of memory allocated here. A core file might describe really big memory areas for which it doesn't provide any data. In that case we really shouldn't calloc mega- or giga-bytes of zeroed out memory. Reported-by: Evgeny Vereshchagin <evvers@ya.ru> Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Don't try to convert too many dyns in dwfl_link_map_reportMark Wielaard2021-12-102-1/+19
| | | | | | | | When trying to read (corrupt) dynamic entries from a core file we only want to read and convert the entries we could read. Also make sure we don't try to allocate too bug a buffer. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Don't install an Elf handle in a Dwfl_Module twiceMark Wielaard2021-12-092-1/+6
| | | | | | | | | | | dwfl_segment_report_module can be called with the same module name, start and end address twice (probably because of a corrupt core file). In that case don't override the main.elf handle if it already exists. https://sourceware.org/bugzilla/show_bug.cgi?id=28655 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Don't trust e_shentsize in dwfl_segment_report_moduleMark Wielaard2021-12-092-2/+7
| | | | | | | | | | | | When calulating the possible section header table end us the actual size of the section headers (sizeof (Elf32_Shdr) or sizeof (Elf64_Shdr)), not the ELF header e_shentsize value, which can be corrupted. This prevents a posssible overflow, but we check the shdrs_end is sane later anyway. https://sourceware.org/bugzilla/show_bug.cgi?id=28659 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Make sure we know the phdr entry size before searching phdrs.Mark Wielaard2021-12-092-1/+5
| | | | | | | | | Without the program header entry size we cannot search through the phdrs. https://sourceware.org/bugzilla/show_bug.cgi?id=28657 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Don't try to convert too many bytes in dwfl_link_map_reportMark Wielaard2021-12-092-2/+21
| | | | | | | | | | When trying to read (corrupt) phdrs from a core file we only want to read and convert the bytes we could read. Also make sure we don't try to allocate too big buffers. https://sourceware.org/bugzilla/show_bug.cgi?id=28666 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Don't read beyond end of file in dwfl_segment_report_moduleMark Wielaard2021-12-082-1/+10
| | | | | | | | | The ELF might not be fully mapped into memory (which probably means the phdrs are bogus). Don't try to read beyond what we have in memory already. Reported-by: Evgeny Vereshchagin <evvers@ya.ru> Signed-off-by: Mark Wielaard <mark@klomp.org>
* dwfl: fix potential overflow when reporting on kernel modulesMatthias Maennich2021-11-202-1/+6
| | | | | | | | | | | | | | | | | | dwfl_linux_kernel_report_modules_ has an outstanding ancient bug when reading kernel module information from a modules list file. The target buffer for the module name was sized too small to hold potential values. Fix that by increasing the value to account for the null termination. In practice, this unlikely ever happened, but it now got diagnosed by LLVM as part of a stricter -Wfortify-source implementation [1]: libdwfl/linux-kernel-modules.c:1019:7: error: 'sscanf' may overflow; destination buffer in argument 3 has size 128, but the corresponding specifier may require size 129 [-Werror,-Wfortify-source] modname, &modsz, &modaddr) == 3) [1] https://github.com/llvm/llvm-project/commit/2db66f8d48beeea835cb9a6940e25bc04ab5d941 Suggested-by: Paul Pluzhnikov <ppluzhnikov@google.com> Signed-off-by: Matthias Maennich <maennich@google.com>
* Improve building with LTOAlexander Miller2021-11-084-6/+13
| | | | | | | | | | | | | | Use symver attribute for symbol versioning instead of .symver assembler directive when available. Convert to use double @ syntax for default version in all cases (required when using the attribute). Add the attributes externally_visible, no_reorder if available when using assembler directives to improve the situation for < gcc-10. This is not 100% reliable, though; -flto-partition=none may still be needed in some cases. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24498 Signed-off-by: Alexander Miller <alex.miller@gmx.de>
* Remove redundant casts of memory allocating functions returning void *Dmitry V. Levin2021-09-092-1/+6
| | | | | | | Return values of functions returning "void *", e.g. calloc, malloc, realloc, xcalloc, xmalloc, and xrealloc, do not need explicit casts. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>