From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by mx.groups.io with SMTP id smtpd.web11.57660.1622553178019267359 for ; Tue, 01 Jun 2021 06:12:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=bpllDtev; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.208.174, mailfrom: gjb@semihalf.com) Received: by mail-lj1-f174.google.com with SMTP id bn21so11851241ljb.1 for ; Tue, 01 Jun 2021 06:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uOT4yCh0O5IqasSXvE258W157Je/vpSrDVhL3i8UOvc=; b=bpllDtevw85pkQ2WpQpYvOR/kyaN+3KHS/0nH7u+WMwZO86hMzGTh1g3xqi1+3NNOA Y6J7kxWrOl9SmTV3irQlNy9Zdh5GnqZCoRwEHI+vML+H7MgMUrRghmgXkzJVFd7lDh7u PhQCAcu57+r/Ecgr8wCaci4okpDR/fa4y+W3AaWOxc6lFyUs5s+Yhc4sgVao7f1J4boC lpMEjCDtovhua6GsUyupBXqIhAl89VIG21PBC77GxYow7TWC396RLd5sPUO9dtl+zDVU v4Mqc+7Bb3Q2o8wMu+R2k04CbRFX9z5okLF3+xmkYk4EYLhz7Hh2dhYHZ7BAGvpoqRso zhIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uOT4yCh0O5IqasSXvE258W157Je/vpSrDVhL3i8UOvc=; b=eTVtnTVlIFxFXAwSJduJ5w0avAkksglclgq8eLPxw2Ybx/a/X0CN6xxcjjEvU6MfVn /v4cFkFR70XH20b93OW3mNzw9gqmMuzik7i+0blQAMv5OWOseTSWc13SlVcr7wNqZ8wY 36/nNhrQj8Ldl9sLDoAxMGa5KB/oznyDUHP/AuC4n7VQYOZTGQfgvj7g+xdw1m9f+kJa UfjI29/0gb6dkrwyv8i+UC/Hw5LOv29c2I2ZmzbY7T8jwIdqbMI+efKq0s9b6tSvaMva Xc2/C5CcBrkAj+MCubGGWmJhHcF16eweq4BlLHY5za4PDv1N77ypPGS1RrD2u74xZLZy Q6HA== X-Gm-Message-State: AOAM531S3i25ooBEd4EaDcC7OCx28e73uoA8a+hjVdwYoVPozwE3beVF MPlAiPE+SI0/S6hVenxdZa5cZXeIvOM/XZYt X-Google-Smtp-Source: ABdhPJzPVYruHPz9Je47CGPUpYHbYodKG0V0iCK9pbtbY22KdljPyTjO60MTR6nDLRYJeGmUjzdsWQ== X-Received: by 2002:a05:651c:2122:: with SMTP id a34mr21102002ljq.286.1622553176056; Tue, 01 Jun 2021 06:12:56 -0700 (PDT) Return-Path: Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id y5sm1681460lfa.148.2021.06.01.06.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jun 2021 06:12:55 -0700 (PDT) From: "Grzegorz Bernacki" To: devel@edk2.groups.io Cc: leif@nuviainc.com, ardb+tianocore@kernel.org, Samer.El-Haj-Mahmoud@arm.com, sunny.Wang@arm.com, mw@semihalf.com, upstream@semihalf.com, jiewen.yao@intel.com, jian.j.wang@intel.com, min.m.xu@intel.com, lersek@redhat.com, Grzegorz Bernacki Subject: [PATCH v2 3/6] SecurityPkg: Add SecureBootDefaultKeysDxe driver Date: Tue, 1 Jun 2021 15:12:26 +0200 Message-Id: <20210601131229.630611-5-gjb@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210601131229.630611-1-gjb@semihalf.com> References: <20210601131229.630611-1-gjb@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This driver initializes default Secure Boot keys and databases based on keys embedded in flash. Signed-off-by: Grzegorz Bernacki --- SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf | 46 +++++++++++++ SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c | 69 ++++++++++++++++++++ SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni | 17 +++++ 3 files changed, 132 insertions(+) create mode 100644 SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf create mode 100644 SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c create mode 100644 SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni diff --git a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf new file mode 100644 index 0000000000..27345eab2e --- /dev/null +++ b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.inf @@ -0,0 +1,46 @@ +## @file +# Initializes Secure Boot default keys +# +# Copyright (c) 2021, ARM Ltd. All rights reserved.
+# Copyright (c) 2021, Semihalf All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SecureBootDefaultKeysDxe + FILE_GUID = C937FCB7-25AC-4376-89A2-4EA8B317DE83 + MODULE_TYPE = DXE_DRIVER + ENTRY_POINT = SecureBootDefaultKeysEntryPoint + +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# +[Sources] + SecureBootDefaultKeysDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + MemoryAllocationLib + UefiDriverEntryPoint + DebugLib + SecureBootVariableLib + +[Guids] + ## SOMETIMES_PRODUCES ## Variable:L"PKDefault" + ## SOMETIMES_PRODUCES ## Variable:L"KEKDefault" + ## SOMETIMES_PRODUCES ## Variable:L"dbDefault" + ## SOMETIMES_PRODUCES ## Variable:L"dbtDefault" + ## SOMETIMES_PRODUCES ## Variable:L"dbxDefault" + gEfiGlobalVariableGuid + +[Depex] + gEfiVariableArchProtocolGuid AND + gEfiVariableWriteArchProtocolGuid + diff --git a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c new file mode 100644 index 0000000000..0928489e15 --- /dev/null +++ b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.c @@ -0,0 +1,69 @@ +/** @file + This driver init default Secure Boot variables + +Copyright (c) 2021, ARM Ltd. All rights reserved.
+Copyright (c) 2021, Semihalf All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + The entry point for SecureBootDefaultKeys driver. + + @param[in] ImageHandle The image handle of the driver. + @param[in] SystemTable The system table. + + @retval EFI_ALREADY_STARTED The driver already exists in system. + @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources. + @retval EFI_SUCCESS All the related protocols are installed on the driver. + @retval Others Fail to get the SecureBootEnable variable. + +**/ +EFI_STATUS +EFIAPI +SecureBootDefaultKeysEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = SecureBootInitPKDefault (); + if (EFI_ERROR (Status)) { + DEBUG((DEBUG_ERROR, "%a: Cannot initialize PKDefault: %r\n", __FUNCTION__, Status)); + return Status; + } + + Status = SecureBootInitKEKDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Cannot initialize KEKDefault: %r\n", __FUNCTION__, Status)); + return Status; + } + Status = SecureBootInitdbDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Cannot initialize dbDefault: %r\n", __FUNCTION__, Status)); + return Status; + } + + Status = SecureBootInitdbtDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: dbtDefault not initialized\n", __FUNCTION__)); + } + + Status = SecureBootInitdbxDefault (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: dbxDefault not initialized\n", __FUNCTION__)); + } + + return Status; +} + diff --git a/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni new file mode 100644 index 0000000000..30f03aee5d --- /dev/null +++ b/SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefaultKeysDxe.uni @@ -0,0 +1,17 @@ +// /** @file +// Provides the capability to intialize Secure Boot default variables +// +// Module which initializes Secure boot default variables. +// +// Copyright (c) 2021, ARM Ltd. All rights reserved.
+// Copyright (c) 2021, Semihalf All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Module which initializes Secure boot default variables" + +#string STR_MODULE_DESCRIPTION #language en-US "This module reads embedded keys and initializes Secure Boot default variables." + -- 2.25.1