Noah Sanci [Fri, 13 May 2022 18:32:27 +0000 (14:32 -0400)]
PR28577: Make run-debuginfod-fd-prefetch-caches.sh test something
Update to the run-debuginfod-fd-prefetch to make the test more
sound.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Noah Sanci [Thu, 2 Jun 2022 18:26:46 +0000 (14:26 -0400)]
Added debuginfod.service.8 manual page.
Signed-off-by: Noah Sanci <nsanci@redhat.com>
Mark Wielaard [Thu, 2 Jun 2022 15:36:39 +0000 (17:36 +0200)]
tests: Disable run-debuginfod-federation-metrics.sh for old libmicrohttpd
On really old libmicrohttpd the run-debuginfod-federation-metrics.sh
test will crash debuginfod after too many file descriptors have been
used. libmicrohttpd looses track of the state and aborts instead of
producing an error. Just disable the testcase on these very old versions.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 15 May 2022 19:53:41 +0000 (21:53 +0200)]
libdwfl: Update docs and nonnull attributes for dwfl_module_addrinfo
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>
Mark Wielaard [Sun, 8 May 2022 19:16:10 +0000 (21:16 +0200)]
debuginfod: update mtime of interval_path as early as possible
Call utime on interval_path file as soon as the thread is committed to
cleanup the cache files. This will prevent other threads trying to
also commit to cleaning the cache files. Having multiple threads try
to clean the cache simultaniously doesn't improve cleanup speed
because the threads will try to delete the files in the same order.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 8 May 2022 17:27:48 +0000 (19:27 +0200)]
debuginfod: Remove debuginfod_init_cache
debuginfod_init_cache would create all config files if they didn't
exist yet. It always made two stat calls. Then debuginfod_clean_cache
would call debuginfod_config_cache which did the same checks and
created any missing config files. Just make sure the cache_path
directory exists and remove debuginfod_init_cache before calling
debuginfod_clean_cache.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 8 May 2022 21:55:19 +0000 (23:55 +0200)]
debuginfod: Make sure debuginfod_config_cache always returns valid stat
If the condig file which value was requested from
debuginfod_config_cache didn't exist yet, stat would fail and no valid
struct stat would be returned even when the file was correctly
created. Fix this by always using O_CREAT to open the file, and reuse
that file descriptor to call fstat and for either writing the default
value or reading the config file value.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 8 May 2022 08:59:52 +0000 (10:59 +0200)]
debuginfod: Always request servname from getnameinfo for conninfo.
When getting the connection info getnameinfo is called getting the
hostname and servname except when the sockaddr is a pure ipv6
address. In that last case only hostname is requested. Since servname
is stack allocated and not initialized it might contain garbage which
is then put in the log. Just always request both hostname and servname
with NI_NUMERICHOST | NI_NUMERICSERV.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 8 May 2022 09:00:42 +0000 (11:00 +0200)]
strip: Add more NULL check
When gelf_getshdr, gelf_getrela, gelf_getrel or gelf_getsymshndx
return NULL it is an internal error which we want to report instead of
crashing.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 9 May 2022 16:47:45 +0000 (18:47 +0200)]
libdw: Add sanity check to store_implicit_value
Don't just skip the block length, but check it is equal to the
op->number that we are going to use as length.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 9 May 2022 16:20:02 +0000 (18:20 +0200)]
debuginfod: Check all curl_easy_setopt calls
curl_easy_setup can fail for various reasons. Add a curl_easy_setopt_ck
macro to check all curl_easy_setopt calls and provides a human readable
error message in verbose mode.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 9 May 2022 15:32:24 +0000 (17:32 +0200)]
debuginfod: Check result of curl_easy_getinfo in debuginfod_write_callback
This was the only place in debuginfod-client.c where we didn't check
the result of curl_easy_getinfo. Just check it to make things consistent.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Tue, 10 May 2022 10:31:04 +0000 (12:31 +0200)]
elfcompress: Add sanity checks to make sure to not override variable
The process_file code is a little tricky. Add sanity checks to make
sure shstrtab_name, shstrtab_newname and symstrents are only set once.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Noah Sanci [Fri, 13 May 2022 14:27:29 +0000 (10:27 -0400)]
PR28577: run-debuginfod-fd-prefetch-caches.sh now tests something
run-debuginfod-fd-prefetch-caches.sh now tests the maximum fd
and mb values of prefetch and fd (least recently used) caches.
Signed-off-by: Noah Sanci <nsanci@redhat.com>
Mark Wielaard [Thu, 5 May 2022 22:29:28 +0000 (00:29 +0200)]
debuginfod: Use MHD_USE_EPOLL for libmicrohttpd version 0.9.51 or higher
Also disable MHD_USE_THREAD_PER_CONNECTION when using MHD_USE_EPOLL.
https://sourceware.org/bugzilla/show_bug.cgi?id=29123
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 5 May 2022 21:59:57 +0000 (23:59 +0200)]
debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails
On a systems that have ipv6 disabled debuginfod doesn't start up
anymore because libhttpd MHD_USE_DUAL_STACK only works if it can
open an ipv6 socket. If MHD_start_daemon with MHD_USE_DUAL_STACK
fails try again without that flag set.
https://sourceware.org/bugzilla/show_bug.cgi?id=29122
Signed-off-by: Mark Wielaard <mark@klomp.org>
Frank Ch. Eigler [Mon, 9 May 2022 23:26:07 +0000 (19:26 -0400)]
debuginfod.8: Tweak wording of fdcache operation & parameters.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Noah Sanci [Mon, 9 May 2022 17:15:04 +0000 (13:15 -0400)]
PR29098: debuginfod - set default prefetch cache size to >0
Added default value to fdcache_prefetch_mds and fdcache_prefetch_fds.
Defaults to one half of corresponging fdcache's values.
Signed-off-by: Noah Sanci <nsanci@redhat.com>
foo
Frank Ch. Eigler [Wed, 4 May 2022 14:26:42 +0000 (10:26 -0400)]
PR29117: fix fd leak in debuginfod client for cache-miss files
Correct a nasty fd leak and a few less nasty leaks in the debuginfod
client code. The nasty one impacts long-lived apps such as debuginfod
servers.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Mark Wielaard [Tue, 3 May 2022 15:48:55 +0000 (17:48 +0200)]
config: Move the 2>/dev/null inside the sh -c '' quotes for profile.csh.
csh/tcsh would warn about "Ambiguous output redirect" if not done inside
the sh -c command.
Fix-by: наб <nabijaczleweli@nabijaczleweli.xyz>
https://bugzilla.redhat.com/show_bug.cgi?id=2080957
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 2 May 2022 23:35:53 +0000 (01:35 +0200)]
configure: Don't use valgrind and sanitize-undefined for make distcheck
make distcheck would always run with --enable-valgrind and
--enable-sanitize-undefined. Assuming the maintainer would run this just
before doing a release. But this makes distcheck really, really, really
slow. And we have various buildbots now that run various combinations
of valgrind, undefined and/or address sanitizer over every commit now.
This make make distcheck "fast" again.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 25 Apr 2022 16:27:33 +0000 (18:27 +0200)]
Prepare for 0.187
Set version to 0.187
Update NEWS and elfutils.spec.in
Set copyright year in configure.ac and printversion.
Regenerate po/*.po files.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Aaron Merey [Mon, 25 Apr 2022 15:10:46 +0000 (11:10 -0400)]
debuginfod: ensure X-DEBUGINFOD-SIZE contains file size
For archived files X-DEBUGINFOD-SIZE currently contains the size of the
archive instead of the size of the uncompressed file. Fix this.
Also add testcases to verify X-DEBUGINFOD-SIZE contains uncompressed
file sizes.
Signed-off-by: Aaron Merey <amerey@redhat.com>
Aaron Merey [Wed, 12 Jan 2022 03:07:55 +0000 (22:07 -0500)]
debuginfod: Use the debuginfod-size response header
In some cases the content-length header may not be available in order
to pass to a progressfn. If content-length isn't available then attempt
to get the size of the download from the debuginfod-size header instead.
It should be mentioned that if a compressed file (ex. gzip) is being
transferred, the actual transfer length will be less than debuginfod-size.
In this case debuginfod-size is a best-guess upper bound on the size of
the transfer.
Signed-off-by: Aaron Merey <amerey@redhat.com>
Mark Wielaard [Fri, 22 Apr 2022 21:36:30 +0000 (23:36 +0200)]
debuginfod, libdwfl: Initialize libcurl and dlopen debuginfod-client lazily
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>
Frank Ch. Eigler [Sun, 24 Apr 2022 23:39:47 +0000 (19:39 -0400)]
AUTHORS: Use generator script & git mailmap
We can compute a pretty complete list of contributors.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Mark Wielaard [Sun, 24 Apr 2022 17:42:29 +0000 (19:42 +0200)]
libelf: Check for mremap, elf_update needs it for ELF_C_RDWR_MMAP
Add a AC_CHECK_FUNCS configure check for mremap. Some systems like
KFreeBSD and the Hurd don't have it. Also add a configure warning
because without mremap elf_update will often fail when ELF_C_RDWR_MMAP
is used. ELF_C_RDWR_MMAP is an elfutils extension to libelf.
https://sourceware.org/bugzilla/show_bug.cgi?id=27337
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 24 Apr 2022 15:48:39 +0000 (17:48 +0200)]
elfclassify: Fix --no-stdin flag
The no-stdin option was using the wrong flag, classify_flag_stdin,
instead of classify_flag_no_stdin.
https://sourceware.org/bugzilla/show_bug.cgi?id=28724
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 24 Apr 2022 10:16:58 +0000 (12:16 +0200)]
debuginfod: Use MHD_USE_ITC in MHD_start_daemon flags
This prevents the "Server reached connection limit. Closing inbound
connection." issue we have been seeing in the
run-debuginfod-webapi-concurrency.sh testcase. From the manual:
If the connection limit is reached, MHD’s behavior depends a bit
on other options. If MHD_USE_ITC was given, MHD will stop
accepting connections on the listen socket. This will cause the
operating system to queue connections (up to the listen() limit)
above the connection limit. Those connections will be held until
MHD is done processing at least one of the active connections. If
MHD_USE_ITC is not set, then MHD will continue to accept() and
immediately close() these connections.
https://sourceware.org/bugzilla/show_bug.cgi?id=28708
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sat, 23 Apr 2022 01:20:17 +0000 (03:20 +0200)]
tests: Lower parallel lookups in run-debuginfod-webapi-concurrency.sh
With 100 parallel lookups we sometimes see:
Server reached connection limit. Closing inbound connection.
Lower parallel lookups to 64
Signed-off-by: Mark Wielaard <mark@klomp.org>
наб via Elfutils-devel [Wed, 19 Jan 2022 12:31:35 +0000 (13:31 +0100)]
config: simplify profile.*sh.in
1. Simplify needless sh -c "cat glob 2>/dev/null"
into cat glob 2>/dev/null under sh
and fix re-expansion/-e protection under csh
2. Use $( instead of ` under sh
3. Assign to DEBUGINFOD_URLS directly and either export it or unset it
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Mark Wielaard [Tue, 19 Apr 2022 09:25:42 +0000 (11:25 +0200)]
readelf: Define dyn_mem outside the while loop.
The GCC address sanitizer might complain otherwise:
stack-use-after-scope src/readelf.c:1787 in get_dyn_ents
Signed-off-by: Mark Wielaard <mark@klomp.org>
Di Chen [Tue, 1 Mar 2022 12:44:38 +0000 (20:44 +0800)]
readelf: Don't consider padding DT_NULL as dynamic section entry
when using `$ eu-readelf -d {FILE}` to get the number of dynamic
section entris, it wrongly counts the padding DT_NULLs as dynamic
section entries. However, DT_NULL Marks end of dynamic section.
They should not be considered as dynamic section entries.
https://sourceware.org/bugzilla/show_bug.cgi?id=28928
Signed-off-by: Di Chen <dichen@redhat.com>
Mark Wielaard [Sun, 17 Apr 2022 02:35:44 +0000 (04:35 +0200)]
libdw: Remove unused atomics.h include from libdwP.h
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 14 Apr 2022 11:26:57 +0000 (13:26 +0200)]
tests: Don't try to corrupt sqlite database during test.
In run-debuginfod-federation-sqlite.sh we used to try to corrupt
the sqlite database while the debuginfod server was running and
check it detected errors, but that was unreliably and slightly
dangerous since part of the database was already mapped into memory.
Instead trigger some some random activity, then trigger a shutdown.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Aaron Merey [Fri, 8 Apr 2022 23:37:11 +0000 (19:37 -0400)]
PR29022: 000-permissions files cause problems for backups
000-permission files currently used for negative caching can cause
permission problems for some backup software and disk usage checkers.
Fix this by using empty files for negative caching instead.
Also use each empty file's mtime to determine the time since
last download attempt instead of the cache_miss_s file's mtime.
https://sourceware.org/bugzilla/show_bug.cgi?id=29022
Tested-by: Milian Wolff <mail@milianw.de>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Mark Wielaard [Wed, 13 Apr 2022 15:23:57 +0000 (17:23 +0200)]
libdw: Add DWARF5 package file section identifiers, DW_SECT_*
This only adds the constants. There is no handling of DWARF
package file (dwp) files for now.
https://sourceware.org/bugzilla/show_bug.cgi?id=29048
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 7 Apr 2022 13:16:41 +0000 (15:16 +0200)]
config: Add versioned requires on libs/libelf for debuginfod-client
elfutils-debuginfod-client contains the debuginfod-client binary
which is uses libelf and libdw. Add explicit versioned requires
on elfutils-libs and elfutils-libelf so they will always be in sync
like done with all other inter sub package dependencies.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Aaron Merey [Wed, 6 Apr 2022 17:38:04 +0000 (13:38 -0400)]
debuginfod: Include "IPv4 IPv6" in server startup message
At startup debuginfod prints a message indicating the port which the
server is listening to. Prior to commit
4e4082be03 this message would
include "IPv4" and/or "IPv6"
[...] (48671/48671): started http server on IPv4 IPv6 port=8002
As of commit
4e4082be03 the IP versions have been removed from this
message. This change can cause issues in any applications that
parse the message for this information. Fix this by adding
"IPv4 IPv6" back to the message.
Signed-off-by: Aaron Merey <amerey@redhat.com>
Mark Wielaard [Fri, 1 Apr 2022 10:19:20 +0000 (12:19 +0200)]
libelf: Return already gotten Elf_Data from elf_getdata_rawchunk
elf_getdata_rawchunk keeps a list of Elf_Data_Chunk to track which
Elf_Data structures have already been requested. This allows elf_end
to clean up all internal data structures and the Elf_Data d_buf if
it was malloced.
But it didn't check if a chunk was already requested earlier. This
meant that if for example dwelf_elf_gnu_build_id was called multiple
times to lookup a build-id from the phdrs a new Elf_Data_Chunk was
created. This could slowly leak memory.
So also keep track of the offset from which the size and type of
the rawdata was requested so we can return existing data if it is
requested multiple times.
Note that the current cache is a simple linked list but the chain
is normally not that long. It is normally used to get chunks from
the phdrs, and there are normally less than 10.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Frank Ch. Eigler [Sun, 3 Apr 2022 23:42:48 +0000 (19:42 -0400)]
debuginfod: use single ipv4+ipv6 microhttpd daemon configuration
Use a single MHD_USE_DUAL_STACK mhd daemon. This way, the thread
connection pool is not doubled, saving memory and better matching user
expectations. A slight tweak to logging is required to pull IPv4
remote addresses back out, and also to allow IPv6 ::-laden address
forwarding through federation links.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Frank Ch. Eigler [Sun, 3 Apr 2022 16:47:17 +0000 (12:47 -0400)]
PR28708: debuginfod: use MHD_USE_EPOLL for microhttpd threads
Testing on s390x and other architectures indicates that this
configuration reduces thundering-herd wakeups and saturation of a
small number of threads. The run-debuginfod-webapi-concurrency.sh
test appears solid now.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Mark Wielaard [Tue, 29 Mar 2022 22:17:08 +0000 (00:17 +0200)]
libelf: Also copy/convert partial datastructures in xlate functions
The generated xlate functions can only convert full datastructures,
dropping any trailing partial data on the floor. That means some of
the data might be undefined. Just copy over the trailing bytes as
is. That data isn't really usable. But at least it is defined data.
https://sourceware.org/bugzilla/show_bug.cgi?id=29000
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 27 Mar 2022 19:08:36 +0000 (21:08 +0200)]
Introduce error_exit as a noreturn variant of error (EXIT_FAILURE, ...)
error (EXIT_FAILURE, ...) should be noreturn but on some systems it
isn't. This may cause warnings about code that should not be
reachable. So have an explicit error_exit wrapper that is noreturn
(because it calls exit explicitly). Use error_exit in all tools under
the src directory.
https://bugzilla.redhat.com/show_bug.cgi?id=2068692
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 24 Mar 2022 23:00:47 +0000 (00:00 +0100)]
elflint: Recognize NT_FDO_PACKAGING_METADATA
Signed-off-by: Mark Wielaard <mark@klomp.org>
Luca Boccassi [Sun, 21 Nov 2021 19:43:18 +0000 (19:43 +0000)]
libebl: recognize FDO Packaging Metadata ELF note
As defined on: https://systemd.io/COREDUMP_PACKAGE_METADATA/
this note will be used starting from Fedora 36. Allow
readelf --notes to pretty print it:
Note section [ 3] '.note.package' of 76 bytes at offset 0x2e8:
Owner Data size Type
FDO 57 FDO_PACKAGING_METADATA
Packaging Metadata: {"type":"deb","name":"fsverity-utils","version":"1.3-1"}
Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
Mark Wielaard [Thu, 24 Mar 2022 22:06:09 +0000 (23:06 +0100)]
libelf: Sync elf.h from glibc.
Adds EM_INTELGT, NT_ARM_TAGGED_ADDR_CTRL, NT_ARM_PAC_ENABLED_KEYS,
ELF_NOTE_FDO, NT_FDO_PACKAGING_METADATA and OpenRISC 1000 specific
relocs.
It also adds and renames some GNU_PROPERTY constants. But none of the
constants the elfutils code uses was renamed or given a different
constant value.
dwelf_elf_e_machine_string was updated to handle EM_INTELGT.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 20 Mar 2022 23:34:24 +0000 (00:34 +0100)]
configure: Don't check whether -m64 works for 32bit host biarch check
Running a 32bit backtrace test against a 64bit binary doesn't work.
Only a 64bit binary can backtrace a 32bit binary. So disable the
biarch check that inserts -m64 for a 32bit host.
https://sourceware.org/bugzilla/show_bug.cgi?id=24158
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 20 Mar 2022 23:13:56 +0000 (00:13 +0100)]
tests: Check addsections test binary is 64bit for run-large-elf-file.sh
The test binary should be 64bit to be able to create 4GB, or larger,
ELF files.
https://sourceware.org/bugzilla/show_bug.cgi?id=28975
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 23 Mar 2022 00:20:56 +0000 (01:20 +0100)]
libelf: Correct alignment of ELF_T_GNUHASH data for ELFCLASS64
ELF_T_GNUHASH data is just 32bit words for ELFCLASS32. But for
ELFCLASS64 it is a mix of 32bit and 64bit words. In the
elf_cvt_gnuhash function we rely on the alignment of the whole to be
64bit word aligned, even though the first 4 words are
32bits. Otherwise we might try to convert an unaligned 64bit word.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 20 Mar 2022 21:21:05 +0000 (22:21 +0100)]
libelf: Don't overflow offsets in elf_cvt_Verneed and elf_cvt_Verdef
The conversion functions for Verdef and Verneed keep offsets to the next
structure. Make sure that following vd_aux, vda_next, vd_next, vn_aux,
vna_next and vn_next don't overflow (and wrap around) the offsets.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Fri, 18 Mar 2022 15:44:53 +0000 (16:44 +0100)]
libdwfl: Use memcpy to assign image header field values
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>
Mark Wielaard [Fri, 18 Mar 2022 15:01:20 +0000 (16:01 +0100)]
libdwfl: Close ar members when they cannot be processed.
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>
Mark Wielaard [Thu, 17 Mar 2022 23:59:38 +0000 (00:59 +0100)]
libelf: Check alignment of Verdef, Verdaux, Verneed and Vernaux offsets
The Verdef, Verdaux, Verneed and Vernaux structures contain fields
which point to the next structures. Make sure these offsets are
correctly aligned for the structures they point to.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 17 Mar 2022 13:03:06 +0000 (14:03 +0100)]
libelf: Make sure ar_size starts with a digit before calling atol.
The ar_size field is a 10 character string, not zero terminated, of
decimal digits right padded with spaces. Make sure it actually starts
with a digit before calling atol on it. We already make sure it is
zero terminated. Otherwise atol might produce unexpected results.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 17 Mar 2022 12:58:56 +0000 (13:58 +0100)]
libelf: Take map offset into account for Shdr alignment check in elf_begin
The sh_num function tries to get at the zero section Shdr directly.
When the file is mmapped it has to make sure the offset into the file
to the start of the Elf structure is taken into account when trying to
cast the address to make sure the alignment is correct.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 14 Mar 2022 12:13:34 +0000 (13:13 +0100)]
configure: Use AS_HELP_STRING instead of AC_HELP_STRING.
In most places we already used AS_HELP_STRING. A few places used
AC_HELP_STRING. Which has been deprecated for a long time. Use
AS_HELP_STRING instead of AC_HELP_STRING everywhere.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Fri, 11 Mar 2022 14:44:21 +0000 (15:44 +0100)]
addr2line: Make --absolute the default, add --relative option.
Make --absolute (including the compilation directory in file names)
the default and add a new option --relative to get the previous
default behavior.
https://www.sourceware.org/bugzilla/show_bug.cgi?id=28951
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 10 Mar 2022 16:03:36 +0000 (17:03 +0100)]
configure: Test for _FORTIFY_SOURCE=3 support.
_FORTIFY_SOURCE=3 adds extra glibc (dynamic) fortification checks
when using GCC 12.
This adds a configure check to see if -D_FORTIFY_SOURCE=3 can be used.
If not, configure will fall back to -D_FORTIFY_SOURCE=2.
On some older glibc versions (glibc 2.17) using -D_FORTIFY_SOURCE=3
provides the same fortification as _FORTIFY_SOURCE=2. On some newer
glibc versions and older GCC (glibc 2.34 amd gcc 11) using
-D_FORTIFY_SOURCE=3 produces a not supported warning (and we fall
back to -D_FORTIFY_SOURCE=2). With newer glibc and newer GCC versions
(glibc 2.35 and gcc 12) -D_FORTIFY_SOURCE=3 will use the newer dynamic
fortification checks.
This patch also makes sure that AC_PROG_CXX is used earlier so that
CXXFLAGS is always setup correctly (even if we then don't use it).
And it outputs both the CFLAGS and CXXFLAGS as used at the end.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 16 Feb 2022 13:47:46 +0000 (14:47 +0100)]
backends: Use PTRACE_GETREGSET for ppc_set_initial_registers_tid
The code in ppc_initreg.c used PTRACE_PEEKUSER to fetch all registers
one by one. Which is slightly inefficient. It did this because it wanted
things to work on linux 2.6.18 which didn't support PTRACE_GETREGSET.
PTRACE_GETREGSET was only officially since 2.6.34 (but backported
to some earlier versions). It seems ok to require a linux kernel that
supports PTRACE_GETREGSET now. This is much more efficient since it
takes just one ptrace call instead of 44 calls to fetch each register
individually.
For some really old versions we need to include <linux/ptrace.h> to
get PTRACE_GETREGSET defined. And on ppc64 there is no 32bit version
of struct pt_regs available, so we define that ourselves and check
how much data is returned to know whether this is a full pt_regs or
one for a 32bit process. An alternative would be to use the raw
iov_base bytes with 64bit or 32bit offset constants to get at the
registers instead of using a struct with names.
The code works for inspecting a 32bit process from a 64bit build,
but not the other way around (the previous code also didn't). This
could work if we also defined and used a 64bit pt_regs struct on
ppc32. But it seems a use case that is not really used (it was hard
enough finding ppc32 setups to test this on).
Tested against ppc and ppc64 on linux 2.6.32 and glibc 2.12 and
ppc and ppc64 on linux 3.10.0 with glibc 2.17.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Frank Ch. Eigler [Mon, 31 Jan 2022 23:13:40 +0000 (18:13 -0500)]
man debuginfod-client-config.7: Elaborate $DEBUGINFOD_URLS
Add reference to /etc/profile.d and /etc/debuginfod/*.urls as possible
source of default. (No need to autoconf @prefix@ it, these paths are
customarily distro standard rather than elfutils configurables.)
Drop warning about federation loops, due to protection via PR27917 (0.186).
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Mark Wielaard [Thu, 6 Jan 2022 16:58:59 +0000 (17:58 +0100)]
libdwfl: Declare possible zero sized arrays only when non-zero
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>
Mark Wielaard [Thu, 6 Jan 2022 16:35:13 +0000 (17:35 +0100)]
libdwfl: Handle unaligned Dyns in dwfl_segment_report_module
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>
Mark Wielaard [Thu, 6 Jan 2022 15:44:56 +0000 (16:44 +0100)]
libdwfl: Fix overflow check in link_map.c read_addrs
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>
Mark Wielaard [Fri, 24 Dec 2021 01:01:32 +0000 (02:01 +0100)]
libdwfl: Calculate addr to read by hand in link_map.c read_addrs.
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>
Mark Wielaard [Fri, 24 Dec 2021 00:44:57 +0000 (01:44 +0100)]
libdwfl: Call xlatetom on aligned buffers in dwfl_link_map_report
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>
Mark Wielaard [Thu, 23 Dec 2021 22:16:25 +0000 (23:16 +0100)]
libdwfl: Make sure dwfl_elf_phdr_memory_callback returns at least minread
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>
Mark Wielaard [Mon, 20 Dec 2021 23:55:27 +0000 (00:55 +0100)]
libdwfl: Always clean up build_id.memory
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>
Mark Wielaard [Mon, 20 Dec 2021 00:39:21 +0000 (01:39 +0100)]
libdwfl: Handle unaligned Nhdr in dwfl_segment_report_module
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>
Mark Wielaard [Sun, 19 Dec 2021 23:31:33 +0000 (00:31 +0100)]
libdwfl: Handle unaligned Phdr in dwfl_segment_report_module
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>
Mark Wielaard [Sun, 19 Dec 2021 22:58:32 +0000 (23:58 +0100)]
libdwfl: Handle unaligned Ehdr in dwfl_segment_report_module
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>
Mark Wielaard [Sun, 19 Dec 2021 20:11:13 +0000 (21:11 +0100)]
libdwfl: Rewrite GElf_Nhdr reading in dwfl_segment_report_module
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>
Mark Wielaard [Sun, 19 Dec 2021 19:53:34 +0000 (20:53 +0100)]
libdwfl: Make sure dyn_filesz has a sane size
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>
Mark Wielaard [Sun, 19 Dec 2021 19:23:30 +0000 (20:23 +0100)]
libdwfl: Make sure that ph_buffer_size has room for at least one phdr
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>
Mark Wielaard [Sun, 19 Dec 2021 14:52:32 +0000 (15:52 +0100)]
libelf: Only set shdr state when there is at least one shdr
The elf shdr state only needs to be set when scncnt is at least
one. Otherwise e_shoff can be bogus. Also use unsigned arithmetic for
checking e_shoff alignment.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Fri, 17 Dec 2021 17:09:31 +0000 (18:09 +0100)]
libdwfl: Make sure the note len increases each iteration
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>
Mark Wielaard [Fri, 17 Dec 2021 16:43:19 +0000 (17:43 +0100)]
libdwfl: Make dwfl_segment_report_module aware of maximum Elf size
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>
Mark Wielaard [Sat, 18 Dec 2021 01:01:37 +0000 (02:01 +0100)]
libdwfl: Make sure note data is properly aligned.
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>
Mark Wielaard [Fri, 17 Dec 2021 22:51:35 +0000 (23:51 +0100)]
libdwfl: Make sure there is at least one phdr
The buffer read in needs to contain room for at least one Phdr.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Fri, 17 Dec 2021 21:53:13 +0000 (22:53 +0100)]
libdwfl: Make sure there is at least one dynamic entry
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>
Mark Wielaard [Fri, 17 Dec 2021 17:39:09 +0000 (18:39 +0100)]
tests: Use /bin/sh instead of /bin/ls as always there binary
run-debuginfod-query-retry.sh would fail when /bin/ls wasn't available.
Use /bin/sh instead which really is always available.
GNU Guix doesn't have any other standard binary in /bin except for sh.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 8 Dec 2021 17:02:27 +0000 (18:02 +0100)]
libdwfl: Add overflow check while iterating in dwfl_segment_report_module
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>
Mark Wielaard [Wed, 15 Dec 2021 23:29:22 +0000 (00:29 +0100)]
libdwfl: Make sure phent is sane and there is at least one phdr
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>
Mark Wielaard [Tue, 14 Dec 2021 15:12:31 +0000 (16:12 +0100)]
libelf: Use offsetof to get field of unaligned
gcc undefined sanitizer flags:
elf_begin.c:230:18: runtime error: member access within misaligned
address 0xf796400a for type 'struct Elf64_Shdr', which requires 4 byte
alignment struct.
We aren't actually accessing the field member of the struct, but are
taking the address of it. Which the compiler can take as a hint that
the address is correctly aligned. But we can do the same by adding
the field offsetof to the base address. Which doesn't trigger a
runtime error.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Alexander Kanavin [Thu, 9 Dec 2021 09:51:23 +0000 (10:51 +0100)]
debuginfod/debuginfod-client.c: use long for cache time configurations
time_t is platform dependent and some of architectures e.g.
x32, riscv32, arc use 64bit time_t even while they are 32bit
architectures, therefore directly using integer printf formats will not
work portably.
Use a plain long everywhere as the intervals are small enough
that it will not be problematic.
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Mark Wielaard [Sun, 12 Dec 2021 22:26:18 +0000 (23:26 +0100)]
libdwfl: Don't allocate more than SIZE_MAX in dwfl_segment_report_module.
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>
Frank Ch. Eigler [Thu, 9 Dec 2021 03:41:47 +0000 (22:41 -0500)]
PR28661: debuginfo connection thread pool support
Add an option -C, which activates libmicrohttpd's thread-pool mode for
handling incoming http connections. Add libmicrohttpd error-logging
callback function so as to receive indication of its internal errors,
and relay counts to our metrics. Some of these internal errors tipped
us off to a microhttpd bug that thread pooling works around. Document
in debuginfod.8 page. Hand-tested against "ulimit -u NNN" shells, and
with a less strenuous new test case.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Mark Wielaard [Thu, 9 Dec 2021 20:24:18 +0000 (21:24 +0100)]
libdwfl: Don't try to convert too many dyns in dwfl_link_map_report
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>
Mark Wielaard [Wed, 8 Dec 2021 22:44:34 +0000 (23:44 +0100)]
libdwfl: Don't install an Elf handle in a Dwfl_Module twice
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>
Mark Wielaard [Wed, 8 Dec 2021 21:20:17 +0000 (22:20 +0100)]
libdwfl: Don't trust e_shentsize in dwfl_segment_report_module
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>
Mark Wielaard [Wed, 8 Dec 2021 19:48:45 +0000 (20:48 +0100)]
libdwfl: Make sure we know the phdr entry size before searching phdrs.
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>
Mark Wielaard [Wed, 8 Dec 2021 12:39:47 +0000 (13:39 +0100)]
libdwfl: Don't try to convert too many bytes in dwfl_link_map_report
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>
Mark Wielaard [Thu, 9 Dec 2021 17:00:05 +0000 (18:00 +0100)]
debuginfod: Don't format clog using 'right' or 'setw(20)'.
Keep the logs just plain unformatted text.
This really is a workaround for an apparent bug with gcc 8.3
-fsanitizer=undefined on arm32, which complains about the
'right' formatter:
debuginfod.cxx:3472:12: runtime error: reference binding to
misaligned address 0x00561ec9 for type '<unknown>', which
requires 2 byte alignment
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sun, 5 Dec 2021 01:22:26 +0000 (02:22 +0100)]
configure: Add --enable-sanitize-address
--enable-sanitize-address makes sure that all code is compiled with
-fsanitizer=address and all tests run against libasan.
It can be combined with --enable-sanitize-undefined, but not with
--enable-valgrind.
In maintainer mode there is one program that causes leaks, i386_gendis,
so disable leak detection for that program.
One testcase, test_nlist, needs special linker flags, make sure it also
uses -fsanitizer=address when using the address sanitizer.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sat, 4 Dec 2021 01:57:24 +0000 (02:57 +0100)]
debuginfod: Fix debuginfod_pool leak
gcc address sanitizer detected a dangling debuginfod_client handler
when debuginfod exits. Make sure to groom the debuginfod client pool
before exit after all threads are done.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sat, 4 Dec 2021 00:18:42 +0000 (01:18 +0100)]
tests: varlocs workaround format-overflow errors
In function ‘printf’,
inlined from ‘handle_attr’ at varlocs.c:932:3:
error: ‘%s’ directive argument is null [-Werror=format-overflow=]
The warning is technically correct. A %s argument should not be
NULL. Although in practice all implementations will print it as
"(null)". Workaround this by simply changing the dwarf string
functions to return an "<unknown>" string. The test is for the correct
names, either "(null)" or "<unknown>" would make it fail (also remove
a now unnecessary assert, the switch statement will check for unknown
opcodes anyway).
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sat, 4 Dec 2021 00:08:48 +0000 (01:08 +0100)]
readelf: Workaround stringop-truncation error
In function ‘strncpy’,
inlined from ‘print_ehdr’ at readelf.c:1175:4:
error: ‘__builtin_strncpy’ specified bound 512 equals destination size
[-Werror=stringop-truncation]
strncpy doesn't terminate the copied string if there is not enough
room. We compensate later by explicitly adding a zero terminator at
buf[sizeof (buf) - 1]. Normally gcc does see this, but with
-fsanitize=address there is too much (checking) code in between. But
it is actually better to not let strncpy do too much work, so
substract one from the size.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 1 Dec 2021 11:32:27 +0000 (12:32 +0100)]
debuginfod: Check result of calling MHD_add_response_header.
Although unlikely the MHD_add_response_header can fail for
various reasons. If it fails something odd is going on.
So check we can actually add a response header and log an
error if we cannot.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 8 Dec 2021 13:26:54 +0000 (14:26 +0100)]
libdwfl: Don't read beyond end of file in dwfl_segment_report_module
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>
Frank Ch. Eigler [Wed, 8 Dec 2021 15:20:58 +0000 (10:20 -0500)]
debuginfod: correct concurrency bug in fdcache metrics
The intern() function called set_metrics() outside a necessary lock
being held. helgrind identified this race condition. No QA impact.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>