[PATCH] Insert random NOPs to increase security against ROP attacks (llvm)

JF Bastien jfb at chromium.org
Sat Aug 23 12:15:54 PDT 2014


================
Comment at: include/llvm/CodeGen/NOPInsertion.h:26
@@ +25,3 @@
+
+  NOPInsertion();
+
----------------
You probably want to add the `virtual` dtor too.

================
Comment at: include/llvm/CodeGen/NOPInsertion.h:28
@@ +27,3 @@
+
+  bool runOnMachineFunction(MachineFunction &MF);
+
----------------
`override`

================
Comment at: lib/CodeGen/NOPInsertion.cpp:71
@@ +70,3 @@
+  RandomNumberGenerator *RNG = Fn.getFunction()->getParent()->createRNG(this);
+  for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
+    MachineBasicBlock::iterator FirstTerm = BB->getFirstTerminator();
----------------
Use the new C++11 syntax, here and in other parts of this patch.

================
Comment at: lib/CodeGen/NOPInsertion.cpp:83
@@ +82,3 @@
+      for (unsigned i = 0; i < MaxNOPsPerInstruction; i++) {
+        unsigned Roll = (*RNG)() % 100; // FIXME: not uniform
+        if (Roll >= NOPInsertionPercentage)
----------------
Do fix :)

================
Comment at: lib/Target/X86/X86InstrInfo.cpp:5321
@@ +5320,3 @@
+    { X86::EDI, X86::RDI },
+  };
+
----------------
I'd like to have an explanation of these clever NOPs, it's not obvious from the source.

================
Comment at: lib/Target/X86/X86InstrInfo.cpp:5323
@@ +5322,3 @@
+
+  unsigned Type = (*RNG)() % MAX_NOPS;
+
----------------
You should fix this distribution too.

================
Comment at: test/CodeGen/X86/nop-insert-percentage.ll:5
@@ -4,3 +4,3 @@
 ; RUN:     | FileCheck %s --check-prefix=PERCENT50
-; RUN: llc < %s -rng-seed=5 -nop-insertion -nop-insertion-percentage=100 \
+; RUN: llc < %s -mtriple=x86_64-linux -rng-seed=5 -nop-insertion -nop-insertion-percentage=100 \
 ; RUN:     | FileCheck %s --check-prefix=PERCENT100
----------------
Also add tests for x86-32 (same below).

http://reviews.llvm.org/D3392






More information about the llvm-commits mailing list