LLVM  12.0.0git
Classes | Namespaces | Macros | Typedefs | Functions | Variables
X86LoadValueInjectionLoadHardening.cpp File Reference
#include "ImmutableGraph.h"
#include "X86.h"
#include "X86Subtarget.h"
#include "X86TargetMachine.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineDominanceFrontier.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/RDFGraph.h"
#include "llvm/CodeGen/RDFLiveness.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DOTGraphTraits.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/GraphWriter.h"
#include "llvm/Support/raw_ostream.h"
Include dependency graph for X86LoadValueInjectionLoadHardening.cpp:

Go to the source code of this file.

Classes

struct  llvm::GraphTraits< MachineGadgetGraph * >
 
struct  llvm::DOTGraphTraits< MachineGadgetGraph * >
 

Namespaces

 llvm
 This class represents lattice values for constants.
 

Macros

#define PASS_KEY   "x86-lvi-load"
 
#define DEBUG_TYPE   PASS_KEY
 

Typedefs

typedef int(* OptimizeCutT) (unsigned int *nodes, unsigned int nodes_size, unsigned int *edges, int *edge_values, int *cut_edges, unsigned int edges_size)
 

Functions

 STATISTIC (NumFences, "Number of LFENCEs inserted for LVI mitigation")
 
 STATISTIC (NumFunctionsConsidered, "Number of functions analyzed")
 
 STATISTIC (NumFunctionsMitigated, "Number of functions for which mitigations " "were deployed")
 
 STATISTIC (NumGadgets, "Number of LVI gadgets detected during analysis")
 
static void WriteGadgetGraph (raw_ostream &OS, MachineFunction &MF, MachineGadgetGraph *G)
 
 INITIALIZE_PASS_BEGIN (X86LoadValueInjectionLoadHardeningPass, PASS_KEY, "X86 LVI load hardening", false, false) INITIALIZE_PASS_END(X86LoadValueInjectionLoadHardeningPass
 

Variables

static cl::opt< std::string > OptimizePluginPath (PASS_KEY "-opt-plugin", cl::desc("Specify a plugin to optimize LFENCE insertion"), cl::Hidden)
 
static cl::opt< boolNoConditionalBranches (PASS_KEY "-no-cbranch", cl::desc("Don't treat conditional branches as disclosure gadgets. This " "may improve performance, at the cost of security."), cl::init(false), cl::Hidden)
 
static cl::opt< boolEmitDot (PASS_KEY "-dot", cl::desc("For each function, emit a dot graph depicting potential LVI gadgets"), cl::init(false), cl::Hidden)
 
static cl::opt< boolEmitDotOnly (PASS_KEY "-dot-only", cl::desc("For each function, emit a dot graph depicting potential LVI " "gadgets, and do not insert any fences"), cl::init(false), cl::Hidden)
 
static cl::opt< boolEmitDotVerify (PASS_KEY "-dot-verify", cl::desc("For each function, emit a dot graph to stdout depicting " "potential LVI gadgets, used for testing purposes only"), cl::init(false), cl::Hidden)
 
static llvm::sys::DynamicLibrary OptimizeDL
 
static OptimizeCutT OptimizeCut = nullptr
 
 PASS_KEY
 
X86 LVI load hardening
 
X86 LVI load false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   PASS_KEY

Definition at line 70 of file X86LoadValueInjectionLoadHardening.cpp.

◆ PASS_KEY

#define PASS_KEY   "x86-lvi-load"

Definition at line 69 of file X86LoadValueInjectionLoadHardening.cpp.

Referenced by WriteGadgetGraph().

Typedef Documentation

◆ OptimizeCutT

typedef int(* OptimizeCutT) (unsigned int *nodes, unsigned int nodes_size, unsigned int *edges, int *edge_values, int *cut_edges, unsigned int edges_size)

Definition at line 107 of file X86LoadValueInjectionLoadHardening.cpp.

Function Documentation

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( X86LoadValueInjectionLoadHardeningPass  ,
PASS_KEY  ,
"X86 LVI load hardening ,
false  ,
false   
)

Referenced by WriteGadgetGraph().

◆ STATISTIC() [1/4]

STATISTIC ( NumFences  ,
"Number of LFENCEs inserted for LVI mitigation"   
)

◆ STATISTIC() [2/4]

STATISTIC ( NumFunctionsConsidered  ,
"Number of functions analyzed"   
)

◆ STATISTIC() [3/4]

STATISTIC ( NumFunctionsMitigated  ,
"Number of functions for which mitigations " "were deployed"   
)

◆ STATISTIC() [4/4]

STATISTIC ( NumGadgets  ,
"Number of LVI gadgets detected during analysis  
)

◆ WriteGadgetGraph()

static void WriteGadgetGraph ( raw_ostream OS,
MachineFunction MF,
MachineGadgetGraph *  G 
)
static

Definition at line 246 of file X86LoadValueInjectionLoadHardening.cpp.

References llvm::X86::AddrBaseReg, llvm::X86::AddrIndexReg, assert(), llvm::MachineBasicBlock::back(), llvm::MachineBasicBlock::begin(), Builder, llvm::BuildMI(), llvm::raw_fd_ostream::close(), llvm::dbgs(), llvm::RegState::Dead, llvm::tgtok::Def, E, EmitDot, EmitDotOnly, EmitDotVerify, llvm::MachineBasicBlock::empty(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::MachineBasicBlock::end(), llvm::errs(), F(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::for_each(), llvm::MachineFunction::front(), G, llvm::sys::DynamicLibrary::getAddressOfSymbol(), llvm::MachineInstr::getDesc(), llvm::MachineBasicBlock::getFirstTerminator(), llvm::MachineFunction::getFunction(), llvm::MachineLoopInfo::getLoopDepth(), llvm::X86II::getMemoryOperandNo(), llvm::MachineFunction::getName(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::X86II::getOperandBias(), llvm::MachineOperand::getParent(), llvm::MachineInstr::getParent(), llvm::sys::DynamicLibrary::getPermanentLibrary(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getPrevNode(), llvm::MachineOperand::getReg(), llvm::MachineFunction::getRegInfo(), llvm::MachineFunction::getSubtarget(), llvm::Function::hasOptNone(), I, INITIALIZE_PASS_BEGIN(), INITIALIZE_PASS_DEPENDENCY(), llvm::SmallSet< T, N, C >::insert(), llvm::MachineInstr::isBranch(), llvm::MachineInstr::isCall(), llvm::MachineInstr::isConditionalBranch(), llvm::MachineOperand::isReg(), llvm::sys::DynamicLibrary::isValid(), LLVM_DEBUG, llvm::MachineInstr::mayLoad(), llvm::MachineInstr::mayLoadOrStore(), MBB, llvm::X86ISD::MFENCE, MI, N, NoConditionalBranches, llvm::none_of(), OptimizeCut, OptimizePluginPath, llvm::outs(), PASS_KEY, llvm::MachineInstr::print(), llvm::Ref, Reg, llvm::report_fatal_error(), llvm::cl::Sink, llvm::sort(), llvm::Sched::Source, llvm::MachineBasicBlock::successors(), TII, TRI, llvm::MCInstrDesc::TSFlags, UseMI, llvm::MachineInstr::uses(), and llvm::WriteGraph().

Variable Documentation

◆ EmitDot

cl::opt<bool> EmitDot(PASS_KEY "-dot", cl::desc( "For each function, emit a dot graph depicting potential LVI gadgets"), cl::init(false), cl::Hidden)
static

Referenced by WriteGadgetGraph().

◆ EmitDotOnly

cl::opt<bool> EmitDotOnly(PASS_KEY "-dot-only", cl::desc("For each function, emit a dot graph depicting potential LVI " "gadgets, and do not insert any fences"), cl::init(false), cl::Hidden)
static

Referenced by WriteGadgetGraph().

◆ EmitDotVerify

cl::opt<bool> EmitDotVerify(PASS_KEY "-dot-verify", cl::desc("For each function, emit a dot graph to stdout depicting " "potential LVI gadgets, used for testing purposes only"), cl::init(false), cl::Hidden)
static

Referenced by WriteGadgetGraph().

◆ false

X86 LVI load false

Definition at line 819 of file X86LoadValueInjectionLoadHardening.cpp.

◆ hardening

X86 LVI load hardening

Definition at line 819 of file X86LoadValueInjectionLoadHardening.cpp.

◆ NoConditionalBranches

cl::opt<bool> NoConditionalBranches(PASS_KEY "-no-cbranch", cl::desc("Don't treat conditional branches as disclosure gadgets. This " "may improve performance, at the cost of security."), cl::init(false), cl::Hidden)
static

Referenced by WriteGadgetGraph().

◆ OptimizeCut

OptimizeCutT OptimizeCut = nullptr
static

Definition at line 110 of file X86LoadValueInjectionLoadHardening.cpp.

Referenced by WriteGadgetGraph().

◆ OptimizeDL

llvm::sys::DynamicLibrary OptimizeDL
static

Definition at line 106 of file X86LoadValueInjectionLoadHardening.cpp.

◆ OptimizePluginPath

cl::opt<std::string> OptimizePluginPath(PASS_KEY "-opt-plugin", cl::desc("Specify a plugin to optimize LFENCE insertion"), cl::Hidden)
static

Referenced by WriteGadgetGraph().

◆ PASS_KEY

PASS_KEY

Definition at line 819 of file X86LoadValueInjectionLoadHardening.cpp.