[PATCH v2 3/4] aarch64: Support enforcing BTI on dependencies
Yury Khrustalev
yury.khrustalev@arm.com
Wed Nov 19 16:35:20 GMT 2025
---
sysdeps/aarch64/cpu-features.h | 5 +++++
sysdeps/aarch64/dl-bti.c | 16 +++++++++++++++-
sysdeps/aarch64/linkmap.h | 1 +
sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c | 2 +-
4 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/sysdeps/aarch64/cpu-features.h b/sysdeps/aarch64/cpu-features.h
index ef4e947e8c..855990b575 100644
--- a/sysdeps/aarch64/cpu-features.h
+++ b/sysdeps/aarch64/cpu-features.h
@@ -54,6 +54,11 @@
|| (MIDR_PARTNUM(midr) == 0x002 \
&& MIDR_VARIANT(midr) == 0)))
+enum {
+ BTI_CHECK_PERMISSIVE = 0,
+ BTI_CHECK_ENFORCED = 1,
+};
+
struct cpu_features
{
uint64_t midr_el1;
diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c
index de6130470e..3215a4575b 100644
--- a/sysdeps/aarch64/dl-bti.c
+++ b/sysdeps/aarch64/dl-bti.c
@@ -31,6 +31,9 @@
void
_dl_bti_protect (struct link_map *map, int fd)
{
+ /* If we try to enable BTI protection, MAP must be BTI marked. */
+ map->l_mach.bti = true;
+
const size_t pagesz = GLRO(dl_pagesize);
const ElfW(Phdr) *phdr;
@@ -72,7 +75,6 @@ bti_failed (struct link_map *l, const char *program)
N_("failed to turn on BTI protection"));
}
-
/* Enable BTI for L and its dependencies. */
void
@@ -84,10 +86,22 @@ _dl_bti_check (struct link_map *l, const char *program)
if (l->l_mach.bti_fail)
bti_failed (l, program);
+ /* We enforce BTI if tunable is set and if this object has BTI marking. */
+ bool enforce_bti = GLRO (dl_aarch64_bti) == BTI_CHECK_ENFORCED;
+
for (unsigned int i = 0; i < l->l_searchlist.r_nlist; i++)
{
struct link_map *dep = l->l_searchlist.r_list[i];
if (dep->l_mach.bti_fail)
bti_failed (dep, program);
+#ifdef SHARED
+ /* Ignore BTI marking on ld.so: its properties are not processed and
+ kernel is responsible for setting up BTI protection for the
+ loader. */
+ if (is_rtld_link_map (dep->l_real))
+ continue;
+#endif
+ if (enforce_bti && !dep->l_mach.bti)
+ bti_failed (dep, program);
}
}
diff --git a/sysdeps/aarch64/linkmap.h b/sysdeps/aarch64/linkmap.h
index e56c890aea..4cd0492209 100644
--- a/sysdeps/aarch64/linkmap.h
+++ b/sysdeps/aarch64/linkmap.h
@@ -24,4 +24,5 @@ struct link_map_machine
void *tlsdesc_table; /* Address of TLS descriptor hash table. */
bool bti_fail; /* Failed to enable Branch Target Identification. */
bool gcs; /* Guarded Control Stack marking. */
+ bool bti; /* Branch Target Identification marking. */
};
diff --git a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c
index 20083b1475..7c34c8ddba 100644
--- a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c
+++ b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c
@@ -63,7 +63,7 @@ PROCINFO_CLASS struct cpu_features _dl_aarch64_cpu_features
PROCINFO_CLASS unsigned long _dl_aarch64_bti
# endif
# ifndef PROCINFO_DECL
-= 0
+= BTI_CHECK_PERMISSIVE
# endif
# if !defined SHARED || defined PROCINFO_DECL
;
--
2.47.3
More information about the Libc-alpha
mailing list