summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-01-21 01:05:30 +0000
committergVisor bot <gvisor-bot@google.com>2021-01-21 01:05:30 +0000
commit23a86430206216c66c66daac9a928a363cd0bcf5 (patch)
tree847b8fa88e3bc8bc2c8271781980ba5456e677a8 /pkg/sentry
parent3343995a4129f2533531e3f81e983b3137338080 (diff)
parentca9a45f282a08a88df19c93d5968d720b5153c41 (diff)
Merge release-20210112.0-50-gca9a45f28 (automated)
Diffstat (limited to 'pkg/sentry')
-rw-r--r--pkg/sentry/fsimpl/gofer/filesystem.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/pkg/sentry/fsimpl/gofer/filesystem.go b/pkg/sentry/fsimpl/gofer/filesystem.go
index 91d5dc174..8f95473b6 100644
--- a/pkg/sentry/fsimpl/gofer/filesystem.go
+++ b/pkg/sentry/fsimpl/gofer/filesystem.go
@@ -36,16 +36,26 @@ import (
// Sync implements vfs.FilesystemImpl.Sync.
func (fs *filesystem) Sync(ctx context.Context) error {
// Snapshot current syncable dentries and special file FDs.
+ fs.renameMu.RLock()
fs.syncMu.Lock()
ds := make([]*dentry, 0, len(fs.syncableDentries))
for d := range fs.syncableDentries {
+ // It's safe to use IncRef here even though fs.syncableDentries doesn't
+ // hold references since we hold fs.renameMu. Note that we can't use
+ // TryIncRef since cached dentries at zero references should still be
+ // synced.
d.IncRef()
ds = append(ds, d)
}
+ fs.renameMu.RUnlock()
sffds := make([]*specialFileFD, 0, len(fs.specialFileFDs))
for sffd := range fs.specialFileFDs {
- sffd.vfsfd.IncRef()
- sffds = append(sffds, sffd)
+ // As above, fs.specialFileFDs doesn't hold references. However, unlike
+ // dentries, an FD that has reached zero references can't be
+ // resurrected, so we can use TryIncRef.
+ if sffd.vfsfd.TryIncRef() {
+ sffds = append(sffds, sffd)
+ }
}
fs.syncMu.Unlock()