- Notifications
You must be signed in to change notification settings - Fork 13.9k
CFI: Fix types that implement Fn, FnMut, or FnOnce #144936
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
base: master
Are you sure you want to change the base?
Conversation
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8b21653
to bb63853
Compare This comment has been minimized.
This comment has been minimized.
bb63853
to 8df6ab8
Compare There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see more explanation for the fix in this PR. Specifically, the issue and the PR don't actually describe what kind of CFI violation was being encountered here before, or how it's being fixed by this erasure?
The comment in #144641 (comment) mentions:
The only special handling in the code is for closures, coroutines, and coroutine closures, but not for arbitrary types that implement these traits.
Does this make the code that is special-cased for closure-like types redundant?
compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs Outdated Show resolved Hide resolved
compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs Outdated Show resolved Hide resolved
@maurer wrote a lot of this erasure logic, I'd be interested if he has a take on this approach as well |
My first reaction here is that I think this is a bug in |
Specifically, d5bf25c seems to address this more simply - basically, it looks like I missed Update: It looks like the adjustment I'm proposing would also cause:
This looks OK to me, and has the added benefit of automatically picking up new shim types when added. If we wanted to be more conservative, we could instead do 0026b9c which fixes the tests in question with a minimal change - it only re-normalizes |
@maurer Thank you for your time looking at it! Much appreciated. I'm wondering whether we should change approach in this code and cover each case explicitly (like we do for encoding) so we could express our intent clearly and know when something is handled (or not) and the side effects of it (also clearly). |
I added a commit message at https://github.com/maurer/rust/tree/cfi-fix - I hadn't bothered because I just expected you to squash it onto your commit if you agreed with the direction. Re: being more explicit with casing out, I think maybe the way to do that (which should definitely be a future PR if at all) would be:
I don't know how much maintenance this saves us, mostly depends on how often we're sprinkling new |
This comment has been minimized.
This comment has been minimized.
@maurer Just picked it into this PR. Thank you! (I had to fix some compilation errors, but I believe the PR is going to be squashed before being merged anyway so it should be fine.) I'll take a look at covering each case explicitly and your suggestion, and send a separate PR and CC you when I've something. Thanks again! |
@rustbot ready |
|
r? compiler |
This comment has been minimized.
This comment has been minimized.
It checks that the function pointer to be called at a call site has the expected/same type (i.e., type id) its function definition, and this is a helper to perform type erasure for when it's expected at call sites.
Yes, agreed. I suggested the same above. I'll work on that on a subsequent PR.
Thank you very much for your time on this! Much appreciated. |
2ddb8aa
to b9f4303
Compare
|
This comment has been minimized.
This comment has been minimized.
b9f4303
to 9a85176
Compare This comment has been minimized.
This comment has been minimized.
9a85176
to ea08a7d
Compare @bors r=lcnr |
CFI: Fix types that implement Fn, FnMut, or FnOnce When looking for instances which could either be dynamically called through a vtable or through a concrete trait method, we missed `FnPtrShim`, instead only looking at `Item` and closure-likes. Fixes rust-lang#144641. cc `@1c3t3a` `@Jakob-Koschel`
Rollup of 7 pull requests Successful merges: - #144936 (CFI: Fix types that implement Fn, FnMut, or FnOnce) - #147000 (std: Add Motor OS std library port) - #147732 (remove duplicate inline macro) - #147738 (Don't highlight `let` expressions as having type `bool` in let-chain error messages) - #147744 (miri subtree update) - #147751 (Use `bit_set::Word` in a couple more places.) - #147752 (style-guide: fix typo for empty struct advice) r? `@ghost` `@rustbot` modify labels: rollup
When looking for instances which could either be dynamically called through a vtable or through a concrete trait method, we missed `FnPtrShim`, instead only looking at `Item` and closure-likes.
ea08a7d
to 3821bac
Compare @bors r=lcnr |
CFI: Fix types that implement Fn, FnMut, or FnOnce When looking for instances which could either be dynamically called through a vtable or through a concrete trait method, we missed `FnPtrShim`, instead only looking at `Item` and closure-likes. Fixes rust-lang#144641. cc `@1c3t3a` `@Jakob-Koschel`
Rollup of 6 pull requests Successful merges: - #144936 (CFI: Fix types that implement Fn, FnMut, or FnOnce) - #147468 (Implement fs api set_times and set_times_nofollow) - #147660 (rustdoc-search: stringdex 0.0.2) - #147735 (Micro-optimization in `FunctionCx::initialize_locals`) - #147764 (Undo CopyForDeref assertion in const qualif) - #147783 (bootstrap: migrate to object 0.37) r? `@ghost` `@rustbot` modify labels: rollup
When looking for instances which could either be dynamically called through a vtable or through a concrete trait method, we missed
FnPtrShim
, instead only looking atItem
and closure-likes. Fixes #144641.cc @1c3t3a @Jakob-Koschel