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

Add support for control-flow protection #4239

Closed
wants to merge 5 commits into from

Conversation

kubo39
Copy link
Contributor

@kubo39 kubo39 commented Oct 24, 2022

This implementation is fully inspired by -fcf-protection in Clang, with options none|branch|return|full.

This implementation is fully inspired by `-fcf-protection` in Clang,
with options `none|branch|return|full`.

- related: ldc-developers#2511
- LLVM side: https://reviews.llvm.org/D40478
driver/cl_options.cpp Outdated Show resolved Hide resolved
@kubo39 kubo39 marked this pull request as ready for review October 24, 2022 16:03
@JohanEngelen
Copy link
Member

Cool that you implemented this. Did you try it? I'm wondering how it works / what it does. Do you need runtime support? (i.e. link with an LLVM lib?)

@JohanEngelen
Copy link
Member

Reference to current Clang implementation: https://github.com/llvm/llvm-project/blob/5f5e0199c1a650c41e1ea6e0c18d3c0b29f45023/clang/lib/CodeGen/CodeGenModule.cpp#L753-L764

Can you look into the difference between llvm::Module::Min and Override ?

@kubo39
Copy link
Contributor Author

kubo39 commented Oct 24, 2022

Did you try it? I'm wondering how it works / what it does. Do you need runtime support? (i.e. link with an LLVM lib?)

Wow, good catch! I tested under my old Linux/WSL with Intel SDE and this did not work as expected.
(evil.d is copied and modified from https://smallkirby.hatenablog.com/entry/2020/09/10/230629)

$ uname -mrv
4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64
$ readelf -a ./evil | grep feature:
$ echo $?
1
$ ../sde/sde -tgl -cet -cet-stderr -cet-call-stack -- ./evil
Using old Linux kernel interface
Syscall EMU: ARCH_X86_FEATURE_1_STATUS: 0x000000012 0x7ff2bb39c000 0x000001000
Syscall EMU: ARCH_X86_FEATURE_1_DISABLE: 0x000000003
Syscall EMU: ARCH_X86_FEATURE_1_LOCK
Start
I am evil moratorium.
CET is winner...

I'd like to keep this as drafted PR.

Can you look into the difference between llvm::Module::Min and Override ?

Sure. I hadn't noticed this changes.

https://reviews.llvm.org/D130065 llvm::Module::Min looks better.

@kubo39 kubo39 marked this pull request as draft October 24, 2022 20:01
@kubo39
Copy link
Contributor Author

kubo39 commented Oct 24, 2022

llvm::Module::Min was added in llvm/llvm-project@b0343a3.

@thewilsonator
Copy link
Contributor

If this is only enabled for LLVM 15, then do note that we do not currently have any CI set up to test this. see #4221

@JohanEngelen
Copy link
Member

Did you try it? I'm wondering how it works / what it does. Do you need runtime support? (i.e. link with an LLVM lib?)

Wow, good catch! I tested under my old Linux/WSL with Intel SDE and this did not work as expected. (evil.d is copied and modified from https://smallkirby.hatenablog.com/entry/2020/09/10/230629)

Can you add this as a runnable test case?

(we also have such very basic integration tests for e.g. address sanitizer)

Note that there is still value for this feature even if it does not (yet) work fully by itself. If runtime support is needed, that can be added separately from the LLVM IR modifications that you do in this PR.

@kubo39
Copy link
Contributor Author

kubo39 commented Jul 23, 2023

duplicated with #4437

@kubo39 kubo39 closed this Jul 23, 2023
@kubo39 kubo39 deleted the support-cf-protection branch July 23, 2023 22:17
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.

3 participants