From: "Kun Qin" <kuqin12@gmail.com>
To: devel@edk2.groups.io
Cc: Jiewen Yao <jiewen.yao@intel.com>,
Jian J Wang <jian.j.wang@intel.com>, Min Xu <min.m.xu@intel.com>
Subject: [PATCH v2 03/11] SecurityPkg: SecureBootVariableLib: Updated time based payload creator
Date: Mon, 13 Jun 2022 13:39:34 -0700 [thread overview]
Message-ID: <20220613203943.704-4-kuqin12@gmail.com> (raw)
In-Reply-To: <20220613203943.704-1-kuqin12@gmail.com>
From: Kun Qin <kuqin@microsoft.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3909
This change updated the interface of 'CreateTimeBasedPayload' by
requiring the caller to provide a timestamp, instead of relying on time
protocol to be ready during runtime. It intends to extend the library
availability during boot environment.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
---
SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.c | 53 ++++++++++++--------
SecurityPkg/Include/Library/SecureBootVariableLib.h | 9 +++-
SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf | 8 +--
3 files changed, 40 insertions(+), 30 deletions(-)
diff --git a/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.c b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.c
index e0d137666e0e..3b33a356aba3 100644
--- a/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.c
+++ b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.c
@@ -6,8 +6,10 @@
(C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2021, ARM Ltd. All rights reserved.<BR>
Copyright (c) 2021, Semihalf All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+#include <Uefi.h>
#include <Guid/GlobalVariable.h>
#include <Guid/AuthenticatedVariableFormat.h>
#include <Guid/ImageAuthentication.h>
@@ -21,6 +23,21 @@
#include <Library/SecureBootVariableLib.h>
#include "Library/DxeServicesLib.h"
+// This time can be used when deleting variables, as it should be greater than any variable time.
+EFI_TIME mMaxTimestamp = {
+ 0xFFFF, // Year
+ 0xFF, // Month
+ 0xFF, // Day
+ 0xFF, // Hour
+ 0xFF, // Minute
+ 0xFF, // Second
+ 0x00,
+ 0x00000000, // Nanosecond
+ 0,
+ 0,
+ 0x00
+};
+
/** Creates EFI Signature List structure.
@param[in] Data A pointer to signature data.
@@ -118,7 +135,7 @@ ConcatenateSigList (
@param[in] KeyFileGuid A pointer to to the FFS filename GUID
@param[out] SigListsSize A pointer to size of signature list
- @param[out] SigListOut a pointer to a callee-allocated buffer with signature lists
+ @param[out] SigListsOut a pointer to a callee-allocated buffer with signature lists
@retval EFI_SUCCESS Create time based payload successfully.
@retval EFI_NOT_FOUND Section with key has not been found.
@@ -210,28 +227,30 @@ SecureBootFetchData (
pointer to NULL to wrap an empty payload.
On output, Pointer to the new payload date buffer allocated from pool,
it's caller's responsibility to free the memory when finish using it.
+ @param[in] Time Pointer to time information to created time based payload.
@retval EFI_SUCCESS Create time based payload successfully.
@retval EFI_OUT_OF_RESOURCES There are not enough memory resources to create time based payload.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
@retval Others Unexpected error happens.
-**/
+--*/
EFI_STATUS
+EFIAPI
CreateTimeBasedPayload (
- IN OUT UINTN *DataSize,
- IN OUT UINT8 **Data
+ IN OUT UINTN *DataSize,
+ IN OUT UINT8 **Data,
+ IN EFI_TIME *Time
)
{
- EFI_STATUS Status;
UINT8 *NewData;
UINT8 *Payload;
UINTN PayloadSize;
EFI_VARIABLE_AUTHENTICATION_2 *DescriptorData;
UINTN DescriptorSize;
- EFI_TIME Time;
- if ((Data == NULL) || (DataSize == NULL)) {
+ if ((Data == NULL) || (DataSize == NULL) || (Time == NULL)) {
+ DEBUG ((DEBUG_ERROR, "%a(), invalid arg\n", __FUNCTION__));
return EFI_INVALID_PARAMETER;
}
@@ -247,6 +266,7 @@ CreateTimeBasedPayload (
DescriptorSize = OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo) + OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData);
NewData = (UINT8 *)AllocateZeroPool (DescriptorSize + PayloadSize);
if (NewData == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a() Out of resources.\n", __FUNCTION__));
return EFI_OUT_OF_RESOURCES;
}
@@ -256,19 +276,7 @@ CreateTimeBasedPayload (
DescriptorData = (EFI_VARIABLE_AUTHENTICATION_2 *)(NewData);
- ZeroMem (&Time, sizeof (EFI_TIME));
- Status = gRT->GetTime (&Time, NULL);
- if (EFI_ERROR (Status)) {
- FreePool (NewData);
- return Status;
- }
-
- Time.Pad1 = 0;
- Time.Nanosecond = 0;
- Time.TimeZone = 0;
- Time.Daylight = 0;
- Time.Pad2 = 0;
- CopyMem (&DescriptorData->TimeStamp, &Time, sizeof (EFI_TIME));
+ CopyMem (&DescriptorData->TimeStamp, Time, sizeof (EFI_TIME));
DescriptorData->AuthInfo.Hdr.dwLength = OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData);
DescriptorData->AuthInfo.Hdr.wRevision = 0x0200;
@@ -277,6 +285,7 @@ CreateTimeBasedPayload (
if (Payload != NULL) {
FreePool (Payload);
+ Payload = NULL;
}
*DataSize = DescriptorSize + PayloadSize;
@@ -296,6 +305,7 @@ CreateTimeBasedPayload (
**/
EFI_STATUS
+EFIAPI
DeleteVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid
@@ -319,7 +329,7 @@ DeleteVariable (
Attr = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
- Status = CreateTimeBasedPayload (&DataSize, &Data);
+ Status = CreateTimeBasedPayload (&DataSize, &Data, &mMaxTimestamp);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Fail to create time-based data payload: %r", Status));
return Status;
@@ -351,6 +361,7 @@ DeleteVariable (
**/
EFI_STATUS
+EFIAPI
SetSecureBootMode (
IN UINT8 SecureBootMode
)
diff --git a/SecurityPkg/Include/Library/SecureBootVariableLib.h b/SecurityPkg/Include/Library/SecureBootVariableLib.h
index 7b7afd9cde7c..9f2d41220b70 100644
--- a/SecurityPkg/Include/Library/SecureBootVariableLib.h
+++ b/SecurityPkg/Include/Library/SecureBootVariableLib.h
@@ -6,6 +6,7 @@ Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2021, ARM Ltd. All rights reserved.<BR>
Copyright (c) 2021, Semihalf All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -24,6 +25,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
--*/
EFI_STATUS
+EFIAPI
SetSecureBootMode (
IN UINT8 SecureBootMode
);
@@ -73,6 +75,7 @@ SecureBootFetchData (
pointer to NULL to wrap an empty payload.
On output, Pointer to the new payload date buffer allocated from pool,
it's caller's responsibility to free the memory when finish using it.
+ @param[in] Time Pointer to time information to created time based payload.
@retval EFI_SUCCESS Create time based payload successfully.
@retval EFI_OUT_OF_RESOURCES There are not enough memory resources to create time based payload.
@@ -81,9 +84,11 @@ SecureBootFetchData (
--*/
EFI_STATUS
+EFIAPI
CreateTimeBasedPayload (
- IN OUT UINTN *DataSize,
- IN OUT UINT8 **Data
+ IN OUT UINTN *DataSize,
+ IN OUT UINT8 **Data,
+ IN EFI_TIME *Time
);
/**
diff --git a/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
index ed7af3dd9cd5..87db5a258021 100644
--- a/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
+++ b/SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
@@ -4,6 +4,7 @@
#
# Copyright (c) 2021, ARM Ltd. All rights reserved.<BR>
# Copyright (c) 2021, Semihalf All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -68,12 +69,5 @@ [Guids]
## PRODUCES ## Variable:L"CustomMode"
gEfiCustomModeEnableGuid
- gEfiCertTypeRsa2048Sha256Guid ## CONSUMES
gEfiCertX509Guid ## CONSUMES
gEfiCertPkcs7Guid ## CONSUMES
-
- gDefaultPKFileGuid
- gDefaultKEKFileGuid
- gDefaultdbFileGuid
- gDefaultdbxFileGuid
- gDefaultdbtFileGuid
--
2.35.1.windows.2
next prev parent reply other threads:[~2022-06-13 20:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-13 20:39 [PATCH v2 00/11] Enhance Secure Boot Variable Libraries Kun Qin
2022-06-13 20:39 ` [PATCH v2 01/11] SecurityPkg: UefiSecureBoot: Definitions of cert and payload structures Kun Qin
2022-06-13 20:39 ` [PATCH v2 02/11] SecurityPkg: PlatformPKProtectionLib: Added PK protection interface Kun Qin
2022-06-13 20:39 ` Kun Qin [this message]
2022-06-13 20:39 ` [PATCH v2 04/11] SecurityPkg: SecureBootVariableLib: Updated signature list creator Kun Qin
2022-06-13 20:39 ` [PATCH v2 05/11] SecurityPkg: SecureBootVariableLib: Added newly supported interfaces Kun Qin
2022-06-13 20:39 ` [PATCH v2 06/11] SecurityPkg: SecureBootVariableProvisionLib: Updated implementation Kun Qin
2022-06-13 20:39 ` [PATCH v2 07/11] SecurityPkg: Secure Boot Drivers: Added common header files Kun Qin
2022-06-13 20:39 ` [PATCH v2 08/11] SecurityPkg: SecureBootConfigDxe: Updated invocation pattern Kun Qin
2022-06-13 20:39 ` [PATCH v2 09/11] SecurityPkg: SecureBootVariableLib: Added unit tests Kun Qin
2022-06-13 20:39 ` [PATCH v2 10/11] OvmfPkg: Pipeline: Resolve SecureBootVariableLib dependency Kun Qin
2022-06-13 20:39 ` [PATCH v2 11/11] EmulatorPkg: " Kun Qin
2022-06-24 9:08 ` Ni, Ray
2022-06-30 19:44 ` [edk2-devel] [PATCH v2 00/11] Enhance Secure Boot Variable Libraries Michael Kubacki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220613203943.704-4-kuqin12@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox