@@ -251,12 +251,21 @@ struct arch_elf_state {
int flags;
};
-#define ARM64_ELF_BTI (1 << 0)
+#define ARM64_ELF_INTERP_BTI (1 << 0)
+#define ARM64_ELF_EXEC_BTI (1 << 1)
#define INIT_ARCH_ELF_STATE { \
.flags = 0, \
}
+static inline int arm64_elf_bti_flag(bool is_interp)
+{
+ if (is_interp)
+ return ARM64_ELF_INTERP_BTI;
+ else
+ return ARM64_ELF_EXEC_BTI;
+}
+
static inline int arch_parse_elf_property(u32 type, const void *data,
size_t datasz, bool compat,
bool has_interp, bool is_interp,
@@ -272,9 +281,9 @@ static inline int arch_parse_elf_property(u32 type, const void *data,
if (datasz != sizeof(*p))
return -ENOEXEC;
- if (system_supports_bti() && has_interp == is_interp &&
+ if (system_supports_bti() &&
(*p & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
- arch->flags |= ARM64_ELF_BTI;
+ arch->flags |= arm64_elf_bti_flag(is_interp);
}
return 0;
@@ -702,18 +702,8 @@ core_initcall(tagged_addr_init);
int arch_elf_adjust_prot(int prot, const struct arch_elf_state *state,
bool has_interp, bool is_interp)
{
- /*
- * For dynamically linked executables the interpreter is
- * responsible for setting PROT_BTI on everything except
- * itself.
- */
- if (is_interp != has_interp)
- return prot;
-
- if (!(state->flags & ARM64_ELF_BTI))
- return prot;
-
- if (prot & PROT_EXEC)
+ if ((prot & PROT_EXEC) &&
+ (state->flags & arm64_elf_bti_flag(is_interp)))
prot |= PROT_BTI;
return prot;