1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-04-19 01:04:13 +03:00
glibc/elf/dl-execstack-tunable.c
Adhemerval Zanella 12a497c716 elf: Extend glibc.rtld.execstack tunable to force executable stack (BZ 32653)
From the bug report [1], multiple programs still require to dlopen
shared libraries with either missing PT_GNU_STACK or with the executable
bit set.  Although, in some cases, it seems to be a hard-craft assembly
source without the required .note.GNU-stack marking (so the static linker
is forced to set the stack executable if the ABI requires it), other
cases seem that the library uses trampolines [2].

Unfortunately, READ_IMPLIES_EXEC is not an option since on some ABIs
(x86_64), the kernel clears the bit, making it unsupported.  To avoid
reinstating the broken code that changes stack permission on dlopen
(0ca8785a28), this patch extends the glibc.rtld.execstack tunable to
allow an option to force an executable stack at the program startup.

The tunable is a security issue because it defeats the PT_GNU_STACK
hardening.  It has the slight advantage of making it explicit by the
caller, and, as for other tunables, this is disabled for setuid binaries.
A tunable also allows us to eventually remove it, but from previous
experiences, it would require some time.

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

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=32653
[2] https://github.com/conda-forge/ctng-compiler-activation-feedstock/issues/143
Reviewed-by: Sam James <sam@gentoo.org>
2025-04-08 16:19:49 -03:00

40 lines
1.4 KiB
C

/* Stack executability handling for GNU dynamic linker.
Copyright (C) 2025 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <ldsodefs.h>
#include <dl-tunables.h>
void
_dl_handle_execstack_tunable (void)
{
switch (TUNABLE_GET (glibc, rtld, execstack, int32_t, NULL))
{
case stack_tunable_mode_disable:
if ((__glibc_unlikely (GL(dl_stack_flags)) & PF_X))
_dl_fatal_printf (
"Fatal glibc error: executable stack is not allowed\n");
break;
case stack_tunable_mode_force:
if (_dl_make_stack_executable (&__libc_stack_end) != 0)
_dl_fatal_printf (
"Fatal glibc error: cannot enable executable stack as tunable requires");
break;
}
}