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 LLVM KCFI support to the Rust compiler #105109

Merged
merged 2 commits into from
Dec 10, 2022
Merged

Conversation

rcvalle
Copy link
Member

@rcvalle rcvalle commented Dec 1, 2022

This PR adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.)

Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Thank you again, @bjorn3, @eddyb, @nagisa, and @ojeda, for all the help!

@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2022

r? @wesleywiser

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 1, 2022
@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2022

These commits modify compiler targets.
(See the Target Tier Policy.)

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Dec 1, 2022
@rust-log-analyzer

This comment has been minimized.

@rcvalle
Copy link
Member Author

rcvalle commented Dec 1, 2022

I'll take a look at this fasthash build failure soon.

Cargo.lock Outdated Show resolved Hide resolved
Copy link
Contributor

@ojeda ojeda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few trivial comments, though it looks fine to my untrained eyes.

compiler/rustc_symbol_mangling/src/typeid.rs Outdated Show resolved Hide resolved
compiler/rustc_symbol_mangling/src/typeid.rs Show resolved Hide resolved
src/doc/unstable-book/src/compiler-flags/sanitizer.md Outdated Show resolved Hide resolved
src/doc/unstable-book/src/compiler-flags/sanitizer.md Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member

bjorn3 commented Dec 2, 2022

You will need to add the new dependencies to the list at

const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[

@rcvalle
Copy link
Member Author

rcvalle commented Dec 2, 2022

You will need to add the new dependencies to the list at

const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[

That is what I was looking for! Thank you!

rcvalle added a commit to rcvalle/rustc-dev-guide that referenced this pull request Dec 9, 2022
This commit adds initial documentation for LLVM Kernel Control Flow
Integrity (KCFI) support to the Rust compiler (see rust-lang/rust#105109
and rust-lang/rust#89653).
rcvalle and others added 2 commits December 8, 2022 17:24
This commit adds LLVM Kernel Control Flow Integrity (KCFI) support to
the Rust compiler. It initially provides forward-edge control flow
protection for operating systems kernels for Rust-compiled code only by
aggregating function pointers in groups identified by their return and
parameter types. (See llvm/llvm-project@cff5bef.)

Forward-edge control flow protection for C or C++ and Rust -compiled
code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code
share the same virtual address space) will be provided in later work as
part of this project by identifying C char and integer type uses at the
time types are encoded (see Type metadata in the design document in the
tracking issue rust-lang#89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
This commit adds initial documentation for LLVM Kernel Control Flow
Integrity (KCFI) support to the Rust compiler (see rust-lang#105109 and rust-lang#89653).

Co-authored-by: Miguel Ojeda <ojeda@users.noreply.github.com>
@bjorn3
Copy link
Member

bjorn3 commented Dec 9, 2022

This is an unstable feature and is closely related to the (non-kernel) CFI work that was recently added without requiring an FCP. As such I think it is fine to land this without FCP too.

r? @bjorn3

@bors r+

@bors
Copy link
Contributor

bors commented Dec 9, 2022

📌 Commit e1741ba has been approved by bjorn3

It is now in the queue for this repository.

@rustbot rustbot assigned bjorn3 and unassigned wesleywiser Dec 9, 2022
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 9, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 10, 2022
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#98391 (Reimplement std's thread parker on top of events on SGX)
 - rust-lang#104019 (Compute generator sizes with `-Zprint_type_sizes`)
 - rust-lang#104512 (Set `download-ci-llvm = "if-available"` by default when `channel = dev`)
 - rust-lang#104901 (Implement masking in FileType comparison on Unix)
 - rust-lang#105082 (Fix Async Generator ABI)
 - rust-lang#105109 (Add LLVM KCFI support to the Rust compiler)
 - rust-lang#105505 (Don't warn about unused parens when they are used by yeet expr)
 - rust-lang#105514 (Introduce `Span::is_visible`)
 - rust-lang#105516 (Update cargo)
 - rust-lang#105522 (Remove wrong note for short circuiting operators)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 947fe7e into rust-lang:master Dec 10, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 10, 2022
bjorn3 pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Dec 14, 2022
This commit adds initial documentation for LLVM Kernel Control Flow
Integrity (KCFI) support to the Rust compiler (see rust-lang/rust#105109
and rust-lang/rust#89653).

pub fn target() -> Target {
let opts = TargetOptions {
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
features: "+strict-align,+neon,+fp-armv8".into(),
supported_sanitizers: SanitizerSet::KCFI,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the aarch64-unknown-none-softfloat target also support KCFI?

@rcvalle rcvalle added the PG-exploit-mitigations Project group: Exploit mitigations label Mar 13, 2023
@rcvalle rcvalle deleted the rust-kcfi branch May 22, 2023 17:54
antoyo pushed a commit to antoyo/rust that referenced this pull request Jun 19, 2023
Add LLVM KCFI support to the Rust compiler

This PR adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.)

Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue rust-lang#89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Thank you again, `@bjorn3,` `@eddyb,` `@nagisa,` and `@ojeda,` for all the help!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants