From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by mx.groups.io with SMTP id smtpd.web08.27554.1623663831594854818 for ; Mon, 14 Jun 2021 02:43:52 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=XnSvEH0f; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.208.170, mailfrom: gjb@semihalf.com) Received: by mail-lj1-f170.google.com with SMTP id x14so19275210ljp.7 for ; Mon, 14 Jun 2021 02:43:51 -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=/Lnw88+cqkklSMOsWsbBSfkbIRrjdsFjGpSmCZJa850=; b=XnSvEH0fL7z127ySwWnB1eKjKe0S8+8qjQzbRl2yZE0DsJPvkP6EfVWL4cBVJY06Uc 7LaTvLgf6IF1A70DSY8k0ZwRVrPN+8BrM96HI81TbjtVVquYSFsIi543nVjLnCLh00Ww nfgOwGcOEF+q5fulwgtYus39el6MkT6ZMxmZ0XmhafwPZQRcP40qQaiLkGcCTs+ioqqx jinnE3KBCr4r7uqulDCXdZrrWx6qdlS2rGaoi6rw7jhdsD21TMKYiaAd1bdOBAsT+Swz nX+LB78iB1QyyseIcJzTexzNhjC5rBMJPQEiBaNDiZtSt0ef/gtwhqF6U9kMy6vUQayn XxzQ== 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=/Lnw88+cqkklSMOsWsbBSfkbIRrjdsFjGpSmCZJa850=; b=MFRyGmIUEwbaRUsiQiS4LkxOpZf7PA5xtVFP1ox2j8ByVz3/cVr27DaRp2L2hC7Kdy 0OkRhIObPGYavmihoXNkWsEYuPNeorXz/Uo3lvx7QE9JQ7E0jzkP9N+/jsuG8sUufojj I0+dF8rzy+Svztx3kewHlgE+CR51mL38KFOWiX627ioR3XmqxJ76ukyrA58xBIezqL1j sYmMkcTJHkg1WXhyzd00SEydZNlUFwYLXewuMHjAI6M01wI4Ngbo7pjlmUZKy3OCvjn3 7cwKrqQcGbet5hc7aCLD9GYKeX4P35RKTBGeVwrVOPwJ4fXkL6qzqA5+1bbn6M0KWWTx V0IQ== X-Gm-Message-State: AOAM533ObagdekmlSFIJ4yywVt5cYTJHlRwRPCm2fX7VSNg4jMzNQKpO Y3lgz6aTG0AHlJ2YOssCCxHM9xEZzBQwKQQc X-Google-Smtp-Source: ABdhPJzhnABvBlugGKKFmFIpQj89aeEVJc8mSCCSWWOJLsZRDOgjr+6kHAK4XdJmjmNaRf2t26cFdg== X-Received: by 2002:a2e:9788:: with SMTP id y8mr12220162lji.100.1623663829640; Mon, 14 Jun 2021 02:43:49 -0700 (PDT) Return-Path: Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id c32sm367777lfv.30.2021.06.14.02.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 02:43:49 -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, sami.mujawar@arm.com, afish@apple.com, ray.ni@intel.com, jordan.l.justen@intel.com, rebecca@bsdio.com, grehan@freebsd.org, thomas.abraham@arm.com, chasel.chiu@intel.com, nathaniel.l.desimone@intel.com, gaoliming@byosoft.com.cn, eric.dong@intel.com, michael.d.kinney@intel.com, zailiang.sun@intel.com, yi.qian@intel.com, graeme@nuviainc.com, rad@semihalf.com, pete@akeo.ie, Grzegorz Bernacki Subject: [PATCH v3 8/8] MdeModulePkg: Use SecureBootVariableLib in PlatformVarCleanupLib. Date: Mon, 14 Jun 2021 11:43:08 +0200 Message-Id: <20210614094308.2314345-11-gjb@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210614094308.2314345-1-gjb@semihalf.com> References: <20210614094308.2314345-1-gjb@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This commits removes CreateTimeBasedPayload() function from PlatformVarCleanupLib and uses exactly the same function from SecureBootVariableLib. Signed-off-by: Grzegorz Bernacki --- MdeModulePkg/Library/PlatformVarCleanupLib/PlatformVarCleanupLib.inf | 2 + MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanup.h | 1 + MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanupLib.c | 84 -------------------- 3 files changed, 3 insertions(+), 84 deletions(-) diff --git a/MdeModulePkg/Library/PlatformVarCleanupLib/PlatformVarCleanupLib.inf b/MdeModulePkg/Library/PlatformVarCleanupLib/PlatformVarCleanupLib.inf index 8d5db826a0..493d03e1d8 100644 --- a/MdeModulePkg/Library/PlatformVarCleanupLib/PlatformVarCleanupLib.inf +++ b/MdeModulePkg/Library/PlatformVarCleanupLib/PlatformVarCleanupLib.inf @@ -34,6 +34,7 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec [LibraryClasses] UefiBootServicesTableLib @@ -44,6 +45,7 @@ PrintLib MemoryAllocationLib HiiLib + SecureBootVariableLib [Guids] gEfiIfrTianoGuid ## SOMETIMES_PRODUCES ## GUID diff --git a/MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanup.h b/MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanup.h index c809a7086b..94fbc7d2a4 100644 --- a/MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanup.h +++ b/MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanup.h @@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include diff --git a/MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanupLib.c b/MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanupLib.c index 3875d614bb..204f1e00ad 100644 --- a/MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanupLib.c +++ b/MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanupLib.c @@ -319,90 +319,6 @@ DestroyUserVariableNode ( } } -/** - Create a time based data payload by concatenating the EFI_VARIABLE_AUTHENTICATION_2 - descriptor with the input data. NO authentication is required in this function. - - @param[in, out] DataSize On input, the size of Data buffer in bytes. - On output, the size of data returned in Data - buffer in bytes. - @param[in, out] Data On input, Pointer to data buffer to be wrapped or - 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 after using it. - - @retval EFI_SUCCESS Create time based payload successfully. - @retval EFI_OUT_OF_RESOURCES There are not enough memory resourses to create time based payload. - @retval EFI_INVALID_PARAMETER The parameter is invalid. - @retval Others Unexpected error happens. - -**/ -EFI_STATUS -CreateTimeBasedPayload ( - IN OUT UINTN *DataSize, - IN OUT UINT8 **Data - ) -{ - EFI_STATUS Status; - UINT8 *NewData; - UINT8 *Payload; - UINTN PayloadSize; - EFI_VARIABLE_AUTHENTICATION_2 *DescriptorData; - UINTN DescriptorSize; - EFI_TIME Time; - - if (Data == NULL || DataSize == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // At user physical presence, the variable does not need to be signed but the - // parameters to the SetVariable() call still need to be prepared as authenticated - // variable. So we create EFI_VARIABLE_AUTHENTICATED_2 descriptor without certificate - // data in it. - // - Payload = *Data; - PayloadSize = *DataSize; - - DescriptorSize = OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo) + OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData); - NewData = (UINT8 *) AllocateZeroPool (DescriptorSize + PayloadSize); - if (NewData == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - if ((Payload != NULL) && (PayloadSize != 0)) { - CopyMem (NewData + DescriptorSize, Payload, PayloadSize); - } - - 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)); - - DescriptorData->AuthInfo.Hdr.dwLength = OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData); - DescriptorData->AuthInfo.Hdr.wRevision = 0x0200; - DescriptorData->AuthInfo.Hdr.wCertificateType = WIN_CERT_TYPE_EFI_GUID; - CopyGuid (&DescriptorData->AuthInfo.CertType, &gEfiCertPkcs7Guid); - - if (Payload != NULL) { - FreePool (Payload); - } - - *DataSize = DescriptorSize + PayloadSize; - *Data = NewData; - return EFI_SUCCESS; -} - /** Create a counter based data payload by concatenating the EFI_VARIABLE_AUTHENTICATION descriptor with the input data. NO authentication is required in this function. -- 2.25.1