Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport commits to support Control Flow Guard #61

Conversation

ajpaverd
Copy link

These commits from LLVM 10.0 are required to enable Windows Control Flow Guard (CFG). CFG is an exploit mitigation technology on Microsoft Windows to limit the available targets of indirect jumps. This provides security benefits when Rust is linked against C/C++ code.

Rustc currently supports the -Z control_flow_guard option to emit the necessary LLVM module flags. These commits enable LLVM to add the necessary CFG functionality when the module flags are present.

Rust tracking issue: rust-lang/rust#68793
CFG documentation: https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard

ajpaverd and others added 4 commits May 18, 2020 10:23
Summary:
A new function pass (Transforms/CFGuard/CFGuard.cpp) inserts CFGuard checks on
indirect function calls, using either the check mechanism (X86, ARM, AArch64) or
or the dispatch mechanism (X86-64). The check mechanism requires a new calling
convention for the supported targets. The dispatch mechanism adds the target as
an operand bundle, which is processed by SelectionDAG. Another pass
(CodeGen/CFGuardLongjmp.cpp) identifies and emits valid longjmp targets, as
required by /guard:cf. This feature is enabled using the `cfguard` CC1 option.

Reviewers: thakis, rnk, theraven, pcc

Subscribers: ychen, hans, metalcanine, dmajor, tomrittervg, alex, mehdi_amini, mgorny, javed.absar, kristof.beyls, hiraditya, steven_wu, dexonsmith, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D65761
Ran:
    git show  --diff-filter=A --stat d157a9b | grep '|' | \
    awk '{ print $1 }' | xargs dos2unix
AL is only used for varargs on SysV platforms. Don't forward it on
Windows. This allows control flow guard to set up an extra hidden
parameter in RAX, as described in PR44049.

This also has the effect of freeing up RAX for use in virtual member
pointer thunks, which may also be a nice little code size improvement on
Win64.

Fixes PR44049

Reviewers: ajpaverd, efriedma, hans

Differential Revision: https://reviews.llvm.org/D70413
Summary:
Avoid using the `nocf_check` attribute with Control Flow Guard. Instead, use a
new `"guard_nocf"` function attribute to indicate that checks should not be
added on indirect calls within that function. Add support for
`__declspec(guard(nocf))` following the same syntax as MSVC.

Reviewers: rnk, dmajor, pcc, hans, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, tomrittervg, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D72167
@nikic nikic mentioned this pull request May 18, 2020
8 tasks
@cuviper
Copy link
Member

cuviper commented May 20, 2020

FYI, the LLVM 10 upgrade in rust-lang/rust#67759 is finally queued to merge, which I suppose will make this PR moot.

@cuviper
Copy link
Member

cuviper commented May 21, 2020

Ok, we've now landed on LLVM 10! Please open a new PR if there's anything else you need.

@cuviper cuviper closed this May 21, 2020
vext01 pushed a commit to vext01/llvm-project that referenced this pull request Apr 27, 2023
61: Fix changes to stackmaps made by the register allocator. r=ltratt a=ptersilie



Co-authored-by: Lukas Diekmann <lukas.diekmann@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants