From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Cc: "H . J . Lu" <hjl.tools@gmail.com>,
Florian Weimer <fweimer@redhat.com>,
Zack Weinberg <zack@owlfolio.org>
Subject: [PATCH v3 0/4] Improve executable stack handling
Date: Tue, 18 Jun 2024 16:40:18 -0300 [thread overview]
Message-ID: <20240618194102.2059389-1-adhemerval.zanella@linaro.org> (raw)
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 executable stack transition failure does not
undo the previous transitions (meaning that if the library fails to load,
there can be thread stacks with executable stacks), this behavior was
used on recent CVE [1] as a vector for RCE.
The second patch changes the behavior where 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.
The fourth patch also adds a tunable, glibc.rtld.execstack, which can be
used to control whether executable stacks are allowed from either the
main program or dependencies. The default is to allow executable stacks.
The executable stacks default permission is checked against the one
provided by the PT_GNU_STACK from program headers (if present). The
tunable also disables the stack permission change if any dependency
requires an executable stack at loading time.
* Changes from v2:
- Removed the dlopen executable stack support.
- Allow program and dependencies with executable stack as default.
- Rename tunable from glibc.rtld.noexecstack to glibc.rtld.execstack.
* Changes from v1:
- Fixed tests invocation without --enable-hardcoded-path-in-tests.
- Added hurd, hppa, mips exceptions.
Adhemerval Zanella (4):
elf: Consolidate stackinfo.h
elf: Do not change stack permission on dlopen/dlmopen
elf: Add tst-execstack-prog-static
elf: Add glibc.rtld.execstack
NEWS | 12 ++
elf/Makefile | 49 +++++++
elf/dl-load.c | 13 +-
elf/dl-support.c | 5 +
elf/dl-tunables.list | 6 +
elf/rtld.c | 4 +
elf/tst-execstack-prog-static.c | 1 +
elf/tst-execstack.c | 142 ++++++++------------
elf/tst-rtld-list-tunables.exp | 1 +
manual/tunables.texi | 19 +++
nptl/allocatestack.c | 19 ---
sysdeps/aarch64/stackinfo.h | 33 -----
sysdeps/arc/stackinfo.h | 33 -----
sysdeps/csky/stackinfo.h | 29 ----
sysdeps/generic/stackinfo.h | 15 ++-
sysdeps/loongarch/stackinfo.h | 33 -----
sysdeps/nios2/stackinfo.h | 33 -----
sysdeps/nptl/pthreadP.h | 6 -
sysdeps/powerpc/{ => powerpc32}/stackinfo.h | 8 +-
sysdeps/riscv/stackinfo.h | 33 -----
sysdeps/unix/sysv/linux/Versions | 3 -
sysdeps/unix/sysv/linux/dl-execstack.c | 67 +--------
sysdeps/unix/sysv/linux/mips/Makefile | 7 +
23 files changed, 183 insertions(+), 388 deletions(-)
create mode 100644 elf/tst-execstack-prog-static.c
delete mode 100644 sysdeps/aarch64/stackinfo.h
delete mode 100644 sysdeps/arc/stackinfo.h
delete mode 100644 sysdeps/csky/stackinfo.h
delete mode 100644 sysdeps/loongarch/stackinfo.h
delete mode 100644 sysdeps/nios2/stackinfo.h
rename sysdeps/powerpc/{ => powerpc32}/stackinfo.h (82%)
delete mode 100644 sysdeps/riscv/stackinfo.h
--
2.43.0
next reply other threads:[~2024-06-18 19:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 19:40 Adhemerval Zanella [this message]
2024-06-18 19:40 ` [PATCH v3 1/4] elf: Consolidate stackinfo.h Adhemerval Zanella
2024-06-18 19:40 ` [PATCH v3 2/4] elf: Do not change stack permission on dlopen/dlmopen Adhemerval Zanella
2024-06-18 19:40 ` [PATCH v3 3/4] elf: Add tst-execstack-prog-static Adhemerval Zanella
2024-06-18 19:40 ` [PATCH v3 4/4] elf: Add glibc.rtld.execstack Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240618194102.2059389-1-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=hjl.tools@gmail.com \
--cc=libc-alpha@sourceware.org \
--cc=zack@owlfolio.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).