-
Notifications
You must be signed in to change notification settings - Fork 67
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
bugfix: passthrough: refect CFileHandle struct #106
Conversation
src/passthrough/file_handle.rs
Outdated
#[repr(C)] | ||
pub struct MockCFileHandle { |
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.
Mock feels like testing code.
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.
Thanks, @wllenyj! I have renamed it as CFileHandleInner.
src/passthrough/file_handle.rs
Outdated
// File identifier (sized by caller) [out] | ||
f_handle: *mut libc::c_char, | ||
f_handle: Vec<u8>, |
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.
f_handle: Vec<u8>, | |
type CFileHandle = FamStructWrapper<CFileHandleInner>; | |
pub struct CFileHandlerInner { | |
handle_bytes: u32, | |
handle_type: i32, | |
f_handle: __IncompleteArrayField<libc::c_char> | |
} |
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.
Thanks, @wllenyj! As CFileHandle needs to implement some traits, like Ord, PartialOrd, I use a CFileHandleWrapper instead, which is used as a memory of CFileHandle struct.
91ba3dd
to
26f5bf9
Compare
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.
Looks good to me.
26f5bf9
to
986d135
Compare
dc1a676
to
852192c
Compare
Previously, CFileHandle uses a *mut libc::c_char to transfer data between user space and kernel space. The system call "name_to_handle_at" will return the data with "copy_to_user". This may cause a bug because the memory layout of CFileHandle fields may be noncontinuous with the dynamically-sized array's. Therefore, the "copy_to_user" may destroy the stack. This is reproduced on aarch64 only when using "opt-level=3" to compile. This commit refectors the CFileHandle struct with FarmStruct trait to ensure the memory layout to be continuous. The trait enables struct to own a dynamically-sized array at the end of the struct like zero-array in C language. We refector the related implementation so that "copy_to_user" won't write outside the CFileHandle and destroy the user stack. Besides, add some units and fix clippy warnings. Signed-off-by: xuejun-xj <[email protected]>
852192c
to
7fa4f72
Compare
Previously, CFileHandle uses a *mut libc::c_char to transfer data between user space and kernel space. The system call "name_to_handle_at" will return the data with "copy_to_user". This may cause a bug because the memory layout of CFileHandle fields may be noncontinuous with the dynamically-sized array's. Therefore, the "copy_to_user" may destroy the stack. This is reproduced on aarch64 only when using "opt-level=3" to compile.
This commit refectors the CFileHandle struct with FarmStruct trait to ensure the memory layout to be continuous. The trait enables struct to own a dynamically-sized array at the end of the struct like zero-array in C language. We refector the related implementation so that "copy_to_user" won't write outside the CFileHandle and destroy the user stack.
Besides, add some units and fix clippy warnings.