Skip to content
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: read/write fd dropped unexpectedly. #184

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

WeiZhang555
Copy link
Collaborator

read/write function invokes

self.check_fd_flags(data, f.as_raw_fd(), flags)?;

which takes ownership of data and it's inner File, after the function call returns, File will be dropped and cannot be read/write later anymore, causing a failed read/write.

This bug is triggered when no_open config option is set, in this case, self.get_data opens a new file and it's dropped immediately after check_fd_flags.

The bug can be solved by create a new clone of data by data.clone(), the original data(and inner File) can be kept in whole lifetime of read/write function.

read/write function invokes

```
self.check_fd_flags(data, f.as_raw_fd(), flags)?;
```

which takes ownership of `data` and it's inner `File`, after the function
call returns, File will be dropped and cannot be read/write later
anymore, causing a failed read/write.

This bug is triggered when `no_open` config option is set, in this case,
`self.get_data` opens a new file and it's dropped immediately after
`check_fd_flags`.

The bug can be solved by create a new clone of data by `data.clone()`,
the original data(and inner File) can be kept in whole lifetime of read/write
function.

Signed-off-by: Wei Zhang <[email protected]>
@@ -1479,4 +1483,144 @@ mod tests {
assert!(!fs.cfg.no_open);
assert!(!fs.cfg.writeback);
}

impl ZeroCopyReader for File {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these needed? The commit message does not seem to explain it.

Copy link
Collaborator Author

@WeiZhang555 WeiZhang555 Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resides in mod tests, at https://github.com/cloud-hypervisor/fuse-backend-rs/pull/184/files/9ca710da29796b759d6d782e8dd2d9209d5bf838#diff-7f83e7da9ae6f4daf23fadb16185e191349a8f96620bd58d29483e3b28ec1a1cR1593

I need a &mut dyn ZeroCopyReader, in fuse-backend-rs, I didn't find a convenient implementation of ZeroCopyReader and ZeroCopyWriter, so I have to implement one in mod tests for test usage.

@WeiZhang555 WeiZhang555 merged commit 8e289bd into cloud-hypervisor:master Feb 5, 2024
9 checks passed
@WeiZhang555 WeiZhang555 deleted the bugfix-fd-drop branch February 5, 2024 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants