Commit 32b02fb6 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

unionfs: copy fuse.Attr before modifying return value of branch cache

Fixes a race condition.
parent c5492cd9
...@@ -496,6 +496,9 @@ func (fs *unionFS) Truncate(path string, size uint64, context *fuse.Context) (co ...@@ -496,6 +496,9 @@ func (fs *unionFS) Truncate(path string, size uint64, context *fuse.Context) (co
code = fs.fileSystems[0].Truncate(path, size, context) code = fs.fileSystems[0].Truncate(path, size, context)
} }
if code.Ok() { if code.Ok() {
newAttr := *r.attr
r.attr = &newAttr
r.attr.Size = size r.attr.Size = size
now := time.Now() now := time.Now()
r.attr.SetTimes(nil, &now, &now) r.attr.SetTimes(nil, &now, &now)
...@@ -518,6 +521,8 @@ func (fs *unionFS) Utimens(name string, atime *time.Time, mtime *time.Time, cont ...@@ -518,6 +521,8 @@ func (fs *unionFS) Utimens(name string, atime *time.Time, mtime *time.Time, cont
} }
if code.Ok() { if code.Ok() {
now := time.Now() now := time.Now()
newAttr := *r.attr
r.attr = &newAttr
r.attr.SetTimes(atime, mtime, &now) r.attr.SetTimes(atime, mtime, &now)
fs.setBranch(name, r) fs.setBranch(name, r)
} }
...@@ -531,6 +536,9 @@ func (fs *unionFS) Chown(name string, uid uint32, gid uint32, context *fuse.Cont ...@@ -531,6 +536,9 @@ func (fs *unionFS) Chown(name string, uid uint32, gid uint32, context *fuse.Cont
return r.code return r.code
} }
newAttr := *r.attr
r.attr = &newAttr
if os.Geteuid() != 0 { if os.Geteuid() != 0 {
return fuse.EPERM return fuse.EPERM
} }
...@@ -559,6 +567,8 @@ func (fs *unionFS) Chmod(name string, mode uint32, context *fuse.Context) (code ...@@ -559,6 +567,8 @@ func (fs *unionFS) Chmod(name string, mode uint32, context *fuse.Context) (code
if r.attr == nil { if r.attr == nil {
return r.code return r.code
} }
newAttr := *r.attr
r.attr = &newAttr
if r.code != fuse.OK { if r.code != fuse.OK {
return r.code return r.code
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment