Skip to content

Fix CFI: f32 and f64 are encoded incorrectly for cross-language CFI - #115151

Merged
bors merged 1 commit into
rust-lang:masterfrom
rcvalle:rust-cfi-fix-115150
Aug 25, 2023
Merged

Fix CFI: f32 and f64 are encoded incorrectly for cross-language CFI#115151
bors merged 1 commit into
rust-lang:masterfrom
rcvalle:rust-cfi-fix-115150

Conversation

@rcvalle

Copy link
Copy Markdown
Member

Fix#115150 by encoding f32 and f64 correctly for cross-language CFI. I missed changing the encoding for f32 and f64 when I introduced the integer normalization option in #105452 as integer normalization does not include floating point. f32 and f64 should be always encoded as f and d since they are both FFI safe when their representation are the same (i.e., IEEE 754) for both the Rust compiler and Clang.

@rustbot

Copy link
Copy Markdown
Collaborator

r? @WaffleLapkin

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

@rustbotrustbot 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. labels Aug 23, 2023
@rcvalle

Copy link
Copy Markdown
MemberAuthor

r? @bjorn3

@rustbotrustbot assigned bjorn3 and unassigned WaffleLapkinAug 23, 2023
@rcvallercvalle added the PG-exploit-mitigations Project group: Exploit mitigations label Aug 23, 2023
@rcvallercvalle changed the title Fix CFI: f32 and f64 are encoded incorrectly for cFix CFI: f32 and f64 are encoded incorrectly for cross-language CFIAug 23, 2023
Comment threadcompiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs Outdated
Comment threadcompiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be better to link to something describing the f and d prefixes that the encoding expects for IEEE-754 floats?

@rcvallercvalleAug 25, 2023

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Humm... those are just the Itanium C++ encoding for these builtin types (see https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin). Instead of referencing it, I think it makes more sense to explain why they can be directly used here (similarly to how it's explained in line 446 for ty::Bool). What do you think?

Fixrust-lang#115150 by encoding f32 and f64 correctly for cross-language CFI. I
missed changing the encoding for f32 and f64 when I introduced the
integer normalization option in rust-lang#105452 as integer normalization does
not include floating point. `f32` and `f64` should be always encoded as
`f` and `d` since they are both FFI safe when their representation are
the same (i.e., IEEE 754) for both the Rust compiler and Clang.
@rcvalle
rcvalleforce-pushed the rust-cfi-fix-115150 branch from d9f2b60 to 5d6e2d7CompareAugust 25, 2023 04:02
@compiler-errors

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@bors

bors commented Aug 25, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit 5d6e2d7 has been approved by compiler-errors

It is now in the queue for this repository.

@borsbors 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 Aug 25, 2023
@rcvalle

Copy link
Copy Markdown
MemberAuthor

Thank you for your time, @compiler-errors! Much appreciated.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2023
…iaskrgr
Rollup of 5 pull requests
Successful merges:
- rust-lang#114754 (Name what ln_gamma does)
- rust-lang#115081 (Allow overwriting ExpnId for concurrent decoding)
- rust-lang#115151 (Fix CFI: f32 and f64 are encoded incorrectly for cross-language CFI)
- rust-lang#115169 (remove some unnecessary ignore-debug clauses)
- rust-lang#115190 (Add comment to the push_trailing function)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit adc0c91 into rust-lang:masterAug 25, 2023
@rustbotrustbot added this to the 1.74.0 milestone Aug 25, 2023
@rcvalle
rcvalle deleted the rust-cfi-fix-115150 branch April 22, 2024 23:06
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PG-exploit-mitigationsProject group: Exploit mitigationsS-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

CFI: f32 and f64 are encoded incorrectly for cross-language CFI

6 participants

@rcvalle@rustbot@compiler-errors@bors@bjorn3@WaffleLapkin