Skip to content

Commit c9da599

Browse files
committed
preinstall: Reverse the logic of the *SupportRequired flags.
Every other flag works in reverse and has to be specified in order to permit an error condition as ok. Reverse the logic in these flags so that they also have to be specified in order to permit support for specific PCRs to be missing.
1 parent 7a23cc5 commit c9da599

File tree

5 files changed

+297
-267
lines changed

5 files changed

+297
-267
lines changed

efi/preinstall/checks.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,46 @@ import (
3333
type CheckFlags int
3434

3535
const (
36-
// PlatformFirmwareProfileSupportRequired indicates that support for
36+
// PermitNoPlatformFirmwareProfileSupport indicates that support for
3737
// [secboot_efi.WithPlatformFirmwareProfile] to generate profiles for
38-
// PCR 0 is not optional.
39-
PlatformFirmwareProfileSupportRequired CheckFlags = 1 << iota
38+
// PCR 0 is optional.
39+
PermitNoPlatformFirmwareProfileSupport CheckFlags = 1 << iota
4040

41-
// PlatformConfigProfileSupportRequired indicates that support for
41+
// PermitNoPlatformConfigProfileSupportd indicates that support for
4242
// generating profiles for PCR 1 is not optional.
4343
//
44-
// Note that this currently is not supported by the
45-
// [github.com/snapcore/secboot/efi] package.
46-
PlatformConfigProfileSupportRequired
44+
// Note that this is currently mandatory because this profile is not
45+
// supported by the [github.com/snapcore/secboot/efi] package.
46+
PermitNoPlatformConfigProfileSupport
4747

48-
// DriversAndAppsProfileSupportRequired indicates that support for
48+
// PermitNoDriversAndAppsProfileSupport indicates that support for
4949
// [secboot_efi.WithDriversAndAppsProfile] to generate profiles for
50-
// PCR 2 is not optional.
51-
DriversAndAppsProfileSupportRequired
50+
// PCR 2 is optional.
51+
PermitNoDriversAndAppsProfileSupport
5252

53-
// DriversAndAppsConfigProfileSupportRequired indicates that support
54-
// for generating profiles for PCR 3 is not optional.
53+
// PermitNoDriversAndAppsConfigProfileSupport indicates that support
54+
// for generating profiles for PCR 3 is optional.
5555
//
56-
// Note that this currently is not supported by the
57-
// [github.com/snapcore/secboot/efi] package.
58-
DriversAndAppsConfigProfileSupportRequired
56+
// Note that this is currently mandatory because this profile is not
57+
// supported by the [github.com/snapcore/secboot/efi] package.
58+
PermitNoDriversAndAppsConfigProfileSupport
5959

60-
// BootManagerCodeProfileSupportRequired indicates that support for
60+
// PermitNoBootManagerCodeProfileSupport indicates that support for
6161
// [secboot_efi.WithBootManagerCodeProfile] to generate profiles for
62-
// PCR 4 is not optional.
63-
BootManagerCodeProfileSupportRequired
62+
// PCR 4 is optional.
63+
PermitNoBootManagerCodeProfileSupport
6464

65-
// BootManagerConfigProfileSupportRequired indicates that support
66-
// for generating profiles for PCR 5 is not optional.
65+
// PermitNoBootManagerConfigProfileSupport indicates that support
66+
// for generating profiles for PCR 5 is optional.
6767
//
68-
// Note that this currently is not supported by the
69-
// [github.com/snapcore/secboot/efi] package.
70-
BootManagerConfigProfileSupportRequired
68+
// Note that this is currently mandatory because this profile is not
69+
// supported by the [github.com/snapcore/secboot/efi] package.
70+
PermitNoBootManagerConfigProfileSupport
7171

72-
// SecureBootPolicyProfileSupportRequired indicates that support for
72+
// PermitNoSecureBootPolicyProfileSupport indicates that support for
7373
// [secboot_efi.WithSecureBootPolicyProfile] to generate profiles for
74-
// PCR 7 is not optional.
75-
SecureBootPolicyProfileSupportRequired
74+
// PCR 7 is optional.
75+
PermitNoSecureBootPolicyProfileSupport
7676

7777
// PermitWeakPCRBanks permits selecting a weak PCR algorithm if
7878
// no other valid ones are available. This currently only includes
@@ -234,25 +234,25 @@ func RunChecks(ctx context.Context, flags CheckFlags, loadedImages []secboot_efi
234234
// checkFirmwareLogAndChoosePCRBank will return an error if any of these PCRs
235235
// are inconsistent with the reconstructed log.
236236
var mandatoryPcrs tpm2.HandleList
237-
if flags&PlatformFirmwareProfileSupportRequired > 0 {
237+
if flags&PermitNoPlatformFirmwareProfileSupport == 0 {
238238
mandatoryPcrs = append(mandatoryPcrs, internal_efi.PlatformFirmwarePCR)
239239
}
240-
if flags&PlatformConfigProfileSupportRequired > 0 {
240+
if flags&PermitNoPlatformConfigProfileSupport == 0 {
241241
mandatoryPcrs = append(mandatoryPcrs, internal_efi.PlatformConfigPCR)
242242
}
243-
if flags&DriversAndAppsProfileSupportRequired > 0 {
243+
if flags&PermitNoDriversAndAppsProfileSupport == 0 {
244244
mandatoryPcrs = append(mandatoryPcrs, internal_efi.DriversAndAppsPCR)
245245
}
246-
if flags&DriversAndAppsConfigProfileSupportRequired > 0 {
246+
if flags&PermitNoDriversAndAppsConfigProfileSupport == 0 {
247247
mandatoryPcrs = append(mandatoryPcrs, internal_efi.DriversAndAppsConfigPCR)
248248
}
249-
if flags&BootManagerCodeProfileSupportRequired > 0 {
249+
if flags&PermitNoBootManagerCodeProfileSupport == 0 {
250250
mandatoryPcrs = append(mandatoryPcrs, internal_efi.BootManagerCodePCR)
251251
}
252-
if flags&BootManagerConfigProfileSupportRequired > 0 {
252+
if flags&PermitNoBootManagerConfigProfileSupport == 0 {
253253
mandatoryPcrs = append(mandatoryPcrs, internal_efi.BootManagerConfigPCR)
254254
}
255-
if flags&SecureBootPolicyProfileSupportRequired > 0 {
255+
if flags&PermitNoSecureBootPolicyProfileSupport == 0 {
256256
mandatoryPcrs = append(mandatoryPcrs, internal_efi.SecureBootPolicyPCR)
257257
}
258258

@@ -368,7 +368,7 @@ func RunChecks(ctx context.Context, flags CheckFlags, loadedImages []secboot_efi
368368
// PCR1 profiles are not supported yet.
369369
err := &PlatformConfigPCRError{errors.New("generating profiles for PCR 1 is not supported yet")}
370370
switch {
371-
case flags&PlatformConfigProfileSupportRequired > 0:
371+
case flags&PermitNoPlatformConfigProfileSupport == 0:
372372
deferredErrs = append(deferredErrs, err)
373373
default:
374374
result.Flags |= NoPlatformConfigProfileSupport
@@ -392,7 +392,7 @@ func RunChecks(ctx context.Context, flags CheckFlags, loadedImages []secboot_efi
392392
// PCR3 profiles are not supported yet
393393
err := &DriversAndAppsConfigPCRError{errors.New("generating profiles for PCR 3 is not supported yet")}
394394
switch {
395-
case flags&DriversAndAppsConfigProfileSupportRequired > 0:
395+
case flags&PermitNoDriversAndAppsConfigProfileSupport == 0:
396396
deferredErrs = append(deferredErrs, err)
397397
default:
398398
result.Flags |= NoDriversAndAppsConfigProfileSupport
@@ -405,7 +405,7 @@ func RunChecks(ctx context.Context, flags CheckFlags, loadedImages []secboot_efi
405405
// the reconstructed log value.
406406
pcr4Result, err := checkBootManagerCodeMeasurements(ctx, runChecksEnv, log, result.PCRAlg, loadedImages)
407407
switch {
408-
case err != nil && flags&BootManagerCodeProfileSupportRequired > 0:
408+
case err != nil && flags&PermitNoBootManagerCodeProfileSupport == 0:
409409
deferredErrs = append(deferredErrs, &BootManagerCodePCRError{err})
410410
case err != nil:
411411
result.Flags |= NoBootManagerCodeProfileSupport
@@ -441,7 +441,7 @@ func RunChecks(ctx context.Context, flags CheckFlags, loadedImages []secboot_efi
441441
// PCR5 profiles are not supported yet
442442
err := &BootManagerConfigPCRError{errors.New("generating profiles for PCR 5 is not supported yet")}
443443
switch {
444-
case flags&BootManagerConfigProfileSupportRequired > 0:
444+
case flags&PermitNoBootManagerConfigProfileSupport == 0:
445445
deferredErrs = append(deferredErrs, err)
446446
default:
447447
result.Flags |= NoBootManagerConfigProfileSupport
@@ -458,7 +458,7 @@ func RunChecks(ctx context.Context, flags CheckFlags, loadedImages []secboot_efi
458458
}
459459
pcr7Result, err := checkSecureBootPolicyMeasurementsAndObtainAuthorities(ctx, runChecksEnv, log, result.PCRAlg, iblImage)
460460
switch {
461-
case err != nil && flags&SecureBootPolicyProfileSupportRequired > 0:
461+
case err != nil && flags&PermitNoSecureBootPolicyProfileSupport == 0:
462462
deferredErrs = append(deferredErrs, &SecureBootPolicyPCRError{err})
463463
case err != nil:
464464
result.Flags |= NoSecureBootPolicyProfileSupport

efi/preinstall/checks_context.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,19 @@ type RunChecksContext struct {
154154
// API [RunChecksContext] should be executed again with the new set of flags, should the user wish to
155155
// change them. In this case, the caller should pass the PostInstallChecks flag as an initial flag.
156156
//
157-
// There is no need for the caller to supply any of these *SupportRequired flags as the initial flags,
158-
// and this may have the effect of limiting the number of devices which pass the checks.
157+
// There is no need for the caller to specify any of the PermitNo*ProfileSupport flags as the initial
158+
// flags, and they will be ignored anyway.
159159
func NewRunChecksContext(initialFlags CheckFlags, loadedImages []secboot_efi.Image, profileOpts PCRProfileOptionsFlags) *RunChecksContext {
160+
defaultFlags := PermitNoPlatformFirmwareProfileSupport |
161+
PermitNoPlatformConfigProfileSupport |
162+
PermitNoDriversAndAppsProfileSupport |
163+
PermitNoDriversAndAppsConfigProfileSupport |
164+
PermitNoBootManagerCodeProfileSupport |
165+
PermitNoBootManagerConfigProfileSupport |
166+
PermitNoSecureBootPolicyProfileSupport
160167
return &RunChecksContext{
161168
env: runChecksEnv,
162-
flags: initialFlags,
169+
flags: initialFlags | defaultFlags,
163170
loadedImages: loadedImages,
164171
profileOpts: profileOpts,
165172
// Populate actions that are always available or available by default
@@ -560,19 +567,19 @@ func (c *RunChecksContext) Run(ctx context.Context, action Action, args ...any)
560567
for _, pcr := range requiredPCRsErr.PCRs {
561568
switch pcr {
562569
case 0:
563-
c.flags |= PlatformFirmwareProfileSupportRequired
570+
c.flags &^= PermitNoPlatformFirmwareProfileSupport
564571
case 1:
565-
c.flags |= PlatformConfigProfileSupportRequired
572+
c.flags &^= PermitNoPlatformConfigProfileSupport
566573
case 2:
567-
c.flags |= DriversAndAppsProfileSupportRequired
574+
c.flags &^= PermitNoDriversAndAppsProfileSupport
568575
case 3:
569-
c.flags |= DriversAndAppsConfigProfileSupportRequired
576+
c.flags &^= PermitNoDriversAndAppsConfigProfileSupport
570577
case 4:
571-
c.flags |= BootManagerCodeProfileSupportRequired
578+
c.flags &^= PermitNoBootManagerCodeProfileSupport
572579
case 5:
573-
c.flags |= BootManagerConfigProfileSupportRequired
580+
c.flags &^= PermitNoBootManagerConfigProfileSupport
574581
case 7:
575-
c.flags |= SecureBootPolicyProfileSupportRequired
582+
c.flags &^= PermitNoSecureBootPolicyProfileSupport
576583
}
577584
}
578585
}

0 commit comments

Comments
 (0)