aboutsummaryrefslogtreecommitdiff
path: root/debug
AgeCommit message (Collapse)AuthorFilesLines
2025-07-25debug: Only run sframe tests if run-built-tests is enabledAdhemerval Zanella1-0/+2
2025-07-24Disable SFrame support by defaultAdhemerval Zanella3-6/+100
And add extra checks to enable for binutils 2.45 and if the architecture explicitly enables it. When SFrame is disabled, all the related code is also not enabled for backtrace() and _dl_find_object(), so SFrame backtracking is not used even if the binary has the SFrame segment. This patch also adds some other related fixes: * Fixed an issue with AC_CHECK_PROG_VER, where the READELF_SFRAME usage prevented specifying a different readelf through READELF environment variable at configure time. * Add an extra arch-specific internal definition, libc_cv_support_sframe, to disable --enable-sframe on architectures that have binutils but not glibc support (s390x). * Renamed the tests without the .sframe segment and move the tst-backtrace1 from pthread to debug. * Use the built compiler strip to remove the .sframe segment, instead of the system one (which might not support SFrame). Checked on x86_64-linux-gnu and aarch64-linux-gnu. Reviewed-by: Sam James <sam@gentoo.org>
2025-07-24debug: Link tst-sprintf-fortify-rdonly-static with -Wl,-z,relro [BZ 33183]John David Anglin1-0/+1
This test requires relro_format be placed in the PT_GNU_RELRO segment. The ELF linker enables -z relro support by default on all Linux targets except FRV, HPPA, IA64 and MIPS. On these targets, we need to explicitly link with -z relro to place relro_format in the PT_GNU_RELRO segment. Signed-off-by: John David Anglin <dave.anglin@bell.net>
2025-07-18elf: Initialize GLRO (dl_read_only_area) after static dlopen (bug 33139)Florian Weimer2-0/+13
The _dl_read_only_area function in the uninitialized ld.so after static dlopen is not able to find anything. Instead, we need to redirect to the code from the statically linked main program. Fixes commit d60fffe28a46b2a41fc308c1804ff02375d27408 ("debug: Improve '%n' fortify detection (BZ 30932)"). Reviewed-by: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
2025-07-18debug: Do not link tst-sprintf-fortify-rdonly against the dlopen moduleFlorian Weimer1-3/+3
The test intends to load tst-sprintf-fortify-rdonly-dlopen.so via dlopen, and directly linking against it prevents that. Reviewed-by: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
2025-07-14SFrame: Add tests that uses DWARF backtracerClaudiu Zissulescu1-0/+28
When SFrame is enabled, we need to tests DW backtracer as well. Do this by executing the same backtrace tests with .sframe section stripped. Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com> Reviewed-by: DJ Delorie <dj@redhat.com>
2025-07-14elf: Add SFrame stack tracingClaudiu Zissulescu1-1/+45
This patch adds the necessary bits to enable stack tracing using SFrame. In the case the new SFrame stack tracing procedure doesn't find SFrame related info, the stack tracing falls back on default Dwarf implementation. The new SFrame stack tracing procedure is added to debug/backtrace.c file, the support functions are added in sysdeps folder, namely sframe.h, read-sframe.c and read-sfame.h. Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com> Reviewed-by: DJ Delorie <dj@redhat.com>
2025-03-24Add _FORTIFY_SOURCE support for inet_ptonAaron Merey4-0/+56
Add function __inet_pton_chk which calls __chk_fail when the size of argument dst is too small. inet_pton is redirected to __inet_pton_chk or __inet_pton_warn when _FORTIFY_SOURCE is > 0. Also add tests to debug/tst-fortify.c, update the abilist with __inet_pton_chk and mention inet_pton fortification in maint.texi. Co-authored-by: Frédéric Bérat <fberat@redhat.com> Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-03-21debug: Improve '%n' fortify detection (BZ 30932)Adhemerval Zanella5-29/+221
The 7bb8045ec0 path made the '%n' fortify check ignore EMFILE errors while trying to open /proc/self/maps, and this added a security issue where EMFILE can be attacker-controlled thus making it ineffective for some cases. The EMFILE failure is reinstated but with a different error message. Also, to improve the false positive of the hardening for the cases where no new files can be opened, the _dl_readonly_area now uses _dl_find_object to check if the memory area is within a writable ELF segment. The procfs method is still used as fallback. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Arjun Shankar <arjun@redhat.com>
2025-03-21Add _FORTIFY_SOURCE support for inet_ntopFrédéric Bérat4-0/+55
- Create the __inet_ntop_chk routine that verifies that the builtin size of the destination buffer is at least as big as the size given by the user. - Redirect calls from inet_ntop to __inet_ntop_chk or __inet_ntop_warn - Update the abilist for this new routine - Update the manual to mention the new fortification Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert109-109/+109
2024-12-23include/sys/cdefs.h: Add __attribute_optimization_barrier__Adhemerval Zanella2-2/+2
Add __attribute_optimization_barrier__ to disable inlining and cloning on a function. For Clang, expand it to __attribute__ ((optnone)) Otherwise, expand it to __attribute__ ((noinline, clone)) Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-11-26debug: Fix tst-longjmp_chk3 build failure on HurdFlorian Weimer1-0/+1
Explicitly include <unistd.h> for _exit and getpid.
2024-11-25Silence most -Wzero-as-null-pointer-constant diagnosticsAlejandro Colomar1-1/+1
Replace 0 by NULL and {0} by {}. Omit a few cases that aren't so trivial to fix. Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059> Link: <https://software.codidact.com/posts/292718/292759#answer-292759> Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-25debug: Wire up tst-longjmp_chk3Florian Weimer2-4/+10
The test was added in commit ac8cc9e300a002228eb7e660df3e7b333d9a7414 without all the required Makefile scaffolding. Tweak the test so that it actually builds (including with dynamic SIGSTKSZ). Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-10-08stdlib: Make abort/_Exit AS-safe (BZ 26275)Adhemerval Zanella3-7/+7
The recursive lock used on abort does not synchronize with a new process creation (either by fork-like interfaces or posix_spawn ones), nor it is reinitialized after fork(). Also, the SIGABRT unblock before raise() shows another race condition, where a fork or posix_spawn() call by another thread, just after the recursive lock release and before the SIGABRT signal, might create programs with a non-expected signal mask. With the default option (without POSIX_SPAWN_SETSIGDEF), the process can see SIG_DFL for SIGABRT, where it should be SIG_IGN. To fix the AS-safe, raise() does not change the process signal mask, and an AS-safe lock is used if a SIGABRT is installed or the process is blocked or ignored. With the signal mask change removal, there is no need to use a recursive loc. The lock is also taken on both _Fork() and posix_spawn(), to avoid the spawn process to see the abort handler as SIG_DFL. A read-write lock is used to avoid serialize _Fork and posix_spawn execution. Both sigaction (SIGABRT) and abort() requires to lock as writer (since both change the disposition). The fallback is also simplified: there is no need to use a loop of ABORT_INSTRUCTION after _exit() (if the syscall does not terminate the process, the system is broken). The proposed fix changes how setjmp works on a SIGABRT handler, where glibc does not save the signal mask. So usage like the below will now always abort. static volatile int chk_fail_ok; static jmp_buf chk_fail_buf; static void handler (int sig) { if (chk_fail_ok) { chk_fail_ok = 0; longjmp (chk_fail_buf, 1); } else _exit (127); } [...] signal (SIGABRT, handler); [....] chk_fail_ok = 1; if (! setjmp (chk_fail_buf)) { // Something that can calls abort, like a failed fortify function. chk_fail_ok = 0; printf ("FAIL\n"); } Such cases will need to use sigsetjmp instead. The _dl_start_profile calls sigaction through _profil, and to avoid pulling abort() on loader the call is replaced with __libc_sigaction. Checked on x86_64-linux-gnu and aarch64-linux-gnu. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-10-01Do not use -Wp to disable fortify (BZ 31928)Adhemerval Zanella1-9/+10
The -Wp does not work properly if the compiler is configured to enable fortify by default, since it bypasses the compiler driver (which defines the fortify flags in this case). This patch is similar to the one used on Ubuntu [1]. I checked with a build for x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, s390x-linux-gnu, and riscv64-linux-gnu with gcc-13 that enables the fortify by default. Co-authored-by: Matthias Klose <matthias.klose@canonical.com> [1] https://git.launchpad.net/~ubuntu-core-dev/ubuntu/+source/glibc/tree/debian/patches/ubuntu/fix-fortify-source.patch Reviewed-by: DJ Delorie <dj@redhat.com>
2024-09-10debug: Fix read error handling in pcprofiledumpFlorian Weimer1-36/+47
The reading loops did not check for read failures. Addresses a static analysis report. Manually tested by compiling a program with the GCC's -finstrument-functions option, running it with “LD_PRELOAD=debug/libpcprofile.so PCPROFILE_OUTPUT=output-file”, and reviewing the output of “debug/pcprofiledump output-file”.
2024-07-26support: Add FAIL test failure helperMaciej W. Rozycki1-7/+1
Add a FAIL test failure helper analogous to FAIL_RET, that does not cause the current function to return, providing a standardized way to report a test failure with a message supplied while permitting the caller to continue executing, for further reporting, cleaning up, etc. Update existing test cases that provide a conflicting definition of FAIL by removing the local FAIL definition and then as follows: - tst-fortify-syslog: provide a meaningful message in addition to the file name already added by <support/check.h>; 'support_record_failure' is already called by 'support_print_failure_impl' invoked by the new FAIL test failure helper. - tst-ctype: no update to FAIL calls required, with the name of the file and the line number within of the failure site additionally included by the new FAIL test failure helper, and error counting plus count reporting upon test program termination also already provided by 'support_record_failure' and 'support_report_failure' respectively, called by 'support_print_failure_impl' and 'adjust_exit_status' also respectively. However in a number of places 'printf' is called and the error count adjusted by hand, so update these places to make use of FAIL instead. And last but not least adjust the final summary just to report completion, with any error count following as reported by the test driver. - test-tgmath2: no update to FAIL calls required, with the name of the file of the failure site additionally included by the new FAIL test failure helper. Also there is no need to track the return status by hand as any call to FAIL will eventually cause the test case to return an unsuccesful exit status regardless of the return status from the test function, via a call to 'adjust_exit_status' made by the test driver. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-05-14Unify output from backtrace_symbols_fd with backtrace_symbols (bug 31730)Andreas Schwab1-2/+8
2024-02-06string: Add hidden builtin definition for __strcpy_chk.Stefan Liebler1-0/+1
Otherwise on at least x86_64 and s390x there is an unwanted PLT entry in libc.so when configured with --enable-fortify-source=3 and build with -Os. This is observed in elf/check-localplt Extra PLT reference: libc.so: __strcpy_chk The call to PLT entry is in inet/ruserpass.c. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2024-01-12debug/getwd_chk.c: warning should be emitted for the __getwd_chk symbol.Frederic Cambus1-1/+1
Otherwise the warning message for the getwd symbol ends up being duplicated. Signed-off-by: Frederic Cambus <fred@statdns.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
2024-01-01Update copyright dates not handled by scripts/update-copyrightsPaul Eggert2-2/+2
I've updated copyright dates in glibc for 2024. This is the patch for the changes not generated by scripts/update-copyrights and subsequent build / regeneration of generated files.
2024-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert109-109/+109
2023-12-29debug: Add fortify wprintf testsAdhemerval Zanella2-0/+106
Similar to other printf-like ones. It requires to be in a different process so we can change the orientation of stdout. Checked on aarch64, armhf, x86_64, and i686.
2023-12-29debug: Add fortify syslog testsAdhemerval Zanella2-0/+133
It requires to be in a container tests to avoid logging bogus information on the system. The syslog also requires to be checked in a different process because the internal printf call will abort with the internal syslog lock taken (which makes subsequent syslog calls deadlock). Checked on aarch64, armhf, x86_64, and i686. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-12-29debug: Add fortify dprintf testsAdhemerval Zanella1-0/+22
Similar to other printf-like ones. Checked on aarch64, armhf, x86_64, and i686. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-12-29debug: Increase tst-fortify checks for compiler without __va_arg_pack supportAdhemerval Zanella1-5/+1
The fortify wrappers for varargs functions already add fallbacks to builtins calls if __va_arg_pack is not supported. Checked on aarch64, armhf, x86_64, and i686. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-12-29debug: Adapt fortify tests to libsupportAdhemerval Zanella6-40/+39
Checked on aarch64, armhf, x86_64, and i686. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-10-04debug: Add regression tests for BZ 30932Adhemerval Zanella2-0/+84
Checked on x86_64-linux-gnu. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-08-03chk: Add and fix hidden builtin definitions for *_chkSamuel Thibault2-0/+2
Otherwise on gnu-i686 there are unwanted PLT entries in libc.so when fortification is enabled. Tested for i686-gnu, x86_64-gnu, i686-linux-gnu and x86_64-linux-gnu
2023-08-03Subject: hurd: Make __realpath return EINVAL on NULL bufSamuel Thibault1-1/+10
As Posix and stdlib/test-canon.c expects it, and rather than letting pathconf crash.
2023-07-05misc/bits/select2.h: Clearly separate declaration from definitionsFrédéric Bérat1-0/+1
The __fdelt_chk declaration needs to be available so that libc_hidden_proto can be used while not redefining __FD_ELT. Thus, misc/bits/select-decl.h is created to hold the corresponding prototypes. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-07-05unistd: Avoid PLT entries with _FORTIFY_SOURCEFrédéric Bérat2-0/+2
The change is meant to avoid unwanted PLT entries for the read_chk, getdomainname_chk and getlogin_r_chk routines when _FORTIFY_SOURCE is set. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-07-05wchar: Avoid PLT entries with _FORTIFY_SOURCEFrédéric Bérat2-0/+2
The change is meant to avoid unwanted PLT entries for the wmemset and wcrtomb routines when _FORTIFY_SOURCE is set. On top of that, ensure that *_chk routines have their hidden builtin definitions available. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-07-05stdio: Ensure *_chk routines have their hidden builtin definition availableFrédéric Bérat4-1/+20
If libc_hidden_builtin_{def,proto} isn't properly set for *_chk routines, there are unwanted PLT entries in libc.so. There is a special case with __asprintf_chk: If ldbl_* macros are used for asprintf, ABI gets broken on s390x, if it isn't, ppc64le isn't building due to multiple asm redirections. This is due to the inclusion of bits/stdio-lbdl.h for ppc64le whereas it isn't for s390x. This header creates redirections, which are not compatible with the ones generated using libc_hidden_def. Yet, we can't use libc_hidden_ldbl_proto on s390x since it will not create a simple strong alias (e.g. as done on x86_64), but a versioned alias, leading to ABI breakage. This results in errors on s390x: /usr/bin/ld: glibc/iconv/../libio/bits/stdio2.h:137: undefined reference to `__asprintf_chk' Original __asprintf_chk symbols: 00000000001395b0 T __asprintf_chk 0000000000177e90 T __nldbl___asprintf_chk __asprintf_chk symbols with ldbl_* macros: 000000000012d590 t ___asprintf_chk 000000000012d590 t __asprintf_chk@@GLIBC_2.4 000000000012d590 t __GI___asprintf_chk 000000000012d590 t __GL____asprintf_chk___asprintf_chk 0000000000172240 T __nldbl___asprintf_chk __asprintf_chk symbols with the patch: 000000000012d590 t ___asprintf_chk 000000000012d590 T __asprintf_chk 000000000012d590 t __GI___asprintf_chk 0000000000172240 T __nldbl___asprintf_chk Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2023-07-05string: Ensure *_chk routines have their hidden builtin definition availableFrédéric Bérat5-0/+5
If libc_hidden_builtin_{def,proto} isn't properly set for *_chk routines, there are unwanted PLT entries in libc.so. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-07-05Exclude routines from fortificationFrédéric Bérat1-6/+6
Since the _FORTIFY_SOURCE feature uses some routines of Glibc, they need to be excluded from the fortification. On top of that: - some tests explicitly verify that some level of fortification works appropriately, we therefore shouldn't modify the level set for them. - some objects need to be build with optimization disabled, which prevents _FORTIFY_SOURCE to be used for them. Assembler files that implement architecture specific versions of the fortified routines were not excluded from _FORTIFY_SOURCE as there is no C header included that would impact their behavior. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-22debug/readlink{, at}_chk.c: Harmonize declaration and definitionFrederic Berat2-2/+4
The declaration and definition of these routines aren't consistent. Make the definition of __readlink_chk and __readlinkat_chk match the declaration of the routines they fortify. While there are no problems today this avoids any future potential problems related to the mismatch. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-14Add the wcslcpy, wcslcat functionsFlorian Weimer5-0/+83
These functions are about to be added to POSIX, under Austin Group issue 986. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-14Implement strlcpy and strlcat [BZ #178]Florian Weimer5-0/+99
These functions are about to be added to POSIX, under Austin Group issue 986. The fortified strlcat implementation does not raise SIGABRT if the destination buffer does not contain a null terminator, it just inherits the non-failing regular strlcat behavior. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2023-06-02Fix all the remaining misspellings -- BZ 25337Paul Pluzhnikov3-3/+3
2023-05-16debug: Reformat Makefile.Carlos O'Donell1-16/+18
Fix list terminator whitspace. Sort using scripts/sort-makefile-lines.py. No code generation changes observed in binary artifacts. No regressions on x86_64 and i686.
2023-04-17debug: Re-flow and sort routines variable in MakefileFlorian Weimer1-24/+87
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2023-01-25stdio-common: Handle -1 buffer size in __sprintf_chk & co (bug 30039)Florian Weimer2-0/+131
This shows up as an assertion failure when sprintf is called with a specifier like "%.8g" and libquadmath is linked in: Fatal glibc error: printf_buffer_as_file.c:31 (__printf_buffer_as_file_commit): assertion failed: file->stream._IO_write_ptr <= file->next->write_end Fix this by detecting pointer wraparound in __vsprintf_internal and saturate the addition to the end of the address space instead. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
2023-01-06Update copyright dates not handled by scripts/update-copyrightsJoseph Myers2-2/+2
I've updated copyright dates in glibc for 2023. This is the patch for the changes not generated by scripts/update-copyrights and subsequent build / regeneration of generated files.
2023-01-06Update copyright dates with scripts/update-copyrightsJoseph Myers101-101/+101
2022-11-09debug: Fix typo in tests-unsupported ruleAdhemerval Zanella1-1/+1
From commit 2e274cd8c1ebd0bd0c43a7f2e5433685740938ca.
2022-11-08Linux: Add ppoll fortify symbol for 64 bit time_t (BZ# 29746)Adhemerval Zanella1-12/+29
Similar to ppoll, the poll.h header needs to redirect the poll call to a proper fortified ppoll with 64 bit time_t support. The implementation is straightforward, just need to add a similar check as __poll_chk and call the 64 bit time_t ppoll version. The debug fortify tests are also extended to cover 64 bit time_t for affected ABIs. Unfortunately it requires an aditional symbol, which makes backport tricky. One possibility is to add a static inline version if compiler supports is and call abort instead of __chk_fail, so fortified version will call __poll64 in the end. Another possibility is to just remove the fortify support for _TIME_BITS=64. Checked on i686-linux-gnu.
2022-10-28Fix invalid pointer dereference in wcpcpy_chkSzabolcs Nagy1-2/+1
The src pointer is const and points to a different object, so accessing dest via src is invalid. Reviewed-by: Florian Weimer <fweimer@redhat.com>