Skip to content

Conversation

rcvalle
Copy link
Member

@rcvalle rcvalle commented Aug 23, 2023

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
Collaborator

rustbot commented Aug 23, 2023

r? @WaffleLapkin

(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. labels Aug 23, 2023
@rcvalle
Copy link
Member Author

rcvalle commented Aug 23, 2023

r? @bjorn3

@rustbot rustbot assigned bjorn3 and unassigned WaffleLapkin Aug 23, 2023
@rcvalle rcvalle added the PG-exploit-mitigations Project group: Exploit mitigations label Aug 23, 2023
@rcvalle rcvalle changed the title Fix CFI: f32 and f64 are encoded incorrectly for c Fix CFI: f32 and f64 are encoded incorrectly for cross-language CFI Aug 23, 2023
// Rust's f32 and f64 single (32-bit) and double (64-bit) precision floating-point types
// have IEEE-754 binary32 and binary64 floating-point layouts, respectively.
//
// (See https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html#fixed-width-floating-point-types.)
Copy link
Member

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?

Copy link
Member Author

@rcvalle rcvalle Aug 25, 2023

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?

Fix rust-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 rcvalle force-pushed the rust-cfi-fix-115150 branch from d9f2b60 to 5d6e2d7 Compare August 25, 2023 04:02
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 25, 2023

📌 Commit 5d6e2d7 has been approved by compiler-errors

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 Aug 25, 2023
@rcvalle
Copy link
Member Author

rcvalle commented Aug 25, 2023

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:master Aug 25, 2023
@rustbot rustbot 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
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