-
Notifications
You must be signed in to change notification settings - Fork 44
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
vtpm: add safety comments and fix small issues #574
base: main
Are you sure you want to change the base?
vtpm: add safety comments and fix small issues #574
Conversation
CC @cclaudio |
16b78f7
to
774cd0d
Compare
v2:
|
CI is failing https://github.com/coconut-svsm/svsm/actions/runs/12428229021/job/34699433885?pr=574#step:7:1353 with:
@joergroedel I'm not sure if it's related to this PR. |
It looks like for some reason now the CI container doesn't have |
774cd0d
to
548d1f3
Compare
v3:
|
Thanks, waiting a bit more for @cclaudio to approve. |
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.
LGTM.
For some reason my inbox message filters did not pick this one, sorry about that. |
// SAFETY: vaddr is just mapped, and its size is PAGE_SIZE | ||
let buffer = unsafe { from_raw_parts_mut(vaddr.as_mut_ptr::<u8>(), PAGE_SIZE) }; |
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.
Is this truly safe though? Isn't this a shared buffer? Creating a mutable reference to it is unsound if the contents can be modified by the guest.
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.
The guest should not touch it while issuing the SVSM call, which IIUC is also sync. @cclaudio can you confirm this?
`Layout::from_size_align(size, align)` can return an error if following conditions are not met: - align must not be zero, - align must be a power of two, - size, when rounded up to the nearest multiple of align, must not overflow isize (i.e., the rounded value must be less than or equal to isize::MAX). Conditions on `align` are always met, but the size is specified by the caller, so it can fail. Let's propagate the error instead of panic. Signed-off-by: Stefano Garzarella <[email protected]>
The current implementation lacks some requirements defined by POSIX documentation of `void *realloc(void *ptr, size_t size);`: - If ptr is a null pointer, realloc() shall be equivalent to malloc() for the specified size. - If the size of the space requested is zero, the behavior shall be implementation-defined. In this case we are following Linux implementation, from malloc(3) man page: - If size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr). [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html Signed-off-by: Stefano Garzarella <[email protected]>
Add SAFETY comments around calls to GlobalAlloc and checks as required by the documentation[1], especially on non-zero size and pointer validity. [1] https://doc.rust-lang.org/alloc/alloc/trait.GlobalAlloc.html Signed-off-by: Stefano Garzarella <[email protected]>
Add SAFETY comments around FFI calls and some checks for return values. Signed-off-by: Stefano Garzarella <[email protected]>
Add SAFETY comment around `from_raw_parts_mut()` call. Signed-off-by: Stefano Garzarella <[email protected]>
In several places we use `if let Ok(foo) = func() {` creating large indented blocks, let's replace with `let Ok(foo) = func() else {` by immediately returning a null pointer and reducing the indentation to make the code more readable. Suggested-by: Carlos López <[email protected]> Signed-off-by: Stefano Garzarella <[email protected]>
548d1f3
to
73efb3d
Compare
v4:
|
This is part of the effort for #228 to enable
undocumented_unsafe_blocks
clippy lint.