Skip to content

Commit 6693224

Browse files
committed
fusefrontend: Don't chown gocryptfs.diriv files.
The current code has a risk of race-conditions, since we pass a path containing "/" to Fchownat. We could fix this by opening a file descriptor, however, this does not seem worth the effort. We also don't chown *.name files.
1 parent fcaca5f commit 6693224

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

internal/fusefrontend/fs.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package fusefrontend
55

66
import (
77
"os"
8-
"path/filepath"
98
"sync"
109
"syscall"
1110
"time"
@@ -326,19 +325,8 @@ func (fs *FS) Chown(path string, uid uint32, gid uint32, context *fuse.Context)
326325
return fuse.ToStatus(err)
327326
}
328327
defer syscall.Close(dirfd)
329-
code = fuse.ToStatus(syscallcompat.Fchownat(dirfd, cName, int(uid), int(gid), unix.AT_SYMLINK_NOFOLLOW))
330-
if !code.Ok() {
331-
return code
332-
}
333-
if !fs.args.PlaintextNames {
334-
// When filename encryption is active, every directory contains
335-
// a "gocryptfs.diriv" file. This file should also change the owner.
336-
// Instead of checking if "cName" is a directory, we just blindly
337-
// execute the chown on "cName/gocryptfs.diriv" and ignore errors.
338-
dirIVPath := filepath.Join(cName, nametransform.DirIVFilename)
339-
syscallcompat.Fchownat(dirfd, dirIVPath, int(uid), int(gid), unix.AT_SYMLINK_NOFOLLOW)
340-
}
341-
return fuse.OK
328+
err = syscallcompat.Fchownat(dirfd, cName, int(uid), int(gid), unix.AT_SYMLINK_NOFOLLOW)
329+
return fuse.ToStatus(err)
342330
}
343331

344332
// Mknod - FUSE call. Create a device file.

internal/fusefrontend/fs_dir.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package fusefrontend
55
import (
66
"fmt"
77
"io"
8-
"path/filepath"
98
"runtime"
109
"syscall"
1110

@@ -124,16 +123,11 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu
124123
err = syscallcompat.Fchownat(dirfd, cName, int(context.Owner.Uid),
125124
int(context.Owner.Gid), unix.AT_SYMLINK_NOFOLLOW)
126125
if err != nil {
127-
tlog.Warn.Printf("Mkdir %q: Fchownat(1) %d:%d failed: %v", cName, context.Owner.Uid, context.Owner.Gid, err)
126+
tlog.Warn.Printf("Mkdir %q: Fchownat %d:%d failed: %v", cName, context.Owner.Uid, context.Owner.Gid, err)
128127
// In case of a failure, we don't want to proceed setting more
129128
// permissive modes.
130129
return fuse.ToStatus(err)
131130
}
132-
err = syscallcompat.Fchownat(dirfd, filepath.Join(cName, nametransform.DirIVFilename),
133-
int(context.Owner.Uid), int(context.Owner.Gid), unix.AT_SYMLINK_NOFOLLOW)
134-
if err != nil {
135-
tlog.Warn.Printf("Mkdir %q: Fchownat(2) %d:%d failed: %v", cName, context.Owner.Uid, context.Owner.Gid, err)
136-
}
137131
}
138132
// Set mode
139133
if origMode != mode {

0 commit comments

Comments
 (0)