From 07ad4b3703912a246a9b75713fd757dc2be9a29d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 17 Nov 2026 21:21:19 +0100 Subject: mount: start serving ctlsock only after the FUSE mount is initialized ctlsocksrv.Serve() was started at the end of initFuseFrontend(), before initGoFuse() calls fs.NewNodeFS(), which initializes the root inode. In forward mode, EncryptPath/DecryptPath call prepareAtSyscallMyself(), which calls Inode.IsRoot() and dereferences the still-nil bridge pointer. As the socket is opened before asking for the password, a client can queue a request during the password prompt. It is then accepted right away and races initGoFuse(). If it wins, gocryptfs crashes with a nil pointer dereference. The race detector reports the race on every such run. Start Serve() in doMount() after initGoFuse() returns. The socket is still opened early, and queued requests wait in the listen backlog. Co-Authored-By: Claude Opus 5.5 --- mount.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'mount.go') diff --git a/mount.go b/mount.go index 489ae31..fd6c313 100644 --- a/mount.go +++ b/mount.go @@ -109,6 +109,12 @@ func doMount(args *argContainer) { defer wipeKeys() // Initialize go-fuse FUSE server srv := initGoFuse(fs, args) + // Start serving the control socket only now. fusefrontend's + // EncryptPath/DecryptPath use the root inode, which go-fuse initializes + // in initGoFuse. Requests that arrived earlier wait in the listen backlog. + if args._ctlsockFd != nil { + go ctlsocksrv.Serve(args._ctlsockFd, fs.(ctlsocksrv.Interface)) + } if x, ok := fs.(AfterUnmounter); ok { defer x.AfterUnmount() } @@ -351,11 +357,6 @@ func initFuseFrontend(args *argContainer) (rootNode fs.InodeEmbedder, wipeKeys f } else { rootNode = fusefrontend.NewRootNode(frontendArgs, cEnc, nameTransform) } - // We have opened the socket early so that we cannot fail here after - // asking the user for the password - if args._ctlsockFd != nil { - go ctlsocksrv.Serve(args._ctlsockFd, rootNode.(ctlsocksrv.Interface)) - } return rootNode, func() { cCore.Wipe() } } -- cgit v1.2.3