]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Merge branch 'for-next/bti-user' into for-next/bti
authorWill Deacon <will@kernel.org>
Tue, 5 May 2020 14:15:58 +0000 (15:15 +0100)
committerWill Deacon <will@kernel.org>
Tue, 5 May 2020 14:15:58 +0000 (15:15 +0100)
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

14 files changed:
1  2 
Documentation/filesystems/proc.rst
arch/arm64/Kconfig
arch/arm64/include/asm/cpucaps.h
arch/arm64/include/asm/cpufeature.h
arch/arm64/include/asm/esr.h
arch/arm64/include/asm/kvm_emulate.h
arch/arm64/include/asm/sysreg.h
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/entry-common.c
arch/arm64/kernel/process.c
arch/arm64/kernel/ptrace.c
fs/binfmt_elf.c
fs/proc/task_mmu.c
include/linux/mm.h

index 38b606991065b3df4f075bb3120dc9e5db09bf71,ed5465d0f4350e29fb3d2b47324563e4a418979e..9969bf4c0c44f6370cb65c59486f071a0178edc4
@@@ -511,39 -489,37 +511,40 @@@ does not take into account swapped out 
  "THPeligible" indicates whether the mapping is eligible for allocating THP
  pages - 1 if true, 0 otherwise. It just shows the current status.
  
 -"VmFlags" field deserves a separate description. This member represents the kernel
 -flags associated with the particular virtual memory area in two letter encoded
 -manner. The codes are the following:
 -    rd  - readable
 -    wr  - writeable
 -    ex  - executable
 -    sh  - shared
 -    mr  - may read
 -    mw  - may write
 -    me  - may execute
 -    ms  - may share
 -    gd  - stack segment growns down
 -    pf  - pure PFN range
 -    dw  - disabled write to the mapped file
 -    lo  - pages are locked in memory
 -    io  - memory mapped I/O area
 -    sr  - sequential read advise provided
 -    rr  - random read advise provided
 -    dc  - do not copy area on fork
 -    de  - do not expand area on remapping
 -    ac  - area is accountable
 -    nr  - swap space is not reserved for the area
 -    ht  - area uses huge tlb pages
 -    ar  - architecture specific flag
 -    dd  - do not include area into core dump
 -    sd  - soft-dirty flag
 -    mm  - mixed map area
 -    hg  - huge page advise flag
 -    nh  - no-huge page advise flag
 -    mg  - mergable advise flag
 +"VmFlags" field deserves a separate description. This member represents the
 +kernel flags associated with the particular virtual memory area in two letter
 +encoded manner. The codes are the following:
 +
 +    ==    =======================================
 +    rd    readable
 +    wr    writeable
 +    ex    executable
 +    sh    shared
 +    mr    may read
 +    mw    may write
 +    me    may execute
 +    ms    may share
 +    gd    stack segment growns down
 +    pf    pure PFN range
 +    dw    disabled write to the mapped file
 +    lo    pages are locked in memory
 +    io    memory mapped I/O area
 +    sr    sequential read advise provided
 +    rr    random read advise provided
 +    dc    do not copy area on fork
 +    de    do not expand area on remapping
 +    ac    area is accountable
 +    nr    swap space is not reserved for the area
 +    ht    area uses huge tlb pages
 +    ar    architecture specific flag
 +    dd    do not include area into core dump
 +    sd    soft dirty flag
 +    mm    mixed map area
 +    hg    huge page advise flag
 +    nh    no huge page advise flag
 +    mg    mergable advise flag
+     bt  - arm64 BTI guarded page
 +    ==    =======================================
  
  Note that there is no guarantee that every flag and associated mnemonic will
  be present in all further kernel releases. Things get changed, the flags may
index 40fb05d96c6072c9357cf69965ca006c0a5fdb27,53c77711f7522cda5a5212f4e1344039574994be..43be825d0730a6c8657402342fcec9da84a99f3c
@@@ -9,6 -9,8 +9,7 @@@ config ARM6
        select ACPI_MCFG if (ACPI && PCI)
        select ACPI_SPCR_TABLE if ACPI
        select ACPI_PPTT if ACPI
 -      select ARCH_CLOCKSOURCE_DATA
+       select ARCH_BINFMT_ELF_STATE
        select ARCH_HAS_DEBUG_VIRTUAL
        select ARCH_HAS_DEVMEM_IS_ALLOWED
        select ARCH_HAS_DMA_PREP_COHERENT
index 8eb5a088ae6588c8c0f2332b31ca92945eda9b66,58e776c22aab8b9341e507552705181f3536929f..7b6051494f717116e4c3510167bb5095f2726a6b
  #define ARM64_WORKAROUND_SPECULATIVE_AT_NVHE  48
  #define ARM64_HAS_E0PD                                49
  #define ARM64_HAS_RNG                         50
 -#define ARM64_BTI                             51
 +#define ARM64_HAS_AMU_EXTN                    51
 +#define ARM64_HAS_ADDRESS_AUTH                        52
 +#define ARM64_HAS_GENERIC_AUTH                        53
++#define ARM64_BTI                             54
  
- #define ARM64_NCAPS                           54
 -#define ARM64_NCAPS                           52
++#define ARM64_NCAPS                           55
  
  #endif /* __ASM_CPUCAPS_H */
index afe08251ff95640818a89453db51d2127258a11c,e3ebcc59e83b5bc1075f4f4b69bef8a072442358..99ab13a07a1d7d0d2f2454f2837a9e597fb59f6f
@@@ -680,6 -613,17 +680,11 @@@ static inline bool system_has_prio_mask
               system_uses_irq_prio_masking();
  }
  
 -      return IS_ENABLED(CONFIG_ARM64_BTI) &&
 -              cpus_have_const_cap(ARM64_BTI);
 -}
 -
 -static inline bool system_capabilities_finalized(void)
 -{
 -      return static_branch_likely(&arm64_const_caps_ready);
+ static inline bool system_supports_bti(void)
+ {
++      return IS_ENABLED(CONFIG_ARM64_BTI) && cpus_have_const_cap(ARM64_BTI);
+ }
  #define ARM64_BP_HARDEN_UNKNOWN               -1
  #define ARM64_BP_HARDEN_WA_NEEDED     0
  #define ARM64_BP_HARDEN_NOT_REQUIRED  1
Simple merge
index a30b4eec7cb40048c92d9d4261765446c2365af8,dee51c1dcb93a24bd3f3529b80b4e6423ebacd5e..6ea53e6e8b262b1497de1e9cc4b0b4be493f04c3
@@@ -505,12 -504,14 +505,14 @@@ static inline unsigned long vcpu_data_h
        return data;            /* Leave LE untouched */
  }
  
 -static inline void kvm_skip_instr(struct kvm_vcpu *vcpu, bool is_wide_instr)
 +static __always_inline void kvm_skip_instr(struct kvm_vcpu *vcpu, bool is_wide_instr)
  {
-       if (vcpu_mode_is_32bit(vcpu))
+       if (vcpu_mode_is_32bit(vcpu)) {
                kvm_skip_instr32(vcpu, is_wide_instr);
-       else
+       } else {
                *vcpu_pc(vcpu) += 4;
+               *vcpu_cpsr(vcpu) &= ~PSR_BTYPE_MASK;
+       }
  
        /* advance the singlestep state machine */
        *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS;
Simple merge
index 9fac745aa7bb248771bf113c7b3e8539707af51a,e6d31776e49bddcaa49663ba9e1f50ffb675f8d8..b234d6f71cba6402a57bc833473b77bdfde2edba
@@@ -1409,25 -1349,21 +1411,40 @@@ static bool can_use_gic_priorities(cons
  }
  #endif
  
+ #ifdef CONFIG_ARM64_BTI
+ static void bti_enable(const struct arm64_cpu_capabilities *__unused)
+ {
+       /*
+        * Use of X16/X17 for tail-calls and trampolines that jump to
+        * function entry points using BR is a requirement for
+        * marking binaries with GNU_PROPERTY_AARCH64_FEATURE_1_BTI.
+        * So, be strict and forbid other BRs using other registers to
+        * jump onto a PACIxSP instruction:
+        */
+       sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_BT0 | SCTLR_EL1_BT1);
+       isb();
+ }
+ #endif /* CONFIG_ARM64_BTI */
 +/* Internal helper functions to match cpu capability type */
 +static bool
 +cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap)
 +{
 +      return !!(cap->type & ARM64_CPUCAP_OPTIONAL_FOR_LATE_CPU);
 +}
 +
 +static bool
 +cpucap_late_cpu_permitted(const struct arm64_cpu_capabilities *cap)
 +{
 +      return !!(cap->type & ARM64_CPUCAP_PERMITTED_FOR_LATE_CPU);
 +}
 +
 +static bool
 +cpucap_panic_on_conflict(const struct arm64_cpu_capabilities *cap)
 +{
 +      return !!(cap->type & ARM64_CPUCAP_PANIC_ON_CONFLICT);
 +}
 +
  static const struct arm64_cpu_capabilities arm64_features[] = {
        {
                .desc = "GIC system register CPU interface",
Simple merge
Simple merge
Simple merge
diff --cc fs/binfmt_elf.c
index 13f25e241ac46cbd2f5ffa23de45e60a035a0c1a,cceb29d6ef1d9ff14c0f4eab0b811fee1c0db786..4adb963cdb830661c794969272a8aeb5e23ee578
@@@ -819,11 -941,16 +940,16 @@@ out_free_interp
                        goto out_free_dentry;
  
                /* Pass PT_LOPROC..PT_HIPROC headers to arch code */
+               elf_property_phdata = NULL;
                elf_ppnt = interp_elf_phdata;
 -              for (i = 0; i < loc->interp_elf_ex.e_phnum; i++, elf_ppnt++)
 +              for (i = 0; i < interp_elf_ex->e_phnum; i++, elf_ppnt++)
                        switch (elf_ppnt->p_type) {
+                       case PT_GNU_PROPERTY:
+                               elf_property_phdata = elf_ppnt;
+                               break;
                        case PT_LOPROC ... PT_HIPROC:
 -                              retval = arch_elf_pt_proc(&loc->interp_elf_ex,
 +                              retval = arch_elf_pt_proc(interp_elf_ex,
                                                          elf_ppnt, interpreter,
                                                          true, &arch_state);
                                if (retval)
        }
  
        if (interpreter) {
 -              elf_entry = load_elf_interp(&loc->interp_elf_ex,
 +              elf_entry = load_elf_interp(interp_elf_ex,
                                            interpreter,
-                                           load_bias, interp_elf_phdata);
+                                           load_bias, interp_elf_phdata,
+                                           &arch_state);
                if (!IS_ERR((void *)elf_entry)) {
                        /*
                         * load_elf_interp() returns relocation
Simple merge
Simple merge