Skip to content

Commit 80e4e56

Browse files
committed
Merge branch 'for-next/bti-user' into for-next/bti
Merge in user support for Branch Target Identification, which narrowly missed the cut for 5.7 after a late ABI concern. * for-next/bti-user: arm64: bti: Document behaviour for dynamically linked binaries arm64: elf: Fix allnoconfig kernel build with !ARCH_USE_GNU_PROPERTY arm64: BTI: Add Kconfig entry for userspace BTI mm: smaps: Report arm64 guarded pages in smaps arm64: mm: Display guarded pages in ptdump KVM: arm64: BTI: Reset BTYPE when skipping emulated instructions arm64: BTI: Reset BTYPE when skipping emulated instructions arm64: traps: Shuffle code to eliminate forward declarations arm64: unify native/compat instruction skipping arm64: BTI: Decode BYTPE bits when printing PSTATE arm64: elf: Enable BTI at exec based on ELF program properties elf: Allow arch to tweak initial mmap prot flags arm64: Basic Branch Target Identification support ELF: Add ELF program property parsing support ELF: UAPI and Kconfig additions for ELF program properties
2 parents 6a8b55e + 5d1b631 commit 80e4e56

35 files changed

+564
-74
lines changed

Documentation/arm64/cpu-feature-registers.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ infrastructure:
176176
+------------------------------+---------+---------+
177177
| SSBS | [7-4] | y |
178178
+------------------------------+---------+---------+
179+
| BT | [3-0] | y |
180+
+------------------------------+---------+---------+
179181

180182

181183
4) MIDR_EL1 - Main ID Register

Documentation/arm64/elf_hwcaps.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ HWCAP2_RNG
236236

237237
Functionality implied by ID_AA64ISAR0_EL1.RNDR == 0b0001.
238238

239+
HWCAP2_BTI
240+
241+
Functionality implied by ID_AA64PFR0_EL1.BT == 0b0001.
242+
243+
239244
4. Unused AT_HWCAP bits
240245
-----------------------
241246

Documentation/filesystems/proc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ encoded manner. The codes are the following:
543543
hg huge page advise flag
544544
nh no huge page advise flag
545545
mg mergable advise flag
546+
bt - arm64 BTI guarded page
546547
== =======================================
547548

548549
Note that there is no guarantee that every flag and associated mnemonic will

arch/arm64/Kconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config ARM64
99
select ACPI_MCFG if (ACPI && PCI)
1010
select ACPI_SPCR_TABLE if ACPI
1111
select ACPI_PPTT if ACPI
12+
select ARCH_BINFMT_ELF_STATE
1213
select ARCH_HAS_DEBUG_VIRTUAL
1314
select ARCH_HAS_DEVMEM_IS_ALLOWED
1415
select ARCH_HAS_DMA_PREP_COHERENT
@@ -32,6 +33,7 @@ config ARM64
3233
select ARCH_HAS_SYSCALL_WRAPPER
3334
select ARCH_HAS_TEARDOWN_DMA_OPS if IOMMU_SUPPORT
3435
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
36+
select ARCH_HAVE_ELF_PROT
3537
select ARCH_HAVE_NMI_SAFE_CMPXCHG
3638
select ARCH_INLINE_READ_LOCK if !PREEMPTION
3739
select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION
@@ -61,6 +63,7 @@ config ARM64
6163
select ARCH_INLINE_SPIN_UNLOCK_IRQRESTORE if !PREEMPTION
6264
select ARCH_KEEP_MEMBLOCK
6365
select ARCH_USE_CMPXCHG_LOCKREF
66+
select ARCH_USE_GNU_PROPERTY
6467
select ARCH_USE_QUEUED_RWLOCKS
6568
select ARCH_USE_QUEUED_SPINLOCKS
6669
select ARCH_SUPPORTS_MEMORY_FAILURE
@@ -1584,6 +1587,28 @@ endmenu
15841587

15851588
menu "ARMv8.5 architectural features"
15861589

1590+
config ARM64_BTI
1591+
bool "Branch Target Identification support"
1592+
default y
1593+
help
1594+
Branch Target Identification (part of the ARMv8.5 Extensions)
1595+
provides a mechanism to limit the set of locations to which computed
1596+
branch instructions such as BR or BLR can jump.
1597+
1598+
To make use of BTI on CPUs that support it, say Y.
1599+
1600+
BTI is intended to provide complementary protection to other control
1601+
flow integrity protection mechanisms, such as the Pointer
1602+
authentication mechanism provided as part of the ARMv8.3 Extensions.
1603+
For this reason, it does not make sense to enable this option without
1604+
also enabling support for pointer authentication. Thus, when
1605+
enabling this option you should also select ARM64_PTR_AUTH=y.
1606+
1607+
Userspace binaries must also be specifically compiled to make use of
1608+
this mechanism. If you say N here or the hardware does not support
1609+
BTI, such binaries can still run, but you get no additional
1610+
enforcement of branch destinations.
1611+
15871612
config ARM64_E0PD
15881613
bool "Enable support for E0PD"
15891614
default y

arch/arm64/include/asm/cpucaps.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
#define ARM64_HAS_AMU_EXTN 51
6262
#define ARM64_HAS_ADDRESS_AUTH 52
6363
#define ARM64_HAS_GENERIC_AUTH 53
64+
#define ARM64_BTI 54
6465

65-
#define ARM64_NCAPS 54
66+
#define ARM64_NCAPS 55
6667

6768
#endif /* __ASM_CPUCAPS_H */

arch/arm64/include/asm/cpufeature.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,11 @@ static inline bool system_has_prio_mask_debugging(void)
680680
system_uses_irq_prio_masking();
681681
}
682682

683+
static inline bool system_supports_bti(void)
684+
{
685+
return IS_ENABLED(CONFIG_ARM64_BTI) && cpus_have_const_cap(ARM64_BTI);
686+
}
687+
683688
#define ARM64_BP_HARDEN_UNKNOWN -1
684689
#define ARM64_BP_HARDEN_WA_NEEDED 0
685690
#define ARM64_BP_HARDEN_NOT_REQUIRED 1

arch/arm64/include/asm/elf.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@
114114

115115
#ifndef __ASSEMBLY__
116116

117+
#include <uapi/linux/elf.h>
117118
#include <linux/bug.h>
119+
#include <linux/errno.h>
120+
#include <linux/fs.h>
121+
#include <linux/types.h>
118122
#include <asm/processor.h> /* for signal_minsigstksz, used by ARCH_DLINFO */
119123

120124
typedef unsigned long elf_greg_t;
@@ -224,6 +228,52 @@ extern int aarch32_setup_additional_pages(struct linux_binprm *bprm,
224228

225229
#endif /* CONFIG_COMPAT */
226230

231+
struct arch_elf_state {
232+
int flags;
233+
};
234+
235+
#define ARM64_ELF_BTI (1 << 0)
236+
237+
#define INIT_ARCH_ELF_STATE { \
238+
.flags = 0, \
239+
}
240+
241+
static inline int arch_parse_elf_property(u32 type, const void *data,
242+
size_t datasz, bool compat,
243+
struct arch_elf_state *arch)
244+
{
245+
/* No known properties for AArch32 yet */
246+
if (IS_ENABLED(CONFIG_COMPAT) && compat)
247+
return 0;
248+
249+
if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
250+
const u32 *p = data;
251+
252+
if (datasz != sizeof(*p))
253+
return -ENOEXEC;
254+
255+
if (system_supports_bti() &&
256+
(*p & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
257+
arch->flags |= ARM64_ELF_BTI;
258+
}
259+
260+
return 0;
261+
}
262+
263+
static inline int arch_elf_pt_proc(void *ehdr, void *phdr,
264+
struct file *f, bool is_interp,
265+
struct arch_elf_state *state)
266+
{
267+
return 0;
268+
}
269+
270+
static inline int arch_check_elf(void *ehdr, bool has_interp,
271+
void *interp_ehdr,
272+
struct arch_elf_state *state)
273+
{
274+
return 0;
275+
}
276+
227277
#endif /* !__ASSEMBLY__ */
228278

229279
#endif

arch/arm64/include/asm/esr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define ESR_ELx_EC_PAC (0x09) /* EL2 and above */
2323
/* Unallocated EC: 0x0A - 0x0B */
2424
#define ESR_ELx_EC_CP14_64 (0x0C)
25-
/* Unallocated EC: 0x0d */
25+
#define ESR_ELx_EC_BTI (0x0D)
2626
#define ESR_ELx_EC_ILL (0x0E)
2727
/* Unallocated EC: 0x0F - 0x10 */
2828
#define ESR_ELx_EC_SVC32 (0x11)

arch/arm64/include/asm/exception.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static inline u32 disr_to_esr(u64 disr)
3434
asmlinkage void enter_from_user_mode(void);
3535
void do_mem_abort(unsigned long addr, unsigned int esr, struct pt_regs *regs);
3636
void do_undefinstr(struct pt_regs *regs);
37+
void do_bti(struct pt_regs *regs);
3738
asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr);
3839
void do_debug_exception(unsigned long addr_if_watchpoint, unsigned int esr,
3940
struct pt_regs *regs);

arch/arm64/include/asm/hwcap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#define KERNEL_HWCAP_BF16 __khwcap2_feature(BF16)
9595
#define KERNEL_HWCAP_DGH __khwcap2_feature(DGH)
9696
#define KERNEL_HWCAP_RNG __khwcap2_feature(RNG)
97+
#define KERNEL_HWCAP_BTI __khwcap2_feature(BTI)
9798

9899
/*
99100
* This yields a mask that user programs can use to figure out what

0 commit comments

Comments
 (0)