History

arm64: Basic Branch Target Identification support

This patch adds the bare minimum required to expose the ARMv8.5 Branch Target Identification feature to userspace. By itself, this does _not_ automatically enable BTI for any initial executable pages mapped by execve(). This will come later, but for now it should be possible to enable BTI manually on those pages by using mprotect() from within the target process. Other arches already using the generic mman.h are already using 0x10 for arch-specific prot flags, so we use that for PROT_BTI here. For consistency, signal handler entry points in BTI guarded pages are required to be annotated as such, just like any other function. This blocks a relatively minor attack vector, but comforming userspace will have the annotations anyway, so we may as well enforce them.

Dave Martin committed 6 years ago

Commit 8ef8f361 parent 00e19ce23 files · +172 −4Browse files

Unified · Split

23 files
  1. Documentation/arm64/cpu-feature-registers.rst +2 −0
  2. Documentation/arm64/elf_hwcaps.rst +5 −0
  3. arch/arm64/include/asm/cpucaps.h +2 −1
  4. arch/arm64/include/asm/cpufeature.h +6 −0
  5. arch/arm64/include/asm/esr.h +1 −1
  6. arch/arm64/include/asm/exception.h +1 −0
  7. arch/arm64/include/asm/hwcap.h +1 −0
  8. arch/arm64/include/asm/mman.h +37 −0
  9. arch/arm64/include/asm/pgtable-hwdef.h +1 −0
  10. arch/arm64/include/asm/pgtable.h +1 −1
  11. arch/arm64/include/asm/ptrace.h +1 −0
  12. arch/arm64/include/asm/sysreg.h +4 −0
  13. arch/arm64/include/uapi/asm/hwcap.h +1 −0
  14. arch/arm64/include/uapi/asm/mman.h +9 −0
  15. arch/arm64/include/uapi/asm/ptrace.h +9 −0
  16. arch/arm64/kernel/cpufeature.c +33 −0
  17. arch/arm64/kernel/cpuinfo.c +1 −0
  18. arch/arm64/kernel/entry-common.c +11 −0
  19. arch/arm64/kernel/ptrace.c +1 −1
  20. arch/arm64/kernel/signal.c +16 −0
  21. arch/arm64/kernel/syscall.c +18 −0
  22. arch/arm64/kernel/traps.c +8 −0
  23. include/linux/mm.h +3 −0
Documentation/arm64/cpu-feature-registers.rst+2−0
@@ -176,6 +176,8 @@ infrastructure: · 175 unmodified lines
176 +------------------------------+---------+---------+176 +------------------------------+---------+---------+
177 | SSBS | [7-4] | y |177 | SSBS | [7-4] | y |
178 +------------------------------+---------+---------+178 +------------------------------+---------+---------+
179 | BT | [3-0] | y |
180 +------------------------------+---------+---------+
179 181
180 182
181 4) MIDR_EL1 - Main ID Register183 4) MIDR_EL1 - Main ID Register
Documentation/arm64/elf_hwcaps.rst+5−0
@@ -236,6 +236,11 @@ HWCAP2_RNG · 235 unmodified lines
236 236
237 Functionality implied by ID_AA64ISAR0_EL1.RNDR == 0b0001.237 Functionality implied by ID_AA64ISAR0_EL1.RNDR == 0b0001.
238 238
239HWCAP2_BTI
240
241 Functionality implied by ID_AA64PFR0_EL1.BT == 0b0001.
242
243
2394. Unused AT_HWCAP bits2444. Unused AT_HWCAP bits
240-----------------------245-----------------------
241 246
arch/arm64/include/asm/cpucaps.h+2−1
@@ -58,7 +58,8 @@ · 57 unmodified lines
58#define ARM64_WORKAROUND_SPECULATIVE_AT_NVHE 4858#define ARM64_WORKAROUND_SPECULATIVE_AT_NVHE 48
59#define ARM64_HAS_E0PD 4959#define ARM64_HAS_E0PD 49
60#define ARM64_HAS_RNG 5060#define ARM64_HAS_RNG 50
61#define ARM64_BTI 51
61 62
62#define ARM64_NCAPS 5163#define ARM64_NCAPS 52
63 64
64#endif /* __ASM_CPUCAPS_H */65#endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/cpufeature.h+6−0
@@ -613,6 +613,12 @@ static inline bool system_has_prio_mask_debugging(void) · 612 unmodified lines
613 system_uses_irq_prio_masking();613 system_uses_irq_prio_masking();
614}614}
615 615
616static inline bool system_supports_bti(void)
617{
618 return IS_ENABLED(CONFIG_ARM64_BTI) &&
619 cpus_have_const_cap(ARM64_BTI);
620}
621
616static inline bool system_capabilities_finalized(void)622static inline bool system_capabilities_finalized(void)
617{623{
618 return static_branch_likely(&arm64_const_caps_ready);624 return static_branch_likely(&arm64_const_caps_ready);
arch/arm64/include/asm/esr.h+1−1
@@ -22,7 +22,7 @@ · 21 unmodified lines
22#define ESR_ELx_EC_PAC (0x09) /* EL2 and above */22#define ESR_ELx_EC_PAC (0x09) /* EL2 and above */
23/* Unallocated EC: 0x0A - 0x0B */23/* Unallocated EC: 0x0A - 0x0B */
24#define ESR_ELx_EC_CP14_64 (0x0C)24#define ESR_ELx_EC_CP14_64 (0x0C)
25/* Unallocated EC: 0x0d */25#define ESR_ELx_EC_BTI (0x0D)
26#define ESR_ELx_EC_ILL (0x0E)26#define ESR_ELx_EC_ILL (0x0E)
27/* Unallocated EC: 0x0F - 0x10 */27/* Unallocated EC: 0x0F - 0x10 */
28#define ESR_ELx_EC_SVC32 (0x11)28#define ESR_ELx_EC_SVC32 (0x11)
arch/arm64/include/asm/exception.h+1−0
@@ -34,6 +34,7 @@ static inline u32 disr_to_esr(u64 disr) · 33 unmodified lines
34asmlinkage void enter_from_user_mode(void);34asmlinkage void enter_from_user_mode(void);
35void do_mem_abort(unsigned long addr, unsigned int esr, struct pt_regs *regs);35void do_mem_abort(unsigned long addr, unsigned int esr, struct pt_regs *regs);
36void do_undefinstr(struct pt_regs *regs);36void do_undefinstr(struct pt_regs *regs);
37void do_bti(struct pt_regs *regs);
37asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr);38asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr);
38void do_debug_exception(unsigned long addr_if_watchpoint, unsigned int esr,39void do_debug_exception(unsigned long addr_if_watchpoint, unsigned int esr,
39 struct pt_regs *regs);40 struct pt_regs *regs);
arch/arm64/include/asm/hwcap.h+1−0
@@ -94,6 +94,7 @@ · 93 unmodified lines
94#define KERNEL_HWCAP_BF16 __khwcap2_feature(BF16)94#define KERNEL_HWCAP_BF16 __khwcap2_feature(BF16)
95#define KERNEL_HWCAP_DGH __khwcap2_feature(DGH)95#define KERNEL_HWCAP_DGH __khwcap2_feature(DGH)
96#define KERNEL_HWCAP_RNG __khwcap2_feature(RNG)96#define KERNEL_HWCAP_RNG __khwcap2_feature(RNG)
97#define KERNEL_HWCAP_BTI __khwcap2_feature(BTI)
97 98
98/*99/*
99 * This yields a mask that user programs can use to figure out what100 * This yields a mask that user programs can use to figure out what
arch/arm64/include/asm/mman.h+37−0
@@ -0,0 +1,37 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __ASM_MMAN_H__
3#define __ASM_MMAN_H__
4
5#include <linux/compiler.h>
6#include <linux/types.h>
7#include <uapi/asm/mman.h>
8
9static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot,
10 unsigned long pkey __always_unused)
11{
12 if (system_supports_bti() && (prot & PROT_BTI))
13 return VM_ARM64_BTI;
14
15 return 0;
16}
17#define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey)
18
19static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
20{
21 return (vm_flags & VM_ARM64_BTI) ? __pgprot(PTE_GP) : __pgprot(0);
22}
23#define arch_vm_get_page_prot(vm_flags) arch_vm_get_page_prot(vm_flags)
24
25static inline bool arch_validate_prot(unsigned long prot,
26 unsigned long addr __always_unused)
27{
28 unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM;
29
30 if (system_supports_bti())
31 supported |= PROT_BTI;
32
33 return (prot & ~supported) == 0;
34}
35#define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
36
37#endif /* ! __ASM_MMAN_H__ */
arch/arm64/include/asm/pgtable-hwdef.h+1−0
@@ -151,6 +151,7 @@ · 150 unmodified lines
151#define PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */151#define PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
152#define PTE_AF (_AT(pteval_t, 1) << 10) /* Access Flag */152#define PTE_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
153#define PTE_NG (_AT(pteval_t, 1) << 11) /* nG */153#define PTE_NG (_AT(pteval_t, 1) << 11) /* nG */
154#define PTE_GP (_AT(pteval_t, 1) << 50) /* BTI guarded */
154#define PTE_DBM (_AT(pteval_t, 1) << 51) /* Dirty Bit Management */155#define PTE_DBM (_AT(pteval_t, 1) << 51) /* Dirty Bit Management */
155#define PTE_CONT (_AT(pteval_t, 1) << 52) /* Contiguous range */156#define PTE_CONT (_AT(pteval_t, 1) << 52) /* Contiguous range */
156#define PTE_PXN (_AT(pteval_t, 1) << 53) /* Privileged XN */157#define PTE_PXN (_AT(pteval_t, 1) << 53) /* Privileged XN */
arch/arm64/include/asm/pgtable.h+1−1
@@ -660,7 +660,7 @@ static inline phys_addr_t pgd_page_paddr(pgd_t pgd) · 659 unmodified lines
660static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)660static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
661{661{
662 const pteval_t mask = PTE_USER | PTE_PXN | PTE_UXN | PTE_RDONLY |662 const pteval_t mask = PTE_USER | PTE_PXN | PTE_UXN | PTE_RDONLY |
663 PTE_PROT_NONE | PTE_VALID | PTE_WRITE;663 PTE_PROT_NONE | PTE_VALID | PTE_WRITE | PTE_GP;
664 /* preserve the hardware dirty information */664 /* preserve the hardware dirty information */
665 if (pte_hw_dirty(pte))665 if (pte_hw_dirty(pte))
666 pte = pte_mkdirty(pte);666 pte = pte_mkdirty(pte);
arch/arm64/include/asm/ptrace.h+1−0
@@ -35,6 +35,7 @@ · 34 unmodified lines
35#define GIC_PRIO_PSR_I_SET (1 << 4)35#define GIC_PRIO_PSR_I_SET (1 << 4)
36 36
37/* Additional SPSR bits not exposed in the UABI */37/* Additional SPSR bits not exposed in the UABI */
38
38#define PSR_IL_BIT (1 << 20)39#define PSR_IL_BIT (1 << 20)
39 40
40/* AArch32-specific ptrace requests */41/* AArch32-specific ptrace requests */
arch/arm64/include/asm/sysreg.h+4−0
@@ -514,6 +514,8 @@ · 513 unmodified lines
514#endif514#endif
515 515
516/* SCTLR_EL1 specific flags. */516/* SCTLR_EL1 specific flags. */
517#define SCTLR_EL1_BT1 (BIT(36))
518#define SCTLR_EL1_BT0 (BIT(35))
517#define SCTLR_EL1_UCI (BIT(26))519#define SCTLR_EL1_UCI (BIT(26))
518#define SCTLR_EL1_E0E (BIT(24))520#define SCTLR_EL1_E0E (BIT(24))
519#define SCTLR_EL1_SPAN (BIT(23))521#define SCTLR_EL1_SPAN (BIT(23))
@@ -620,10 +622,12 @@ · 100 unmodified lines
620 622
621/* id_aa64pfr1 */623/* id_aa64pfr1 */
622#define ID_AA64PFR1_SSBS_SHIFT 4624#define ID_AA64PFR1_SSBS_SHIFT 4
625#define ID_AA64PFR1_BT_SHIFT 0
623 626
624#define ID_AA64PFR1_SSBS_PSTATE_NI 0627#define ID_AA64PFR1_SSBS_PSTATE_NI 0
625#define ID_AA64PFR1_SSBS_PSTATE_ONLY 1628#define ID_AA64PFR1_SSBS_PSTATE_ONLY 1
626#define ID_AA64PFR1_SSBS_PSTATE_INSNS 2629#define ID_AA64PFR1_SSBS_PSTATE_INSNS 2
630#define ID_AA64PFR1_BT_BTI 0x1
627 631
628/* id_aa64zfr0 */632/* id_aa64zfr0 */
629#define ID_AA64ZFR0_F64MM_SHIFT 56633#define ID_AA64ZFR0_F64MM_SHIFT 56
arch/arm64/include/uapi/asm/hwcap.h+1−0
@@ -73,5 +73,6 @@ · 72 unmodified lines
73#define HWCAP2_BF16 (1 << 14)73#define HWCAP2_BF16 (1 << 14)
74#define HWCAP2_DGH (1 << 15)74#define HWCAP2_DGH (1 << 15)
75#define HWCAP2_RNG (1 << 16)75#define HWCAP2_RNG (1 << 16)
76#define HWCAP2_BTI (1 << 17)
76 77
77#endif /* _UAPI__ASM_HWCAP_H */78#endif /* _UAPI__ASM_HWCAP_H */
arch/arm64/include/uapi/asm/mman.h+9−0
@@ -0,0 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2#ifndef _UAPI__ASM_MMAN_H
3#define _UAPI__ASM_MMAN_H
4
5#include <asm-generic/mman.h>
6
7#define PROT_BTI 0x10 /* BTI guarded page */
8
9#endif /* ! _UAPI__ASM_MMAN_H */
arch/arm64/include/uapi/asm/ptrace.h+9−0
@@ -46,6 +46,7 @@ · 45 unmodified lines
46#define PSR_I_BIT 0x0000008046#define PSR_I_BIT 0x00000080
47#define PSR_A_BIT 0x0000010047#define PSR_A_BIT 0x00000100
48#define PSR_D_BIT 0x0000020048#define PSR_D_BIT 0x00000200
49#define PSR_BTYPE_MASK 0x00000c00
49#define PSR_SSBS_BIT 0x0000100050#define PSR_SSBS_BIT 0x00001000
50#define PSR_PAN_BIT 0x0040000051#define PSR_PAN_BIT 0x00400000
51#define PSR_UAO_BIT 0x0080000052#define PSR_UAO_BIT 0x00800000
@@ -55,6 +56,8 @@ · 3 unmodified lines
55#define PSR_Z_BIT 0x4000000056#define PSR_Z_BIT 0x40000000
56#define PSR_N_BIT 0x8000000057#define PSR_N_BIT 0x80000000
57 58
59#define PSR_BTYPE_SHIFT 10
60
58/*61/*
59 * Groups of PSR bits62 * Groups of PSR bits
60 */63 */
@@ -63,6 +66,12 @@ · 2 unmodified lines
63#define PSR_x 0x0000ff00 /* Extension */66#define PSR_x 0x0000ff00 /* Extension */
64#define PSR_c 0x000000ff /* Control */67#define PSR_c 0x000000ff /* Control */
65 68
69/* Convenience names for the values of PSTATE.BTYPE */
70#define PSR_BTYPE_NONE (0b00 << PSR_BTYPE_SHIFT)
71#define PSR_BTYPE_JC (0b01 << PSR_BTYPE_SHIFT)
72#define PSR_BTYPE_C (0b10 << PSR_BTYPE_SHIFT)
73#define PSR_BTYPE_J (0b11 << PSR_BTYPE_SHIFT)
74
66/* syscall emulation path in ptrace */75/* syscall emulation path in ptrace */
67#define PTRACE_SYSEMU 3176#define PTRACE_SYSEMU 31
68#define PTRACE_SYSEMU_SINGLESTEP 3277#define PTRACE_SYSEMU_SINGLESTEP 32
arch/arm64/kernel/cpufeature.c+33−0
@@ -179,6 +179,8 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { · 178 unmodified lines
179 179
180static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {180static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
181 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_SSBS_SHIFT, 4, ID_AA64PFR1_SSBS_PSTATE_NI),181 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_SSBS_SHIFT, 4, ID_AA64PFR1_SSBS_PSTATE_NI),
182 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_BTI),
183 FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_BT_SHIFT, 4, 0),
182 ARM64_FTR_END,184 ARM64_FTR_END,
183};185};
184 186
@@ -1347,6 +1349,21 @@ static bool can_use_gic_priorities(const struct arm64_cpu_capabilities *entry, · 1162 unmodified lines
1347}1349}
1348#endif1350#endif
1349 1351
1352#ifdef CONFIG_ARM64_BTI
1353static void bti_enable(const struct arm64_cpu_capabilities *__unused)
1354{
1355 /*
1356 * Use of X16/X17 for tail-calls and trampolines that jump to
1357 * function entry points using BR is a requirement for
1358 * marking binaries with GNU_PROPERTY_AARCH64_FEATURE_1_BTI.
1359 * So, be strict and forbid other BRs using other registers to
1360 * jump onto a PACIxSP instruction:
1361 */
1362 sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_BT0 | SCTLR_EL1_BT1);
1363 isb();
1364}
1365#endif /* CONFIG_ARM64_BTI */
1366
1350static const struct arm64_cpu_capabilities arm64_features[] = {1367static const struct arm64_cpu_capabilities arm64_features[] = {
1351 {1368 {
1352 .desc = "GIC system register CPU interface",1369 .desc = "GIC system register CPU interface",
@@ -1671,6 +1688,19 @@ static const struct arm64_cpu_capabilities arm64_features[] = { · 318 unmodified lines
1671 .sign = FTR_UNSIGNED,1688 .sign = FTR_UNSIGNED,
1672 .min_field_value = 1,1689 .min_field_value = 1,
1673 },1690 },
1691#endif
1692#ifdef CONFIG_ARM64_BTI
1693 {
1694 .desc = "Branch Target Identification",
1695 .capability = ARM64_BTI,
1696 .type = ARM64_CPUCAP_SYSTEM_FEATURE,
1697 .matches = has_cpuid_feature,
1698 .cpu_enable = bti_enable,
1699 .sys_reg = SYS_ID_AA64PFR1_EL1,
1700 .field_pos = ID_AA64PFR1_BT_SHIFT,
1701 .min_field_value = ID_AA64PFR1_BT_BTI,
1702 .sign = FTR_UNSIGNED,
1703 },
1674#endif1704#endif
1675 {},1705 {},
1676};1706};
@@ -1781,6 +1811,9 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { · 104 unmodified lines
1781 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_F64MM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_F64MM, CAP_HWCAP, KERNEL_HWCAP_SVEF64MM),1811 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_F64MM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_F64MM, CAP_HWCAP, KERNEL_HWCAP_SVEF64MM),
1782#endif1812#endif
1783 HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SSBS_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_SSBS_PSTATE_INSNS, CAP_HWCAP, KERNEL_HWCAP_SSBS),1813 HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SSBS_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_SSBS_PSTATE_INSNS, CAP_HWCAP, KERNEL_HWCAP_SSBS),
1814#ifdef CONFIG_ARM64_BTI
1815 HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_BT_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_BT_BTI, CAP_HWCAP, KERNEL_HWCAP_BTI),
1816#endif
1784#ifdef CONFIG_ARM64_PTR_AUTH1817#ifdef CONFIG_ARM64_PTR_AUTH
1785 HWCAP_MULTI_CAP(ptr_auth_hwcap_addr_matches, CAP_HWCAP, KERNEL_HWCAP_PACA),1818 HWCAP_MULTI_CAP(ptr_auth_hwcap_addr_matches, CAP_HWCAP, KERNEL_HWCAP_PACA),
1786 HWCAP_MULTI_CAP(ptr_auth_hwcap_gen_matches, CAP_HWCAP, KERNEL_HWCAP_PACG),1819 HWCAP_MULTI_CAP(ptr_auth_hwcap_gen_matches, CAP_HWCAP, KERNEL_HWCAP_PACG),
arch/arm64/kernel/cpuinfo.c+1−0
@@ -92,6 +92,7 @@ static const char *const hwcap_str[] = { · 91 unmodified lines
92 "bf16",92 "bf16",
93 "dgh",93 "dgh",
94 "rng",94 "rng",
95 "bti",
95 NULL96 NULL
96};97};
97 98
arch/arm64/kernel/entry-common.c+11−0
@@ -188,6 +188,14 @@ static void notrace el0_undef(struct pt_regs *regs) · 187 unmodified lines
188}188}
189NOKPROBE_SYMBOL(el0_undef);189NOKPROBE_SYMBOL(el0_undef);
190 190
191static void notrace el0_bti(struct pt_regs *regs)
192{
193 user_exit_irqoff();
194 local_daif_restore(DAIF_PROCCTX);
195 do_bti(regs);
196}
197NOKPROBE_SYMBOL(el0_bti);
198
191static void notrace el0_inv(struct pt_regs *regs, unsigned long esr)199static void notrace el0_inv(struct pt_regs *regs, unsigned long esr)
192{200{
193 user_exit_irqoff();201 user_exit_irqoff();
@@ -255,6 +263,9 @@ asmlinkage void notrace el0_sync_handler(struct pt_regs *regs) · 61 unmodified lines
255 case ESR_ELx_EC_UNKNOWN:263 case ESR_ELx_EC_UNKNOWN:
256 el0_undef(regs);264 el0_undef(regs);
257 break;265 break;
266 case ESR_ELx_EC_BTI:
267 el0_bti(regs);
268 break;
258 case ESR_ELx_EC_BREAKPT_LOW:269 case ESR_ELx_EC_BREAKPT_LOW:
259 case ESR_ELx_EC_SOFTSTP_LOW:270 case ESR_ELx_EC_SOFTSTP_LOW:
260 case ESR_ELx_EC_WATCHPT_LOW:271 case ESR_ELx_EC_WATCHPT_LOW:
arch/arm64/kernel/ptrace.c+1−1
@@ -1874,7 +1874,7 @@ void syscall_trace_exit(struct pt_regs *regs) · 1873 unmodified lines
1874 */1874 */
1875#define SPSR_EL1_AARCH64_RES0_BITS \1875#define SPSR_EL1_AARCH64_RES0_BITS \
1876 (GENMASK_ULL(63, 32) | GENMASK_ULL(27, 25) | GENMASK_ULL(23, 22) | \1876 (GENMASK_ULL(63, 32) | GENMASK_ULL(27, 25) | GENMASK_ULL(23, 22) | \
1877 GENMASK_ULL(20, 13) | GENMASK_ULL(11, 10) | GENMASK_ULL(5, 5))1877 GENMASK_ULL(20, 13) | GENMASK_ULL(5, 5))
1878#define SPSR_EL1_AARCH32_RES0_BITS \1878#define SPSR_EL1_AARCH32_RES0_BITS \
1879 (GENMASK_ULL(63, 32) | GENMASK_ULL(22, 22) | GENMASK_ULL(20, 20))1879 (GENMASK_ULL(63, 32) | GENMASK_ULL(22, 22) | GENMASK_ULL(20, 20))
1880 1880
arch/arm64/kernel/signal.c+16−0
@@ -732,6 +732,22 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, · 731 unmodified lines
732 regs->regs[29] = (unsigned long)&user->next_frame->fp;732 regs->regs[29] = (unsigned long)&user->next_frame->fp;
733 regs->pc = (unsigned long)ka->sa.sa_handler;733 regs->pc = (unsigned long)ka->sa.sa_handler;
734 734
735 /*
736 * Signal delivery is a (wacky) indirect function call in
737 * userspace, so simulate the same setting of BTYPE as a BLR
738 * <register containing the signal handler entry point>.
739 * Signal delivery to a location in a PROT_BTI guarded page
740 * that is not a function entry point will now trigger a
741 * SIGILL in userspace.
742 *
743 * If the signal handler entry point is not in a PROT_BTI
744 * guarded page, this is harmless.
745 */
746 if (system_supports_bti()) {
747 regs->pstate &= ~PSR_BTYPE_MASK;
748 regs->pstate |= PSR_BTYPE_C;
749 }
750
735 if (ka->sa.sa_flags & SA_RESTORER)751 if (ka->sa.sa_flags & SA_RESTORER)
736 sigtramp = ka->sa.sa_restorer;752 sigtramp = ka->sa.sa_restorer;
737 else753 else
arch/arm64/kernel/syscall.c+18−0
@@ -98,6 +98,24 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, · 97 unmodified lines
98 regs->orig_x0 = regs->regs[0];98 regs->orig_x0 = regs->regs[0];
99 regs->syscallno = scno;99 regs->syscallno = scno;
100 100
101 /*
102 * BTI note:
103 * The architecture does not guarantee that SPSR.BTYPE is zero
104 * on taking an SVC, so we could return to userspace with a
105 * non-zero BTYPE after the syscall.
106 *
107 * This shouldn't matter except when userspace is explicitly
108 * doing something stupid, such as setting PROT_BTI on a page
109 * that lacks conforming BTI/PACIxSP instructions, falling
110 * through from one executable page to another with differing
111 * PROT_BTI, or messing with BTYPE via ptrace: in such cases,
112 * userspace should not be surprised if a SIGILL occurs on
113 * syscall return.
114 *
115 * So, don't touch regs->pstate & PSR_BTYPE_MASK here.
116 * (Similarly for HVC and SMC elsewhere.)
117 */
118
101 cortex_a76_erratum_1463225_svc_handler();119 cortex_a76_erratum_1463225_svc_handler();
102 local_daif_restore(DAIF_PROCCTX);120 local_daif_restore(DAIF_PROCCTX);
103 user_exit();121 user_exit();
arch/arm64/kernel/traps.c+8−0
@@ -411,6 +411,13 @@ void do_undefinstr(struct pt_regs *regs) · 410 unmodified lines
411}411}
412NOKPROBE_SYMBOL(do_undefinstr);412NOKPROBE_SYMBOL(do_undefinstr);
413 413
414void do_bti(struct pt_regs *regs)
415{
416 BUG_ON(!user_mode(regs));
417 force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc);
418}
419NOKPROBE_SYMBOL(do_bti);
420
414#define __user_cache_maint(insn, address, res) \421#define __user_cache_maint(insn, address, res) \
415 if (address >= user_addr_max()) { \422 if (address >= user_addr_max()) { \
416 res = -EFAULT; \423 res = -EFAULT; \
@@ -753,6 +760,7 @@ static const char *esr_class_str[] = { · 336 unmodified lines
753 [ESR_ELx_EC_CP10_ID] = "CP10 MRC/VMRS",760 [ESR_ELx_EC_CP10_ID] = "CP10 MRC/VMRS",
754 [ESR_ELx_EC_PAC] = "PAC",761 [ESR_ELx_EC_PAC] = "PAC",
755 [ESR_ELx_EC_CP14_64] = "CP14 MCRR/MRRC",762 [ESR_ELx_EC_CP14_64] = "CP14 MCRR/MRRC",
763 [ESR_ELx_EC_BTI] = "BTI",
756 [ESR_ELx_EC_ILL] = "PSTATE.IL",764 [ESR_ELx_EC_ILL] = "PSTATE.IL",
757 [ESR_ELx_EC_SVC32] = "SVC (AArch32)",765 [ESR_ELx_EC_SVC32] = "SVC (AArch32)",
758 [ESR_ELx_EC_HVC32] = "HVC (AArch32)",766 [ESR_ELx_EC_HVC32] = "HVC (AArch32)",
include/linux/mm.h+3−0
@@ -324,6 +324,9 @@ extern unsigned int kobjsize(const void *objp); · 323 unmodified lines
324#elif defined(CONFIG_SPARC64)324#elif defined(CONFIG_SPARC64)
325# define VM_SPARC_ADI VM_ARCH_1 /* Uses ADI tag for access control */325# define VM_SPARC_ADI VM_ARCH_1 /* Uses ADI tag for access control */
326# define VM_ARCH_CLEAR VM_SPARC_ADI326# define VM_ARCH_CLEAR VM_SPARC_ADI
327#elif defined(CONFIG_ARM64)
328# define VM_ARM64_BTI VM_ARCH_1 /* BTI guarded page, a.k.a. GP bit */
329# define VM_ARCH_CLEAR VM_ARM64_BTI
327#elif !defined(CONFIG_MMU)330#elif !defined(CONFIG_MMU)
328# define VM_MAPPED_COPY VM_ARCH_1 /* T if mapped copy of data (nommu mmap) */331# define VM_MAPPED_COPY VM_ARCH_1 /* T if mapped copy of data (nommu mmap) */
329#endif332#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t