-
Notifications
You must be signed in to change notification settings - Fork 164
sysvar: Fix UB in sysvar loading #451
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
Conversation
|
If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client |
|
Good find, and thanks for moving on it quickly @jamie-osec! This is similar to an auditor-noted issue in p-token (since remedied), and it should be fixed. Your proposed fix isn't quite there yet. I'm away from my machine, but for now I've approved the CI so that you can easily see its objections. |
c8b6e1c to
f092baa
Compare
|
If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client |
febo
left a comment
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.
Good catch! Just left a couple of nits.
|
I've been investigating this further to confirm the issue and I've realized the problem is actually that
While the original issue is library-level UB according to the documentation, it does not appear to be currently considered UB by Rust, and Miri does not report an issue. |
|
If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client |
2deb83c to
5d6f0da
Compare
|
If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client |
|
Addressed the UB nits, and pushed a fix for the root cause.
I'm not familiar enough with the context to know if this breakage was intended - it seems unlikely given that the signature is still returning (Relevant: #87) |
Indeed, this is why it didn't raise red flags earlier, but it's still a good idea to fix it, as it violates the contract of |
Thanks for tracking down the issue! FYI, we likely want to use the general syscall when possible due to #235. |
Using bincode on-chain will most likely offset any gains from |
Yes, I'm definitely not suggesting we require/encourage bincode. |
|
@jamie-osec, thanks much for your work here. Due to the need to fix the 3.1.0 crate in the interim, I'm going to close this PR and just revert to the old (3.0.0) sysvar behavior for now. Then, we'll ensure everything works properly and cleanly implement an update. There are clearly some test coverage improvements needed. Your UB fix will be incorporated and I'll make sure you receive attribution for it. I'll tag you on the new PR once open. |
|
Great, thanks for the update |
#257 (comment)
Slices must be initialized, but the implementation of
Sysvar::getcreates a&mut [u8]from an uninitialized buffer. This causes UB and miscompiles.Resolve this by introducing a new private function which takes a mutable pointer (may be uninitialized) and use that instead.