Skip to content

Commit ba6745f

Browse files
committed
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe: Add SV Boot state
Signed-off-by: Michał Żygowski <[email protected]>
1 parent ce2df1d commit ba6745f

File tree

4 files changed

+132
-4
lines changed

4 files changed

+132
-4
lines changed

SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfig.vfr

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ formset
8383
flags = INTERACTIVE | RESET_REQUIRED,
8484
endcheckbox;
8585

86+
// Hidden checkbox for provisioned state, to be used in callback
87+
// whe nefautl settigns are restored.
88+
suppressif TRUE;
89+
checkbox varid = SECUREBOOT_CONFIGURATION.SvBootProvisioned,
90+
questionid = KEY_SOVEREIGN_BOOT_PROVISIONED,
91+
prompt = STRING_TOKEN(STR_SOVEREIGN_BOOT_PRIVISIONED_PROMPT),
92+
help = STRING_TOKEN(STR_SOVEREIGN_BOOT_PRIVISIONED_HELP),
93+
flags = INTERACTIVE | RESET_REQUIRED,
94+
endcheckbox;
95+
endif;
96+
97+
text
98+
help = STRING_TOKEN(STR_SOVEREIGN_BOOT_STATE_HELP),
99+
text = STRING_TOKEN(STR_SOVEREIGN_BOOT_STATE_PROMPT),
100+
text = STRING_TOKEN(STR_SOVEREIGN_BOOT_STATE_CONTENT);
101+
86102
disableif ideqval SECUREBOOT_CONFIGURATION.SvBootEnable == 0;
87103
subtitle text = STRING_TOKEN(STR_NULL);
88104
//

SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ HII_VENDOR_DEVICE_PATH mSecureBootHiiVendorDevicePath = {
5959
};
6060

6161
BOOLEAN mIsEnterSecureBootForm = FALSE;
62+
BOOLEAN mResetSvBootState = FALSE;
6263

6364
//
6465
// OID ASN.1 Value for Hash Algorithms
@@ -301,7 +302,7 @@ SaveSecureBootVariable (
301302
/**
302303
Set Sovereign Boot configuration into variable space.
303304
304-
@param[in] SvBootEnable The satte of Sovereign Boot.
305+
@param[in] SvBootEnable The state of Sovereign Boot.
305306
306307
@retval EFI_SUCCESS The operation is finished successfully.
307308
@retval Others Other errors as indicated.
@@ -350,6 +351,53 @@ SaveSovereignBootVariable (
350351
return Status;
351352
}
352353

354+
/**
355+
Resets Sovereign Boot configuration and saves it into variable space.
356+
357+
@retval EFI_SUCCESS The operation is finished successfully.
358+
@retval Others Other errors as indicated.
359+
360+
**/
361+
EFI_STATUS
362+
ResetSovereignBootState (
363+
SECUREBOOT_CONFIG_PRIVATE_DATA *Private
364+
)
365+
{
366+
SOVEREIGN_BOOT_WIZARD_NV_CONFIG SvBootConfig;
367+
EFI_STATUS Status;
368+
UINT32 Attrs;
369+
UINTN VarSize;
370+
371+
VarSize = sizeof(SOVEREIGN_BOOT_WIZARD_NV_CONFIG);
372+
373+
Status = gRT->GetVariable (
374+
SV_BOOT_CONFIG_VAR,
375+
&gSovereignBootWizardFormSetGuid,
376+
&Attrs,
377+
&VarSize,
378+
&SvBootConfig
379+
);
380+
381+
if (EFI_ERROR (Status) ||
382+
Attrs != (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS) ||
383+
VarSize != sizeof(SOVEREIGN_BOOT_WIZARD_NV_CONFIG)
384+
) {
385+
SvBootConfig.SvBootEnabled = FixedPcdGetBool (PcdSovereignBootDefaultState);
386+
}
387+
388+
SvBootConfig.SvBootProvisioned = FALSE;
389+
390+
Status = gRT->SetVariable (
391+
SV_BOOT_CONFIG_VAR,
392+
&gSovereignBootWizardFormSetGuid,
393+
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
394+
sizeof (SOVEREIGN_BOOT_WIZARD_NV_CONFIG),
395+
&SvBootConfig
396+
);
397+
398+
return Status;
399+
}
400+
353401
/**
354402
This code checks if the encode type and key strength of X.509
355403
certificate is qualified.
@@ -3528,6 +3576,12 @@ SecureBootExtractConfigFromVariable (
35283576
ConfigData->SvBootProvisioned = SvBootConfig->SvBootProvisioned;
35293577
FreePool (SvBootConfig);
35303578
}
3579+
3580+
HiiSetString (
3581+
Private->HiiHandle,
3582+
STRING_TOKEN (STR_SOVEREIGN_BOOT_STATE_CONTENT),
3583+
ConfigData->SvBootProvisioned ? L"Yes" : L"No",
3584+
NULL);
35313585
}
35323586

35333587
if (SecureBootEnable != NULL) {
@@ -4989,6 +5043,21 @@ SecureBootCallback (
49895043
goto EXIT;
49905044
}
49915045

5046+
if (Action == EFI_BROWSER_ACTION_SUBMITTED) {
5047+
Status = EFI_UNSUPPORTED;
5048+
if (QuestionId == KEY_SOVEREIGN_BOOT_PROVISIONED) {
5049+
Status = EFI_SUCCESS;
5050+
if (mResetSvBootState && !Value->b) {
5051+
Status = ResetSovereignBootState (Private);
5052+
if (GetBrowserDataResult) {
5053+
SecureBootExtractConfigFromVariable (Private, IfrNvData);
5054+
}
5055+
mResetSvBootState = FALSE;
5056+
}
5057+
}
5058+
goto EXIT;
5059+
}
5060+
49925061
if ((Action != EFI_BROWSER_ACTION_CHANGED) &&
49935062
(Action != EFI_BROWSER_ACTION_CHANGING) &&
49945063
(Action != EFI_BROWSER_ACTION_FORM_CLOSE) &&
@@ -5547,6 +5616,16 @@ SecureBootCallback (
55475616
Status = KeyEnrollReset ();
55485617
}
55495618

5619+
if (EFI_ERROR (Status)) {
5620+
return Status;
5621+
}
5622+
5623+
// Resetting the keys need to reset the Sovereign Boot state
5624+
// as we will no longer have the trusted keys in db
5625+
if (FixedPcdGetBool (PcdSovereignBootEnabled)) {
5626+
Status = ResetSovereignBootState (Private);
5627+
}
5628+
55505629
//
55515630
// Update secure boot strings after key reset
55525631
//
@@ -5573,6 +5652,17 @@ SecureBootCallback (
55735652
if (UserSelection == EfiHiiPopupSelectionYes) {
55745653
Status = KeyEraseAll ();
55755654
}
5655+
5656+
if (EFI_ERROR (Status)) {
5657+
return Status;
5658+
}
5659+
5660+
// Erasing the keys need to reset the Sovereign Boot state
5661+
// as we will no longer have the trusted keys in db
5662+
if (FixedPcdGetBool (PcdSovereignBootEnabled)) {
5663+
Status = ResetSovereignBootState (Private);
5664+
}
5665+
55765666
//
55775667
// Update secure boot strings after key reset
55785668
//
@@ -5589,12 +5679,19 @@ SecureBootCallback (
55895679
// If disabling, we need to restore Secure Boot keys
55905680
if (!Value->b) {
55915681
Status = KeyEnrollReset ();
5592-
5682+
if (EFI_ERROR (Status)) {
5683+
break;
5684+
}
5685+
// Reset the Sovereign Boot provisioning state
5686+
Status = ResetSovereignBootState (Private);
5687+
if (EFI_ERROR (Status)) {
5688+
break;
5689+
}
55935690
//
55945691
// Update secure boot strings after key reset
55955692
//
5596-
if (Status == EFI_SUCCESS) {
5597-
Status = UpdateSecureBootString (Private);
5693+
Status = UpdateSecureBootString (Private);
5694+
if (GetBrowserDataResult) {
55985695
SecureBootExtractConfigFromVariable (Private, IfrNvData);
55995696
}
56005697
}
@@ -5647,6 +5744,13 @@ SecureBootCallback (
56475744
}
56485745
break;
56495746
}
5747+
case KEY_SOVEREIGN_BOOT_PROVISIONED:
5748+
{
5749+
Status = EFI_SUCCESS;
5750+
Value->b = FALSE;
5751+
mResetSvBootState = TRUE;
5752+
break;
5753+
}
56505754
default:
56515755
break;
56525756
}

SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigNvData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
7777

7878
#define KEY_SOVEREIGN_BOOT_ENABLE 0x1120
7979
#define KEY_LAUNCH_SOVEREIGN_BOOT_WIZARD 0x1121
80+
#define KEY_SOVEREIGN_BOOT_PROVISIONED 0x1122
8081

8182
#define LABEL_KEK_DELETE 0x1200
8283
#define LABEL_DB_DELETE 0x1201

SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigStrings.uni

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
168168

169169
#string STR_LAUNCH_SOVEREIGN_BOOT_WIZARD_HELP #language en-US "Manually invoke Sovereign Boot Wizard to modify/augment the Sovereign Boot settings."
170170
#string STR_LAUNCH_SOVEREIGN_BOOT_WIZARD_PROMPT #language en-US "> Launch Sovereign Boot Wizard"
171+
172+
#string STR_SOVEREIGN_BOOT_PRIVISIONED_HELP #language en-US "Sovereign Boot provisioning state"
173+
#string STR_SOVEREIGN_BOOT_PRIVISIONED_PROMPT #language en-US "Sovereign Boot Provisioned"
174+
175+
#string STR_SOVEREIGN_BOOT_STATE_HELP #language en-US "Sovereign Boot provisioning state"
176+
#string STR_SOVEREIGN_BOOT_STATE_PROMPT #language en-US "Sovereign Boot Provisioned"
177+
#string STR_SOVEREIGN_BOOT_STATE_CONTENT #language en-US "Unknown"

0 commit comments

Comments
 (0)