diff options
author | Adin Scannell <ascannell@google.com> | 2020-02-25 12:16:43 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-02-25 12:17:52 -0800 |
commit | 53504e29ca27b8dc9e098fbb88983fdbce90cca3 (patch) | |
tree | 5a5729b4de0d9199d4fed8b8b17613140c88e8f1 /pkg/sentry/fs/mount_test.go | |
parent | d7b73792515d1ac34c8d8c41ef5de379f22f002b (diff) |
Fix mount refcount issue.
Each mount is holds a reference on a root Dirent, but the mount itself may
live beyond it's own reference. This means that a call to Root() can come
after the associated reference has been dropped.
Instead of introducing a separate layer of references for mount objects,
we simply change the Root() method to use TryIncRef() and allow it to return
nil if the mount is already gone. This requires updating a small number of
callers and minimizes the change (since VFSv2 will replace this code shortly).
PiperOrigin-RevId: 297174230
Diffstat (limited to 'pkg/sentry/fs/mount_test.go')
-rw-r--r-- | pkg/sentry/fs/mount_test.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/pkg/sentry/fs/mount_test.go b/pkg/sentry/fs/mount_test.go index e672a438c..a3d10770b 100644 --- a/pkg/sentry/fs/mount_test.go +++ b/pkg/sentry/fs/mount_test.go @@ -36,11 +36,12 @@ func mountPathsAre(root *Dirent, got []*Mount, want ...string) error { gotPaths := make(map[string]struct{}, len(got)) gotStr := make([]string, len(got)) for i, g := range got { - groot := g.Root() - name, _ := groot.FullName(root) - groot.DecRef() - gotStr[i] = name - gotPaths[name] = struct{}{} + if groot := g.Root(); groot != nil { + name, _ := groot.FullName(root) + groot.DecRef() + gotStr[i] = name + gotPaths[name] = struct{}{} + } } if len(got) != len(want) { return fmt.Errorf("mount paths are different, got: %q, want: %q", gotStr, want) |