Skip to content

CFI: Only erase leading non-passed arguments #123438

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

Closed
wants to merge 5 commits into from

Conversation

maurer
Copy link
Contributor

@maurer maurer commented Apr 4, 2024

This PR switches to only erasing the first non-passed argument, and only when it's a "rust-call" function.

r? @compiler-errors
cc @rcvalle

I've left this as draft because I don't want to try to land adjustments until KCFI function pointers are in, and they just failed bors for unknown reasons.

maurer and others added 5 commits April 2, 2024 18:24
Previously, we had `NO_SELF_TYPE_ERASURE`, a negative configuration. Now
we have `ERASE_SELF_TYPE`, a positive configuration.
KCFI needs to be able to tell which kind of `ReifyShim` it is examining
in order to decide whether to use a concrete type (`FnPtr` case) or an
abstract case (`Vtable` case). You can *almost* tell this from context,
but there is one case where you can't - if a trait has a method which is
*not* `#[track_caller]`, with an impl that *is* `#[track_caller]`, both
the vtable and a function pointer created from that method will be
`ReifyShim(def_id)`.

Currently, the reason is optional to ensure no additional unique
`ReifyShim`s are added without KCFI on. However, the case in which an
extra `ReifyShim` is created is sufficiently rare that this may be worth
revisiting to reduce complexity.
Adds support for both CFI and KCFI for attaching concrete and abstract
types to functions. KCFI does this through generation of `ReifyShim` on
any function pointer that could go in a vtable, and checking the
`ReifyReason` when emitting the instance. CFI does this by attaching
both the concrete and abstract type to every instance.

TypeID codegen tests are switched to be anchored on the left rather than
the right in order to allow emission of additional type attachments.

Fixes rust-lang#115953
Since we're now using an approach which is a variant of rust-lang#123082 (that
transforms closures into dynamic Fn traits but isolating it to the Fn
call methods only) instead of rust-lang#121962 or rust-lang#122573, skipping non-passed
arguments shouldn't be necessary for KCFI anymore and we can claim back
the reduced granularity.

This reverts commit f2f0d25.
The purpose of erasing non-passed arguments was to support the
compiler's implicit cast between `call(ZSTClosure, (T, U, ..))` and
`fn(T, U, ..)`.

We can narrow this erasure by only performing it if the call Abi was
"rust-call".
@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations 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 Apr 4, 2024
@bors
Copy link
Collaborator

bors commented Apr 4, 2024

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

@rcvalle
Copy link
Member

rcvalle commented Apr 4, 2024

As I mentioned to you on Zulip already, this doesn't really solve the problem, it just gates removing all non-passed arguments of Rust ABI functions/methods/calls, which is actually only where they're applicable/exist and interest us, behind a typeid option.

@maurer maurer closed this Apr 4, 2024
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-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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants