-
Notifications
You must be signed in to change notification settings - Fork 57
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
Soundness issue with msg_send!
#112
Comments
Idea 1Just wrap all your message sends in a new function: fn call_my_selector(obj: &mut Object) {
unsafe { msg_send![obj, my_selector] }
} Which, well, is probably a good idea anyway because of the difficulties with determining the type of input and return types. Still not entirely sure this is sound though, since we're effectively turning an Idea 2Add Idea 3Pass the object in
(Which would unfortunately require message sends to |
@madsmtm would it help anything if we stopped trying to have Maybe instead of trying to treat pointers to Objective-C objects like Rust references, we should just be honest about the safety and have more Or, less drastic but maybe we should at least have |
A first step would be to add
I think this would now behave similar to
Huh, never considered that. Actually it may not even be possible to soundly implement autoreleasepools in Rust (under current Stacked Borrows) - I'll look into that at some point, if it is, then this is a non-issue, if not, it's probably an issue that the UCG WG would like to know about.
I don't think this is a clear "either is better" situation - On one hand, doing this would ensure that A reasonable middle ground would maybe be to use Anyhow, as you know, I'd like to see more (safe) Objective-C code in the wild, so I believe the trade-off in increased complexity on our end to accommodate this is worth it, but I recognize the very real possibility that I'll change my mind on this at some point. |
This fixes a long-standing soundness issue with how message sending is done whilst mutating the receiver, see: SSheldon/rust-objc#112. We were effectively mutating behind either `&&mut T` or `&T`, where `T` is zero-sized and contains `UnsafeCell`, so while it is still uncertain exactly how much of an issue this actually is, the approach we use now is definitely sound! Also makes it clearer that `msg_send!` does not consume `Id`s, it only needs a reference to those.
This fixes a long-standing soundness issue with how message sending is done whilst mutating the receiver, see: SSheldon/rust-objc#112. We were effectively mutating behind either `&&mut T` or `&T`, where `T` is zero-sized and contains `UnsafeCell`, so while it is still uncertain exactly how much of an issue this actually is, the approach we use now is definitely sound! Also makes it clearer that `msg_send!` does not consume `Id`s, it only needs a reference to those.
This fixes a long-standing soundness issue with how message sending is done whilst mutating the receiver, see: SSheldon/rust-objc#112. We were effectively mutating behind either `&&mut T` or `&T`, where `T` is zero-sized and contains `UnsafeCell`, so while it is still uncertain exactly how much of an issue this actually is, the approach we use now is definitely sound! Also makes it clearer that `msg_send!` does not consume `Id`s, it only needs a reference to those.
This fixes a long-standing soundness issue with how message sending is done whilst mutating the receiver, see: SSheldon/rust-objc#112. We were effectively mutating behind either `&&mut T` or `&T`, where `T` is zero-sized and contains `UnsafeCell`, so while it is still uncertain exactly how much of an issue this actually is, the approach we use now is definitely sound! Also makes it clearer that `msg_send!` does not consume `Id`s, it only needs a reference to those.
So, during my work on
objc2
I decided to test some things in Miri, to try to get a feel for how sound everything is, and found this issue (which is currently present in both crates).Below is a piece of code that tries to mutate an ivar on an object, resembling fairly closely something that is quite commonly done in
winit
. Try placing it underobjc/examples/msg_send_unsound.rs
, and runningcargo miri run --example msg_send_unsound
.You should see the following miri error, which makes sense as explained in the code comments:
A bit more info
The problem is that you have to somehow specify that the object is mutated by the message send, which you can't really do properly.
Just to illustrate that this is indeed an issue with how
msg_send!
works, try applying the following quick patch which changesmsg_send!
to always require mutable objects (obviously not a real fix):Then you'll get the expected
rustc
error:This is similar to the problem with nulls I noted in #102, and probably requires some kind of change in
msg_send!
, though I don't actually know how to do this yet (suggestions appreciated).The text was updated successfully, but these errors were encountered: