mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-18 19:36:36 +00:00

Add a CFI protection check that is implemented by building a graph and inspecting the output to deduce if the indirect CF instruction is CFI protected. Also added the output of this instruction to printIndirectInstructions(). Reviewers: vlad.tsyrklevich Subscribers: llvm-commits, kcc, pcc, mgorny Differential Revision: https://reviews.llvm.org/D38428 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316610 91177308-0d34-0410-b5e6-96231b3b80d8
64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
//===-- llvm-cfi-verify.cpp - CFI Verification tool for LLVM --------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This tool verifies Control Flow Integrity (CFI) instrumentation by static
|
|
// binary anaylsis. See the design document in /docs/CFIVerify.rst for more
|
|
// information.
|
|
//
|
|
// This tool is currently incomplete. It currently only does disassembly for
|
|
// object files, and searches through the code for indirect control flow
|
|
// instructions, printing them once found.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lib/FileAnalysis.h"
|
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::object;
|
|
using namespace llvm::cfi_verify;
|
|
|
|
cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
|
|
cl::Required);
|
|
|
|
ExitOnError ExitOnErr;
|
|
|
|
void printIndirectCFInstructions(const FileAnalysis &Verifier) {
|
|
for (uint64_t Address : Verifier.getIndirectInstructions()) {
|
|
const auto &InstrMeta = Verifier.getInstructionOrDie(Address);
|
|
outs() << format_hex(Address, 2) << " |"
|
|
<< Verifier.getMCInstrInfo()->getName(
|
|
InstrMeta.Instruction.getOpcode())
|
|
<< " ";
|
|
InstrMeta.Instruction.print(outs());
|
|
outs() << "\n";
|
|
outs() << " Protected? "
|
|
<< Verifier.isIndirectInstructionCFIProtected(Address) << "\n";
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
cl::ParseCommandLineOptions(argc, argv);
|
|
|
|
InitializeAllTargetInfos();
|
|
InitializeAllTargetMCs();
|
|
InitializeAllAsmParsers();
|
|
InitializeAllDisassemblers();
|
|
|
|
FileAnalysis Verifier = ExitOnErr(FileAnalysis::Create(InputFilename));
|
|
printIndirectCFInstructions(Verifier);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|