HelpText<"Disable FixupGadgets pass (x86 only)">;
def ffixup_gadgets : Flag<["-"], "ffixup-gadgets">, Group<f_Group>, Flags<[CoreOption]>,
HelpText<"Replace ROP friendly instructions with safe alternatives (x86 only)">;
+def fno_ret_clean : Flag<["-"], "fno-ret-clean">, Group<f_Group>, Flags<[CoreOption]>,
+ HelpText<"Disable ret-clean pass">;
+def fret_clean : Flag<["-"], "fret-clean">, Group<f_Group>, Flags<[CoreOption]>,
+ HelpText<"Clean return address from stack after call">;
def ftrivial_auto_var_init_stop_after : Joined<["-"], "ftrivial-auto-var-init-stop-after=">, Group<f_Group>,
Flags<[CC1Option, CoreOption]>, HelpText<"Stop initializing trivial automatic stack variables after the specified number of instances">,
MarshallingInfoInt<LangOpts<"TrivialAutoVarInitStopAfter">>;
CmdArgs.push_back(Args.MakeArgString(Twine("-x86-fixup-gadgets=true")));
}
+ // -ret-clean
+ if (Arg *A = Args.getLastArg(options::OPT_fno_ret_clean,
+ options::OPT_fret_clean)) {
+ CmdArgs.push_back(Args.MakeArgString(Twine("-mllvm")));
+ if (A->getOption().matches(options::OPT_fno_ret_clean))
+ CmdArgs.push_back(Args.MakeArgString(Twine("-x86-ret-clean=false")));
+ else if (A->getOption().matches(options::OPT_fret_clean))
+ CmdArgs.push_back(Args.MakeArgString(Twine("-x86-ret-clean=true")));
+ }
+
RenderSCPOptions(TC, Args, CmdArgs);
RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
/// ROP friendly instructions with alternatives.
FunctionPass *createX86FixupGadgetsPass();
+/// Return a Machine Function pass that attempts to replace
+/// RET instructions with a cleaning sequence
+FunctionPass *createX86RetCleanPass();
+
/// This pass replaces EVEX encoded of AVX-512 instructiosn by VEX
/// encoding when possible in order to reduce code size.
FunctionPass *createX86EvexToVexInsts();
addPass(createX86IndirectThunksPass());
addPass(createX86ReturnThunksPass());
+ addPass(createX86RetCleanPass());
+
// Insert extra int3 instructions after trailing call instructions to avoid
// issues in the unwinder.
if (TT.isOSWindows() && TT.getArch() == Triple::x86_64)
-# $OpenBSD: Makefile,v 1.18 2023/11/11 18:35:38 robert Exp $
+# $OpenBSD: Makefile,v 1.19 2024/06/02 15:40:42 deraadt Exp $
LIB= LLVMX86CodeGen
NOPROFILE=
X86FastISel.cpp \
X86FixupBWInsts.cpp \
X86FixupGadgets.cpp \
+ X86RetClean.cpp \
X86FixupLEAs.cpp \
X86AvoidStoreForwardingBlocks.cpp \
X86DynAllocaExpander.cpp \
-.\" $OpenBSD: clang-local.1,v 1.23 2022/02/18 00:39:18 jca Exp $
+.\" $OpenBSD: clang-local.1,v 1.24 2024/06/02 15:40:43 deraadt Exp $
.\"
.\" Copyright (c) 2016 Pascal Stumpf <pascal@stumpf.co>
.\"
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\"
-.Dd $Mdocdate: February 18 2022 $
+.Dd $Mdocdate: June 2 2024 $
.Dt CLANG-LOCAL 1
.Os
.Sh NAME
option.
.It
.Nm clang
+includes a security pass that can clear the return address on the
+stack upon return from calling a function, on i386 and amd64.
+This can be enabled with the
+.Fl fret-clean
+option.
+.It
+.Nm clang
includes the retguard security feature on amd64, arm64, mips64, powerpc
and powerpc64.
This feature can be disabled with the