summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl/verity/verity.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-08-31 12:50:31 -0700
committergVisor bot <gvisor-bot@google.com>2020-08-31 12:52:21 -0700
commit911cecaa34f15d9591fa060d943c35791adca855 (patch)
tree76525e1d8f6a12f9890c0853e0308e2fb7823671 /pkg/sentry/fsimpl/verity/verity.go
parentba25485d96833b3852c2fbbca508414b3b96d430 (diff)
Implement walk in gvisor verity fs
Implement walk directories in gvisor verity file system. For each step, the child dentry is verified against a verified parent root hash. PiperOrigin-RevId: 329358747
Diffstat (limited to 'pkg/sentry/fsimpl/verity/verity.go')
-rw-r--r--pkg/sentry/fsimpl/verity/verity.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/pkg/sentry/fsimpl/verity/verity.go b/pkg/sentry/fsimpl/verity/verity.go
index 1c5b07aa5..eedb5f484 100644
--- a/pkg/sentry/fsimpl/verity/verity.go
+++ b/pkg/sentry/fsimpl/verity/verity.go
@@ -41,6 +41,18 @@ const Name = "verity"
// tree file for "/foo" is "/.merkle.verity.foo".
const merklePrefix = ".merkle.verity."
+// merkleoffsetInParentXattr is the extended attribute name specifying the
+// offset of child root hash in its parent's Merkle tree.
+const merkleOffsetInParentXattr = "user.merkle.offset"
+
+// merkleSizeXattr is the extended attribute name specifying the size of data
+// hashed by the corresponding Merkle tree. For a file, it's the size of the
+// whole file. For a directory, it's the size of all its children's root hashes.
+const merkleSizeXattr = "user.merkle.size"
+
+// sizeOfInt32 is the size in bytes for a 32 bit integer in extended attributes.
+const sizeOfInt32 = 4
+
// noCrashOnVerificationFailure indicates whether the sandbox should panic
// whenever verification fails. If true, an error is returned instead of
// panicking. This should only be set for tests.
@@ -48,6 +60,11 @@ const merklePrefix = ".merkle.verity."
// flag.
var noCrashOnVerificationFailure bool
+// verityMu synchronizes enabling verity files, protects files or directories
+// from being enabled by different threads simultaneously. It also ensures that
+// verity does not access files that are being enabled.
+var verityMu sync.RWMutex
+
// FilesystemType implements vfs.FilesystemType.
type FilesystemType struct{}
@@ -215,6 +232,8 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt
copy(d.rootHash, iopts.RootHash)
d.vfsd.Init(d)
+ fs.rootDentry = d
+
return &fs.vfsfs, &d.vfsd, nil
}