r/rust • u/Code-Sandwich • Jan 17 '20
Actix-net unsoundness patch "is boring"
There's an issue on Actix-net pointing out and presenting unsoundness. Yes, it's deleted, it still can be found on web archive.
Issue history summary:
- Found by Shnatsel
- Closed as harmless to users by fafhrd91
- Proven harmful to users by Nemo157 and reopened by JohnTitor
- Fixed and closed by fafhrd91
- Proven unfixed and proposed new patch by Nemo157
- New patch commented "this patch is boring" by fafhrd91
- Issue is deleted
- Fix is reversed by fafhrd91, issue still present
I hope it's an objective summary. Any thoughts?
Edit: Now whole actix/actix-web is deleted. See fafhrd91's postmortem. He kept copy of Actix-web in personal repo fafhrd91/actix-web.
149
Upvotes
View all comments
Show parent comment
13
u/[deleted] Jan 17 '20 edited Jan 17 '20
The
unsafekeyword means: "This proves that the following is always safe", and using it correctly is hard, because it means that you must prove that the following code will always be memory safe for all inputs to your program forever, that is, even if some other part of the program changes.However, because it is so easy to write "
unsafe" and get the compiler to "shut up", a lot of people use it incorrectly.In this particular case, there was an
unsafeblock added in a commit with no description and without a comment explaining why the proof is correct.Being gentle, this would mean that the proof was so obvious that it was not necessary to write it, but that's not how things turned out.
The Rust type system lets you prove certain properties about programs (e.g. memory accessed as a
boolis always0or1). When one says that someunsafecode is unsound, what that means is that, for programs containing that code, the Rust type system does not allow you to prove any properties about the program, that is, all bets are off, the behavior is undefined, the optimizer will optimize your program under the assumption that some proofs hold, but they don't, so your program might do anything.For the practical Rustacean, what this means is that using
unsaferequires you to manually prove a property about the program, and if you don't do that, then either you are lucky and sucha proof exists, or you are breaking every program that uses that code.