Skip to content

Fix use-after-free - #178

Merged
infeo merged 1 commit into
developfrom
fix/win-unmount-use-after-free
Nov 2, 2026
Merged

infeo merged 1 commit into
developfrom
fix/win-unmount-use-after-free

Conversation

@infeo

@infeo infeo commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

This PR fixes a use-after-free bug when unmounting a filesyste on Windows.

Fixes #176.

Winfsp shows the peculiarity that fuse3_unmount() does not unmount, it frees struct fuse (fsp_fuse3_unmount() -> fsp_fuse_destroy()), which the run loop still dereferences while it winds down. The volume is detached by the run loop itself, in fsp_fuse_loop_stop() -> FspFileSystemDelete().

The fix reproduces fsp_fuse3_main_real's ordering exactly, and fsp_fuse_loop_internal's if (!f->exited) guard (fuse_loop.c:319) covers the case where fuse3_exit lands before the loop starts waiting.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a Windows crash that could occur when unmounting a filesystem while its run loop was winding down.
    • Improved the reliability of repeated mount and unmount cycles on Windows.
  • Documentation
    • Clarified when filesystem resources should be released during shutdown.

address winfsp peculiarity
@infeo infeo added this to the 0.8.0 milestone Nov 2, 2026
@infeo infeo self-assigned this Nov 2, 2026
Copilot AI balanced review requested due to automatic review settings November 2, 2026 12:33
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between fc0df80 and 930d308.

Files selected for processing: 4
  • CHANGELOG.md
  • jfuse-api/src/main/java/org/cryptomator/jfuse/api/FuseMount.java
  • jfuse-tests/src/test/java/org/cryptomator/jfuse/tests/UnmountStressIT.java
  • jfuse-win/src/main/java/org/cryptomator/jfuse/win/FuseMountImpl.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The Windows mount implementation now signals the run loop before unmounting and destroying FUSE resources. A Windows-only integration test performs repeated mount, file operation, and close cycles.

Changes: Windows unmount lifecycle

Layer / File(s) Summary
Shutdown resource ordering
jfuse-api/src/main/java/org/cryptomator/jfuse/api/FuseMount.java, jfuse-win/src/main/java/org/cryptomator/jfuse/win/FuseMountImpl.java, CHANGELOG.md
The API documentation assigns release of run-loop resources to destroy(). The Windows implementation calls fuse3_exit() in unmount() and calls fuse3_unmount() before fuse3_destroy() in destroy(). The changelog records the Windows unmount crash fix.
Repeated mount and close test
jfuse-tests/src/test/java/org/cryptomator/jfuse/tests/UnmountStressIT.java
A Windows-only test runs 30 mount and close cycles. Each cycle writes and verifies a file, checks a directory listing, deletes the file, and closes the filesystem with a timeout.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Low · up to 930d3

The change fixes the Windows crash that occurred when unmounting. In the rare case where closing is interrupted or the loop takes over 10 seconds to stop, the native WinFsp cleanup is now skipped and its memory can leak. This is a narrow edge case, so the change is mergeable, though the maintainers should be aware of it.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately identifies the main change: fixing a use-after-free during Windows filesystem unmount. It is concise and specific.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Cross-thread native WinFsp lifetime and shutdown changes require Windows stress-test validation against WinFsp 2025 and CI-pinned 2.0.23075, which this review environment cannot provide.

No open issues 🎉

What changed in this PR

Fixes the Windows unmount use-after-free described in #176 by deferring WinFsp resource cleanup until after the run loop exits.

Changes:

  • Moves fuse3_unmount() from unmount() to destroy(), leaving unmount() to signal loop exit.
  • Adds a Windows regression test covering 30 mount, file-operation, and close cycles.
  • Documents the lifecycle requirement and records the crash fix in the changelog.
File Description
jfuse-win/​src/​main/​java/​org/​cryptomator/​jfuse/​win/​FuseMountImpl.java Defers native resource cleanup to destroy().
jfuse-tests/​src/​test/​java/​org/​cryptomator/​jfuse/​tests/​UnmountStressIT.java Adds repeated Windows mount/unmount regression coverage.
jfuse-api/​src/​main/​java/​org/​cryptomator/​jfuse/​api/​FuseMount.java Clarifies that unmount must preserve resources still used by the loop.
CHANGELOG.md Records the Windows unmount crash fix.

Review effort: Balanced

@infeo

infeo commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Windows succeeds, linux fails due to outdated workflow script

@infeo
infeo merged commit 9853d00 into develop Nov 2, 2026
9 of 11 checks passed
@infeo
infeo deleted the fix/win-unmount-use-after-free branch November 2, 2026 12:42
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.

Windows: use-after-free in Fuse.close() – fuse3_unmount() frees struct fuse while the loop thread is still in fsp_fuse_loop_stop()

2 participants