summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry')
-rw-r--r--pkg/sentry/fs/mount.go4
-rw-r--r--pkg/sentry/fs/mount_test.go4
-rw-r--r--pkg/sentry/fs/proc/mounts.go8
3 files changed, 12 insertions, 4 deletions
diff --git a/pkg/sentry/fs/mount.go b/pkg/sentry/fs/mount.go
index a2943b097..1d05a36a7 100644
--- a/pkg/sentry/fs/mount.go
+++ b/pkg/sentry/fs/mount.go
@@ -198,10 +198,12 @@ func (msrc *MountSource) Submounts() []*MountSource {
return ms
}
-// Root returns the root dirent of this mount.
+// Root returns the root dirent of this mount. Callers must call DecRef on the
+// returned dirent.
func (msrc *MountSource) Root() *Dirent {
msrc.mu.Lock()
defer msrc.mu.Unlock()
+ msrc.root.IncRef()
return msrc.root
}
diff --git a/pkg/sentry/fs/mount_test.go b/pkg/sentry/fs/mount_test.go
index 3a053c154..968b435ab 100644
--- a/pkg/sentry/fs/mount_test.go
+++ b/pkg/sentry/fs/mount_test.go
@@ -204,7 +204,9 @@ func mountPathsAre(root *Dirent, got []*MountSource, want ...string) error {
}
gotPaths := make(map[string]struct{}, len(got))
for _, g := range got {
- n, _ := g.Root().FullName(root)
+ groot := g.Root()
+ n, _ := groot.FullName(root)
+ groot.DecRef()
gotPaths[n] = struct{}{}
}
for _, w := range want {
diff --git a/pkg/sentry/fs/proc/mounts.go b/pkg/sentry/fs/proc/mounts.go
index 76092567d..3d276dfa5 100644
--- a/pkg/sentry/fs/proc/mounts.go
+++ b/pkg/sentry/fs/proc/mounts.go
@@ -44,7 +44,9 @@ func forEachMountSource(t *kernel.Task, fn func(string, *fs.MountSource)) {
return ms[i].ID() < ms[j].ID()
})
for _, m := range ms {
- mountPath, desc := m.Root().FullName(rootDir)
+ mroot := m.Root()
+ mountPath, desc := mroot.FullName(rootDir)
+ mroot.DecRef()
if !desc {
// MountSources that are not descendants of the chroot jail are ignored.
continue
@@ -88,7 +90,9 @@ func (mif *mountInfoFile) ReadSeqFileData(handle seqfile.SeqHandle) ([]seqfile.S
// (3) Major:Minor device ID. We don't have a superblock, so we
// just use the root inode device number.
- sa := m.Root().Inode.StableAttr
+ mroot := m.Root()
+ sa := mroot.Inode.StableAttr
+ mroot.DecRef()
fmt.Fprintf(&buf, "%d:%d ", sa.DeviceFileMajor, sa.DeviceFileMinor)
// (4) Root: the pathname of the directory in the filesystem