Skip to content

Commit 120822c

Browse files
committed
Set disk identifier for confidential UVM's scratch
Confidential UVMs boot with a scratch that is completely empty (not even a partition table on it). The UVM formats it as a part of the boot flow. However, the UVM needs a way to correctly identify and distinguish between the scratch & boot VHDs. We do this by setting a pre-defined GUID in the VirtualDiskIdentifier field of the VHD metadata. A fixed pre-defined GUID will be set in the metadata of every UVM's scratch. Signed-off-by: Amit Barve <[email protected]>
1 parent 38c6693 commit 120822c

35 files changed

+156
-44
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23.0
55
require (
66
github.com/Microsoft/cosesign1go v1.4.0
77
github.com/Microsoft/didx509go v0.0.3
8-
github.com/Microsoft/go-winio v0.6.2
8+
github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29
99
github.com/blang/semver/v4 v4.0.0
1010
github.com/cenkalti/backoff/v4 v4.3.0
1111
github.com/containerd/cgroups/v3 v3.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ github.com/Microsoft/cosesign1go v1.4.0 h1:VdiqzsilEE6t1GQi98I/h0WpVFM7AyMEeyP8u
55
github.com/Microsoft/cosesign1go v1.4.0/go.mod h1:1La/HcGw19rRLhPW0S6u55K6LKfti+GQSgGCtrfhVe8=
66
github.com/Microsoft/didx509go v0.0.3 h1:n/owuFOXVzCEzSyzivMEolKEouBm9G0NrEDgoTekM8A=
77
github.com/Microsoft/didx509go v0.0.3/go.mod h1:wWt+iQsLzn3011+VfESzznLIp/Owhuj7rLF7yLglYbk=
8-
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
9-
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
8+
github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29 h1:0kQAzHq8vLs7Pptv+7TxjdETLf/nIqJpIB4oC6Ba4vY=
9+
github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29/go.mod h1:ZWa7ssZJT30CCDGJ7fk/2SBTq9BIQrrVjrcss0UW2s0=
1010
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
1111
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
1212
github.com/agnivade/levenshtein v1.2.0 h1:U9L4IOT0Y3i0TIlUIDJ7rVUziKi/zPbrJGaFrtYH3SY=

internal/uvm/create_wcow.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/Microsoft/go-winio"
1414
"github.com/Microsoft/go-winio/pkg/guid"
15+
"github.com/Microsoft/go-winio/vhd"
1516
"github.com/pkg/errors"
1617
"github.com/sirupsen/logrus"
1718
"go.opencensus.io/trace"
@@ -31,6 +32,18 @@ import (
3132
"github.com/Microsoft/hcsshim/pkg/securitypolicy"
3233
)
3334

35+
var (
36+
// A predefined GUID for UtilityVMs to identify a scratch VHD that is completely empty/unformatted.
37+
// This GUID is set in the metadata of the VHD and thus can be reliably used to identify the disk.
38+
// a7b3c5d1-4e2f-4a8b-9c6d-1e3f5a7b9c2d
39+
unformattedScratchIdentifier = &guid.GUID{
40+
Data1: 0xa7b3c5d1,
41+
Data2: 0x4e2f,
42+
Data3: 0x4a8b,
43+
Data4: [8]byte{0x9c, 0x6d, 0x1e, 0x3f, 0x5a, 0x7b, 0x9c, 0x2d},
44+
}
45+
)
46+
3447
type ConfidentialWCOWOptions struct {
3548
GuestStateFilePath string // The vmgs file path
3649
SecurityPolicyEnabled bool // Set when there is a security policy to apply on actual SNP hardware, use this rathen than checking the string length
@@ -406,6 +419,10 @@ func prepareSecurityConfigDoc(ctx context.Context, uvm *UtilityVM, opts *Options
406419
return nil, errors.Wrap(err, "failed to grant vm access to scratch VHD")
407420
}
408421

422+
if err = vhd.SetVirtualDiskIdentifier(opts.BootFiles.BlockCIMFiles.ScratchVHDPath, *unformattedScratchIdentifier); err != nil {
423+
return nil, fmt.Errorf("process option virtual disk identifier: %w", err)
424+
}
425+
409426
// boot depends on scratch being attached at LUN 0, it MUST ALWAYS remain at LUN 0
410427
doc.VirtualMachine.Devices.Scsi[guestrequest.ScsiControllerGuids[0]].Attachments["0"] = hcsschema.Attachment{
411428
Path: opts.BootFiles.BlockCIMFiles.ScratchVHDPath,

test/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/Microsoft/hcsshim/test
33
go 1.23.0
44

55
require (
6-
github.com/Microsoft/go-winio v0.6.2
6+
github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29
77
github.com/Microsoft/hcsshim v0.13.0
88
github.com/containerd/cgroups/v3 v3.0.5
99
github.com/containerd/containerd/api v1.9.0

test/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/Microsoft/cosesign1go v1.4.0 h1:VdiqzsilEE6t1GQi98I/h0WpVFM7AyMEeyP8u
66
github.com/Microsoft/cosesign1go v1.4.0/go.mod h1:1La/HcGw19rRLhPW0S6u55K6LKfti+GQSgGCtrfhVe8=
77
github.com/Microsoft/didx509go v0.0.3 h1:n/owuFOXVzCEzSyzivMEolKEouBm9G0NrEDgoTekM8A=
88
github.com/Microsoft/didx509go v0.0.3/go.mod h1:wWt+iQsLzn3011+VfESzznLIp/Owhuj7rLF7yLglYbk=
9-
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
10-
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
9+
github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29 h1:0kQAzHq8vLs7Pptv+7TxjdETLf/nIqJpIB4oC6Ba4vY=
10+
github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29/go.mod h1:ZWa7ssZJT30CCDGJ7fk/2SBTq9BIQrrVjrcss0UW2s0=
1111
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
1212
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
1313
github.com/agnivade/levenshtein v1.2.0 h1:U9L4IOT0Y3i0TIlUIDJ7rVUziKi/zPbrJGaFrtYH3SY=

vendor/github.com/Microsoft/go-winio/.golangci.yml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Microsoft/go-winio/backup.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Microsoft/go-winio/backuptar/tar.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Microsoft/go-winio/file.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Microsoft/go-winio/fileinfo.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)