Skip to content

Commit 38c6693

Browse files
committed
Fix panic in HasConfidentialPolicy for LCOW.
`HasConfidentialPolicy` assumed that the UVM creation options saved in the UtilityVM struct will always be of type `OptionsWCOW` & `OptionsLCOW`. However, for LCOW we store the options as a pointer (i.e type `*OptionsLCOW`) whereas for WCOW we store the options as a value (i.e type `OptionsWCOW`). This caused the `HasConfidentialPolicy` method to panic when testing the policy for LCOW UtilityVM types. Easy fix would be to just update the switch case to `*OptionsLCOW` instead of `OptionsLCOW`, but it seems better to use the same type (create options pointer) for both LCOW & WCOW to avoid such issues in future. In the long run we also want to refactor this and have a common set of methods/types for handling confidential options for LCOW & WCOW. Signed-off-by: Amit Barve <[email protected]>
1 parent 6efa5fd commit 38c6693

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

internal/uvm/create_wcow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func CreateWCOW(ctx context.Context, opts *OptionsWCOW) (_ *UtilityVM, err error
505505
devicesPhysicallyBacked: opts.FullyPhysicallyBacked,
506506
vsmbNoDirectMap: opts.NoDirectMap,
507507
noWritableFileShares: opts.NoWritableFileShares,
508-
createOpts: *opts,
508+
createOpts: opts,
509509
blockCIMMounts: make(map[string]*UVMMountedBlockCIMs),
510510
}
511511

internal/uvm/security_policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ func (uvm *UtilityVM) InjectPolicyFragment(ctx context.Context, fragment *ctrdta
167167
// returns if this instance of the UtilityVM is created with confidential policy
168168
func (uvm *UtilityVM) HasConfidentialPolicy() bool {
169169
switch opts := uvm.createOpts.(type) {
170-
case OptionsWCOW:
170+
case *OptionsWCOW:
171171
return opts.SecurityPolicyEnabled
172-
case OptionsLCOW:
172+
case *OptionsLCOW:
173173
return opts.SecurityPolicyEnabled
174174
default:
175175
panic("unexpected options type")

internal/uvm/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ func (uvm *UtilityVM) Start(ctx context.Context) (err error) {
339339

340340
if uvm.HasConfidentialPolicy() && uvm.OS() == "windows" {
341341
copts := []WCOWConfidentialUVMOpt{
342-
WithWCOWSecurityPolicy(uvm.createOpts.(OptionsWCOW).SecurityPolicy),
343-
WithWCOWSecurityPolicyEnforcer(uvm.createOpts.(OptionsWCOW).SecurityPolicyEnforcer),
342+
WithWCOWSecurityPolicy(uvm.createOpts.(*OptionsWCOW).SecurityPolicy),
343+
WithWCOWSecurityPolicyEnforcer(uvm.createOpts.(*OptionsWCOW).SecurityPolicyEnforcer),
344344
}
345345
if err := uvm.SetWCOWConfidentialUVMOptions(ctx, copts...); err != nil {
346346
return err

0 commit comments

Comments
 (0)