[AArch64] Introduce AArch64SLSHardeningPass, implementing hardening of RET and BR...
authorKristof Beyls <kristof.beyls@arm.com>
Thu, 11 Jun 2020 06:42:16 +0000 (07:42 +0100)
committerKristof Beyls <kristof.beyls@arm.com>
Thu, 11 Jun 2020 06:51:17 +0000 (07:51 +0100)
commit0ee176edc8b4a6f20527e907bfd026b07a27e7ef
tree457a454f20ea3eac71197cdae41ec344f7a39f29
parent6b8628a1f036bc34cb0499e15da6df9a130ec287
[AArch64] Introduce AArch64SLSHardeningPass, implementing hardening of RET and BR instructions.

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
14 files changed:
llvm/lib/Target/AArch64/AArch64.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.h
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64SLSHardening.cpp [new file with mode: 0644]
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/lib/Target/AArch64/CMakeLists.txt
llvm/test/CodeGen/AArch64/O0-pipeline.ll
llvm/test/CodeGen/AArch64/O3-pipeline.ll
llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll [new file with mode: 0644]
llvm/test/CodeGen/AArch64/speculation-hardening-sls.mir [new file with mode: 0644]