aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/node_helpers.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2026-11-11 21:11:43 +0100
committerJakob Unterwurzacher2026-11-11 21:11:43 +0100
commitdfdf47d790fa758a9f443764ad296e86c9007ece (patch)
treedb488b0b7400742d5e7d42832fb8d246eb3ca4a7 /internal/fusefrontend_reverse/node_helpers.go
parent8caa5dddeebaf7116c9fa12a64cac1aca567df58 (diff)
reverse: don't follow symlinks when serving gocryptfs.conf
.gocryptfs.reverse.conf is passed through to gocryptfs.conf in the reverse view unencrypted. lookupConf, VirtualConfNode.Getattr and VirtualConfNode.Open accessed it via syscall.Stat/Open on the full path, following symlinks. Anybody with write access to the backing directory could replace it with a symlink to, for example, /etc/shadow and read the target in plaintext through the mount when gocryptfs runs as root. Add RootNode.openConf(), which opens the file relative to the backing dir with O_NOFOLLOW|O_NONBLOCK (O_NONBLOCK so a FIFO cannot hang us) and rejects anything that is not a regular file. Use it for all three. Add TestConfigSymlink as a regression test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/fusefrontend_reverse/node_helpers.go')
-rw-r--r--internal/fusefrontend_reverse/node_helpers.go8
1 files changed, 3 insertions, 5 deletions
diff --git a/internal/fusefrontend_reverse/node_helpers.go b/internal/fusefrontend_reverse/node_helpers.go
index dc8d928..8a15689 100644
--- a/internal/fusefrontend_reverse/node_helpers.go
+++ b/internal/fusefrontend_reverse/node_helpers.go
@@ -11,7 +11,6 @@ import (
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
- "github.com/rfjakob/gocryptfs/v2/internal/configfile"
"github.com/rfjakob/gocryptfs/v2/internal/pathiv"
"github.com/rfjakob/gocryptfs/v2/internal/syscallcompat"
)
@@ -190,13 +189,12 @@ func (n *Node) lookupDiriv(ctx context.Context, out *fuse.EntryOut) (ch *fs.Inod
// lookupConf returns a new Inode for the gocryptfs.conf file
func (n *Node) lookupConf(ctx context.Context, out *fuse.EntryOut) (ch *fs.Inode, errno syscall.Errno) {
rn := n.rootNode()
- p := filepath.Join(rn.args.Cipherdir, configfile.ConfReverseName)
- var st syscall.Stat_t
- err := syscall.Stat(p, &st)
+ fd, st, err := rn.openConf()
if err != nil {
errno = fs.ToErrno(err)
return
}
+ syscall.Close(fd)
// Get unique inode number
rn.inoMap.TranslateStat(&st)
out.Attr.FromStat(&st)
@@ -205,7 +203,7 @@ func (n *Node) lookupConf(ctx context.Context, out *fuse.EntryOut) (ch *fs.Inode
}
// Create child node
id := rn.uniqueStableAttr(uint32(st.Mode), st.Ino)
- node := &VirtualConfNode{path: p}
+ node := &VirtualConfNode{}
ch = n.NewInode(ctx, node, id)
return
}