aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Pilkington2026-04-18 14:58:26 +0200
committerrfjakob2026-05-07 21:10:33 +0200
commit1a03e993cf898bd66125d88dcd682dc056a398d6 (patch)
treecb3e80ae4d1b0135a365aa04a90751f629bd2416
parenta991be3da536b2d57e5b481f0657c3651ea22194 (diff)
mount: mount ro if cipherdir is on a ro filesystem (don't allow rw)HEADmaster
-rw-r--r--mount.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/mount.go b/mount.go
index f7378aa..2508409 100644
--- a/mount.go
+++ b/mount.go
@@ -449,9 +449,18 @@ func initGoFuse(rootNode fs.InodeEmbedder, args *argContainer) *fuse.Server {
if runtime.GOOS == "darwin" {
opts["volname"] = strings.Replace(path.Base(args.mountpoint), ",", "_", -1)
}
+ underlyingFilesystemRo, err := isReadOnlyFilesystem(args.cipherdir)
+ if err != nil {
+ tlog.Debug.Printf("Error checking if cipherdir is on a read-only filesystem: %s", err)
+ } else if underlyingFilesystemRo && args.rw {
+ tlog.Fatal.Printf("Writeable mount explicitly requested but cipherdir %s is on a read-only filesystem, refusing.", args.cipherdir)
+ os.Exit(exitcodes.Usage)
+ } else if underlyingFilesystemRo && !args.ro {
+ tlog.Info.Printf("Cipherdir %s is on a read-only filesystem, mounting as read-only.", args.cipherdir)
+ }
// The kernel enforces read-only operation, we just have to pass "ro".
- // Reverse mounts are always read-only.
- if args.ro || args.reverse {
+ // Reverse mounts and mounts with cipherdirs on read-only filesystems are always read-only.
+ if args.ro || args.reverse || underlyingFilesystemRo {
opts["ro"] = ""
} else if args.rw {
opts["rw"] = ""
@@ -562,3 +571,16 @@ func unmount(srv *fuse.Server, mountpoint string) {
}
}
}
+
+const (
+ ST_RDONLY = 0x1
+)
+
+func isReadOnlyFilesystem(path string) (bool, error) {
+ var stat syscall.Statfs_t
+ if err := syscall.Statfs(path, &stat); err != nil {
+ return false, err
+ }
+
+ return (stat.Flags & ST_RDONLY) != 0, nil
+}