54 lines
2.5 KiB
Plaintext
54 lines
2.5 KiB
Plaintext
$OpenBSD: patch-include_llvm_CodeGen_TargetFrameLowering_h,v 1.2 2018/08/21 06:56:09 ajacoutot Exp $
|
|
|
|
- Add RETGUARD to clang for amd64. This security mechanism uses per-function
|
|
random cookies to protect access to function return instructions, with the
|
|
effect that the integrity of the return address is protected, and function
|
|
return instructions are harder to use in ROP gadgets.
|
|
|
|
On function entry the return address is combined with a per-function random
|
|
cookie and stored in the stack frame. The integrity of this value is verified
|
|
before function return, and if this check fails, the program aborts. In this way
|
|
RETGUARD is an improved stack protector, since the cookies are per-function. The
|
|
verification routine is constructed such that the binary space immediately
|
|
before each ret instruction is padded with int03 instructions, which makes these
|
|
return instructions difficult to use in ROP gadgets. In the kernel, this has the
|
|
effect of removing approximately 50% of total ROP gadgets, and 15% of unique
|
|
ROP gadgets compared to the 6.3 release kernel. Function epilogues are
|
|
essentially gadget free, leaving only the polymorphic gadgets that result from
|
|
jumping into the instruction stream partway through other instructions. Work to
|
|
remove these gadgets will continue through other mechanisms.
|
|
- Refactor retguard to make adding additional arches easier.
|
|
|
|
Index: include/llvm/CodeGen/TargetFrameLowering.h
|
|
--- include/llvm/CodeGen/TargetFrameLowering.h.orig
|
|
+++ include/llvm/CodeGen/TargetFrameLowering.h
|
|
@@ -15,6 +15,7 @@
|
|
#define LLVM_CODEGEN_TARGETFRAMELOWERING_H
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
+#include "llvm/CodeGen/ReturnProtectorLowering.h"
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
@@ -164,6 +165,20 @@ class TargetFrameLowering { (public)
|
|
MachineBasicBlock &MBB) const = 0;
|
|
virtual void emitEpilogue(MachineFunction &MF,
|
|
MachineBasicBlock &MBB) const = 0;
|
|
+
|
|
+ virtual const ReturnProtectorLowering *getReturnProtector() const {
|
|
+ return nullptr;
|
|
+ }
|
|
+
|
|
+ /// insertReturnProtectorPrologue/Epilogue - Insert ret-protector code
|
|
+ virtual void insertReturnProtectorPrologue(MachineFunction &MF,
|
|
+ MachineBasicBlock &MBB) const
|
|
+ {}
|
|
+ virtual bool insertReturnProtectorEpilogue(MachineFunction &MF,
|
|
+ MachineBasicBlock &MBB) const
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
|
|
/// Replace a StackProbe stub (if any) with the actual probe code inline
|
|
virtual void inlineStackProbe(MachineFunction &MF,
|