glibc/sysdeps
Adhemerval Zanella 0ca8785a28 elf: Do not change stack permission on dlopen/dlmopen
If some shared library loaded with dlopen/dlmopen requires an executable
stack, either implicitly because of a missing GNU_STACK ELF header
(where the ABI default flags implies in the executable bit) or explicitly
because of the executable bit from GNU_STACK; the loader will try to set
the both the main thread and all thread stacks (from the pthread cache)
as executable.

Besides the issue where any __nptl_change_stack_perm failure does not
undo the previous executable transition (meaning that if the library
fails to load, there can be thread stacks with executable stacks), this
behavior was used on a CVE [1] as a vector for RCE.

This patch changes that if a shared library requires an executable
stack, and the current stack is not executable, dlopen fails.  The
change is done only for dynamically loaded modules, if the program
or any dependency requires an executable stack, the loader will still
change the main thread before program execution and any thread created
with default stack configuration.

[1] https://www.qualys.com/2023/07/19/cve-2023-38408/rce-openssh-forwarded-ssh-agent.txt

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2024-12-31 09:04:20 -03:00
..
aarch64 aarch64: Regenerate ulps 2024-12-20 07:12:30 +01:00
alpha math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
arc math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
arm elf: Introduce is_rtld_link_map 2024-12-20 15:52:57 +01:00
csky math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
generic elf: Do not change stack permission on dlopen/dlmopen 2024-12-31 09:04:20 -03:00
gnu sysdeps: Re-flow and sort multiline gnu/Makefile definitions 2024-08-07 11:02:03 -03:00
hppa nptl: hppa: replace __get_cr27 with __thread_pointer 2024-12-27 17:41:02 +01:00
htl htl: move pthread_cond_timedwait, pthread_cond_clockwait, pthread_cond_wait into libc. 2024-12-22 23:37:30 +01:00
hurd hurd: Move internal functions to internal header 2024-03-23 22:43:07 +01:00
i386 i386: Regenerate ulps 2024-12-20 12:40:17 +01:00
ieee754 math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
loongarch math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
m68k math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
mach elf: Do not change stack permission on dlopen/dlmopen 2024-12-31 09:04:20 -03:00
microblaze math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
mips elf: Introduce is_rtld_link_map 2024-12-20 15:52:57 +01:00
nptl elf: Do not change stack permission on dlopen/dlmopen 2024-12-31 09:04:20 -03:00
or1k math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
posix posix: fix system when a child cannot be created [BZ #32450] 2024-12-20 22:57:06 +01:00
powerpc elf: Introduce is_rtld_link_map 2024-12-20 15:52:57 +01:00
pthread Use empty initializer to silence GCC 4.9 or older 2024-12-16 04:06:30 +08:00
riscv math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
s390 math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
sh elf: Introduce is_rtld_link_map 2024-12-20 15:52:57 +01:00
sparc math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
unix elf: Do not change stack permission on dlopen/dlmopen 2024-12-31 09:04:20 -03:00
wordsize-32 Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wordsize-64 Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
x86 include/sys/cdefs.h: Add __attribute_optimization_barrier__ 2024-12-23 06:28:55 +08:00
x86_64 elf: Remove the GET_ADDR_ARGS and related macros from the TLS code 2024-12-27 07:29:56 +01:00