Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use *at() syscalls for Rmdir, Chmod, Chown and Mkdir #179

Merged
merged 4 commits into from
Nov 30, 2017

Conversation

slackner
Copy link
Contributor

Patch 1 fixes an existing TODO in the code.

Patch 2 and 3 changes the implementation of Chmod and Chown, such that openBackingPath and *at() syscalls are used. The general idea would be that in the long term, we try to use openBackingPath everywhere. When we later want to harden gocryptfs against symlink race-conditions (maybe optional, since it probably will be a bit slower), it is sufficient to change only a single function, instead of adding checks everywhere in the code.

Patch 4 should fix the remaining issue from #177.

return syscall.Unlinkat(dirfd, path)
// Unlinkat syscall. In old versions the 'flags' argument was missing, so
// manually call it by using the corresponding syscall number.
func Unlinkat(dirfd int, path string, flags int) (err error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get a test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syscall itself? Or do you mean tests which use Rmdir in a FUSE mount?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the syscall itself.

The Go stdlib uses https://golang.org/src/syscall/mksyscall.pl to autogenerate the wrappers, and different prototypes for amd64 ( https://golang.org/src/syscall/syscall_linux_amd64.go ) and the rest ( https://golang.org/src/syscall/syscall_linux.go ). Looks hard enough to get right (on 32 bit and 64 bit!) to warrant a test

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I will add a test for syscallat as well)

@@ -24,22 +24,22 @@ import (

const dsStoreName = ".DS_Store"

func (fs *FS) mkdirWithIv(cPath string, mode uint32) error {
func (fs *FS) mkdirWithIv(dirfd *os.File, cName string, mode uint32) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a comment explaining the arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -75,16 +75,17 @@ func fdReadDirIV(fd *os.File) (iv []byte, err error) {
// WriteDirIV - create diriv file inside "dir" (absolute ciphertext path)
// This function is exported because it is used from pathfs_frontend, main,
// and also the automated tests.
func WriteDirIV(dir string) error {
func WriteDirIV(dirfd *os.File, dir string) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function comment needs to be updated and dirfd explained.

Question: If dirfd != nil, can "dir" contain slashes? Should we check + panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

It wouldn't be a problem if it contains slashes. Not sure if we should be too strict here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would work because the syscall accepts it, but is it a bug in gocryptfs if that happens?

@rfjakob rfjakob merged commit 614745e into rfjakob:master Nov 30, 2017
@rfjakob
Copy link
Owner

rfjakob commented Nov 30, 2017

I'm going to make the darwin syscalls testable on linux, and I don't want to cause merge conflicts, so I'll just pull this now. My nitpicks can be fixed later. Thanks!

@slackner
Copy link
Contributor Author

As I see you have already pushed your changes, looks awesome! :)
I will later open a new pull request for the comment fixes

slackner added a commit to slackner/gocryptfs that referenced this pull request Nov 30, 2017
@slackner slackner deleted the syscallcompat2 branch November 30, 2017 21:16
rfjakob pushed a commit that referenced this pull request Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants