llvm-6502/lib/IR
Peter Collingbourne 7ffec838a2 Protection against stack-based memory corruption errors using SafeStack
This patch adds the safe stack instrumentation pass to LLVM, which separates
the program stack into a safe stack, which stores return addresses, register
spills, and local variables that are statically verified to be accessed
in a safe way, and the unsafe stack, which stores everything else. Such
separation makes it much harder for an attacker to corrupt objects on the
safe stack, including function pointers stored in spilled registers and
return addresses. You can find more information about the safe stack, as
well as other parts of or control-flow hijack protection technique in our
OSDI paper on code-pointer integrity (http://dslab.epfl.ch/pubs/cpi.pdf)
and our project website (http://levee.epfl.ch).

The overhead of our implementation of the safe stack is very close to zero
(0.01% on the Phoronix benchmarks). This is lower than the overhead of
stack cookies, which are supported by LLVM and are commonly used today,
yet the security guarantees of the safe stack are strictly stronger than
stack cookies. In some cases, the safe stack improves performance due to
better cache locality.

Our current implementation of the safe stack is stable and robust, we
used it to recompile multiple projects on Linux including Chromium, and
we also recompiled the entire FreeBSD user-space system and more than 100
packages. We ran unit tests on the FreeBSD system and many of the packages
and observed no errors caused by the safe stack. The safe stack is also fully
binary compatible with non-instrumented code and can be applied to parts of
a program selectively.

This patch is our implementation of the safe stack on top of LLVM. The
patches make the following changes:

- Add the safestack function attribute, similar to the ssp, sspstrong and
  sspreq attributes.

- Add the SafeStack instrumentation pass that applies the safe stack to all
  functions that have the safestack attribute. This pass moves all unsafe local
  variables to the unsafe stack with a separate stack pointer, whereas all
  safe variables remain on the regular stack that is managed by LLVM as usual.

- Invoke the pass as the last stage before code generation (at the same time
  the existing cookie-based stack protector pass is invoked).

- Add unit tests for the safe stack.

Original patch by Volodymyr Kuznetsov and others at the Dependable Systems
Lab at EPFL; updates and upstreaming by myself.

Differential Revision: http://reviews.llvm.org/D6094

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239761 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-15 21:07:11 +00:00
..
AsmWriter.cpp C++11 Rangify loops in AssemblyWriter::printModule, NFC. 2015-06-13 17:50:47 +00:00
AttributeImpl.h Add missing dereferenceable_or_null getters 2015-05-06 17:41:54 +00:00
Attributes.cpp Protection against stack-based memory corruption errors using SafeStack 2015-06-15 21:07:11 +00:00
AutoUpgrade.cpp [opaque pointer type] Pass explicit type to Load instruction creation in AutoUpgrade 2015-05-20 21:46:30 +00:00
BasicBlock.cpp Set proper debug location for branch added in BasicBlock::splitBasicBlock(). 2015-06-11 18:25:54 +00:00
CMakeLists.txt [opaque pointer type] Explicit pointee type for GEPOperator/GEPConstantExpr. 2015-05-08 00:42:26 +00:00
Comdat.cpp IR: Add COMDATs to the IR 2014-06-27 18:19:56 +00:00
ConstantFold.cpp Refix a use of explicit pointer types in GEP constant folding 2015-06-12 18:22:03 +00:00
ConstantFold.h Recommit r236670: [opaque pointer type] Pass explicit pointer type through GEP constant folding"" 2015-05-07 17:28:58 +00:00
ConstantRange.cpp [ConstantRange] Split makeICmpRegion in two. 2015-03-18 00:41:24 +00:00
Constants.cpp Replace all accesses to User::OperandList with getter and setter methods. NFC. 2015-06-12 17:48:05 +00:00
ConstantsContext.h Fix some odd whitespace and formatting errors while making 2015-05-18 21:49:02 +00:00
Core.cpp [C API] Add LLVMStructGetTypeAtIndex. 2015-06-04 09:09:53 +00:00
DataLayout.cpp COFF: Let globals with private linkage reside in their own section 2015-03-17 23:54:51 +00:00
DebugInfo.cpp IR: Give 'DI' prefix to debug info metadata 2015-04-29 16:38:44 +00:00
DebugInfoMetadata.cpp IR / debug info: Add a DWOId field to DICompileUnit, 2015-05-21 20:37:30 +00:00
DebugLoc.cpp IR: Give 'DI' prefix to debug info metadata 2015-04-29 16:38:44 +00:00
DiagnosticInfo.cpp MIR Serialization: Connect the machine function analysis pass to the MIR parser. 2015-06-15 20:30:22 +00:00
DiagnosticPrinter.cpp MIR Serialization: Connect the machine function analysis pass to the MIR parser. 2015-06-15 20:30:22 +00:00
DIBuilder.cpp IR / debug info: Add a DWOId field to DICompileUnit, 2015-05-21 20:37:30 +00:00
Dominators.cpp [DomTree] verifyDomTree to unconditionally perform DT verification 2015-05-06 08:18:41 +00:00
Function.cpp ArgumentPromotion: Drop sret attribute on functions that are only called directly. 2015-06-10 21:14:34 +00:00
GCOV.cpp Remove more superfluous .str() and replace std::string concatenation with Twine. 2015-03-30 15:42:36 +00:00
Globals.cpp Rename NumOperands to make it clear its managed by the User. NFC. 2015-06-12 17:48:10 +00:00
GVMaterializer.cpp [Layering] Move GVMaterializer.h into the IR library where its 2014-03-06 03:50:29 +00:00
InlineAsm.cpp Silence sign compare warning. NFC. 2015-03-29 20:49:03 +00:00
Instruction.cpp De-duplicate common expression, NFC. 2015-06-15 17:03:35 +00:00
Instructions.cpp Rename NumOperands to make it clear its managed by the User. NFC. 2015-06-12 17:48:10 +00:00
IntrinsicInst.cpp IR: Split Metadata from Value 2014-12-09 18:38:53 +00:00
IRBuilder.cpp Change Function::getIntrinsicID() to return an Intrinsic::ID. NFC. 2015-05-20 17:16:39 +00:00
IRPrintingPasses.cpp uselistorder: Pull the bit through PrintModulePass 2015-04-15 02:38:06 +00:00
LegacyPassManager.cpp Rangify more for loops in LegacyPassManager.cpp. 2015-06-05 17:48:47 +00:00
LLVMBuild.txt
LLVMContext.cpp MIR Serialization: Connect the machine function analysis pass to the MIR parser. 2015-06-15 20:30:22 +00:00
LLVMContextImpl.cpp Add the i128 builtin type to LLVM. 2015-04-17 15:32:15 +00:00
LLVMContextImpl.h Move the name pointer out of Value into a map that lives on the 2015-06-01 22:24:01 +00:00
Makefile
Mangler.cpp Revert "Move dllimport name mangling to IR mangler." 2015-06-11 01:31:48 +00:00
MDBuilder.cpp Add isConstant argument to MDBuilder::createTBAAStructTagNode 2015-06-01 14:53:55 +00:00
Metadata.cpp Move the name pointer out of Value into a map that lives on the 2015-06-01 22:24:01 +00:00
MetadataImpl.h Added missing header for the explicit dependency on MDNode. 2015-02-04 00:20:52 +00:00
MetadataTracking.cpp IR: Store RAUW support and Context in the same pointer, NFC 2015-01-19 19:02:06 +00:00
Module.cpp While in GlobalValue fix the function(s) that don't follow the 2015-05-15 18:20:14 +00:00
module.modulemap [modules] Add module maps for LLVM. These are not quite ready for prime-time 2014-05-21 02:46:14 +00:00
Operator.cpp Put GEPOperator member function definition in the appropriate .cpp file 2015-05-21 21:17:12 +00:00
Pass.cpp Refactoring cl::parser construction and initialization. 2015-01-22 21:01:12 +00:00
PassManager.cpp [PM] Push the debug option for the new pass manager into the opt tool 2015-01-13 22:42:38 +00:00
PassRegistry.cpp Revert r231276 (including r231277): Add a lock() function in PassRegistry to speed up multi-thread synchronization. 2015-03-05 17:53:00 +00:00
Statepoint.cpp Add invoke related functionality into StatepointSite classes. 2015-02-19 11:02:11 +00:00
SymbolTableListTraitsImpl.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
Type.cpp Int128 is also a built-in preconstructed type. 2015-06-02 23:56:53 +00:00
TypeFinder.cpp Fix Value dangling reference debug output 2015-03-10 23:55:38 +00:00
Use.cpp Fix a URL (NFC) 2014-08-21 21:09:24 +00:00
User.cpp Move OperandList to be allocated prior to User for hung off subclasses. 2015-06-12 17:48:18 +00:00
Value.cpp Rename NumOperands to make it clear its managed by the User. NFC. 2015-06-12 17:48:10 +00:00
ValueSymbolTable.cpp Changed renaming of local symbols by inserting a dot vefore the numeric suffix. 2015-05-12 16:47:30 +00:00
ValueTypes.cpp Add support for v1i128 type. 2015-04-17 16:11:05 +00:00
Verifier.cpp Protection against stack-based memory corruption errors using SafeStack 2015-06-15 21:07:11 +00:00