aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/x86
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2024-01-12 10:19:41 -0800
committerH.J. Lu <hjl.tools@gmail.com>2024-01-15 06:59:23 -0800
commit457bd9cf2e27550dd66b2d8f3c5a8dbd0dfb398f (patch)
tree1674e1b7e3ee439c9271313ac122894e9f820126 /sysdeps/x86
parent7100d9ae21e2737f96f824259167788aabd8308f (diff)
downloadglibc-457bd9cf2e27550dd66b2d8f3c5a8dbd0dfb398f.tar
glibc-457bd9cf2e27550dd66b2d8f3c5a8dbd0dfb398f.tar.gz
glibc-457bd9cf2e27550dd66b2d8f3c5a8dbd0dfb398f.tar.bz2
glibc-457bd9cf2e27550dd66b2d8f3c5a8dbd0dfb398f.zip
x86-64: Check if mprotect works before rewriting PLT
Systemd execution environment configuration may prohibit changing a memory mapping to become executable: MemoryDenyWriteExecute= Takes a boolean argument. If set, attempts to create memory mappings that are writable and executable at the same time, or to change existing memory mappings to become executable, or mapping shared memory segments as executable, are prohibited. When it is set, systemd service stops working if PLT rewrite is enabled. Check if mprotect works before rewriting PLT. This fixes BZ #31230. This also works with SELinux when deny_execmem is on. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'sysdeps/x86')
-rw-r--r--sysdeps/x86/cpu-features.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index 46bdaffbc2..25e6622a79 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -28,10 +28,16 @@ extern void TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *)
attribute_hidden;
#if defined SHARED && defined __x86_64__
+# include <dl-plt-rewrite.h>
+
static void
TUNABLE_CALLBACK (set_plt_rewrite) (tunable_val_t *valp)
{
- if (valp->numval != 0)
+ /* We must be careful about where we put the call to
+ dl_plt_rewrite_supported() since it may generate
+ spurious SELinux log entries. It should only be
+ attempted if the user requested a PLT rewrite. */
+ if (valp->numval != 0 && dl_plt_rewrite_supported ())
{
/* Use JMPABS only on APX processors. */
const struct cpu_features *cpu_features = __get_cpu_features ();