[PATCH] aarch64: Fix PT_GNU_PROPERTY checks for static exe (BZ 33713)
Yury Khrustalev
yury.khrustalev@arm.com
Fri Dec 12 14:22:27 GMT 2025
All checks related to the PT_GNU_PROPERTY bits would be skipped
if the binary had no PT_GNU_PROPERTY note at all. This meant that
enforcing an abort when some bits are not present was not possible.
Fixes BZ 33713
---
Regression checked on AArch64. OK for trunk?
Base commit: f56382e67e
---
sysdeps/aarch64/Makefile | 7 ++++
sysdeps/aarch64/tst-bti-abort-static.c | 36 ++++++++++++++++++++
sysdeps/unix/sysv/linux/aarch64/Makefile | 5 +--
sysdeps/unix/sysv/linux/aarch64/libc-start.h | 3 +-
4 files changed, 48 insertions(+), 3 deletions(-)
create mode 100644 sysdeps/aarch64/tst-bti-abort-static.c
diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile
index 71aee7fed1..b939bcfc11 100644
--- a/sysdeps/aarch64/Makefile
+++ b/sysdeps/aarch64/Makefile
@@ -140,6 +140,13 @@ $(objpfx)tst-bti-abort-%.out: $(..)sysdeps/aarch64/tst-bti-abort.sh \
$(SHELL) $< $(common-objpfx) $(test-name) '$(run-bti-abort-test)'; \
$(evaluate-test)
+tests-static += \
+ tst-bti-abort-static \
+ # tests-static
+
+tst-bti-abort-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_bti=1
+CFLAGS-tst-bti-abort-static.o += -mbranch-protection=none
+
endif # ifeq (yes,$(have-test-bti))
endif
diff --git a/sysdeps/aarch64/tst-bti-abort-static.c b/sysdeps/aarch64/tst-bti-abort-static.c
new file mode 100644
index 0000000000..83871b1fdb
--- /dev/null
+++ b/sysdeps/aarch64/tst-bti-abort-static.c
@@ -0,0 +1,36 @@
+/* Test to check that static binary without PT_GNU_PROPERTY can
+ still be enforced to have BTI marking (and abort since it
+ doesn't have any).
+ 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 <stdio.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <support/check.h>
+#include <support/support.h>
+#include <support/test-driver.h>
+
+static int
+do_test (void)
+{
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index 6741f8ec00..6ea6048822 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -73,9 +73,10 @@ LDFLAGS-tst-gcs-optional-on += -Wl,-z,gcs=always
LDFLAGS-tst-gcs-optional-off += -Wl,-z,gcs=never
LDFLAGS-tst-gcs-override += -Wl,-z,gcs=never
+CFLAGS-tst-gcs-enforced-static-abort.o += -mbranch-protection=none
+
LDFLAGS-tst-gcs-disabled-static += -Wl,-z,gcs=always
LDFLAGS-tst-gcs-enforced-static += -Wl,-z,gcs=always
-LDFLAGS-tst-gcs-enforced-static-abort += -Wl,-z,gcs=never
LDFLAGS-tst-gcs-optional-static-on += -Wl,-z,gcs=always
LDFLAGS-tst-gcs-optional-static-off += -Wl,-z,gcs=never
LDFLAGS-tst-gcs-override-static += -Wl,-z,gcs=never
@@ -89,7 +90,7 @@ tst-gcs-override-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
tst-gcs-disabled-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
tst-gcs-enforced-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
-tst-gcs-enforced-static-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
+tst-gcs-enforced-static-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1:glibc.cpu.aarch64_bti=0
tst-gcs-optional-static-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
tst-gcs-optional-static-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
tst-gcs-override-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc-start.h b/sysdeps/unix/sysv/linux/aarch64/libc-start.h
index 75ae0a884a..bd2689abe7 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc-start.h
+++ b/sysdeps/unix/sysv/linux/aarch64/libc-start.h
@@ -41,10 +41,11 @@ aarch64_libc_setup_tls (void)
if (ph->p_type == PT_GNU_PROPERTY)
{
_dl_process_pt_gnu_property (main_map, -1, ph);
- _rtld_main_check (main_map, _dl_argv[0]);
break;
}
+ _rtld_main_check (main_map, _dl_argv[0]);
+
if (GL(dl_aarch64_gcs) != 0)
{
int ret = INLINE_SYSCALL_CALL (prctl, PR_SET_SHADOW_STACK_STATUS,
--
2.47.3
More information about the Libc-alpha
mailing list