Skip to content

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

Closed

Description

@c-schelian

Affected versions: jfuse 0.7.3 (via fuse-nio-adapter 7.0.0), also present in 0.8.0-beta1 and develop (as of 2026-10-30). WinFsp 2025, Temurin 25.0.5, Windows 11.

Symptom: The JVM crashes intermittently on unmount with EXCEPTION_ACCESS_VIOLATION in winfsp-x64.dll, always on the jfuse-main-* thread inside fuse3_loop_mt_31. Observed faults: reads from 0xffffffffffffffff, from garbage addresses, and once a DEP violation (calling a freed function pointer). With a mount/unmount stress loop (mount, write+read a 200 KB file, list, delete, unmount) the crash occurs within the first 2–3 cycles in 3 of 3 runs. -Xss2m makes it rarer, but does not fix it.

Root cause:
Fuse.close() calls FuseMountImpl.unmount(), which does:

fuse_h.fuse3_exit(fuse);
fuse_h.fuse3_unmount(fuse);

and only afterwards waits for the loop executor to terminate.

In WinFsp, fsp_fuse3_unmount() calls fsp_fuse_destroy(env, f3->fuse), which frees struct fuse (src/dll/fuse3/fuse2to3.c). Meanwhile, fuse3_exit() has signalled f->LoopEvent, so the loop thread wakes up in fsp_fuse_loop_internal() and runs fsp_fuse_loop_stop(f) → FspFileSystemStopDispatcher(f->FileSystem), FspFileSystemDelete(...), f->ops.destroy(f->data), CloseHandle(f->LoopEvent) (src/dll/fuse/fuse_loop.c). All of these dereference the already-freed f.

WinFsp's own fuse3_main_real uses the safe order: loop returns → fuse3_unmount → fuse3_destroy.

Suggested fix: In Fuse.close(), call fuse3_exit() first, then executor.shutdown() + awaitTermination(), and only after the loop has returned call fuse3_unmount() and fuse3_destroy(). For example, split FuseMount.unmount() into exit() (signal only) and unmount() (free), and call them around the executor wait.

Workaround we verified: Calling fuse3_exit() ourselves and shutting down/awaiting the private executor (via reflection) before calling Fuse.close():

  • 0 crashes in 3 × 300 cycles (network mount with -oUNC) + 1 × 1000 cycles (drive letter mount)
  • also clean when a file is still open for writing during unmount

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions