You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2dbd7de
Browse filesBrowse the repository at this point in the historyBrowse files
fix(write): add renameIdentity option for FUSE mounts with unstable inode numbers
On filesystems like rclone FUSE mounts, rename(2) causes every subsequent
path-based lookup on the destination to return a freshly-minted inode number,
making the post-rename (dev,ino) identity check always fail even with a single
process and zero concurrency. This manifests as a deterministic
FsSafeError("path-mismatch") on every overwrite-mode write through
writeFileInRoot/runPinnedWriteFallback.
Adds renameIdentity: "verify-content-with-lock" to RootDefaults and
RootWriteOptions. When set, the write acquires an exclusive sidecar lock for
the target path, performs the write under that lock, and verifies by comparing
the SHA-256 of the written bytes against the bytes re-read from the target
(using an fd-based stat for the returned identity to stay consistent across all
subsequent lookups). Stale locks from crashed holders are detected via
PID-liveness check and removed automatically. Default behavior is unchanged.
Closes#32
Copy file name to clipboardExpand all lines: docs/security-model.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,7 @@ The library does not advertise different security guarantees per platform — it
90
90
| Mode bits are not a full policy engine |`replaceFileAtomic` and secret-file helpers set requested modes, but you should still set umask and inspect modes when policy requires it. |
91
91
| Archive extraction is path safety, not content safety | Unsafe entry paths and links are rejected; malicious payload contents remain your application layer's problem. |
92
92
| Helper failures degrade fd-relative hardening |`helper-unavailable` falls back in `auto` mode and fails closed in `require` mode. Atomicity and identity checks remain, but parent-directory swaps between validation and mutation are less tightly pinned without the helper. |
93
+
| FUSE mounts with unstable inode numbers | Some FUSE mounts (rclone is a confirmed example) assign a fresh inode number to a path on every lookup after a rename, making the post-rename `(dev, ino)` identity check always fail. Set `renameIdentity: "verify-content-with-lock"` on the root to use a SHA-256 content comparison under a cooperative sidecar lock instead. This verifies that the correct bytes reached the destination and that no cooperating writer interleaved, but it does not prove that the process owns the resulting file object — a same-UID process that ignores the lock could still interleave. See [Writing](writing.md) for details. |
|`not-found`| Parent does not exist and `mkdir` is false. |
193
193
|`not-empty`|`remove()` on a non-empty directory. |
194
194
|`not-removable`|`remove()` could not unlink/rmdir (typically permissions or device busy). |
195
-
|`path-mismatch`| Post-write fd identity check did not match. Almost always a parallel writer. |
195
+
|`path-mismatch`| Post-write fd identity check did not match. Almost always a parallel writer, or a FUSE mount with unstable inode numbers — see `renameIdentity` below. |
Some FUSE mounts — rclone is a confirmed example — assign a fresh inode number to a path on every lookup that follows a rename, even within a single process with zero concurrency. This makes the default post-rename `(dev, ino)` identity check always fail with `path-mismatch`, regardless of whether a race actually occurred.
238
+
239
+
Set `renameIdentity: "verify-content-with-lock"` on the root (or per call) to use a SHA-256 content comparison under a cooperative sidecar lock instead:
240
+
241
+
```ts
242
+
const fs =awaitroot("/mnt/rclone-workspace", {
243
+
renameIdentity: "verify-content-with-lock",
244
+
});
245
+
246
+
awaitfs.write("state.json", body); // succeeds on rclone FUSE
247
+
```
248
+
249
+
**How it works.** A write first runs with the default strict check. If that check detects a `path-mismatch` (genuine race or FUSE inode churn), it acquires an exclusive sidecar lock at `{targetPath}.lock` and retries the full write under that lock. The retry accepts the destination if the SHA-256 of the re-read bytes matches the SHA-256 of the bytes written. The lock is always released before the call returns.
250
+
251
+
**Security note.**`verify-content-with-lock` provides two guarantees: (1) the bytes that reached the destination match the bytes the caller asked to write, and (2) no *cooperating* writer interleaved during the locked retry. It does **not** prove that the process that called `write()` is the exclusive owner of the resulting file object on disk. A same-UID process that deliberately bypasses the sidecar lock can still interleave — this is the same residual risk as any advisory lock and is explicitly outside fs-safe's documented threat model. Do not use this option on directories that are writable by untrusted same-UID processes.
252
+
235
253
## See also
236
254
237
255
-[Atomic writes](atomic.md) — the lower-level `replaceFileAtomic` and friends.
0 commit comments