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>
Mark Wielaard [Sat, 4 Dec 2021 19:21:16 +0000 (20:21 +0100)]
debuginfod: Clear and reset debuginfod_client winning_headers on reuse
gcc address sanitizer detected a leak of the debuginfod_client
winning_headers when the handle was reused. Make sure to free and
reset the winning_headers field before reuse.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 1 Dec 2021 12:12:49 +0000 (13:12 +0100)]
debuginfod: Fix some memory leaks on debuginfod-client error paths.
In a couple of places we might leak some memory when we encounter
an error. tmp_url might leak if realloc failed. escaped_string might
leak when setting up the data handle fails and we don't use it.
And one of the goto out1 should have been goto out2 to make sure
we release all allocated resources on exit (also updated a wrong
comment about that).
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sat, 4 Dec 2021 12:07:04 +0000 (13:07 +0100)]
debuginfod: sqlite3_sharedprefix_fn should not compare past end of string
gcc address sanitizer detected a read after the end of string in
sqlite3_sharedprefix_fn. Make sure to stop comparing the strings when
seeing the zero terminator.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 1 Dec 2021 12:42:50 +0000 (13:42 +0100)]
debuginfod: Use gmtime_r instead of gmtime to avoid data race
Since we are multi-threaded using gmtime might cause a data race
because gmtime reuses a global struct to write data into. Make
sure that each thread uses their own struct tm and use gmtime_r
instead.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 18 Nov 2021 20:34:57 +0000 (21:34 +0100)]
tests: Add -rdynamic to dwfl_proc_attach_LDFLAGS
dwfl-proc-attach uses (overrides) dlopen (so it does nothing). This
seems to cause a versioned dlopen symbol to be pulled in when building
with LTO. Resulting in a link failure (when dlopen isn't integrated
into libc):
/usr/bin/ld: dwfl-proc-attach.o (symbol from plugin): undefined
reference to symbol 'dlopen@@GLIBC_2.2.5'
/usr/bin/ld: /usr/lib64/libdl.so.2: error adding symbols: DSO missing
from command line collect2: error: ld returned 1 exit status
Add -rdynamic to the LDFLAGS to add all symbols to the dynamic symbol
table for dwfl-proc-attach.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Matthias Maennich [Thu, 18 Nov 2021 19:44:50 +0000 (19:44 +0000)]
dwfl: fix potential overflow when reporting on kernel modules
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>
Mark Wielaard [Thu, 11 Nov 2021 14:46:26 +0000 (15:46 +0100)]
tests: Don't set DEBUGINFOD_TIMEOUT
Various tests set DEBUGINFOD_TIMEOUT to 10. Which is less than the default
of 90. None of the tests relied on a lower timeout. So just don't set it.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Érico Nogueira [Thu, 11 Nov 2021 00:17:48 +0000 (21:17 -0300)]
debuginfod: fix compilation on platforms without <error.h>
"system.h" only declares the error() function, so it needs to be in an
'extern "C"' block, otherwise linking fails.
Since we are here, use quotes for "system.h" header, since it's a local
header, not a system one.
Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
Mark Wielaard [Wed, 10 Nov 2021 15:26:07 +0000 (16:26 +0100)]
Prepare for 0.186
Set version to 0.186
Update NEWS and elfutils.spec.in
Regenerate po/*.po files
Signed-off-by: Mark Wielaard <mark@klomp.org>
Frank Ch. Eigler [Sat, 6 Nov 2021 02:26:35 +0000 (22:26 -0400)]
PR28430: debuginfod: support --passive mode
Add support for a limited mode for debuginfod that uses a pure
read-only sqlite index. This mode is useful for load spreading based
on naively shared or replicated databases.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
John M Mellor-Crummey [Wed, 20 Oct 2021 23:19:38 +0000 (18:19 -0500)]
libdw, readelf: Read inlining info in NVIDIA extended line map
As of CUDA 11.2, NVIDIA added extensions to the line map section
of CUDA binaries to represent inlined functions. These extensions
include
- two new fields in a line table row to represent inline
information: context, and functionname,
- two new DWARF extended opcodes: DW_LNE_NVIDIA_inlined_call,
DW_LNE_NVIDIA_set_function_name,
- an additional word in the line table header that indicates
the offset in the .debug_str function where the function
names for this line table begin, and
A line table row for an inlined function contains a non-zero "context"
value. The “context” field indicates the index of the line table row
that serves as the call site for an inlined context.
The "functionname" field in a line table row is only meaningful if the
"context" field of the row is non-zero. A meaningful "functionname"
field contains an index into the .debug_str section relative to the
base offset established in the line table header; the position in the
.debug_str section indicates the name of the inlined function.
These extensions resemble the proposed DWARF extensions
(http://dwarfstd.org/ShowIssue.php?issue=140906.1) by Cary Coutant,
but are not identical.
This commit integrates support for handling NVIDIA's extended line
maps into elfutil's libdw library, by adding two functions
dwarf_linecontext and dwarf_linefunctionname, and the readelf
--debug-dump=line command line utility.
Signed-off-by: John M Mellor-Crummey <johnmc@rice.edu>
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 8 Nov 2021 08:27:51 +0000 (09:27 +0100)]
libdw: dwarf_elf_begin should use either plain, dwo or lto DWARF sections.
When opening an ELF file that contained a mix of plain, dwo or lto .debug
sections the result could be confusing. Add a check to pick just the plain
.debug sections, or the .dwo sections or the .gnu.debuglto_.debug sections
(in that order of preference). That way there is always a consistent set.
https://sourceware.org/bugzilla/show_bug.cgi?id=27367
Signed-off-by: Mark Wielaard <mark@klomp.org>
Alexander Miller [Thu, 18 Feb 2021 02:38:56 +0000 (03:38 +0100)]
Improve building with LTO
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>
Frank Ch. Eigler [Thu, 4 Nov 2021 17:08:35 +0000 (13:08 -0400)]
PR28514: debuginfod: limit groom operation times
For large databases and many stale files, it was possible to starve
rescan operations by numerous groom "nuke" (database delete ops).
Under the theory that including new data is at least as important as
aging old, we now impose a rough deadline on groom queries.
In the process, we discovered that we were commiting some
undefined-behaviour sqlite ops (deleting rows while iterating), which
may explain some previous heisenbug occurrences. So the groom nuke
operations are split into decision & action phases, with associated
progress-tracking metrics.
Testing the timeout facility requires hand-testing beyond the
testsuite (since it requires LARGE databases to show measurable query
times). So confirmed this part by hand.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Frank Ch. Eigler [Thu, 4 Nov 2021 20:26:55 +0000 (16:26 -0400)]
NEWS: make automake check-news / dist happy
automake's check-news option requires not too much new content
before a line that includes the current version number.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Frank Ch. Eigler [Thu, 4 Nov 2021 19:26:33 +0000 (15:26 -0400)]
NEWS: list some 0.186 debuginfod client & server features
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Frank Ch. Eigler [Wed, 18 Aug 2021 22:29:34 +0000 (18:29 -0400)]
PR28240: debuginfod client root-safe negative caching
Negative cache (000-permission) files were incorrectly treated as
valid cached files for the root user, because root can open even
000-perm files without -EACCES. Corrected this checking sequence.
Fixed the debuginfod testsuite to run to completion as root or
as an ordinary user, correcting corresponding permission checks:
stat -c %A $FILE
is right and
[ -w $FILE] [ -r $FILE ]
were wrong.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Mark Wielaard [Mon, 18 Oct 2021 12:35:20 +0000 (14:35 +0200)]
libdw: Don't pass NULL to dwarf_peel_type
commit
c3a6a9dfc "libdw: Use signedness of subrange type to
determine array bounds" introduced a type check on a DIE which
exposed a latent bug in the get_type function. Even if the type
of a DIE couldn't be determined it would call dwarf_peel_type
on it. The gcc undefined sanitizer would flag this as being
undefined behaviour because the second argument of the function
is marked as non-NULL. Fix this by checking we actually have
a non-NULL type DIE.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 6 Oct 2021 20:41:29 +0000 (22:41 +0200)]
libdw: Use signedness of subrange type to determine array bounds
When calculating the array size check if the subrange has an associate
type, if it does then check the type to determine whether the upper
and lower values need to be interpreted as signed of unsigned
values. We default to signed because that is what the testcase
run-aggregate-size.sh testfile-size4 expects (this is an hardwritten
testcase, we could have chosen a different default).
https://sourceware.org/bugzilla/show_bug.cgi?id=28294
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Fri, 15 Oct 2021 13:16:54 +0000 (15:16 +0200)]
debuginfod-client: Stick to + https:// + file:// protocols
Make sure we don't use any of the more experimental protocols
libcurl might support. URLs can be redirected and we might want
to follow http -> https, but not e.g. gopher or pop3.
Suggested-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Mark Wielaard <mark@klomp.org>
Frank Ch. Eigler [Sun, 3 Oct 2021 21:04:24 +0000 (17:04 -0400)]
PR27783: switch default debuginfod-urls to drop-in style files
Rewrote and commented the /etc/profile.d csh and sh script fragments
to take the default $DEBUGINFOD_URLS from the union of drop-in files:
/etc/debuginfod/*.urls. Hand-tested with csh and bash, with
conditions including no prior $DEBUGINFOD_URLS, nonexistent .urls
files, multiple entries in .urls files.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Mark Wielaard [Wed, 6 Oct 2021 21:53:34 +0000 (23:53 +0200)]
tests: Handle dwarf_attr_string returning NULL in show-die-info.c
Reported-by: Jan-Benedict Glaw <jbglaw@lug-owl.de>
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Wed, 6 Oct 2021 21:37:42 +0000 (23:37 +0200)]
elflint.c: Don't dereference databits if bad
elflint.c: In function 'check_sections':
elflint.c:4105:48: error: null pointer dereference [-Werror=null-dereference]
4105 | idx < databits->d_size && ! bad;
| ~~~~~~~~^~~~~~~~
Fix this by testing for ! bad first.
Reported-by: Jan-Benedict Glaw <jbglaw@lug-owl.de>
Signed-off-by: Mark Wielaard <mark@klomp.org>
Di Chen [Wed, 6 Oct 2021 21:04:08 +0000 (17:04 -0400)]
PR28242: debuginfod prometheus metric widening
This patch aims to extend http_responses_* metrics with another label
"type" by getting the extra artifact-type content added as a new
key=value tag.
v2, tweaked patch to perform artifact-type sanitization at point of
vulnerability rather than in general metric tabulation logic.
Signed-off-by: Di Chen <dichen@redhat.com>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
William Cohen [Wed, 29 Sep 2021 18:56:15 +0000 (14:56 -0400)]
RISC-V: PR27925 Add support for LP64 and LP64F ABIs return values
The RISC-V Linux kernel is compiled without floating point (the LP64
ABI) and elfutils could not obtain return value locations for
functions in the kernel. This issue was noticed when Systemtap
generated RISC-V kernel modules for scripts that used $return target
variables in function return probes. This patch adds the needed
support to provide return value information for the LP64 and LP64F
ABIs.
Signed-off-by: William Cohen <wcohen@redhat.com>
Noah Sanci [Fri, 17 Sep 2021 14:45:39 +0000 (10:45 -0400)]
debuginfod: Remove checking for unsafe headers
Some http response header checks were removed such as checking for
Connection and Cache-Control. These headers are not guarenteed to be
received and depend on proxy and libmicrohttpd versions. Checking for
the existance of Content-Length and DEBUGINFOD-* headers is sufficient
since Content-Length is added upon creation of an MHD_Response object
and DEBUGINFOD-* are added manually.
(source on Content-Length being added:
https://www.gnu.org/software/libmicrohttpd/manual/libmicrohttpd.html#
microhttpd_002dresponse-headers )
Signed-off-by: Noah Sanci <nsanci@redhat.com>
Noah Sanci [Fri, 17 Sep 2021 14:45:39 +0000 (10:45 -0400)]
debuginfod: Query debuginfod servers before printing response
While checking PR27277 on some buildbots, greping would fail in
run-debuginfod-response-headers.sh. This was because querying the
debuginfod server occurs after checking if the responseh headers had
arrived, leaving the possibility to leave the querying loop before
outputting the headers which caused the grep failure. Querying now
occurs before checking if response headers have arrived, so that they
will certainly be printed and grep will find them.
Signed-off-by: Noah Sanci <nsanci@redhat.com>
Noah Sanci [Tue, 10 Aug 2021 15:21:35 +0000 (11:21 -0400)]
debuginfod: PR27277 - Describe retrieved files when verbose
Allow users, with enough verbosity, to print the HTTP response headers
upon retrieving a file. These files may include several custome http
response headers such as X-DEBUGINFOD-FILE, X-DEBUGINFOD-SIZE, and
X-DEBUGINFOD-ARCHIVE. These headers are added from the daemon, in
debuginfod.cxx.
E.g output:
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 4095072
Cache-Control: public
Last-Modified: Thu, 09 Sep 2021 19:06:40 GMT
X-FILE: debuginfod
X-FILE-SIZE: 4095072
Content-Type: application/octet-stream
Date: Fri, 10 Sep 2021 16:38:06 GMT
https://sourceware.org/bugzilla/show_bug.cgi?id=27277
Signed-off-by: Noah Sanci <nsanci@redhat.com>
Noah Sanci [Thu, 9 Sep 2021 17:10:33 +0000 (13:10 -0400)]
debuginfod: PR28034 - No longer escape '/', and loop efficiency
Previously, urls containing '/', so most urls, would escape '/' to %2F,
which is undesirable for use in other libraries which may escape
differently. This patch escapes the '/' and replaces all of them
ensuring there are no %2Fs sent.
Some inefficiencies within the code were fixed, such as changing constant
operations of a while loop within a for loop to a while loop outside of
a for loop. Also strlen is no longer used within the loop, simplifying
the interior operations to mere arithmetic.
https://sourceware.org/bugzilla/show_bug.cgi?id=28034
Signed-off-by: Noah Sanci <nsanci@redhat.com>
Frank Ch. Eigler [Tue, 14 Sep 2021 12:15:23 +0000 (08:15 -0400)]
PR28339: debuginfod: fix groom/scan race condition on just-emptied queue
debuginfod's scan and groom operations (thread_main_scanner,
thread_main_fts_source_paths) are intended to be mutually exclusive,
as a substitute for more complicated sql transaction batching. (This
is because scanning / grooming involves inserting or deleting data
from multiple related tables.)
The workq class that governs this in debuginfod.cxx has a problem: if
the workq just becomes empty, its sole entry pulled by a scanner
thread in response to a wait_front(), an 'idler' groomer thread is
ALSO permitted to run, because there is no indication as to when the
scanner thread operation finishes, only when it starts.
Extending the workq with a counter ("fronters") to track any active
scanning activity (even if the workq is empty) lets us block idlers
groomers a little longer.
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Mark Wielaard [Sun, 12 Sep 2021 22:35:55 +0000 (00:35 +0200)]
debuginfod: Add endl after "fdcache emergency flush for filling tmpdir" log
Without the endl the next log message will not start on its own line.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Colin Cross [Fri, 10 Sep 2021 18:07:16 +0000 (11:07 -0700)]
lib: Make error.c more like error(3)
Fix some issues with the error reimplementation to make it match
the specification for error(3).
Flush stdout before printing to stderr. Also flush stderr afterwards,
which is not specified in the man page for error(3), but is what
bionic does.
error(3) prints strerror(errnum) if and only if errnum is nonzero,
but verr prints strerror(errno) unconditionaly. When errnum is nonzero
copy it to errno and use verr, and when it is not set use verrx that
doesn't print errno.
error(3) only exits if status is nonzero, but verr exits uncondtionally.
Use vwarn/vwarnx when status is zero, which don't exit.
Signed-off-by: Colin Cross <ccross@google.com>
Mark Wielaard [Thu, 26 Aug 2021 17:05:45 +0000 (19:05 +0200)]
libdw: set address size, offset size and version on fake CUs
There are three "fake CUs" that are associated with .debug_loc,
.debug_loclist and .debug_addr. These fake CUs are used for "fake
attributes" to provide values that are stored in these sections
instead of in the .debug_info section. These fake CUs didn't have the
address size, offset size and DWARF version set. This meant that
values that depended on those properties might not be interpreted
correctly. One example was the value associated with a DW_OP_addrx
(which comes from the .debug_addr section).
Add a testcase using varlocs to test that addresses can correctly be
retrieved for gcc/clang, DWARF4/5 and 32/64 bits objects.
https://sourceware.org/bugzilla/show_bug.cgi?id=28220
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Thu, 9 Sep 2021 19:51:51 +0000 (21:51 +0200)]
tests: Don't fail run-debuginfod-fd-prefetch-caches.sh if grep -c fails
The set -o errtrace made run-debuginfod-fd-prefetch-caches.sh
fail. On some systems. Add set -o functrace to make it fail consistently.
The failure is because the grep -c for in the log file fails (it
returns zero). Fix this by using || true. But this is only a
workaround. It makes the test pass, but only because all values are
always zero. The test doesn't currently test anything.
Also make sure that err and cleanup are only executed once.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Dmitry V. Levin [Thu, 9 Sep 2021 08:03:00 +0000 (08:03 +0000)]
findtextrel: do not use unbound alloca
This fixes the following compilation warning:
findtextrel.c:184:1: warning: stack usage might be unbounded [-Wstack-usage=]
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Mark Wielaard [Thu, 9 Sep 2021 16:50:54 +0000 (18:50 +0200)]
tests: Cleanup error handling and don't share cache between servers/client
There were still three tests that shared a cache between the servers
and client that queried those servers. Give them all separate caches.
Also the error handler for debuginfod tests wasn't called when a
command inside a function failed. Since testrun is a function, there
would be no metrics or error log files listed if the testrun command
failed. Making it hard to see what went wrong. Fix this by using
set -o errtrace
Signed-off-by: Mark Wielaard <mark@klomp.org>
Dmitry V. Levin [Mon, 6 Sep 2021 10:00:00 +0000 (10:00 +0000)]
Use xasprintf instead of asprintf followed by error(EXIT_FAILURE)
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Mon, 6 Sep 2021 10:00:00 +0000 (10:00 +0000)]
Introduce xasprintf
Similar to other x* functions, xasprintf is like asprintf except that
it dies in case of an error.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Mon, 6 Sep 2021 08:00:00 +0000 (08:00 +0000)]
Remove redundant casts of memory allocating functions returning void *
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>
Dmitry V. Levin [Sun, 5 Sep 2021 08:00:00 +0000 (08:00 +0000)]
src: add -Wno-error=stack-usage= to AM_LDFLAGS
While -Wstack-usage= is already excluded from AM_CFLAGS for various
tools in src using *_no_Wstack_usage variables, this obviously does not
help when LTO is enabled, so add -Wno-error=stack-usage= to AM_LDFLAGS
for linking tools in src.
References: https://sourceware.org/bugzilla/show_bug.cgi?id=24498
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Mark Wielaard [Tue, 7 Sep 2021 21:56:42 +0000 (23:56 +0200)]
tests: Make sure to wait for initial scan and groom cycle earlier
At startup the debuginfod server does a scan and groom cycle. Make
sure to wait for that before making any changes to the scan dirs. And
not just right before triggering a new one with SIGUSR1 for scan or
SIGURS2 for groom.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 6 Sep 2021 23:50:51 +0000 (01:50 +0200)]
tests: Make sure to wait for initial scan and groom cycle
At startup the debuginfod server does a scan and groom cycle. Make
sure to wait for that before triggering a new one with SIGUSR1 or
SIGURST2.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 6 Sep 2021 22:31:00 +0000 (00:31 +0200)]
tests: Only export DEBUGINFOD_URLS when necessary
A couple of test set DEBUGINFOD_URLS before starting a debuginfd
server causing the server to query itself or a nonexisting debuginfod
server as delegate. In most cases it should be set after, except for
the testcase that explicitly checks for errors when using an invalid
URL.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Mon, 6 Sep 2021 21:04:06 +0000 (23:04 +0200)]
tests: Print metrics for both ports on error and fix port selection
On error we would only print the metrics of one port (twice) because
of a typo. Also PORT1 and PORT2 could be equal because of a logic
error. Fix the typo and simplify the port selection by using
non-overlapping ranges to select PORT1 and PORT2.
Mark Wielaard [Mon, 6 Sep 2021 19:48:38 +0000 (21:48 +0200)]
tests: Set DEBUGINFOD_CACHE_PATH for run-debuginfod-{file,query-retry}.sh
Mark Wielaard [Fri, 3 Sep 2021 23:40:53 +0000 (01:40 +0200)]
tests: Make sure all debuginfod tests use a clean database and cache.
Always set DEBUGINFOD_CACHE_PATH to an unique (new) directory
and make sure that each debuginfod invocation uses a new sqlite
database.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Fri, 3 Sep 2021 11:10:43 +0000 (13:10 +0200)]
tests: Add debuginfod-subr.sh to EXTRA_DIST
Signed-off-by: Mark Wielaard <mark@klomp.org>
Noah Sanci [Tue, 10 Aug 2021 15:21:35 +0000 (11:21 -0400)]
debuginfod: Fracture tests/run-debuginfod-find.sh into specific tests
tests/run-debuginfod-find.sh was a massive test script with many broadly
varying tests. This caused the test script to fail when any number of
things went wrong and because of its intertwined nature, detecting the
source of a failure could be difficult. The size of the test script
also meant many unrelated tests were run making the testing process
unnecessarily lengthy.
This patch fractures tests/run-debuginfod-find.sh into smaller, more
manageable individual test script files. This ensures that when failure
occurs, a programmer can easily determine where their patch went
wrong. It also allows programmers to specify exactly which tests to
run, making testing more efficient. Redundancies are also reduced by
placing code in tests/debuginfod-subr.sh.
Signed-off-by: Noah Sanci <nsanci@redhat.com>
Adrian Ratiu [Mon, 30 Aug 2021 15:43:13 +0000 (18:43 +0300)]
configure.ac: rework gnu99 ext check to allow clang
It is true that Clang does not support all gnu99 extensions [1],
but not all of them are used in the codebase and over time there
have been code cleanup efforts to improve Clang support.
For example after commit
779c57ea ("readelf: Pull advance_pc()
in file scope") there are no more nested function declarations
and elfutils now builds fine with Clang.
So in the interest of enabling Clang builds we remove the only
remaining blocker: the configure checks for nested functions and
variable length arrays which are also unused.
Considering mixed decls and code is also part of c99 standard,
the entire check becomes redundant and we can just replace
AC_PROG_CC -> AC_PROG_CC_C99.
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=24964
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Mark Wielaard [Sat, 28 Aug 2021 18:25:56 +0000 (20:25 +0200)]
debuginfod: Turn -d ":memory:" into -d "file::memory:?cache=shared"
debuginfod opens the database twice, once in read/wrote and once in
read-only mode. This means the magic ":memory:" in-memory database
cannot be used as is because the two connections don't really share
the underlying database. Fix this by turning ":memory:" into
":file::memory:?cache=shared" which makes the in-memory database
shared. See https://sqlite.org/inmemorydb.html
Document this in debuginfod.8 and make some tests use -d :memory:
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard [Sat, 28 Aug 2021 13:54:18 +0000 (15:54 +0200)]
tests: Use fresh separate databases for debuginfd forwarded-ttl-limit
Sharing the database between the two debuginfod instances that forward
queries to each other causes issues. Make both debuginfod instances
use a new fresh database.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Di Chen [Fri, 20 Aug 2021 05:03:21 +0000 (13:03 +0800)]
debuginfod: PR27917 - protect against federation loops
If someone misconfigures a debuginfod federation to have loops, and
a nonexistent buildid lookup is attempted, bad things will happen,
as is documented.
This patch aims to reduce the risk by adding an option to debuginfod
that functions kind of like an IP packet's TTL: a limit on the length of
XFF: header that debuginfod is willing to process. If X-Forwarded-For:
exceeds N hops, it will not delegate a local lookup miss to upstream
debuginfods.
Commit
ab38d167c40c99 causes federation loops for non-existent resources
to result in multiple temporary deadlocks, each lasting for
$DEBUGINFOD_TIMEOUT seconds. Since concurrent requests for each unique
resource are now serialized, federation loops can result in one server
thread waiting to acquire a lock while the server thread holding the
lock waits for the first thread to respond to an http request.
This PR can help protect against the above multiple temporary deadlocks
behaviour. Ex. if --forwarded-ttl-limit=0 then the timeout behaviour of
local loops should be avoided.
https://sourceware.org/bugzilla/show_bug.cgi?id=27917
Signed-off-by: Di Chen <dichen@redhat.com>
Mark Wielaard [Fri, 27 Aug 2021 16:47:30 +0000 (18:47 +0200)]
Add lib/error.c
This new file was supposed to be part of
4d6dd0e5a "lib: avoid potential
problems with `-fno-common`".
Signed-off-by: Mark Wielaard <mark@klomp.org>
Saleem Abdulrasool [Fri, 27 Aug 2021 15:51:47 +0000 (15:51 +0000)]
lib: avoid potential problems with `-fno-common`
This properly homes the fallback function into a translation unit rather
than trying to define an inline common definition for the fallback path.
The intent of the original approach was to actually simply avoid adding
a new source file that is used for the fallback path. However, that may
cause trouble with multiple definitions if the symbol does not get vague
linkage (which itself is not particularly great). This simplifies the
behaviour at the cost of an extra inode.
Saleem Abdulrasool [Fri, 27 Aug 2021 15:20:13 +0000 (15:20 +0000)]
lib: remove unused `STROF` definition (NFC)
This definition was in the fallback path, where `sys/cdefs.h` is not
available. Now that we have a single path through here, this macro gets
defined, though is unused. Remove the unused macro definition.
Signed-off-by: Saleem Abdulrasool <abdulras@google.com>
Saleem Abdulrasool [Fri, 20 Aug 2021 20:28:23 +0000 (20:28 +0000)]
handle libc implementations which do not provide `error.h`
Introduce a configure time check for the presence of `error.h`. In the
case that `error.h` is not available, we can fall back to `err.h`.
Although `err.h` is not a C standard header (it is a BSD extension),
many libc implementations provide. If there are targets which do not
provide an implementation of `err.h`, it would be possible to further
extend the implementation to be more portable.
This resolves bug #21008.
Signed-off-by: Saleem Abdulrasool <abdulras@google.com>