Skip to content
  1. Jun 19, 2020
    • Kristof Beyls's avatar
      [AArch64] Avoid incompatibility between SLSBLR mitigation and BTI codegen. · d938ec45
      Kristof Beyls authored
      A "BTI c" instruction only allows jumping/calling to using a BLR* instruction.
      However, the SLSBLR mitigation changes a BLR to a BR to implement the
      function call. Therefore, a "BTI c" check that passed before could
      trigger after the BLR->BL change done by the SLSBLR mitigation.
      However, if the register used in BR is X16 or X17, this trigger will not
      fire (see ArmARM for further details).
      
      Therefore, this patch simply changes the function stubs for the SLSBLR
      mitigation from
      __llvm_slsblr_thunk_x<N>:
          br x<N>
          SpeculationBarrier
      to
      __llvm_slsblr_thunk_x<N>:
          mov x16, x<N>
          br  x16
          SpeculationBarrier
      
      Differential Revision: https://reviews.llvm.org/D81405
      d938ec45
  2. Jun 18, 2020
  3. Jun 12, 2020
    • Huihui Zhang's avatar
      [NFC] Silence compiler warning [-Wmissing-braces]. · bf7961fa
      Huihui Zhang authored
      llvm/lib/Target/AArch64/AArch64SLSHardening.cpp:146:5: warning: suggest braces around initialization of subobject [-Wmissing-braces]
          "__llvm_slsblr_thunk_x0",  "__llvm_slsblr_thunk_x1",
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          {
      llvm/lib/Target/AArch64/AArch64SLSHardening.cpp:168:5: warning: suggest braces around initialization of subobject [-Wmissing-braces]
          AArch64::X0,  AArch64::X1,  AArch64::X2,  AArch64::X3,  AArch64::X4,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          {
      bf7961fa
    • Kristof Beyls's avatar
      [AArch64] Extend AArch64SLSHardeningPass to harden BLR instructions. · c35ed40f
      Kristof Beyls authored
      To make sure that no barrier gets placed on the architectural execution
      path, each
        BLR x<N>
      instruction gets transformed to a
        BL __llvm_slsblr_thunk_x<N>
      instruction, with __llvm_slsblr_thunk_x<N> a thunk that contains
      __llvm_slsblr_thunk_x<N>:
        BR x<N>
        <speculation barrier>
      
      Therefore, the BLR instruction gets split into 2; one BL and one BR.
      This transformation results in not inserting a speculation barrier on
      the architectural execution path.
      
      The mitigation is off by default and can be enabled by the
      harden-sls-blr subtarget feature.
      
      As a linker is allowed to clobber X16 and X17 on function calls, the
      above code transformation would not be correct in case a linker does so
      when N=16 or N=17. Therefore, when the mitigation is enabled, generation
      of BLR x16 or BLR x17 is avoided.
      
      As BLRA* indirect calls are not produced by LLVM currently, this does
      not aim to implement support for those.
      
      Differential Revision:  https://reviews.llvm.org/D81402
      c35ed40f
  4. Jun 11, 2020
    • Kristof Beyls's avatar
      [AArch64] Introduce AArch64SLSHardeningPass, implementing hardening of RET and BR instructions. · 0ee176ed
      Kristof Beyls authored
      Some processors may speculatively execute the instructions immediately
      following RET (returns) and BR (indirect jumps), even though
      control flow should change unconditionally at these instructions.
      To avoid a potential miss-speculatively executed gadget after these
      instructions leaking secrets through side channels, this pass places a
      speculation barrier immediately after every RET and BR instruction.
      
      Since these barriers are never on the correct, architectural execution
      path, performance overhead of this is expected to be low.
      
      On targets that implement that Armv8.0-SB Speculation Barrier extension,
      a single SB instruction is emitted that acts as a speculation barrier.
      On other targets, a DSB SYS followed by a ISB is emitted to act as a
      speculation barrier.
      
      These speculation barriers are implemented as pseudo instructions to
      avoid later passes to analyze them and potentially remove them.
      
      Even though currently LLVM does not produce BRAA/BRAB/BRAAZ/BRABZ
      instructions, these are also mitigated by the pass and tested through a
      MIR test.
      
      The mitigation is off by default and can be enabled by the
      harden-sls-retbr subtarget feature.
      
      Differential Revision:  https://reviews.llvm.org/D81400
      0ee176ed
Loading