Skip to content

Escape and validate special characters in mount option values - #712

Merged
cberner merged 1 commit into
masterfrom
claude/fuser-issues-triage-7tz8v9
Jul 31, 2026
Merged

Escape and validate special characters in mount option values#712
cberner merged 1 commit into
masterfrom
claude/fuser-issues-triage-7tz8v9

Conversation

@cberner

@cberner cberner commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Fixes #424

Mount option values are passed to the kernel, libfuse, and the fusermount helpers inside a comma separated list, so a comma in a value was read as the start of another option: MountOption::FSName("foo,ro") mounted a read-only filesystem named foo. A NUL in a value panicked instead of returning an error.

Following the analysis in the issue:

  • fsname is escaped (, -> \,, \ -> \\) for the consumers that decode backslash escapes, and passed verbatim as the mount(2) source, which needs no escaping.
  • Values that cannot be escaped consistently across those consumers are rejected with InvalidInput from Session::new(): comma and backslash in Subtype and CUSTOM (libfuse does not re-escape them when forwarding to fusermount), and in fsname too on platforms whose mount helpers decode no escapes.
  • NUL is rejected in every value, replacing the panic.

The check lives in Mount::new() rather than Session::new() so that every formatting of an option value can rely on it, including the direct Mount::new() calls in tests.

The deprecated escaping question for fuser::mount/spawn_mount raised at the end of the issue is left alone, as suggested there.

Testing

Unit tests cover the escaping and the per-platform validation rules. A new mount test asserts that the comma in FSName("fuser,ro") reaches /proc/self/mounts as part of the source name and does not appear among the mount options.

Ran green on all three mount backends (pure-rust, libfuse2, libfuse3), both as root (direct mount(2)) and as an unprivileged user going through a real fusermount3, whose argv I logged to confirm it receives -o fsname=fuser\,ro. Reverting just the escaping call makes the new test fail with left: "fuser", right: "fuser,ro", so it does catch the reported bug.

Also clean locally: cargo fmt --check, clippy with --deny warnings (default and --no-default-features), cargo test --all with and without libfuse, cargo doc, the musl target, cargo check --target x86_64-apple-darwin --features=macos-no-mount, and both test_passthrough scripts. The Docker suites (mount_tests, pjdfs_tests, xfstests) could not run in my environment (no Docker daemon), so they are covered only by CI here.


Generated by Claude Code

Mount option values are passed to the kernel, libfuse, and the fusermount helpers
inside a comma separated list, so a comma in a value was read as the start of
another option: MountOption::FSName("foo,ro") mounted a read-only filesystem named
"foo". A NUL in a value panicked instead of returning an error.

fsname is now escaped for the consumers that decode backslash escapes, and passed
verbatim as the mount(2) source, which needs no escaping. Values that cannot be
escaped consistently across those consumers are rejected: comma and backslash in
subtype and custom options, in fsname too on platforms whose mount helpers decode
no escapes, and NUL everywhere.

Fixes #424

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NjYWzn3mu8Sc2y2eACtJM9
@cberner
cberner force-pushed the claude/fuser-issues-triage-7tz8v9 branch from 8aca968 to bbddd3a Compare July 31, 2026 16:03
@cberner
cberner merged commit ad39068 into master Jul 31, 2026
9 checks passed
@cberner
cberner deleted the claude/fuser-issues-triage-7tz8v9 branch July 31, 2026 20:44
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.

Broken handling of commas and backslashes in MountOption

2 participants