]> git.ipfire.org Git - thirdparty/glibc.git/commit
elf: Do not change stack permission on dlopen/dlmopen
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 28 Nov 2024 17:36:43 +0000 (14:36 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 31 Dec 2024 12:04:20 +0000 (09:04 -0300)
commit0ca8785a28515291d4ef074b5b6cfb27434c1d2b
treeba0b23b8b1bcef4d2717f1d605d32ef11518430c
parentca96ea06b37c8601dcc9579dd4c8619322ab1ea1
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>
13 files changed:
NEWS
elf/dl-load.c
elf/dl-support.c
elf/rtld.c
elf/tst-execstack.c
nptl/allocatestack.c
sysdeps/generic/ldsodefs.h
sysdeps/mach/hurd/Makefile
sysdeps/mach/hurd/dl-execstack.c
sysdeps/nptl/pthreadP.h
sysdeps/unix/sysv/linux/Versions
sysdeps/unix/sysv/linux/dl-execstack.c
sysdeps/unix/sysv/linux/mips/Makefile