DefconRome livecoding repository. We will implement a code reuse mitigation inspired by RAP from grsecurity as an LLVM IR pass.
slides here
Run ./install_llvm12.sh
to install the last stable version of LLVM12 if it is not already present in your system.
Fill the pass in RAP/RAP.cpp
and build it with LLVM_DIR=<path to llvm12> ./build.sh
. The default path for LLVM12 should be /usr/lib/llvm-12
, obtain the path running: llvm-config-12 --prefix
.
Compile a sample program using the rap
pass with LLVM_DIR=<path to llvm12> ./test.sh
.
for (Function &F : M) {
[...]
}
for (BasicBlock &BB: F) {
[...]
}
for (Instruction &I: BB) {
[...]
}
NOTICE: never change the items on which you are iterating
IRBuilder<> Builder(I or BB);
Value * V = Builder.CreateINSTR(OPERANDS, ...);
--> you can keep adding instructions
Value * V2 = Builder.CreateINSTR2(OPERANDS2, ...);
Value * V3 = Builder.CreateINSTR3(OPERANDS3, ...);
--> you can combine them
Value * V4 = Builder.CreateINSTR4(V2, V3);
Type::getInt64Ty(M.getContext());
Type::getInt32Ty(M.getContext());
Type::getInt16Ty(M.getContext());
Types have no signs, operations have
Constant *G = M.getOrInsertGlobal(NAME, TYPE)
Globals are constants as they represent an address. To access/moddify the value use load or store operations.
IRBuilder<> Builder(BB);
Value *GlobalValue = Builder.CreateLoad(G);
Builder.CreateStore(NewValue, G);