2016-02-06 19:27:59 +01:00
|
|
|
package fusefrontend
|
2015-11-27 00:03:10 +01:00
|
|
|
|
2015-11-27 23:34:55 +01:00
|
|
|
// This file forwards file encryption operations to cryptfs
|
|
|
|
|
|
|
|
import (
|
2017-11-28 01:11:19 +01:00
|
|
|
"os"
|
2016-02-06 22:54:14 +01:00
|
|
|
"path/filepath"
|
|
|
|
|
2016-02-06 19:20:54 +01:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/configfile"
|
fusefrontend: use OpenDirNofollow in openBackingDir
Rename openBackingPath to openBackingDir and use OpenDirNofollow
to be safe against symlink races. Note that openBackingDir is
not used in several important code paths like Create().
But it is used in Unlink, and the performance impact in the RM benchmark
to be acceptable:
Before
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.bYO: gocryptfs v1.6-12-g930c37e-dirty; go-fuse v20170619-49-gb11e293; 2018-09-08 go1.10.3
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 1.07979 s, 243 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0.882413 s, 297 MB/s
UNTAR: 16.703
MD5: 7.606
LS: 1.349
RM: 3.237
After
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.jK3: gocryptfs v1.6-13-g84d6faf-dirty; go-fuse v20170619-49-gb11e293; 2018-09-08 go1.10.3
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 1.06261 s, 247 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0.947228 s, 277 MB/s
UNTAR: 17.197
MD5: 7.540
LS: 1.364
RM: 3.410
2018-09-08 19:27:33 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
|
2016-06-15 23:30:44 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/internal/tlog"
|
2015-11-27 23:34:55 +01:00
|
|
|
)
|
2015-11-27 00:03:10 +01:00
|
|
|
|
2015-12-08 16:13:29 +01:00
|
|
|
// isFiltered - check if plaintext "path" should be forbidden
|
|
|
|
//
|
|
|
|
// Prevents name clashes with internal files when file names are not encrypted
|
|
|
|
func (fs *FS) isFiltered(path string) bool {
|
|
|
|
if !fs.args.PlaintextNames {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// gocryptfs.conf in the root directory is forbidden
|
2016-02-06 19:20:54 +01:00
|
|
|
if path == configfile.ConfDefaultName {
|
2016-06-15 23:30:44 +02:00
|
|
|
tlog.Info.Printf("The name /%s is reserved when -plaintextnames is used\n",
|
2016-02-06 19:20:54 +01:00
|
|
|
configfile.ConfDefaultName)
|
2015-12-08 16:13:29 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
// Note: gocryptfs.diriv is NOT forbidden because diriv and plaintextnames
|
|
|
|
// are exclusive
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-02-06 22:54:14 +01:00
|
|
|
// GetBackingPath - get the absolute encrypted path of the backing file
|
|
|
|
// from the relative plaintext path "relPath"
|
|
|
|
func (fs *FS) getBackingPath(relPath string) (string, error) {
|
|
|
|
cPath, err := fs.encryptPath(relPath)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
cAbsPath := filepath.Join(fs.args.Cipherdir, cPath)
|
2016-06-15 23:30:44 +02:00
|
|
|
tlog.Debug.Printf("getBackingPath: %s + %s -> %s", fs.args.Cipherdir, relPath, cAbsPath)
|
2016-02-06 22:54:14 +01:00
|
|
|
return cAbsPath, nil
|
|
|
|
}
|
|
|
|
|
fusefrontend: use OpenDirNofollow in openBackingDir
Rename openBackingPath to openBackingDir and use OpenDirNofollow
to be safe against symlink races. Note that openBackingDir is
not used in several important code paths like Create().
But it is used in Unlink, and the performance impact in the RM benchmark
to be acceptable:
Before
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.bYO: gocryptfs v1.6-12-g930c37e-dirty; go-fuse v20170619-49-gb11e293; 2018-09-08 go1.10.3
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 1.07979 s, 243 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0.882413 s, 297 MB/s
UNTAR: 16.703
MD5: 7.606
LS: 1.349
RM: 3.237
After
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.jK3: gocryptfs v1.6-13-g84d6faf-dirty; go-fuse v20170619-49-gb11e293; 2018-09-08 go1.10.3
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 1.06261 s, 247 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0.947228 s, 277 MB/s
UNTAR: 17.197
MD5: 7.540
LS: 1.364
RM: 3.410
2018-09-08 19:27:33 +02:00
|
|
|
// openBackingDir opens the parent ciphertext directory of plaintext path
|
|
|
|
// "relPath" and returns the dirfd and the encrypted basename.
|
|
|
|
// The caller should then use Openat(dirfd, cName, ...) and friends.
|
|
|
|
// openBackingDir is secure against symlink races.
|
|
|
|
func (fs *FS) openBackingDir(relPath string) (*os.File, string, error) {
|
|
|
|
cRelPath, err := fs.encryptPath(relPath)
|
2017-11-28 01:11:19 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
}
|
fusefrontend: use OpenDirNofollow in openBackingDir
Rename openBackingPath to openBackingDir and use OpenDirNofollow
to be safe against symlink races. Note that openBackingDir is
not used in several important code paths like Create().
But it is used in Unlink, and the performance impact in the RM benchmark
to be acceptable:
Before
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.bYO: gocryptfs v1.6-12-g930c37e-dirty; go-fuse v20170619-49-gb11e293; 2018-09-08 go1.10.3
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 1.07979 s, 243 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0.882413 s, 297 MB/s
UNTAR: 16.703
MD5: 7.606
LS: 1.349
RM: 3.237
After
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.jK3: gocryptfs v1.6-13-g84d6faf-dirty; go-fuse v20170619-49-gb11e293; 2018-09-08 go1.10.3
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 1.06261 s, 247 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0.947228 s, 277 MB/s
UNTAR: 17.197
MD5: 7.540
LS: 1.364
RM: 3.410
2018-09-08 19:27:33 +02:00
|
|
|
// Open parent dir
|
|
|
|
dirfd, err := syscallcompat.OpenDirNofollow(fs.args.Cipherdir, filepath.Dir(cRelPath))
|
2017-11-28 01:11:19 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
}
|
fusefrontend: use OpenDirNofollow in openBackingDir
Rename openBackingPath to openBackingDir and use OpenDirNofollow
to be safe against symlink races. Note that openBackingDir is
not used in several important code paths like Create().
But it is used in Unlink, and the performance impact in the RM benchmark
to be acceptable:
Before
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.bYO: gocryptfs v1.6-12-g930c37e-dirty; go-fuse v20170619-49-gb11e293; 2018-09-08 go1.10.3
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 1.07979 s, 243 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0.882413 s, 297 MB/s
UNTAR: 16.703
MD5: 7.606
LS: 1.349
RM: 3.237
After
$ ./benchmark.bash
Testing gocryptfs at /tmp/benchmark.bash.jK3: gocryptfs v1.6-13-g84d6faf-dirty; go-fuse v20170619-49-gb11e293; 2018-09-08 go1.10.3
WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 1.06261 s, 247 MB/s
READ: 262144000 bytes (262 MB, 250 MiB) copied, 0.947228 s, 277 MB/s
UNTAR: 17.197
MD5: 7.540
LS: 1.364
RM: 3.410
2018-09-08 19:27:33 +02:00
|
|
|
return os.NewFile(uintptr(dirfd), cRelPath), filepath.Base(cRelPath), nil
|
2017-11-28 01:11:19 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 16:13:29 +01:00
|
|
|
// encryptPath - encrypt relative plaintext path
|
2015-11-27 00:03:10 +01:00
|
|
|
func (fs *FS) encryptPath(plainPath string) (string, error) {
|
2015-12-08 16:13:29 +01:00
|
|
|
if fs.args.PlaintextNames {
|
|
|
|
return plainPath, nil
|
|
|
|
}
|
2015-11-27 21:48:58 +01:00
|
|
|
fs.dirIVLock.RLock()
|
2016-02-06 22:54:14 +01:00
|
|
|
cPath, err := fs.nameTransform.EncryptPathDirIV(plainPath, fs.args.Cipherdir)
|
2016-06-15 23:30:44 +02:00
|
|
|
tlog.Debug.Printf("encryptPath '%s' -> '%s' (err: %v)", plainPath, cPath, err)
|
2016-02-06 22:54:14 +01:00
|
|
|
fs.dirIVLock.RUnlock()
|
|
|
|
return cPath, err
|
2015-11-27 00:03:10 +01:00
|
|
|
}
|