aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Tools.cpp
diff options
context:
space:
mode:
authorJF Bastien <jfb@google.com>2015-01-14 01:07:51 +0000
committerJF Bastien <jfb@google.com>2015-01-14 01:07:51 +0000
commit4cb557039dbc6d764fa2b16f811f37e5accf2f0d (patch)
tree9f57935d69debeb8c6c05e3b130821d78562c554 /clang/lib/Driver/Tools.cpp
parent934361a4b8661410b5c1d8e1f50f3f1c145e8b7e (diff)
downloadllvm-4cb557039dbc6d764fa2b16f811f37e5accf2f0d.zip
llvm-4cb557039dbc6d764fa2b16f811f37e5accf2f0d.tar.gz
llvm-4cb557039dbc6d764fa2b16f811f37e5accf2f0d.tar.bz2
Insert random noops to increase security against ROP attacks (clang)
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 clang part of the patch. llvm part: D3392 http://reviews.llvm.org/D3393 Patch by Stephen Crane (@rinon) llvm-svn: 225910
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r--clang/lib/Driver/Tools.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index d625c0e..4aecf22 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -3737,6 +3737,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
getToolChain().getTriple().getArch() == llvm::Triple::aarch64_be)
CmdArgs.push_back("-fallow-half-arguments-and-returns");
+ // Translate -frandom-seed to seed the LLVM RNG
+ if (Args.hasArg(options::OPT_frandom_seed_EQ)) {
+ StringRef seed = Args.getLastArgValue(options::OPT_frandom_seed_EQ);
+ CmdArgs.push_back("-backend-option");
+ CmdArgs.push_back(Args.MakeArgString("-rng-seed=" + seed));
+ }
+
+ if (Args.hasArg(options::OPT_fdiversify)) {
+ CmdArgs.push_back("-noop-insertion");
+ }
+
if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {
if (A->getOption().matches(options::OPT_mrestrict_it)) {