summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2020-04-01 12:05:17 -0700
committergVisor bot <gvisor-bot@google.com>2020-04-01 12:06:37 -0700
commit0d1e299079392043fae24c2be524a0eefe7d8085 (patch)
treeb0b563669f5ec703dd66e00fc83a03251196c239 /pkg/sentry
parent38f4501c995d7d915bcd168d58655e67e2b34566 (diff)
Pass configurable FilesystemType to tmpfs.
PiperOrigin-RevId: 304234086
Diffstat (limited to 'pkg/sentry')
-rw-r--r--pkg/sentry/fsimpl/tmpfs/tmpfs.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/pkg/sentry/fsimpl/tmpfs/tmpfs.go b/pkg/sentry/fsimpl/tmpfs/tmpfs.go
index afd9f8533..8bc8818c0 100644
--- a/pkg/sentry/fsimpl/tmpfs/tmpfs.go
+++ b/pkg/sentry/fsimpl/tmpfs/tmpfs.go
@@ -77,6 +77,11 @@ type FilesystemOpts struct {
// RootSymlinkTarget is the target of the root symlink. Only valid if
// RootFileType == S_IFLNK.
RootSymlinkTarget string
+
+ // FilesystemType allows setting a different FilesystemType for this
+ // tmpfs filesystem. This allows tmpfs to "impersonate" other
+ // filesystems, like ramdiskfs and cgroupfs.
+ FilesystemType vfs.FilesystemType
}
// GetFilesystem implements vfs.FilesystemType.GetFilesystem.
@@ -91,15 +96,22 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt
clock: clock,
}
- fs.vfsfs.Init(vfsObj, &fstype, &fs)
-
- typ := uint16(linux.S_IFDIR)
+ rootFileType := uint16(linux.S_IFDIR)
+ newFSType := vfs.FilesystemType(&fstype)
tmpfsOpts, ok := opts.InternalData.(FilesystemOpts)
- if ok && tmpfsOpts.RootFileType != 0 {
- typ = tmpfsOpts.RootFileType
+ if ok {
+ if tmpfsOpts.RootFileType != 0 {
+ rootFileType = tmpfsOpts.RootFileType
+ }
+ if tmpfsOpts.FilesystemType != nil {
+ newFSType = tmpfsOpts.FilesystemType
+ }
}
+
+ fs.vfsfs.Init(vfsObj, newFSType, &fs)
+
var root *inode
- switch typ {
+ switch rootFileType {
case linux.S_IFREG:
root = fs.newRegularFile(creds, 0777)
case linux.S_IFLNK:
@@ -107,7 +119,7 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt
case linux.S_IFDIR:
root = fs.newDirectory(creds, 01777)
default:
- return nil, nil, fmt.Errorf("invalid tmpfs root file type: %#o", typ)
+ return nil, nil, fmt.Errorf("invalid tmpfs root file type: %#o", rootFileType)
}
return &fs.vfsfs, &fs.newDentry(root).vfsd, nil
}