-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Implement read_buf
and vectored read/write for SGX stdio
#137355
base: master
Are you sure you want to change the base?
Conversation
r? @ChrisDenton rustbot has assigned @ChrisDenton. Use |
/// # Panics | ||
/// This function panics if the destination doesn't have the same length as | ||
/// the source. | ||
pub fn copy_to_enclave_uninit(&self, dest: &mut [MaybeUninit<T>]) { |
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.
Needing this “feels” wrong to me. You could do impl<T: UserSafeSized> UserSafeSized for MaybeUninit<T>
and then just create a [MaybeUninit<u8>]
in read_buf
. However, of course the whole point of UserSafe
is that you want to explicitly assume everything you copy out of userspace is initialized, so that would kind of defeat the point.
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.
If both of those options are unsatisfying to you, what would you recommend I do so this can impl read_buf
?
This was explicitly requested by the T-libs reviewer. |
I'm fine with reverting my change to this. Since |
b81e9d2
to
4cfdd68
Compare
I noticed that |
Perhaps |
I think the two would actually be better coexisting, since they serve slightly different purposes. |
How about this? // SAFETY: Requires that `T` is contained within `Self` using transparent representation
unsafe trait UserSafeCopyDestination<T: ?Sized> {
fn as_mut_ptr(&mut self) -> *mut T;
}
unsafe impl<T> UserSafeCopyDestination<T> for T {
fn as_mut_ptr(&mut self) -> *mut T {
self as _
}
}
unsafe impl<T> UserSafeCopyDestination<[T]> for [T] {
fn as_mut_ptr(&mut self) -> *mut [T] {
self as _
}
}
unsafe impl<T> UserSafeCopyDestination<T> for MaybeUninit<T> {
fn as_mut_ptr(&mut self) -> *mut T {
self as *mut Self as _
}
}
unsafe impl<T> UserSafeCopyDestination<[T]> for [MaybeUninit<T>] {
fn as_mut_ptr(&mut self) -> *mut [T] {
self as *mut Self as _
}
}
impl<T: ?Sized> UserRef<T> {
pub fn copy_to_enclave<V: ?Sized + UserSafeCopyDestination<T>>(&self, dest: &mut V) {
unsafe {
assert_eq!(mem::size_of_val(dest), mem::size_of_val(&*self.0.get()));
copy_from_userspace(
self.0.get() as *const T as *const u8,
dest.as_mut_ptr() as *mut u8,
mem::size_of_val(dest),
);
}
}
} |
4cfdd68
to
da0fbf6
Compare
That's much more flexible! I've added a commit with your patch, which I attributed to you. You might want to double-check that the metadata looks good. (FYI, it looks like your fortanix.com email isn't connected to your GitHub account, so you're not linked.) |
And since we've been talking about SGX copying APIs, I think That would be a breaking change, but I see no use of it outside of |
☔ The latest upstream changes (presumably #138155) made this pull request unmergeable. Please resolve the merge conflicts. |
da0fbf6
to
0ec7397
Compare
Co-authored-by: Thalia Archibald <thalia@archibald.dev>
0ec7397
to
d34c289
Compare
Good idea. But then let's also change the name to better describe the behavior. |
d34c289
to
e80df9c
Compare
I've now done so and renamed it to |
r=me if @jethrogb is happy with this PR. |
@ChrisDenton yes please approve |
Thanks! @bors r+ |
It reinterprets uninitialized memory as initialized and does not drop existing elements of the Vec. Fix that. Additionally, make it more general by appending, instead of overwriting existing elements, and rename it to `append_to_enclave_vec`. A caller can simply call `.clear()` before, for the old behavior.
e80df9c
to
c62aa0b
Compare
I had neglected to update the |
Implement
read_buf
,read_vectored
, andwrite_vectored
for the SGX stdio types.Additionally, extend
User<T>::copy_to_enclave
to work for copying to uninitialized values and fix unsoundness inUserRef<[T]>::copy_to_enclave_vec
.cc @jethrogb
Tracked in #136756