Skip to content

Commit

Permalink
fusefrontend: use Lchown when preserving owner
Browse files Browse the repository at this point in the history
This prevents (unlikely) symlink race attacks
  • Loading branch information
rfjakob committed Nov 28, 2016
1 parent 7fc93ec commit a66440c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/fusefrontend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Conte
if fs.args.PreserveOwner {
err = fd.Chown(int(context.Owner.Uid), int(context.Owner.Gid))
if err != nil {
tlog.Warn.Printf("Create: Chown failed: %v", err)
tlog.Warn.Printf("Create: fd.Chown failed: %v", err)
}
}
return NewFile(fd, writeOnly, fs)
Expand Down
13 changes: 6 additions & 7 deletions internal/fusefrontend/fs_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu
err = os.Mkdir(cPath, os.FileMode(mode))
// Set owner
if fs.args.PreserveOwner {
err = os.Chown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
err = os.Lchown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
if err != nil {
tlog.Warn.Printf("Mkdir: Chown failed: %v", err)
tlog.Warn.Printf("Mkdir: Lchown failed: %v", err)
}
}
return fuse.ToStatus(err)
Expand Down Expand Up @@ -94,7 +94,6 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu
return fuse.ToStatus(err)
}
}

// Set permissions back to what the user wanted
if origMode != mode {
err = os.Chmod(cPath, os.FileMode(origMode))
Expand All @@ -104,13 +103,13 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu
}
// Set owner
if fs.args.PreserveOwner {
err = os.Chown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
err = os.Lchown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
if err != nil {
tlog.Warn.Printf("Mkdir: Chown failed: %v", err)
tlog.Warn.Printf("Mkdir: Lchown 1 failed: %v", err)
}
err = os.Chown(filepath.Join(cPath, nametransform.DirIVFilename), int(context.Owner.Uid), int(context.Owner.Gid))
err = os.Lchown(filepath.Join(cPath, nametransform.DirIVFilename), int(context.Owner.Uid), int(context.Owner.Gid))
if err != nil {
tlog.Warn.Printf("Mkdir: Chown failed: %v", err)
tlog.Warn.Printf("Mkdir: Lchown 2 failed: %v", err)
}
}
return fuse.OK
Expand Down

0 comments on commit a66440c

Please sign in to comment.