Skip to content

virtiofs: stop failed directory reads from leaking lookup references - #4836

Open
Pedro Henrique Penna (ppenna) wants to merge 1 commit into
microsoft:mainfrom
nanvix:fix-virtiofs-readdir-lookup-refs
Open

Pedro Henrique Penna (ppenna) wants to merge 1 commit into
microsoft:mainfrom
nanvix:fix-virtiofs-readdir-lookup-refs

Conversation

@ppenna

@ppenna Pedro Henrique Penna (ppenna) commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

A READDIRPLUS in the virtio-fs server that failed partway through discarded entries whose lookups had already taken inode lookup references. The guest sends FORGET only for node IDs it received, so these references were never released: the inodes stayed in the inode map until FUSE_DESTROY. Fixes #4834.

The plain READDIR half of #4834 is already fixed on main by #3440, which removed the per-entry lookup from plain readdir, so this PR covers only READDIRPLUS.

Summary

  • when a directory read fails after its reply already holds entries, return those entries and report the error only when there are none, as libfuse's passthrough example does; the guest's next read starts at the failing entry and gets the error then, so READDIRPLUS entries that took lookup references are no longer discarded
  • apply the same rule to the aggregate synthetic root
  • add regression tests: a READDIRPLUS of a directory or of the aggregate root that fails partway returns the entry holding the reference, reports the error on the next read, and releases the inode on the guest's FORGET

No host condition portably makes a later entry's lookup fail with an error other than EACCES or ENOENT, so the tests inject the failure: read_dir and read_synthetic_root_dir now delegate to private helpers that take the per-child lookup as a closure. The same rule also covers the ENOSPC that #4594 adds to node-ID allocation.

Validation

  • cargo clippy --all-targets -p virtiofs, on Windows x86-64 and with --target x86_64-unknown-linux-gnu
  • cargo doc --no-deps -p virtiofs
  • cargo nextest run --profile agent -p virtiofs
    • Windows x86-64: 60 passed, 1 skipped
    • Linux x86-64 (WSL2): 57 passed
  • cargo xtask fmt --fix

Reverting either fix makes its new test fail.

Copilot AI balanced review requested due to automatic review settings October 31, 2026 20:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the virtio-fs directory-read reference-handling fix.

No open issues 🎉

What changed in this PR

This PR fixes inode lookup-reference leaks in OpenVMM’s virtio-fs directory reads, addressing #4834. It prevents plain listings from registering children and preserves references already included in partial READDIRPLUS replies.

Changes:

  • Use a metadata lookup rather than a reference-taking lookup for plain READDIR.
  • Return accumulated entries when a later lookup fails, including for the aggregate synthetic root.
  • Add regression tests for reference ownership, error delivery on the next read, and cleanup through FORGET.
File Description
vm/​devices/​virtio/​virtiofs/​src/​test_helpers.rs Adds a shared directory-reply decoder for tests.
vm/​devices/​virtio/​virtiofs/​src/​lib.rs Registers the test-only helper module.
vm/​devices/​virtio/​virtiofs/​src/​file.rs Fixes directory-read reference handling and adds regression tests.
vm/​devices/​virtio/​virtiofs/​src/​aggregate.rs Preserves partial synthetic-root replies after lookup errors.
vm/​devices/​virtio/​virtiofs/​src/​aggregate_tests.rs Tests partial replies, retry errors, and reference cleanup for the synthetic root.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

A READDIRPLUS that failed partway through discarded entries whose lookups
had already taken references, so the guest could never forget them.
Return the entries read so far instead, and report the error only when
there are none: the guest's next read starts at the failing entry and
gets the error then. Apply the same rule to the aggregate synthetic root.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 23:19
@ppenna Pedro Henrique Penna (ppenna) changed the title virtiofs: stop directory reads from leaking lookup references virtiofs: stop failed directory reads from leaking lookup references Nov 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change preserving partial READDIRPLUS replies so the guest can release lookup references.

No open issues 🎉

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

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.

virtiofs: directory reads leak inode lookup references

3 participants