From 20ef2127a1028363df8d056a7143c4d263544763 Mon Sep 17 00:00:00 2001 From: Lucas Manning Date: Mon, 31 Oct 2022 14:51:31 -0700 Subject: [PATCH] Lock around optional tag generation. Reported-by: syzbot+339e76d7c2c84cbd70c9@syzkaller.appspotmail.com PiperOrigin-RevId: 485155018 --- pkg/sentry/vfs/mount.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/sentry/vfs/mount.go b/pkg/sentry/vfs/mount.go index a252eff55..400078a2e 100644 --- a/pkg/sentry/vfs/mount.go +++ b/pkg/sentry/vfs/mount.go @@ -179,6 +179,17 @@ func (mnt *Mount) Options() MountOptions { } } +func (mnt *Mount) generateOptionalTags() string { + mnt.vfs.mountMu.Lock() + defer mnt.vfs.mountMu.Unlock() + // TODO(b/249777195): Support MS_SLAVE and MS_UNBINDABLE propagation types. + var optional string + if mnt.propType == Shared { + optional = fmt.Sprintf("shared:%d", mnt.groupID) + } + return optional +} + // addPeer adds oth to mnt's peer group. Both will have the same groupID // and sharedList. vfs.mountMu must be locked. // @@ -1326,7 +1337,7 @@ func (vfs *VirtualFilesystem) GenerateProcMountInfo(ctx context.Context, taskRoo if path == "" { // Either an error occurred, or path is not reachable // from root. - break + continue } // Stat the mount root to get the major/minor device numbers. pop := &PathOperation{ @@ -1337,7 +1348,7 @@ func (vfs *VirtualFilesystem) GenerateProcMountInfo(ctx context.Context, taskRoo if err != nil { // Well that's not good. Ignore this mount. ctx.Warningf("VFS.GenerateProcMountInfo: failed to stat mount root %+v: %v", mnt.root, err) - break + continue } // Format: @@ -1385,9 +1396,7 @@ func (vfs *VirtualFilesystem) GenerateProcMountInfo(ctx context.Context, taskRoo fmt.Fprintf(buf, "%s ", opts) // (7) Optional fields: zero or more fields of the form "tag[:value]". - if mnt.propType == Shared { - fmt.Fprintf(buf, "shared:%d ", mnt.groupID) - } + fmt.Fprintf(buf, "%s ", mnt.generateOptionalTags()) // (8) Separator: the end of the optional fields is marked by a single hyphen. fmt.Fprintf(buf, "- ")