passthrough: handle NFS directory cookies exceeding i64::MAX#228
Open
duanhongyi wants to merge 1 commit into
Open
passthrough: handle NFS directory cookies exceeding i64::MAX#228duanhongyi wants to merge 1 commit into
duanhongyi wants to merge 1 commit into
Conversation
NFSv4 directory cookies (nfs_cookie4) are unsigned 64-bit values. Roughly half of them exceed INT64_MAX, so the current code that casts the cookie to off64_t and calls lseek64() receives EINVAL from nfs_llseek_dir() on the host kernel. Fall back to a linear scan: rewind to the start of the directory and walk getdents64() batches until we find the entry whose d_off equals the target cookie. To avoid returning the target entry itself and causing an infinite loop, skip past it before returning the buffer to the caller. This mirrors the approach taken by virtiofsd in MR !319. Fixes #TODO. Signed-off-by: duanhongyi <duanhongyi@example.com>
duanhongyi
requested review from
bergwolf,
eryugey,
imeoer and
liubogithub
as code owners
July 6, 2026 08:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
passthrough: handle NFS directory cookies exceeding i64::MAX
Problem
NFSv4 directory cookies (
nfs_cookie4, RFC 7530) are unsigned 64-bit values. Roughly half of them exceedINT64_MAX. When a FUSE/virtiofs guest resumes areaddirfrom such a cookie, the current code casts theu64cookie tolibc::off64_t(i64) and callslseek64():On an NFS-backed directory the host kernel's
nfs_llseek_dir()treats the cast value as negative and rejects it withEINVAL. This causesreaddirto fail and directory listings to abort prematurely.This was originally reported in the Kata Containers project while running with dragonball's inline-virtio-fs (which uses
fuse-backend-rs). The same issue was independently fixed invirtiofsdupstream via MR !319.Solution
When
lseek64()fails withEINVALfor a cookie that cannot be represented as a positive signed offset, fall back to a linear scan:getdents64().d_offequals the target cookie.This avoids the trap of returning the target entry itself, which would cause the guest to request the same cookie again and create an infinite loop.
The scan logic is factored into a small helper
skip_to_cookie()so it can be unit-tested without requiring a real NFS mount.Changes
src/passthrough/sync_io.rsPassthroughFs::skip_to_cookie()helper.do_readdir()to detect the too-large-cookie case and use the fallback path.Testing
cargo test --features virtiofs passthrough::sync_io::readdir_cookie_testsAll new tests pass. The existing test suite is unchanged.
Limitations
This is a userspace partial fix, matching the scope of virtiofsd MR !319. If guest code performs an explicit
lseek()on a directory fd using a large cookie, the request still reaches the host NFS kernel and may fail; fully fixing that requires changes to both the guest virtiofs driver and the host NFS kernel.Related