Skip to content

bugfix: read/write fd dropped unexpectedly.#184

Merged
WeiZhang555 merged 1 commit intocloud-hypervisor:masterfrom
WeiZhang555:bugfix-fd-drop
Feb 5, 2024
Merged

bugfix: read/write fd dropped unexpectedly.#184
WeiZhang555 merged 1 commit intocloud-hypervisor:masterfrom
WeiZhang555:bugfix-fd-drop

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 <weizhang555.zw@gmail.com>
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
@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