Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/sentry/fsimpl/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ func (d *dentry) statInternalTo(ctx context.Context, opts *vfs.StatOptions, stat
}

// Preconditions: d.copyMu must be locked for writing.
// +checklocks:d.copyMu
func (d *dentry) updateAfterSetStatLocked(opts *vfs.SetStatOptions) {
if opts.Stat.Mask&linux.STATX_MODE != 0 {
// If the mode was changed, the underlying file's ACL may have changed,
Expand Down
18 changes: 13 additions & 5 deletions pkg/sentry/fsimpl/overlay/regular_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (fd *regularFileFD) getCurrentFD(ctx context.Context) (*vfs.FileDescription
return wrappedFD, nil
}

// +checklocks:fd.mu
func (fd *regularFileFD) currentFDLocked(ctx context.Context) (*vfs.FileDescription, error) {
d := fd.dentry()
statusFlags := fd.vfsfd.StatusFlags()
Expand Down Expand Up @@ -175,17 +176,24 @@ func (fd *regularFileFD) SetStat(ctx context.Context, opts vfs.SetStatOptions) e
return err
}
defer mnt.EndWrite()
if err := d.copyUpLocked(ctx); err != nil {
return err
// d.copiedUp is never cleared once set, so this check can be safely
// performed without holding locks.
if !d.isCopiedUp() {
d.fs.renameMu.RLock()
err := d.copyUpLocked(ctx)
d.fs.renameMu.RUnlock()
if err != nil {
return err
}
}
// Changes to d's attributes are serialized by d.copyMu.
d.copyMu.Lock()
defer d.copyMu.Unlock()
wrappedFD, err := fd.getCurrentFD(ctx)
if err != nil {
return err
}
defer wrappedFD.DecRef(ctx)
// Changes to d's attributes are serialized by d.copyMu.
d.copyMu.Lock()
defer d.copyMu.Unlock()
if err := wrappedFD.SetStat(ctx, opts); err != nil {
return err
}
Expand Down
Loading