Skip to content

Commit

Permalink
bugfix: passthrough: Add MockCFileHandleWrapper
Browse files Browse the repository at this point in the history
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 adds three structs: __IncompleteArrayField, MockCFileHandle
and MockCFileHandleWrapper. We construct a dynamically-sized array with
continous memory address by using FamStruct trait, called
MockCFileHandleWrapper. It will manage the array automatically and
provide useful interfaces to help operate on array. We can thransfer
data during system call safely to protect the user stack.

Besides, we reuse the struct CFileHandle to save the information in Rust
version and provide four useful methods to be operated with
MockCFileHandleWrapper.

Fix clippy warning and update the unit test.

Signed-off-by: xuejun-xj <[email protected]>
  • Loading branch information
xuejun-xj committed Feb 23, 2023
1 parent 6788a74 commit 91ba3dd
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/abi/fuse_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ impl Attr {
mode: st.st_mode,
#[cfg(target_os = "macos")]
mode: st.st_mode as u32,
nlink: st.st_nlink as u32,
nlink: st.st_nlink,
uid: st.st_uid,
gid: st.st_gid,
rdev: st.st_rdev as u32,
Expand Down
Loading

0 comments on commit 91ba3dd

Please sign in to comment.