Skip to content

Document that CFI diverges from Rust wrt. ABI-compatibility rules#155361

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Darksonn:abi-cfi
Apr 28, 2026
Merged

Document that CFI diverges from Rust wrt. ABI-compatibility rules#155361
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Darksonn:abi-cfi

Conversation

@Darksonn
Copy link
Copy Markdown
Member

@Darksonn Darksonn commented Apr 15, 2026

View all comments

The CFI sanitizer is a sanitizer that checks that no ABI-incompatible function calls are made at runtime, but there is currently an unfortunate divergence between the Rust ABI-compatibility rules and what the CFI sanitizer checks. Thus, document that this divergence exists.

There are proposals for how we can align the ABI rules to eliminate this discrepancy, and I would like to follow through with those, but for now I think we can at least document that the discrepancy exists.

For further discussion please see Re-evaluate ABI compatibility rules in light of CFI and Can CFI be made compatible with type erasure schemes? and fn_cast! macro.

cc @rcvalle @samitolvanen @maurer @bjorn3 @RalfJung

Rendered:

image

@Darksonn Darksonn added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-ABI Area: Concerning the application binary interface (ABI) PG-exploit-mitigations Project group: Exploit mitigations A-control-flow-integrity Area: Control Flow Integrity (CFI) security mitigation labels Apr 15, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 15, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 15, 2026

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 7 candidates
  • Random selection from Mark-Simulacrum, jhpratt, scottmcm

Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
@scottmcm
Copy link
Copy Markdown
Member

TBH, I think this is a fundamental flaw in CFI, being coupled to typed-memory concepts that don't exist in Rust.


Since he's been looking at this,
r? RalfJung

@rustbot rustbot assigned RalfJung and unassigned scottmcm Apr 20, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 20, 2026

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

Comment thread library/core/src/primitive_docs.rs Outdated
Comment thread library/core/src/primitive_docs.rs Outdated
@Darksonn
Copy link
Copy Markdown
Member Author

@scottmcm CFI does have some pretty big flaws, but I don't think that's one of them. It's a useful way to detect function pointer mixups, and ABI-compatibility has always been a stronger requirement than just being memory compatible. Just because f32 and u32 are memory compatible does not imply they should be ABI-compatible.

@RalfJung
Copy link
Copy Markdown
Member

The content seems reasonable to me. The one thing I am not sure about is the location. Maybe these docs are a more natural place for CFI-specific documentation?

Comment thread library/core/src/primitive_docs.rs Outdated
Comment on lines +1832 to +1835
/// - `*const T`, `*mut T`, `&T`, `&mut T`, `Box<T>` (specifically, only `Box<T, Global>`), and
/// `NonNull<T>` are all ABI-compatible with each other for all `T`. They are also ABI-compatible
/// with each other for _different_ `T` if they have the same metadata type (`<T as
/// Pointee>::Metadata`).
/// Pointee>::Metadata`). However, see the [Control Flow Integrity] section below for caveats.
Copy link
Copy Markdown
Member Author

@Darksonn Darksonn Apr 28, 2026

Choose a reason for hiding this comment

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

I can move the main docs section, but I'd like to keep this note in this file.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah that makes sense.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

Some changes occurred in src/doc/unstable-book/src/compiler-flags/sanitizer.md

cc @rust-lang/project-exploit-mitigations, @rcvalle

@RalfJung
Copy link
Copy Markdown
Member

@bors squash msg="Document that CFI diverges from Rust wrt. ABI-compatibility rules"

@rust-bors

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 28, 2026

🔨 10 commits were squashed into aef93ca.

@RalfJung
Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 28, 2026

📌 Commit aef93ca has been approved by RalfJung

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 28, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 28, 2026
Document that CFI diverges from Rust wrt. ABI-compatibility rules

The CFI sanitizer is a sanitizer that checks that no ABI-incompatible function calls are made at runtime, but there is currently an unfortunate divergence between the Rust ABI-compatibility rules and what the CFI sanitizer checks. Thus, document that this divergence exists.

There are proposals for how we can align the ABI rules to eliminate this discrepancy, and I would like to follow through with those, but for now I think we can at least document that the discrepancy exists.

For further discussion please see [Re-evaluate ABI compatibility rules in light of CFI](rust-lang/unsafe-code-guidelines#489) and [Can CFI be made compatible with type erasure schemes?](rust-lang#128728) and [`fn_cast!` macro](rust-lang#140803).

cc @rcvalle @samitolvanen @maurer @bjorn3 @RalfJung

Rendered:

<img width="956" height="391" alt="image" src="https://github.com/user-attachments/assets/410d3eaa-9476-4800-9ef8-bbb100a100c5" />
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 28, 2026
Document that CFI diverges from Rust wrt. ABI-compatibility rules

The CFI sanitizer is a sanitizer that checks that no ABI-incompatible function calls are made at runtime, but there is currently an unfortunate divergence between the Rust ABI-compatibility rules and what the CFI sanitizer checks. Thus, document that this divergence exists.

There are proposals for how we can align the ABI rules to eliminate this discrepancy, and I would like to follow through with those, but for now I think we can at least document that the discrepancy exists.

For further discussion please see [Re-evaluate ABI compatibility rules in light of CFI](rust-lang/unsafe-code-guidelines#489) and [Can CFI be made compatible with type erasure schemes?](rust-lang#128728) and [`fn_cast!` macro](rust-lang#140803).

cc @rcvalle @samitolvanen @maurer @bjorn3 @RalfJung

Rendered:

<img width="956" height="391" alt="image" src="https://github.com/user-attachments/assets/410d3eaa-9476-4800-9ef8-bbb100a100c5" />
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #155850 (Only exclude the #155473 change for 1-byte bool-likes)
 - #155923 (Subtree sync for rustc_codegen_cranelift)
 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #155850 (Only exclude the #155473 change for 1-byte bool-likes)
 - #155923 (Subtree sync for rustc_codegen_cranelift)
 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #155923 (Subtree sync for rustc_codegen_cranelift)
 - #155930 (Sync from portable simd 2026 04 28)
 - #155850 (Only exclude the #155473 change for 1-byte bool-likes)
 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
 - #155936 (Rename `SharedContext::emit_dyn_lint*` into `emit_lint*`)
rust-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #155923 (Subtree sync for rustc_codegen_cranelift)
 - #155930 (Sync from portable simd 2026 04 28)
 - #155850 (Only exclude the #155473 change for 1-byte bool-likes)
 - #151994 (switch to v0 mangling by default on stable)
 - #154325 (Tweak irrefutable let else warning output)
 - #155273 (Lock stable_crate_ids once in create_crate_num)
 - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules)
 - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available)
 - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…)
 - #155768 (compiletest: Overhaul the code for running an incremental test revision)
 - #155907 (Handle hkl const closures)
 - #155910 (misc stuff from reading borrowck again :))
 - #155913 (Delete the 12 year old fixme)
 - #155920 (remove review queue triagebot mentions)
 - #155936 (Rename `SharedContext::emit_dyn_lint*` into `emit_lint*`)
@rust-bors rust-bors Bot merged commit 8f15da4 into rust-lang:main Apr 28, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 28, 2026
rust-timer added a commit that referenced this pull request Apr 28, 2026
Rollup merge of #155361 - Darksonn:abi-cfi, r=RalfJung

Document that CFI diverges from Rust wrt. ABI-compatibility rules

The CFI sanitizer is a sanitizer that checks that no ABI-incompatible function calls are made at runtime, but there is currently an unfortunate divergence between the Rust ABI-compatibility rules and what the CFI sanitizer checks. Thus, document that this divergence exists.

There are proposals for how we can align the ABI rules to eliminate this discrepancy, and I would like to follow through with those, but for now I think we can at least document that the discrepancy exists.

For further discussion please see [Re-evaluate ABI compatibility rules in light of CFI](rust-lang/unsafe-code-guidelines#489) and [Can CFI be made compatible with type erasure schemes?](#128728) and [`fn_cast!` macro](#140803).

cc @rcvalle @samitolvanen @maurer @bjorn3 @RalfJung

Rendered:

<img width="956" height="391" alt="image" src="https://github.com/user-attachments/assets/410d3eaa-9476-4800-9ef8-bbb100a100c5" />
@Darksonn Darksonn deleted the abi-cfi branch April 28, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ABI Area: Concerning the application binary interface (ABI) A-control-flow-integrity Area: Control Flow Integrity (CFI) security mitigation A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools 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-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.

4 participants