Skip to content
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

Recursively transform predicates in ty::Dynamic rather than using identity #123045

Closed
wants to merge 2 commits into from

Conversation

compiler-errors
Copy link
Member

It is not correct to be using the identity trait ref for a dyn type. This leads to us downstream not being able to assert the non-existence of things like ty::Alias, ty::Param, ty::ReEarlyParam, etc. and also doesn't allow us to distinguish, e.g., dyn Trait<i32> and dyn Trait<&str>, lol.

Instead, just recursively transform the dyn predicates. We also should definitely be keeping around the projection predicates too.

cc @rcvalle @maurer

@rustbot
Copy link
Collaborator

rustbot commented Mar 25, 2024

r? @lcnr

rustbot has assigned @lcnr.
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

@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 Mar 25, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 25, 2024

Some changes occurred in compiler/rustc_symbol_mangling/src/typeid

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

@compiler-errors
Copy link
Member Author

Is there a way to bulk fix the tests/codegen/sanitizer/cfi/*.rs tests? They're kind of excruciating to edit.

@compiler-errors
Copy link
Member Author

@rcvalle: Specifically, I don't understand what you mean in #116404 (comment). If you disagree w/ this approach, I would appreciate if you constructed a test example that SIGILLs after this PR and not before (or at least describe such a case).

@rcvalle
Copy link
Member

rcvalle commented Mar 25, 2024

I agree with this approach. I just didn't know it was possible/how to do it at the time I implemented it using the identity of the trait that implemented the method (see also my comment on #123012 (comment)).

@maurer
Copy link
Contributor

maurer commented Mar 25, 2024

This looks reasonable to me as well.

@rcvalle
Copy link
Member

rcvalle commented Mar 25, 2024

Is there a way to bulk fix the tests/codegen/sanitizer/cfi/*.rs tests? They're kind of excruciating to edit.

Sorry, I've been creating and maintaining them manually 😞. One thing that might help is to look at the .ll file to get the correct encoding, double check it, and put it in the tests (if you're not doing this already).

@compiler-errors
Copy link
Member Author

Ok well it's gonna take approximately 5 millennia to bless those tests then 💀

@rcvalle
Copy link
Member

rcvalle commented Mar 25, 2024

No worries! I can work on that and send a PR later.

@maurer
Copy link
Contributor

maurer commented Mar 25, 2024

This raised a thought in my mind - once we're done getting everything working, should transform_ty maybe be rewritten to use a type visitor? It seems like we would have gotten this one right "for free" without needing compiler_errors' wisdom if we had been using a visitor instead of manual recursion.

@compiler-errors
Copy link
Member Author

Yes, it could be implemented as a TypeFolder, though we'd need to be careful to walk types correctly given those transform options. Still very doable.

@rcvalle
Copy link
Member

rcvalle commented Mar 25, 2024

I don't know, maybe? If we can do depth-first transformation of types using it, I guess it should work. If it's an improvement, I'm definitively up to it later.

@rcvalle
Copy link
Member

rcvalle commented Mar 25, 2024

FWIW, I don't know how type visitor works in detail, but how we do it now at least forces us to explicitly maintain the types we support encoding for, and are let known otherwise.

@compiler-errors
Copy link
Member Author

I strongly agree that this should be rewritten as a TypeFolder. If you want to guarantee you're actually transforming the types correctly for each specific variant, then just use an exhaustive match. That is off-topic for this PR, though.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

lacking some context, will review once I am back from RustNation

})
})
.collect();
predicates.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed? please add a comment why we have to sort here

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it transforms types to other types, which possibly change their stable order.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, this doesn't matter. We only sort by def path rn lol

@rustbot
Copy link
Collaborator

rustbot commented Mar 30, 2024

Some changes occurred in tests/codegen/sanitizer

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

@bors
Copy link
Contributor

bors commented Apr 4, 2024

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

@compiler-errors
Copy link
Member Author

this pr is stuck in review hell and @maurer has volunteered to just do it themselves and i'm just gonna r+ that

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.

6 participants