From nobody Sun May 5 15:06:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+79224+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79224+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1628818665; cv=none; d=zohomail.com; s=zohoarc; b=QmwjNG6Jzo03BV2hyir9bx9UJS7zocW8Gjf83ZZfXu/chnR1gkcsOXKjDXppwVUMfbHNowqhgcgONtkbWuc+DE5LPJbu7O0ilVzOddKfJO3KQEuXWuohk/iysDXf9qxhQ9l6+TU2bMT/HJnoFGg50UGqmYF2K/Rh7UdpFaDSv4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628818665; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=SBOMDn5Ls/BlylXEilkvI06GYDa48zWZcxywqL3e5AY=; b=kqgGaQSxZP59Df3EKOvEsVTmfXVWeQUCng2MPGiglX0V8cHqw1QOOvAejzYjH/smm6yJeD+dNn7i5iVX3w54QUZhfuocgLl1ffoSVnWPc/FxzSmD5xRT+vVwkAS8zAWWZ3U476GF+K74Ahy9jD4v+UaGkLls8NvWTix8kgwVitc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79224+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1628818665970443.7256620114613; Thu, 12 Aug 2021 18:37:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id sgE1YY1788612xVybbwICjhn; Thu, 12 Aug 2021 18:37:45 -0700 X-Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web10.31266.1628818663702219305 for ; Thu, 12 Aug 2021 18:37:45 -0700 X-Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Fri, 13 Aug 2021 09:37:33 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: , , "'Yao, Jiewen'" , , "'Kinney, Michael D'" Cc: "'Wang, Jian J'" , "'Zhang, Qi1'" , "'Kumar, Rahul1'" References: <20210730175517.2445-1-brbarkel@microsoft.com> <1696A3E2DE5C4DCB.1941@groups.io> <169A57BB10BEC566.13770@groups.io> In-Reply-To: Subject: =?UTF-8?B?5Zue5aSNOiBbRVhURVJOQUxdIFtlZGsyLWRldmVsXSBbUEFUQ0ggdjEgMS8xXSBTZWN1cml0eVBrZy9MaWJyYXJ5OiBBZGQgVHBtMk52VW5kZWZpbmVTcGFjZVNwZWNpYWwgdG8gVHBtMkNvbW1hbmRMaWI=?= Date: Fri, 13 Aug 2021 09:37:35 +0800 Message-ID: <013f01d78fe3$cb33b270$619b1750$@byosoft.com.cn> MIME-Version: 1.0 Thread-Index: AQKw0JBQkMjs/QxFtbsF8Gy1CafftAIpAp74AfH9d7QAtUSWqgGWjx0DAl9ljhMBakX6Yalsofjw Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gaoliming@byosoft.com.cn X-Gm-Message-State: YGl8zGAjybUJemGjbNo0w4GKx1787277AA= Content-Type: multipart/related; boundary="----=_NextPart_000_0140_01D79026.D959D8A0" Content-Language: zh-cn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1628818665; bh=WBRAp0Ad033re7gxnzOQJRJdDuMhXA74Pkheacn9gKA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=ItFPp1LdVF4W1txd5EeDnCJrO+I8kn4RqLLnLdyNmxqTCQyqPocKNmfG7rrxGW/42iA 8bfPSb2QmYih+zBi4gCSg3Um5WbuBDhIVB0GfA+bW1RKX/JbVpixX1j1UBHgrFqrN87vN 5aIw49hO3nxw2F/bSdUfWp2OQ2s0VF9m/Fg= X-Zoho-Virus-Status: 1 X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1628818667579100001 ------=_NextPart_000_0140_01D79026.D959D8A0 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0141_01D79026.D959D8A0" ------=_NextPart_001_0141_01D79026.D959D8A0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Bret: I suggest to define new macro that follows EDKII style. This MACRO is only used in CommandLib. Its impact should be small.=20 =20 Thanks Liming =B7=A2=BC=FE=C8=CB: devel@edk2.groups.io =B4=FA=B1= =ED Bret Barkelew via groups.io =B7=A2=CB=CD=CA=B1=BC=E4: 2021=C4=EA8=D4=C213=C8=D5 8:24 =CA=D5=BC=FE=C8=CB: Yao, Jiewen ; devel@edk2.groups.i= o; bret@corthon.com; Kinney, Michael D =B3=AD=CB=CD: Wang, Jian J ; Zhang, Qi1 ; Kumar, Rahul1 =D6=F7=CC=E2: Re: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Librar= y: Add Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib =20 + @Kinney, Michael D =20 Mike, any thoughts on when =A1=B0sticking with the file convention=A1=B1 br= eaks ECC? Should I just ignore the rest of the file and pass ECC at all costs? =20 - Bret=20 =20 From: Yao, Jiewen =20 Sent: Thursday, August 12, 2021 5:06 PM To: Bret Barkelew ; devel@edk2.groups.io ; bret@corthon.com =20 Cc: Wang, Jian J ; Zhang, Qi1 ; Kumar, Rahul1 Subject: RE: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Ad= d Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib =20 I don=A1=AFt know the answer about ECC or PatchChecker. I just know we need pass CI to merge the patch. =20 Thank you Yao Jiewen =20 From: Bret Barkelew >=20 Sent: Friday, August 13, 2021 1:52 AM To: devel@edk2.groups.io ; bret@corthon.com =20 Cc: Yao, Jiewen >; Wang= , Jian J >; Zhang, Qi1 >; Kumar, Rahul1 > Subject: RE: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Ad= d Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib =20 Thoughts? =20 - Bret=20 =20 From: devel@edk2.groups.io > on behalf of Bret Barkelew via groups.io > Sent: Wednesday, August 11, 2021 12:37:52 PM To: devel@edk2.groups.io >; bret@corthon.com > Cc: Yao, Jiewen >; Jian J Wang >; Qi Zhang >; Rahul Kumar > Subject: Re: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Ad= d Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib=20 =20 Thoughts? =20 - Bret=20 =20 From: devel@edk2.groups.io > on behalf of Bret Barkelew via groups.io > Sent: Wednesday, August 4, 2021 9:32:32 AM To: devel@edk2.groups.io >; bret@corthon.com > Cc: Yao, Jiewen >; Jian J Wang >; Qi Zhang >; Rahul Kumar > Subject: Re: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Ad= d Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib=20 =20 Poking this one. =20 1. It=A1=AFs a easy review with small, obvious code change. 2. I need some answers on =A1=B0when is it okay to violate ECC/PatchCheck, if the new code matches the style of the existing code. Should I endeavor t= o pass the PatchCheck and ECCCheck with this patch only, and leave it in conflict with the rest of the file? =20 Thanks! =20 - Bret=20 =20 From: Bret Barkelew via groups.io =20 Sent: Friday, July 30, 2021 11:08 AM To: devel@edk2.groups.io ; bret@corthon.com =20 Cc: Yao, Jiewen ; Jian J Wang ; Qi Zhang ; Rahul Kumar =20 Subject: Re: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Ad= d Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib =20 Note, even though this keeps with the style of the rest of the file, it breaks ECC: SecurityPkg/Library: Add Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib by corthon =A1=A4 Pull Request #1848 =A1=A4 tianocore/edk2 (github.com) =20 =20 PROGRESS - --Running SecurityPkg: EccCheck Test NO-TARGET --=20 ERROR -=20 ERROR -=20 ERROR - EFI coding style error=20 ERROR - *Error code: 8001=20 ERROR - *Only capital letters are allowed to be used for #define declarations=20 ERROR - *file: //home/vsts/work/1/s/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c=20 ERROR - *Line number: 27=20 ERROR - *The #define name [RC_NV_UndefineSpaceSpecial_nvIndex] does no =20 Thoughts? =20 - Bret=20 =20 From: Bret Barkelew via groups.io =20 Sent: Friday, July 30, 2021 10:55 AM To: devel@edk2.groups.io =20 Cc: Yao, Jiewen ; Jian J Wang ; Qi Zhang ; Rahul Kumar =20 Subject: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Add Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib =20 Used to provision and maintain certain HW-defined NV spaces. REF: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugzill= a.t ianocore.org%2Fshow_bug.cgi%3Fid%3D2994 &data=3D04%7C01%7CBret.Barkelew%40microsoft.com%7Cb7ae3c62047c48fc85d90= 8d9 53833ca0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637632645397602953%7C= U nknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLC= J XVCI6Mn0%3D%7C1000&sdata=3Ds96M3RvxMOY831Vfr1nt%2Fz1h3cyb6jU9eFzvjKO7Dt= c%3 D&reserved=3D0 Signed-off-by: Bret Barkelew > Cc: Jiewen Yao > Cc: Jian J Wang > Cc: Qi Zhang > Cc: Rahul Kumar > --- SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c | 122 ++++++++++++++++++++ SecurityPkg/Include/Library/Tpm2CommandLib.h | 22 ++++ 2 files changed, 144 insertions(+) diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c index 87572de20164..7931fade9190 100644 --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c @@ -24,6 +24,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define RC_NV_UndefineSpace_authHandle (TPM_RC_H + TPM_RC_1) #define RC_NV_UndefineSpace_nvIndex (TPM_RC_H + TPM_RC_2) =20 +#define RC_NV_UndefineSpaceSpecial_nvIndex (TPM_RC_H + TPM_RC_1) + #define RC_NV_Read_authHandle (TPM_RC_H + TPM_RC_1) #define RC_NV_Read_nvIndex (TPM_RC_H + TPM_RC_2) #define RC_NV_Read_size (TPM_RC_P + TPM_RC_1) @@ -74,6 +76,20 @@ typedef struct { TPMS_AUTH_RESPONSE AuthSession; } TPM2_NV_UNDEFINESPACE_RESPONSE; =20 +typedef struct { + TPM2_COMMAND_HEADER Header; + TPMI_RH_NV_INDEX NvIndex; + TPMI_RH_PLATFORM Platform; + UINT32 AuthSessionSize; + TPMS_AUTH_COMMAND AuthSession; +} TPM2_NV_UNDEFINESPACESPECIAL_COMMAND; + +typedef struct { + TPM2_RESPONSE_HEADER Header; + UINT32 AuthSessionSize; + TPMS_AUTH_RESPONSE AuthSession; +} TPM2_NV_UNDEFINESPACESPECIAL_RESPONSE; + typedef struct { TPM2_COMMAND_HEADER Header; TPMI_RH_NV_AUTH AuthHandle; @@ -506,6 +522,112 @@ Done: return Status; } =20 +/** + This command removes an index from the TPM. + + @param[in] NvIndex The NV Index. + @param[in] IndexAuthSession Auth session context for the Index auth/policy + @param[in] PlatAuthSession Auth session context for the Platform auth/policy + + @retval EFI_SUCCESS Operation completed successfully. + @retval EFI_NOT_FOUND The command was returned successfully, but NvIndex is not found. + @retval EFI_UNSUPPORTED Selected NvIndex does not support deletion through this call. + @retval EFI_SECURITY_VIOLATION Deletion is not authorized by current policy session. + @retval EFI_INVALID_PARAMETER The command was unsuccessful. + @retval EFI_DEVICE_ERROR The command was unsuccessful. +**/ +EFI_STATUS +EFIAPI +Tpm2NvUndefineSpaceSpecial ( + IN TPMI_RH_NV_INDEX NvIndex, + IN TPMS_AUTH_COMMAND *IndexAuthSession OPTIONAL, + IN TPMS_AUTH_COMMAND *PlatAuthSession OPTIONAL + ) +{ + EFI_STATUS Status; + TPM2_NV_UNDEFINESPACESPECIAL_COMMAND SendBuffer; + TPM2_NV_UNDEFINESPACESPECIAL_RESPONSE RecvBuffer; + UINT32 SendBufferSize; + UINT32 RecvBufferSize; + UINT8 *Buffer; + UINT32 IndexAuthSize, PlatAuthSize; + TPM_RC ResponseCode; + + // + // Construct command + // + SendBuffer.Header.tag =3D SwapBytes16(TPM_ST_SESSIONS); + SendBuffer.Header.commandCode =3D SwapBytes32(TPM_CC_NV_UndefineSpaceSpecial); + + SendBuffer.NvIndex =3D SwapBytes32 (NvIndex); + SendBuffer.Platform =3D SwapBytes32 (TPM_RH_PLATFORM); + + // + // Marshall the Auth Sessions for the two handles. + Buffer =3D (UINT8 *)&SendBuffer.AuthSession; + // IndexAuthSession + IndexAuthSize =3D CopyAuthSessionCommand (IndexAuthSession, Buffer); + Buffer +=3D IndexAuthSize; + // PlatAuthSession + PlatAuthSize =3D CopyAuthSessionCommand (PlatAuthSession, Buffer); + Buffer +=3D PlatAuthSize; + // AuthSessionSize + SendBuffer.AuthSessionSize =3D SwapBytes32(IndexAuthSize + PlatAuthSize)= ; + + // Update total command size. + SendBufferSize =3D (UINT32)(Buffer - (UINT8 *)&SendBuffer); + SendBuffer.Header.paramSize =3D SwapBytes32 (SendBufferSize); + + // + // send Tpm command + // + RecvBufferSize =3D sizeof (RecvBuffer); + Status =3D Tpm2SubmitCommand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8 *)&RecvBuffer); + if (EFI_ERROR (Status)) { + goto Done; + } + + if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER)) { + DEBUG ((EFI_D_ERROR, "Tpm2NvUndefineSpaceSpecial - RecvBufferSize Erro= r - %x\n", RecvBufferSize)); + Status =3D EFI_DEVICE_ERROR; + goto Done; + } + + ResponseCode =3D SwapBytes32(RecvBuffer.Header.responseCode); + if (ResponseCode !=3D TPM_RC_SUCCESS) { + DEBUG ((EFI_D_ERROR, "Tpm2NvUndefineSpaceSpecial - responseCode - %x\n", SwapBytes32(RecvBuffer.Header.responseCode))); + } + switch (ResponseCode) { + case TPM_RC_SUCCESS: + // return data + break; + case TPM_RC_ATTRIBUTES: + case TPM_RC_ATTRIBUTES + RC_NV_UndefineSpaceSpecial_nvIndex: + Status =3D EFI_UNSUPPORTED; + break; + case TPM_RC_NV_AUTHORIZATION: + Status =3D EFI_SECURITY_VIOLATION; + break; + case TPM_RC_HANDLE + RC_NV_UndefineSpaceSpecial_nvIndex: // TPM_RC_NV_DEFINED: + Status =3D EFI_NOT_FOUND; + break; + case TPM_RC_VALUE + RC_NV_UndefineSpace_nvIndex: + Status =3D EFI_INVALID_PARAMETER; + break; + default: + Status =3D EFI_DEVICE_ERROR; + break; + } + +Done: + // + // Clear AuthSession Content + // + ZeroMem (&SendBuffer, sizeof(SendBuffer)); + ZeroMem (&RecvBuffer, sizeof(RecvBuffer)); + return Status; +} // Tpm2NvUndefineSpaceSpecial() + /** This command reads a value from an area in NV memory previously defined by TPM2_NV_DefineSpace(). =20 diff --git a/SecurityPkg/Include/Library/Tpm2CommandLib.h b/SecurityPkg/Include/Library/Tpm2CommandLib.h index ee8eb622951c..8d7b4998d98d 100644 --- a/SecurityPkg/Include/Library/Tpm2CommandLib.h +++ b/SecurityPkg/Include/Library/Tpm2CommandLib.h @@ -364,6 +364,28 @@ Tpm2NvUndefineSpace ( IN TPMS_AUTH_COMMAND *AuthSession OPTIONAL ); =20 +/** + This command removes an index from the TPM. + + @param[in] NvIndex The NV Index. + @param[in] IndexAuthSession Auth session context for the Index auth/policy + @param[in] PlatAuthSession Auth session context for the Platform auth/policy + + @retval EFI_SUCCESS Operation completed successfully. + @retval EFI_NOT_FOUND The command was returned successfully, but NvIndex is not found. + @retval EFI_UNSUPPORTED Selected NvIndex does not support deletion through this call. + @retval EFI_SECURITY_VIOLATION Deletion is not authorized by current policy session. + @retval EFI_INVALID_PARAMETER The command was unsuccessful. + @retval EFI_DEVICE_ERROR The command was unsuccessful. +**/ +EFI_STATUS +EFIAPI +Tpm2NvUndefineSpaceSpecial ( + IN TPMI_RH_NV_INDEX NvIndex, + IN TPMS_AUTH_COMMAND *IndexAuthSession OPTIONAL, + IN TPMS_AUTH_COMMAND *PlatAuthSession OPTIONAL + ); + /** This command reads a value from an area in NV memory previously defined by TPM2_NV_DefineSpace(). =20 --=20 2.31.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D Groups.io Links: You receive all messages sent to this group. View/Reply Online (#78450): https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.gr= oup s.io%2Fg%2Fdevel%2Fmessage%2F78450 &data=3D04%7C01%7CBret.Barkelew%40microsoft.com%7Cb7ae3c62047c48fc85d90= 8d9 53833ca0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637632645397612922%7C= U nknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLC= J XVCI6Mn0%3D%7C1000&sdata=3DCWxLwgp73z2XQEa%2FN77gsCwRF73xha0RZCKwcFTlrR= E%3 D&reserved=3D0 Mute This Topic: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgroups.= io% 2Fmt%2F84555713%2F1822150 &data=3D04%7C01%7CBret.Barkelew%40micro= soft. com%7Cb7ae3c62047c48fc85d908d953833ca0%7C72f988bf86f141af91ab2d7cd011db47%7= C 1%7C0%7C637632645397612922%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQ= I joiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=3DIWQ6E4yP0ECt3o= YLY Qa%2BnddGfcQEDMgfASlcxRuda%2BQ%3D&reserved=3D0 Group Owner: devel+owner@edk2.groups.io = =20 Unsubscribe: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.gr= oup s.io%2Fg%2Fdevel%2Funsub &data=3D04%7C01%7CBret.Barkelew%40microsoft.com%7Cb7ae3c62047c48fc85d90= 8d9 53833ca0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637632645397612922%7C= U nknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLC= J XVCI6Mn0%3D%7C1000&sdata=3Dqor4Y5FZEH8ch0AEmWDbe97FIQk4V1qx7IURcTHzjAU%= 3D& amp;reserved=3D0 [brbarkel@microsoft.com] -=3D-=3D-=3D-=3D-=3D-=3D =20 =20 =20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79224): https://edk2.groups.io/g/devel/message/79224 Mute This Topic: https://groups.io/mt/84854740/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- ------=_NextPart_001_0141_01D79026.D959D8A0 Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: quoted-printable

Bret:

 I suggest to defin= e new macro that follows EDKII style. This MACRO is only used in CommandLib= . Its impact should be small.

 = ;

Thanks

Lim= ing

=B7=A2=BC=FE=C8=CB: devel@edk2.groups= .io <devel@edk2.groups.io> =B4=FA=B1=ED Bret Barkelew via groups.io
=B7=A2=CB=CD=CA=B1=BC=E4: 2021=C4=EA8=D4=C213=C8=D5 8:24
=CA=D5=BC=FE=C8=CB:
Yao, Jiewen <jiewen.yao@= intel.com>; devel@edk2.groups.io; bret@corthon.com; Kinney, Michael D &l= t;michael.d.kinney@intel.com>
=B3=AD=CB=CD: Wang, Jian J <jian.j.wang@intel.com>= ;; Zhang, Qi1 <qi1.zhang@intel.com>; Kumar, Rahul1 <rahul1.kumar@i= ntel.com>
=D6=F7=CC=E2: Re: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Librar= y: Add Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib

 <= /span>

+ @Kinney, Micha= el D

 

Mike,= any thoughts on when =A1=B0sticking with the file convention=A1=B1 breaks = ECC? Should I just ignore the rest of the file and pass ECC at all costs?

 

- Bret

 

=

From: Yao, Jiewen
= Sent: Thursday, August 12, 2021 5:06 PM
To: Bret Barkelew; devel@edk2.groups.io; bret@corthon.com
Cc: Wang, Jian J; Zhang, Qi1; = Kumar, Rahul1
Subject: = RE: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Add Tpm= 2NvUndefineSpaceSpecial to Tpm2CommandLib

 

I don=A1=AFt know the answer about ECC or PatchC= hecker.

I &nbs= p;just know we need pass CI to merge the patch.

 

Thank you

Yao Jiewen

 

From: Br= et Barkelew <Bret.Barkele= w@microsoft.com>
Sent: Friday, August 13, 2021 1:52 AMTo: devel@edk2.groups.io; bret@corthon.com
Cc: Y= ao, Jiewen <jiewen.yao@intel.com= >; Wang, Jian J <jian.j.= wang@intel.com>; Zhang, Qi1 <qi1.zhang@intel.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>
Subject: RE: [EXT= ERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Add Tpm2NvUndefineS= paceSpecial to Tpm2CommandLib

 

Thoughts?

 

- Bret

 

From: devel@edk2.grou= ps.io <devel@edk2.groups.io<= /a>> on behalf of Bret Barkelew via groups.io <bret.barkelew=3Dmicrosoft.com@groups.i= o>
Sent: Wednesday, August 11, 2021 12:37:52 PM
To:<= /b> devel@edk2.groups.io <devel@edk2.groups.io>; bret@corthon.com <bret@corthon.com>
Cc: Yao, Jiewen <jiewen.yao@intel.com>; Jian J Wan= g <jian.j.wang@intel.com>= ;; Qi Zhang <qi1.zhang@intel.com<= /a>>; Rahul Kumar <rahul1.k= umar@intel.com>
Subject: Re: [EXTERNAL] [edk2-devel] [PATC= H v1 1/1] SecurityPkg/Library: Add Tpm2NvUndefineSpaceSpecial to Tpm2Comman= dLib

 

Thoughts?

 

- Bret

 

=

From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of Bret Barkelew via groups.= io <bret.bark= elew=3Dmicrosoft.com@groups.io>
Sent: Wednesday, August 4,= 2021 9:32:32 AM
To: deve= l@edk2.groups.io <devel@edk2= .groups.io>; bret@corthon.com <bret@corthon.com>
Cc= : Yao, Jiewen <jiewen.yao@in= tel.com>; Jian J Wang <j= ian.j.wang@intel.com>; Qi Zhang <qi1.zhang@intel.com>; Rahul Kumar <rahul1.kumar@intel.com>
Subject: Re: [E= XTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Library: Add Tpm2NvUndefin= eSpaceSpecial to Tpm2CommandLib

 <= /p>

Poking t= his one.

&nb= sp;

    It=A1=AFs a easy review with small, obvious code cha= nge.
  1. I need some answers on = =A1=B0when is it okay to violate ECC/PatchCheck, if the new code matches th= e style of the existing code. Should I endeavor to pass the PatchCheck and = ECCCheck with this patch only, and leave it in conflict with the rest of th= e file?

 

Tha= nks!

 <= o:p>

- Bret =

 

From: Bret Barkelew via groups.io
Sent: Friday, July 30,= 2021 11:08 AM
To: devel@= edk2.groups.io; bret@corthon.com
Cc:
Yao, Jiewen; Jian J Wang; Qi Zhang; Rahul Kumar
Subject: Re: [EXTERNAL] [edk2-devel] [PATCH v1 1= /1] SecurityPkg/Library: Add Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib

 <= o:p>

Note, even t= hough this keeps with the style of the rest of the file, it breaks ECC:

SecurityPkg/Lib= rary: Add Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib by corthon =A1=A4 Pu= ll Request #1848 =A1=A4 tianocore/edk2 (github.com)

 

PROGRESS - --Running SecurityPkg: EccCheck Test NO-TARGET -- =

E= RROR -

= ERROR -

<= div>

ERROR - EFI coding style error =

ERROR - *Error code: 8001

ERROR - *On= ly capital letters are allowed to be used for #define declarations <= /span>

ERROR - *f= ile: //home/vsts/work/1/s/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.= c

= ERROR - *Line number: 27

ERROR - *The #define name [RC_NV_UndefineSpaceSpecia= l_nvIndex] does no

 

Thoughts?<= /p>

 

- Bret

 

<= p class=3Dxxmsonormal>From: Bret Barkelew via grou= ps.io
Sent: Friday, July 30, 2021 10:55 AM
To: devel@edk2.groups.io
Cc: = Yao, Jiewen; Jian J Wang; Qi Zhang; Rahul Kumar=
Subject: [EXTERNAL] [edk2-devel] [PATCH v1 1/1] SecurityPkg/Libr= ary: Add Tpm2NvUndefineSpaceSpecial to Tpm2CommandLib

=

 

U= sed to provision and maintain certain HW-defined NV spaces.

REF: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugz= illa.tianocore.org%2Fshow_bug.cgi%3Fid%3D2994&amp;data=3D04%7C01%7CBret= .Barkelew%40microsoft.com%7Cb7ae3c62047c48fc85d908d953833ca0%7C72f988bf86f1= 41af91ab2d7cd011db47%7C1%7C0%7C637632645397602953%7CUnknown%7CTWFpbGZsb3d8e= yJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&am= p;amp;sdata=3Ds96M3RvxMOY831Vfr1nt%2Fz1h3cyb6jU9eFzvjKO7Dtc%3D&amp;rese= rved=3D0

Signed-off-by: Bret Barkelew <bret.barkelew@microsoft.com>
Cc: Jiewen = Yao <jiewen.yao@intel.com>= ;
Cc: Jian J Wang <jian.j.wa= ng@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 Secur= ityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c | 122 ++++++++++++++++++++ SecurityPkg/Include/Library/Tpm2CommandLib.h    =    |  22 ++++
 2 files changed, 144 insertions(+)
diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c b/Secu= rityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c
index 87572de20164..7931f= ade9190 100644
--- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c<= br>+++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2NVStorage.c
@@ -24,6 +24= ,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #define RC_NV_U= ndefineSpace_authHandle      (TPM_RC_H + TPM_RC_1)=

 #define RC_NV_UndefineSpace_nvIndex    &n= bsp;    (TPM_RC_H + TPM_RC_2)

 

+#define = RC_NV_UndefineSpaceSpecial_nvIndex  (TPM_RC_H + TPM_RC_1)

+
=
 #define RC_NV_Read_authHandle      =          (TPM_RC_H + TPM_RC_1)
<= br> #define RC_NV_Read_nvIndex      &nbs= p;           (TPM_RC_H + = TPM_RC_2)

 #define RC_NV_Read_size     = ;            &n= bsp;   (TPM_RC_P + TPM_RC_1)

@@ -74,6 +76,20 @@ typedef st= ruct {
   TPMS_AUTH_RESPONSE     &nbs= p;   AuthSession;

 } TPM2_NV_UNDEFINESPACE_RESPONSE;<= br>
 

+typedef struct {

+  TPM2_COMMAND_HEADER&n= bsp;      Header;

+  TPMI_RH_NV_INDEX&= nbsp;         NvIndex;

+&nbs= p; TPMI_RH_PLATFORM          P= latform;

+  UINT32       &nb= sp;            AuthS= essionSize;

+  TPMS_AUTH_COMMAND     &= nbsp;   AuthSession;

+} TPM2_NV_UNDEFINESPACESPECIAL_COMMA= ND;

+

+typedef struct {

+  TPM2_RESPONSE_HEADER&n= bsp;      Header;

+  UINT32  = ;            &n= bsp;      AuthSessionSize;

+  TPMS_AUT= H_RESPONSE         AuthSession;
=
+} TPM2_NV_UNDEFINESPACESPECIAL_RESPONSE;

+

 typedef= struct {

   TPM2_COMMAND_HEADER    &n= bsp;  Header;

   TPMI_RH_NV_AUTH   &nb= sp;       AuthHandle;

@@ -506,6 +522,1= 12 @@ Done:
   return Status;

 }

 
=
+/**

+  This command removes an index from the TPM.

= +

+  @param[in]  NvIndex     &nbs= p;       The NV Index.

+  @param[= in]  IndexAuthSession    Auth session context for the I= ndex auth/policy

+  @param[in]  PlatAuthSession  = ;   Auth session context for the Platform auth/policy

+
+  @retval EFI_SUCCESS       &= nbsp;     Operation completed successfully.

+&nb= sp; @retval EFI_NOT_FOUND        &n= bsp;  The command was returned successfully, but NvIndex is not found.=

+  @retval EFI_UNSUPPORTED      =    Selected NvIndex does not support deletion through this call.<= br>
+  @retval EFI_SECURITY_VIOLATION  Deletion is not authori= zed by current policy session.

+  @retval EFI_INVALID_PARAMETER=    The command was unsuccessful.

+  @retval EFI_DEVIC= E_ERROR        The command was unsuccess= ful.

+**/

+EFI_STATUS

+EFIAPI

+Tpm2NvUndefineSp= aceSpecial (

+  IN      TPMI_RH_NV_IND= EX          NvIndex,

+&= nbsp; IN      TPMS_AUTH_COMMAND   &= nbsp;     *IndexAuthSession OPTIONAL,

+  IN=       TPMS_AUTH_COMMAND    &nb= sp;    *PlatAuthSession OPTIONAL

+  )

+{<= br>
+  EFI_STATUS        &n= bsp;            = ;         Status;

+  TP= M2_NV_UNDEFINESPACESPECIAL_COMMAND    SendBuffer;

+&n= bsp; TPM2_NV_UNDEFINESPACESPECIAL_RESPONSE   RecvBuffer;

+=   UINT32          &n= bsp;            = ;           SendBufferSiz= e;

+  UINT32        &nb= sp;            =              Re= cvBufferSize;

+  UINT8       = ;            &n= bsp;            = ;   *Buffer;

+  UINT32     &= nbsp;           &nbs= p;            &= nbsp;   IndexAuthSize, PlatAuthSize;

+  TPM_RC &= nbsp;           &nbs= p;            &= nbsp;       ResponseCode;

+

+&n= bsp; //

+  // Construct command

+  //

+ = ; SendBuffer.Header.tag =3D SwapBytes16(TPM_ST_SESSIONS);

+  Se= ndBuffer.Header.commandCode =3D SwapBytes32(TPM_CC_NV_UndefineSpaceSpecial)= ;

+

+  SendBuffer.NvIndex =3D SwapBytes32 (NvIndex);
=
+  SendBuffer.Platform =3D SwapBytes32 (TPM_RH_PLATFORM);

+=

+  //

+  // Marshall the Auth Sessions for the two= handles.

+  Buffer =3D (UINT8 *)&SendBuffer.AuthSession;
+  // IndexAuthSession

+  IndexAuthSize =3D CopyAuth= SessionCommand (IndexAuthSession, Buffer);

+  Buffer +=3D Index= AuthSize;

+  // PlatAuthSession

+  PlatAuthSize =3D= CopyAuthSessionCommand (PlatAuthSession, Buffer);

+  Buffer += =3D PlatAuthSize;

+  // AuthSessionSize

+  SendBuff= er.AuthSessionSize =3D SwapBytes32(IndexAuthSize + PlatAuthSize);

+<= br>
+  // Update total command size.

+  SendBufferSize = =3D (UINT32)(Buffer - (UINT8 *)&SendBuffer);

+  SendBuffer.= Header.paramSize =3D SwapBytes32 (SendBufferSize);

+

+  = //

+  // send Tpm command

+  //

+  Recv= BufferSize =3D sizeof (RecvBuffer);

+  Status =3D Tpm2SubmitCom= mand (SendBufferSize, (UINT8 *)&SendBuffer, &RecvBufferSize, (UINT8= *)&RecvBuffer);

+  if (EFI_ERROR (Status)) {

+ = ;   goto Done;

+  }

+

+  if (RecvB= ufferSize < sizeof (TPM2_RESPONSE_HEADER)) {

+    = DEBUG ((EFI_D_ERROR, "Tpm2NvUndefineSpaceSpecial - RecvBufferSize Erro= r - %x\n", RecvBufferSize));

+    Status =3D EFI= _DEVICE_ERROR;

+    goto Done;

+  }
+

+  ResponseCode =3D SwapBytes32(RecvBuffer.Header.responseC= ode);

+  if (ResponseCode !=3D TPM_RC_SUCCESS) {

+ =    DEBUG ((EFI_D_ERROR, "Tpm2NvUndefineSpaceSpecial - respon= seCode - %x\n", SwapBytes32(RecvBuffer.Header.responseCode)));

= +  }

+  switch (ResponseCode) {

+  case TPM_RC= _SUCCESS:

+    // return data

+  &nb= sp; break;

+  case TPM_RC_ATTRIBUTES:

+  case TPM_R= C_ATTRIBUTES + RC_NV_UndefineSpaceSpecial_nvIndex:

+  &nbs= p; Status =3D EFI_UNSUPPORTED;

+    break;

+&n= bsp; case TPM_RC_NV_AUTHORIZATION:

+    Status =3D EF= I_SECURITY_VIOLATION;

+    break;

+  case= TPM_RC_HANDLE + RC_NV_UndefineSpaceSpecial_nvIndex: // TPM_RC_NV_DEFINED:<= br>
+    Status =3D EFI_NOT_FOUND;

+  &n= bsp; break;

+  case TPM_RC_VALUE + RC_NV_UndefineSpace_nvIndex:=

+    Status =3D EFI_INVALID_PARAMETER;

+ = ;   break;

+  default:

+    Sta= tus =3D EFI_DEVICE_ERROR;

+    break;

+  = }

+

+Done:

+  //

+  // Clear AuthSess= ion Content

+  //

+  ZeroMem (&SendBuffer, size= of(SendBuffer));

+  ZeroMem (&RecvBuffer, sizeof(RecvBuffer= ));

+  return Status;

+} // Tpm2NvUndefineSpaceSpecial()=

+

 /**

   This command reads a value f= rom an area in NV memory previously defined by TPM2_NV_DefineSpace().
 

diff --git a/SecurityPkg/Include/Library/Tpm2CommandLib.h b= /SecurityPkg/Include/Library/Tpm2CommandLib.h
index ee8eb622951c..8d7b49= 98d98d 100644
--- a/SecurityPkg/Include/Library/Tpm2CommandLib.h
+++ = b/SecurityPkg/Include/Library/Tpm2CommandLib.h
@@ -364,6 +364,28 @@ Tpm2= NvUndefineSpace (
   IN      TPMS_AUT= H_COMMAND         *AuthSession OPTI= ONAL

   );

 

+/**

+  This c= ommand removes an index from the TPM.

+

+  @param[in]&nb= sp; NvIndex          &nbs= p;  The NV Index.

+  @param[in]  IndexAuthSession&nbs= p;   Auth session context for the Index auth/policy

+ = ; @param[in]  PlatAuthSession     Auth session con= text for the Platform auth/policy

+

+  @retval EFI_SUCCE= SS             = Operation completed successfully.

+  @retval EFI_NOT_FOUND = ;          The command was ret= urned successfully, but NvIndex is not found.

+  @retval EFI_UN= SUPPORTED         Selected NvIndex = does not support deletion through this call.

+  @retval EFI_SEC= URITY_VIOLATION  Deletion is not authorized by current policy session.=

+  @retval EFI_INVALID_PARAMETER   The command was u= nsuccessful.

+  @retval EFI_DEVICE_ERROR    = ;    The command was unsuccessful.

+**/

+EFI_S= TATUS

+EFIAPI

+Tpm2NvUndefineSpaceSpecial (

+  IN=       TPMI_RH_NV_INDEX    &nbs= p;     NvIndex,

+  IN   &nbs= p;  TPMS_AUTH_COMMAND         = *IndexAuthSession OPTIONAL,

+  IN     = TPMS_AUTH_COMMAND         *PlatAut= hSession OPTIONAL

+  );

+

 /**

 =   This command reads a value from an area in NV memory previously defi= ned by TPM2_NV_DefineSpace().

 

--
2.31.1.windows.1<= br>


-=3D-=3D-=3D-=3D-=3D-=3D
Groups.io Links: You receive all= messages sent to this group.
View/Reply Online (#78450): https://nam06.s= afelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.groups.io%2Fg%2Fd= evel%2Fmessage%2F78450&amp;data=3D04%7C01%7CBret.Barkelew%40microsoft.c= om%7Cb7ae3c62047c48fc85d908d953833ca0%7C72f988bf86f141af91ab2d7cd011db47%7C= 1%7C0%7C637632645397612922%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQ= IjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=3DCWxLwgp73= z2XQEa%2FN77gsCwRF73xha0RZCKwcFTlrRE%3D&amp;reserved=3D0
Mute Th= is Topic: = https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgroups.= io%2Fmt%2F84555713%2F1822150&amp;data=3D04%7C01%7CBret.Barkelew%40micro= soft.com%7Cb7ae3c62047c48fc85d908d953833ca0%7C72f988bf86f141af91ab2d7cd011d= b47%7C1%7C0%7C637632645397612922%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMD= AiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=3DIWQ= 6E4yP0ECt3oYLYQa%2BnddGfcQEDMgfASlcxRuda%2BQ%3D&amp;reserved=3D0Group Owner: devel+owner@edk= 2.groups.io
Unsubscribe: https://nam06.safelinks.protection.outlook.com/?= url=3Dhttps%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Funsub&amp;data=3D04%7C= 01%7CBret.Barkelew%40microsoft.com%7Cb7ae3c62047c48fc85d908d953833ca0%7C72f= 988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637632645397612922%7CUnknown%7CTWFp= bGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%= 7C1000&amp;sdata=3Dqor4Y5FZEH8ch0AEmWDbe97FIQk4V1qx7IURcTHzjAU%3D&a= mp;reserved=3D0 [brbarkel@microsoft.com]
-=3D-=3D-=3D-=3D-=3D-=3D

 

 

 

<= /o:p>

_._,_._,_

G= roups.io Links:

You receive all messages sent to this group.

Vi= ew/Reply Online (#79224) | | Mute This Topic | New Topic
Your Subscription | Contact Group Owner | Unsubscribe [importer@patchew.org]
_._,_._,_=20 ------=_NextPart_001_0141_01D79026.D959D8A0-- ------=_NextPart_000_0140_01D79026.D959D8A0 Content-Type: image/png; name="image001.png" Content-Transfer-Encoding: base64 Content-ID: iVBORw0KGgoAAAANSUhEUgAAArYAAAADCAYAAABmm0wDAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAS dAAAEnQB3mYfeAAAABl0RVh0U29mdHdhcmUATWljcm9zb2Z0IE9mZmljZX/tNXEAAABrSURBVGhD 7dCxEUAwAIXhhJQsbAgr2cDp0jgbKCgU3Alr5O57E/zvS9O8lq7rQ4wxGAECBAgQIECAAIFaBVIo 5TnPY2yb9qr1hG4CBAgQIECAAAEC6Se4920Zcs4vDgIECBAgQIAAAQK1CnxV+BKJo+GYJAAAAABJ RU5ErkJggg== ------=_NextPart_000_0140_01D79026.D959D8A0--