-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Mitigate MMIO stale data vulnerability #98126
Merged
bors
merged 5 commits into
rust-lang:master
from
fortanix:raoul/mitigate_stale_data_vulnerability
Jun 25, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab3a2a0
Unify copying data from enclave to userspace
raoulstrackx 531752f
Mitigate MMIO stale data vulnerabilities
raoulstrackx 6f7d193
Ensure userspace allocation is 8-byte aligned
raoulstrackx a27aace
Test `copy_to_userspace` function
raoulstrackx 6a6910e
Address reviewer comments
raoulstrackx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use super::alloc::copy_to_userspace; | ||
use super::alloc::User; | ||
|
||
#[test] | ||
fn test_copy_function() { | ||
let mut src = [0u8; 100]; | ||
let mut dst = User::<[u8]>::uninitialized(100); | ||
|
||
for i in 0..src.len() { | ||
src[i] = i as _; | ||
} | ||
|
||
for size in 0..48 { | ||
// For all possible alignment | ||
for offset in 0..8 { | ||
// overwrite complete dst | ||
dst.copy_from_enclave(&[0u8; 100]); | ||
|
||
// Copy src[0..size] to dst + offset | ||
unsafe { copy_to_userspace(src.as_ptr(), dst.as_mut_ptr().offset(offset), size) }; | ||
|
||
// Verify copy | ||
for byte in 0..size { | ||
unsafe { | ||
assert_eq!(*dst.as_ptr().offset(offset + byte as isize), src[byte as usize]); | ||
} | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is writing to
*&seg_sel
, no? Seems like that parameter should be&mut seg_sel
, or perhapsout(reg) seg_sel
to let the compiler give you a scratch register instead.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! I've updated the reference to be
mut
.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.
In general I'd agree that moving to a scratch register would be cleaner. Here I'm more hesitant as so much happens at a micro architectural level that I'm feeling much more at ease by following the Intel example code. Performance overhead is negligent anyway.
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.
According to Intel, you have to use the memory-operand version of verw.