mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
21befa7761
A pass that adds random noops to X86 binaries to introduce diversity with the goal of increasing security against most return-oriented programming attacks. Command line options: -noop-insertion // Enable noop insertion. -noop-insertion-percentage=X // X% of assembly instructions will have a noop prepended (default: 50%, requires -noop-insertion) -max-noops-per-instruction=X // Randomly generate X noops per instruction. ie. roll the dice X times with probability set above (default: 1). This doesn't guarantee X noop instructions. In addition, the following 'quick switch' in clang enables basic diversity using default settings (currently: noop insertion and schedule randomization; it is intended to be extended in the future). -fdiversify This is the llvm part of the patch. clang part: D3393 http://reviews.llvm.org/D3392 Patch by Stephen Crane (@rinon) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225908 91177308-0d34-0410-b5e6-96231b3b80d8
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
//===-- NoopInsertion.h - Noop Insertion ------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This pass adds fine-grained diversity by displacing code using randomly
|
|
// placed (optionally target supplied) Noop instructions.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_CODEGEN_NOOPINSERTION_H
|
|
#define LLVM_CODEGEN_NOOPINSERTION_H
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
#include <random>
|
|
|
|
namespace llvm {
|
|
|
|
class RandomNumberGenerator;
|
|
|
|
class NoopInsertion : public MachineFunctionPass {
|
|
public:
|
|
static char ID;
|
|
|
|
NoopInsertion();
|
|
|
|
private:
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
|
|
std::unique_ptr<RandomNumberGenerator> RNG;
|
|
|
|
// Uniform real distribution from 0 to 100
|
|
std::uniform_real_distribution<double> Distribution =
|
|
std::uniform_real_distribution<double>(0, 100);
|
|
};
|
|
}
|
|
|
|
#endif // LLVM_CODEGEN_NOOPINSERTION_H
|