summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/tools/clang/lib/Driver
diff options
context:
space:
mode:
authormortimer <mortimer@openbsd.org>2018-06-06 00:14:29 +0000
committermortimer <mortimer@openbsd.org>2018-06-06 00:14:29 +0000
commite688c2b0648a80551cf7353d9f455c7cbb98f13c (patch)
treebb3f8b6975fe82bca012e40729fe5e7d66f07427 /gnu/llvm/tools/clang/lib/Driver
parentMove pluart(4) to dev/fdt. (diff)
downloadwireguard-openbsd-e688c2b0648a80551cf7353d9f455c7cbb98f13c.tar.xz
wireguard-openbsd-e688c2b0648a80551cf7353d9f455c7cbb98f13c.zip
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. Remaining work includes adding this mechanism to assembly routines, which must be done by hand. Many thanks to all those who helped test and provide feedback, especially deaadt, tb, espie and naddy. ok deraadt@
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Driver')
-rw-r--r--gnu/llvm/tools/clang/lib/Driver/ToolChains/Clang.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/gnu/llvm/tools/clang/lib/Driver/ToolChains/Clang.cpp b/gnu/llvm/tools/clang/lib/Driver/ToolChains/Clang.cpp
index f1137b2d928..91a656f4a48 100644
--- a/gnu/llvm/tools/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/gnu/llvm/tools/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3978,6 +3978,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
else if (A->getOption().matches(options::OPT_fret_protector))
RetProtector = 1;
}
+ if (RetProtector &&
+ (getToolChain().getArch() == llvm::Triple::x86_64) &&
+ !Args.hasArg(options::OPT_fno_stack_protector) &&
+ !Args.hasArg(options::OPT_pg)) {
+ CmdArgs.push_back(Args.MakeArgString("-D_RET_PROTECTOR"));
+ CmdArgs.push_back(Args.MakeArgString(Twine("-ret-protector")));
+ }
// Translate -mstackrealign
if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,