-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Undefined behavior due to unsafe pinning of BodyStream #1321
Comments
Confirmed the test is crashing test runner. Provided possible fix will be massive and break |
I dunno atm. But it feels that we will have to refactor all the poll-like methods to accept |
Fixes actix#1321 A better fix would be to change `MessageBody` to take a `Pin<&mut Self>`, rather than a `Pin<&mut Self>`. This will avoid requiring the use of `Box` for all consumers by allowing the caller to determine how to pin the `MessageBody` implementation (e.g. via stack pinning). However, doing so is a breaking change that will affect every user of `MessageBody`. By pinning the inner stream ourselves, we can fix the undefined behavior without breaking the API. I've included @sebzim4500's reproduction case as a new test case. However, due to the nature of undefined behavior, this could pass (and not segfault) even if underlying issue were to regress. Unfortunately, until rust-lang/unsafe-code-guidelines#148 is resolved, it's not even possible to write a Miri test that will pass when the bug is fixed.
Fixes actix#1321 A better fix would be to change `MessageBody` to take a `Pin<&mut Self>`, rather than a `Pin<&mut Self>`. This will avoid requiring the use of `Box` for all consumers by allowing the caller to determine how to pin the `MessageBody` implementation (e.g. via stack pinning). However, doing so is a breaking change that will affect every user of `MessageBody`. By pinning the inner stream ourselves, we can fix the undefined behavior without breaking the API. I've included @sebzim4500's reproduction case as a new test case. However, due to the nature of undefined behavior, this could pass (and not segfault) even if underlying issue were to regress. Unfortunately, until rust-lang/unsafe-code-guidelines#148 is resolved, it's not even possible to write a Miri test that will pass when the bug is fixed.
I found a similar issue in actix-codec, if you are going to make a breaking change here then you will probably need one there as well. |
Would this be a 2.x release though if we decide to do this? Should we refactor and shoot for a 3.0 transition for this? I think 2+ has been a good halfway point but I really want to make async/await first order if possible soon. |
IMO we should refactor these unsafe's and shoot for a 3.0 release with a reasonably long alpha/beta period. |
I think that's the best path forward as well now that Future is stable but it'll be hard to "backport" any new work. We most likely wouldn't be able to work on 2+ changes and 3.0 release simultaneously. |
Fixes #1321 A better fix would be to change `MessageBody` to take a `Pin<&mut Self>`, rather than a `Pin<&mut Self>`. This will avoid requiring the use of `Box` for all consumers by allowing the caller to determine how to pin the `MessageBody` implementation (e.g. via stack pinning). However, doing so is a breaking change that will affect every user of `MessageBody`. By pinning the inner stream ourselves, we can fix the undefined behavior without breaking the API. I've included @sebzim4500's reproduction case as a new test case. However, due to the nature of undefined behavior, this could pass (and not segfault) even if underlying issue were to regress. Unfortunately, until rust-lang/unsafe-code-guidelines#148 is resolved, it's not even possible to write a Miri test that will pass when the bug is fixed. Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
Is this still relevant in 3.0.0-beta.9, or is the advisory DB buggy? |
The advisory is not applicable to 3.0 and up. There is a bug in cargo audit where it fails to correctly compare pre release versions. |
@robjtede Thank you and sorry for the noise. For others who might be interested, the upstream issue is rustsec/rustsec#300. |
Expected Behavior
The program below should not segfault when I only write 'safe' code.
Current Behavior
The program below segfaults.
Possible Solution
Change the
MessageBody
trait to take aPin<&mut self>
instead of a&mut self
.Steps to Reproduce (for bugs)
Run the following code in debug mode.
Context
I found this problem by searching for 'unsafe' in the actix-web repo.
rustc -V
): rustc 1.41.0-nightlyThe text was updated successfully, but these errors were encountered: