[x86/SLH] Teach SLH to harden against the "ret2spec" attack by
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Sep 2018 10:59:10 +0000 (10:59 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Sep 2018 10:59:10 +0000 (10:59 +0000)
commit219888d1b2ade782a8aedb9dea7f1421c852b80c
tree4fcd391834a9e5bcba026048ee70f92bbcb1b742
parent51ae9346dbb710dfdaf482351b75d2bda903c0a6
[x86/SLH] Teach SLH to harden against the "ret2spec" attack by
implementing the proposed mitigation technique described in the original
design document.

The idea is to check after calls that the return address used to arrive
at that location is in fact the correct address. In the event of
a mis-predicted return which reaches a *valid* return but not the
*correct* return, this will detect the mismatch much like it would
a mispredicted conditional branch.

This is the last published attack vector that I am aware of in the
Spectre v1 space which is not mitigated by SLH+retpolines. However,
don't read *too* much into that: this is an area of ongoing research
where we expect more issues to be discovered in the future, and it also
makes no attempt to mitigate Spectre v4. Still, this is an important
completeness bar for SLH.

The change here is of course delightfully simple. It was predicated on
cutting support for post-instruction symbols into LLVM which was not at
all simple. Many thanks to Hal Finkel, Reid Kleckner, and Justin Bogner
who helped me figure out how to do a bunch of the complex changes
involved there.

Differential Revision: https://reviews.llvm.org/D50837

llvm-svn: 341358
llvm/docs/SpeculativeLoadHardening.md
llvm/lib/Target/X86/X86SpeculativeLoadHardening.cpp
llvm/test/CodeGen/X86/speculative-load-hardening-call-and-ret.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/speculative-load-hardening-indirect.ll
llvm/test/CodeGen/X86/speculative-load-hardening.ll