summaryrefslogtreecommitdiffstats
path: root/libdwfl (follow)
Commit message (Collapse)AuthorAgeFilesLines
* libdwfl: Add new function dwfl_frame_regDi Chen8 days6-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 Wielaard9 days2-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>
* libdwfl: fix potential NULL pointer dereference when reading link mapOmar Sandoval2021-06-102-1/+5
| | | | | | | | | | | | When read_addrs() was moved into file scope, there was a mistake in converting "buffer" from a closure variable to a parameter: we are checking whether the pointer argument is NULL, not whether the buffer itself is NULL. This causes a NULL pointer dereference when we try to use the NULL buffer later. Fixes: 3bf41d458fb6 ("link_map: Pull read_addrs() into file scope") Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* Come up with startswith function.Martin Liska2021-05-126-10/+26
| | | | | | | New function in system.h that returns true if a string has a given prefix, false otherwise. Use it in place of strncmp. Signed-off-by: Martin Liška <mliska@suse.cz>
* libdwfl: use GNU strerror_r only when available.Érico Rolim2021-02-052-1/+20
| | | | | | | | | | Some C libraries don't provide the GNU version of strerror_r, only the XSI-compliant one. We use the GNU version when available, since it fits the code better, and otherwise use the XSI-compliant one. https://sourceware.org/bugzilla/show_bug.cgi?id=21010 Signed-off-by: Érico Rolim <erico.erc@gmail.com>
* elf-from-memory: Refactor to get rid of nested functionTimm Bäder2021-01-282-65/+56
| | | | | | | Try to unify the 32/64 bit code paths and get rid of the nested handle_segment() this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* elf-from-memory: Restructure code to get rid of nested handle_segment()Timm Bäder2021-01-282-47/+41
| | | | | | | | Use one loop for both 32 and 64 bit case. This allows for only one call site of the old handle_segment(), which we can then inline into the for loop. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* Consistently define _(Str) using dgettext ("elfutils", Str)Dmitry V. Levin2020-12-163-6/+5
| | | | | | | | | | | | | | Move the definition of _(Str) macro to lib/eu-config.h which already provides a definition of N_(Str) macro. Since lib/eu-config.h is appended to config.h, it is included into every compilation unit and therefore both macros are now universally available. Remove all other definitions of N_(Str) and _(Str) macros from other files to avoid conflicts and redundancies. The next step is to replace all uses of gettext(Str) with _(Str). Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* libdwfl: fix spelling typos in comments and ChangeLogDmitry V. Levin2020-12-125-11/+18
| | | | | | | | | | | | | | adresses -> addresses boundery -> boundary explictly -> explicitly fo -> for layed -> laid partical -> particular setion -> section substract -> subtract wil -> will Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* link_map: Pull read_addrs() into file scopeTimm Bäder2020-12-102-47/+62
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* link_map: Pull release_buffer() into file scopeTimm Bäder2020-12-102-16/+37
| | | | | | | Get rid of a nested function this way. Add a memory_closure struct to keep the functions clean. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* libdwfl: switch to DEBUGINFOD_SONAME, remove libdebuginfod.so fallbackDmitry V. Levin2020-12-092-4/+7
| | | | | | | | | | Since DEBUGINFOD_SONAME is as good as ("libdebuginfod-" VERSION ".so") for dlopen, switch to use the name which is a part of the API. Given that DEBUGINFOD_SONAME is always available now, remove the no longer needed fall back to dlopen of "libdebuginfod.so". Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* link_map: Inline consider_phdr() into only callerTimm Bäder2020-12-062-40/+37
| | | | | | This gets rid of the tested function and is shorter. Signed-off-by: Mark Wielaard <mark@klomp.org>