You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
InternalError can trigger memory unsafety (such as use-after-free or double-free) #301
There is an unsafe impl Send<T> for InternalError<T>, making it so one can construct an InternalError with any type, and accidentally send it to another thread. However, the implementation of InternalError isn't actually safe to implement Send for any T.
The drop of the InternalError in the other thread can cause the ref count to race with the clone in the first thread. It's now possible that the 2nd drop (out of 3) will free the allocation. Using the 3rd (the original) afterwards would cause use-after-free bugs. Finally dropping it would cause a double-free.
FWIW, the problem doesn't exist because of failure. It's the unsafe impl of Send and Sync. If those impls were removed, then just the default ones would exist, which are safe.
@seanmonstar do you think I don’t understand impl Send? :)
Reacted by Richard Petrie, Ty Overby, Dmitry, Jarred Nicholls, Joshua Barretto, Flux Xu, Elliott Linder, tomtung, Daniel Dugovic, trackroute and 3 more
I'm just reporting a memory unsafety bug I noticed that can be triggered in safe Rust (safe from a user's perspective). I didn't see an issue mentioning it, so I thought I'd bring it up in case it was missed!
Reacted by Dustin Bensing, Ben Wang, David Tolnay, LunNova, Joel Dice, Dale Bustad, Kellen Frodelius-Fujimoto, Eliza Weisman, Cody Koeninger, Kosta and 9 more
Examining the fix, it seems it declares InnerHttpResponse as Send and Sync, which contains a Body, which can contain a user's Box<ActorHttpContext>. The ActorHttpContext trait doesn't require being Send or Sync, so it's possible to still trigger memory safety errors as a user:
structMyInnocentActor(Rc<String>);implActorHttpContextforMyInnocentActor{// ...}let my_str = Rc::new("foobar".to_owned());let res = HttpResponse::with_body(StatusCode::BAD_REQUEST,Box::new(MyInnocentActor(my_str.clone())));let err = InternalError::from_response(some_err, res);
thread::spawn(move || {let _moved = err;// race in drop of `MyInnocentActor` can mean double-free})let _clone = my_str.clone();// drop 2 and 3
If not another ticket, shouldn't this issue be re-opened for now? It would be good to have an open record, especially if anyone else comes across it and has an idea for the fix.
Reacted by Dan Kolsoi, Ariel Keselman, Dabo, Dmitry, scottmcm, Jarred Nicholls and Chinmay Dalal
Activity
fafhrd91 commentedon Jun 11, 2018
This is know problem. Nowadays everyone seems love to put
Sendin every holefafhrd91 commentedon Jun 12, 2018
This is related to failure, it uses Send everywhere
seanmonstar commentedon Jun 12, 2018
Oh did I open a duplicate issue? Searching didn't bring up any results :(
seanmonstar commentedon Jun 12, 2018
FWIW, the problem doesn't exist because of
failure. It's theunsafe implofSendandSync. If those impls were removed, then just the default ones would exist, which are safe.fafhrd91 commentedon Jun 12, 2018
This is absolutely conscious decision.
fafhrd91 commentedon Jun 12, 2018
@seanmonstar do you think I don’t understand
impl Send? :)seanmonstar commentedon Jun 12, 2018
I'm just reporting a memory unsafety bug I noticed that can be triggered in safe Rust (safe from a user's perspective). I didn't see an issue mentioning it, so I thought I'd bring it up in case it was missed!
fafhrd91 commentedon Jun 12, 2018
Thanks. I will check again if I can implement it without unsafty. I am not sure it can be fixed though
InternalError can trigger memory unsafety #301
InternalError can trigger memory unsafety #301
fafhrd91 commentedon Jun 12, 2018
it fixed partially. it is still possible to trigger memory unsafety though.
seanmonstar commentedon Jun 12, 2018
Awesome!
Examining the fix, it seems it declares
InnerHttpResponseasSendandSync, which contains aBody, which can contain a user'sBox<ActorHttpContext>. TheActorHttpContexttrait doesn't require beingSendorSync, so it's possible to still trigger memory safety errors as a user:Would you rather track that in a separate issue?
fafhrd91 commentedon Jun 12, 2018
I’ll add fix a bit later. No need for ticket
memoryruins commentedon Jun 12, 2018
If not another ticket, shouldn't this issue be re-opened for now? It would be good to have an open record, especially if anyone else comes across it and has an idea for the fix.
do not allow stream or actor responses for internal error #301
fafhrd91 commentedon Jun 12, 2018
I don't need new ticket because it is fixed. but this is annoying and only because of
Fail: Send + Syncdo not allow stream or actor responses for internal error #301
anderejd commentedon Jun 15, 2018
There seems to be more of
unsafe implfor Send and Sync in this library:https://github.com/actix/actix-web/search?q=%22unsafe+impl%22&unscoped_q=%22unsafe+impl%22
Is this library memory safe? If not, then I think it should be documented at the top of the Readme.
Should I open a new issue instead?
By the way, thank you for writing this library :)
axon-q commentedon Jun 15, 2018
@anderejd Please see #289