From 8caa5dddeebaf7116c9fa12a64cac1aca567df58 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 11 Nov 2026 21:05:14 +0100 Subject: fusefrontend: openWriteOnlyFile: reopen the same file, not just the same name openWriteOnlyFile chmods the file via woFd and then reopens it by name. O_NOFOLLOW prevents following symlinks, but cName could still have been replaced by a different regular file in between, and we would return an fd to that file. Add syscallcompat.ReopenFd(): * Linux: open /proc/self/fd/N, which always resolves to the file woFd refers to. * Other platforms: reopen by name and compare dev/ino against woFd, returning EAGAIN on mismatch. Co-Authored-By: Claude Opus 5.5 --- internal/fusefrontend/root_node.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'internal/fusefrontend/root_node.go') diff --git a/internal/fusefrontend/root_node.go b/internal/fusefrontend/root_node.go index 38d070d..fa8781b 100644 --- a/internal/fusefrontend/root_node.go +++ b/internal/fusefrontend/root_node.go @@ -206,7 +206,9 @@ func (rn *RootNode) openWriteOnlyFile(dirfd int, cName string, newFlags int) (rw tlog.Warn.Printf("openWriteOnlyFile: reverting permissions failed: %v", err2) } }() - return syscallcompat.Openat(dirfd, cName, newFlags, 0) + // cName may have been replaced by a different file since we opened woFd. + // ReopenFd makes sure we get the same file we just chmod'ed. + return syscallcompat.ReopenFd(woFd, dirfd, cName, newFlags) } // encryptSymlinkTarget: "data" is encrypted like file contents (GCM) -- cgit v1.2.3