Skip to content

Add cross-language LLVM CFI support to the Rust compiler#105452

Merged
bors merged 2 commits intorust-lang:masterfrom
rcvalle:rust-cfi-3
May 4, 2023
Merged

Add cross-language LLVM CFI support to the Rust compiler#105452
bors merged 2 commits intorust-lang:masterfrom
rcvalle:rust-cfi-3

Conversation

@rcvalle
Copy link
Member

@rcvalle rcvalle commented Dec 8, 2022

This PR adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the -Zsanitizer-cfi-normalize-integers option to be used with Clang -fsanitize-cfi-icall-normalize-integers for normalizing integer types (see https://reviews.llvm.org/D139395).

It provides 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). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653.

Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).

Thank you again, @bjorn3, @nikic, @samitolvanen, and the Rust community for all the help!

@rustbot
Copy link
Collaborator

rustbot commented Dec 8, 2022

r? @cjgillot

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

@rustbot rustbot added 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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 8, 2022
Copy link
Member

Choose a reason for hiding this comment

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

I believe this misses #[repr(transparent)] support.

Copy link
Member

Choose a reason for hiding this comment

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

Is it in transform_ty? How exactly does that function relate to encode_ty and why is it split?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's handled in transform_ty, and its tests are here: https://github.com/rust-lang/rust/blob/master/src/test/codegen/sanitizer-cfi-emit-type-metadata-id-itanium-cxx-abi.rs#L116-L132. transform_ty coalesces types that have the same encoding into a single entity (e.g., c_void into unit), normalizes, and generalizes types before handing them to encode_ty. It greatly simplifies the encoding and compression/substitution logic.

@rcvalle rcvalle force-pushed the rust-cfi-3 branch 3 times, most recently from 8bc3f3d to de462bc Compare December 9, 2022 07:33
@cjgillot
Copy link
Contributor

r? @bjorn3

@rustbot rustbot assigned bjorn3 and unassigned cjgillot Dec 10, 2022
@rust-log-analyzer

This comment has been minimized.

@rcvalle rcvalle force-pushed the rust-cfi-3 branch 4 times, most recently from 4e6f11d to afdeab8 Compare December 14, 2022 07:17
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Dec 16, 2022

☔ The latest upstream changes (presumably #105763) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 15, 2023
@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 26, 2023
@bjorn3
Copy link
Member

bjorn3 commented Apr 26, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 26, 2023

📌 Commit 77b4492 has been approved by bjorn3

It is now in the queue for this repository.

@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 Apr 26, 2023
@bors
Copy link
Collaborator

bors commented Apr 28, 2023

⌛ Testing commit 77b4492 with merge 7e6abfbb80091195d39f4313f2955859588661f7...

@bors
Copy link
Collaborator

bors commented Apr 28, 2023

💔 Test failed - checks-actions

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 28, 2023
@ehuss
Copy link
Contributor

ehuss commented Apr 28, 2023

@bors retry

python setuptools issue

@rust-log-analyzer

This comment has been minimized.

@Manishearth
Copy link
Member

@bors r-

fails the rollup #111162 (comment)

rcvalle added 2 commits May 3, 2023 22:41
This commit adds cross-language LLVM Control Flow Integrity (CFI)
support to the Rust compiler by adding the
`-Zsanitizer-cfi-normalize-integers` option to be used with Clang
`-fsanitize-cfi-icall-normalize-integers` for normalizing integer types
(see https://reviews.llvm.org/D139395).

It provides 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). For more
information about LLVM CFI and cross-language LLVM CFI support for the
Rust compiler, see design document in the tracking issue rust-lang#89653.

Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and
-Zsanitizer-cfi-normalize-integers, and requires proper (i.e.,
non-rustc) LTO (i.e., -Clinker-plugin-lto).
This commit updates the documentation for the LLVM Control Flow
Integrity (CFI) support in the Rust compiler.
@Manishearth
Copy link
Member

@bors r=bjorn3

@bors
Copy link
Collaborator

bors commented May 3, 2023

📌 Commit 9a02f65 has been approved by bjorn3

It is now in the queue for this repository.

/// Allow conditional compilation depending on rust version
(active, cfg_version, "1.45.0", Some(64796), None),
/// Allows to use the `#[cfi_encoding = ""]` attribute.
(active, cfi_encoding, "1.69.0", Some(89653), None),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be CURRENT_RUSTC_VERSION?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.