From nobody Sat May 4 17:07:32 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+84141+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+84141+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1638232773; cv=none; d=zohomail.com; s=zohoarc; b=BWSm532bfOtWE65NsrGEsc+vGXpKqejFlq7d110SHJoFctJkPXGnruPXjVx86i4eDiC5xWgLusnxl8ModDHpQVNjUT4MWySnJu9mZSr6n9p0V14G8q7rUObQbvuZ8uNm9wJbCvDAjFarIcVSFKCA3AxQGK9gixpEpqMNK3uk0Fw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638232773; h=Content-Transfer-Encoding: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=+ryxx8pbzfKmKqGVFrh6BM24ifyLXJWyGXsOtk6XVBY=; b=Vs00G41yRGM0F7vCpDqVTbidbdVY20cMbUo4DM+HWN0S1EQjHvleJxlqXaKw4DnfI/mHvM1gzUHIrXpuTDlXMMy3MSq/9iARxmPBW6Ubm/9pX5rx3hiYT/dfKz/a91BmuG+ozHQNV3zYmzi+wRYMN0DvlhpxyFa8SyweNRsLmbg= 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+84141+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1638232773892664.060252786744; Mon, 29 Nov 2021 16:39:33 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id q3aIYY1788612xe987Aja8jw; Mon, 29 Nov 2021 16:39:33 -0800 X-Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mx.groups.io with SMTP id smtpd.web10.70145.1638232772974617323 for ; Mon, 29 Nov 2021 16:39:33 -0800 X-Received: by mail-pg1-f169.google.com with SMTP id r5so17801132pgi.6 for ; Mon, 29 Nov 2021 16:39:32 -0800 (PST) X-Gm-Message-State: nZZugMjYCHhlC9ogmFIDzuJRx1787277AA= X-Google-Smtp-Source: ABdhPJz753MOLAicHq5IatktmnBv9Pc1UR5FiAQsdU/xcTAnb/5VIBex4isxvwSL1oY8mbaHcRGn6Q== X-Received: by 2002:a63:d413:: with SMTP id a19mr3871898pgh.552.1638232772378; Mon, 29 Nov 2021 16:39:32 -0800 (PST) X-Received: from localhost.localdomain ([50.35.70.63]) by smtp.gmail.com with ESMTPSA id v10sm19286119pfu.123.2021.11.29.16.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 16:39:31 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Hao A Wu , Bret Barkelew , Michael Kubacki Subject: [edk2-devel] [PATCH v1 1/2] MdeModulePkg: VariableSmmRuntimeDxe: Fix Variable Policy Message Length Date: Mon, 29 Nov 2021 16:39:01 -0800 Message-Id: <20211130003902.1884-2-kuqin12@gmail.com> In-Reply-To: <20211130003902.1884-1-kuqin12@gmail.com> References: <20211130003902.1884-1-kuqin12@gmail.com> MIME-Version: 1.0 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,kuqin12@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1638232773; bh=Io+4Ps2Cf3QJDYPGGsGBpyntEpSMoUwRxX0lFakQyTI=; h=Cc:Date:From:Reply-To:Subject:To; b=fQl9T8OUk5zLNrX2mS9qDLOMsTwjByHuAgnsJhVDUwMyPhi43Bkv8kXmhFA3Hc4sGQc M07ExjhpofWCUUJvC53P5SPhIWpDNk+1ILVbkISmYxBAdmOQT6gCIPK9zFxtMMzH0f9pd BIWPaTcClE2LsTaUteD5jQbdKtJv+O2Q5Ds= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1638232774539100003 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3709 In EDKII implementation of variable policy, the DXE runtime agent would communicate to MM to disable, register or query policies. However, these operations populate the value of MessageLength that includes communicate header to include MM communicate header, which mismatches with the description of PI specification. This fix will correct the MessageLength field calculation to exclude the size of MM_COMMUNICATE_HEADER. Cc: Jian J Wang Cc: Liming Gao Cc: Hao A Wu Cc: Bret Barkelew Cc: Michael Kubacki Signed-off-by: Kun Qin --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c | 10 +++= ++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDx= e.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c index 6ae69dffe025..486f95720c92 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c @@ -88,7 +88,7 @@ ProtocolDisableVariablePolicy ( CommHeader =3D mMmCommunicationBuffer; PolicyHeader =3D (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data; CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid ); - CommHeader->MessageLength =3D BufferSize; + CommHeader->MessageLength =3D BufferSize - OFFSET_OF (EFI_MM_COMMUNICATE= _HEADER, Data); PolicyHeader->Signature =3D VAR_CHECK_POLICY_COMM_SIG; PolicyHeader->Revision =3D VAR_CHECK_POLICY_COMM_REVISION; PolicyHeader->Command =3D VAR_CHECK_POLICY_COMMAND_DISABLE; @@ -138,7 +138,7 @@ ProtocolIsVariablePolicyEnabled ( PolicyHeader =3D (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data; CommandParams =3D (VAR_CHECK_POLICY_COMM_IS_ENABLED_PARAMS*)(PolicyHeade= r + 1); CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid ); - CommHeader->MessageLength =3D BufferSize; + CommHeader->MessageLength =3D BufferSize - OFFSET_OF (EFI_MM_COMMUNICATE= _HEADER, Data); PolicyHeader->Signature =3D VAR_CHECK_POLICY_COMM_SIG; PolicyHeader->Revision =3D VAR_CHECK_POLICY_COMM_REVISION; PolicyHeader->Command =3D VAR_CHECK_POLICY_COMMAND_IS_ENABLED; @@ -208,7 +208,7 @@ ProtocolRegisterVariablePolicy ( PolicyHeader =3D (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data; PolicyBuffer =3D (VOID*)(PolicyHeader + 1); CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid ); - CommHeader->MessageLength =3D BufferSize; + CommHeader->MessageLength =3D BufferSize - OFFSET_OF (EFI_MM_COMMUNICATE= _HEADER, Data); PolicyHeader->Signature =3D VAR_CHECK_POLICY_COMM_SIG; PolicyHeader->Revision =3D VAR_CHECK_POLICY_COMM_REVISION; PolicyHeader->Command =3D VAR_CHECK_POLICY_COMMAND_REGISTER; @@ -266,7 +266,7 @@ DumpVariablePolicyHelper ( PolicyHeader =3D (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data; CommandParams =3D (VAR_CHECK_POLICY_COMM_DUMP_PARAMS*)(PolicyHeader + 1); CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid ); - CommHeader->MessageLength =3D BufferSize; + CommHeader->MessageLength =3D BufferSize - OFFSET_OF (EFI_MM_COMMUNICATE= _HEADER, Data); PolicyHeader->Signature =3D VAR_CHECK_POLICY_COMM_SIG; PolicyHeader->Revision =3D VAR_CHECK_POLICY_COMM_REVISION; PolicyHeader->Command =3D VAR_CHECK_POLICY_COMMAND_DUMP; @@ -395,7 +395,7 @@ ProtocolLockVariablePolicy ( CommHeader =3D mMmCommunicationBuffer; PolicyHeader =3D (VAR_CHECK_POLICY_COMM_HEADER*)&CommHeader->Data; CopyGuid( &CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid ); - CommHeader->MessageLength =3D BufferSize; + CommHeader->MessageLength =3D BufferSize - OFFSET_OF (EFI_MM_COMMUNICATE= _HEADER, Data); PolicyHeader->Signature =3D VAR_CHECK_POLICY_COMM_SIG; PolicyHeader->Revision =3D VAR_CHECK_POLICY_COMM_REVISION; PolicyHeader->Command =3D VAR_CHECK_POLICY_COMMAND_LOCK; --=20 2.32.0.windows.1 -=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 (#84141): https://edk2.groups.io/g/devel/message/84141 Mute This Topic: https://groups.io/mt/87392596/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- From nobody Sat May 4 17:07:32 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+84142+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+84142+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1638232774; cv=none; d=zohomail.com; s=zohoarc; b=W21bnat9gezhELE3N9ROx6BHxocMYumKO6SKeu/uGWbDFWt3CV6JCn7+AHM5uNeRKI6XPVLTv87stXABpJCKpjgmsz64nKWLp/ReFbfy1+X8XJoQ7slS0Vs006LKYwmtnIT10qpTOahoqGJGTq7Y1fEZRpVJg5qZlZ1FjA7MLBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638232774; h=Content-Transfer-Encoding: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=8XyG6oWQyf7/TeaEHitN8z+a0wsMzNp+49TqJ3G85+o=; b=ngOuhYupx3nkOT1JqlDoqa2gA8oWB8dVRtQ16mMKdaTegq4w5UtjjCKmA31MHTKDsRTHCOYllbnYBCb0fBeJAbjtn9zOftn3sAGZMA6QuopI7CPxV3+klbrkyIbDj05LIr7WK5tZYAAZJ11fJFepovnyH2M6EGErLIUCWbAA0tk= 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+84142+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1638232774475848.2315995681857; Mon, 29 Nov 2021 16:39:34 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id LirrYY1788612xngdqFWcYCO; Mon, 29 Nov 2021 16:39:34 -0800 X-Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mx.groups.io with SMTP id smtpd.web11.69481.1638232773553688713 for ; Mon, 29 Nov 2021 16:39:33 -0800 X-Received: by mail-pg1-f169.google.com with SMTP id f125so4602461pgc.0 for ; Mon, 29 Nov 2021 16:39:33 -0800 (PST) X-Gm-Message-State: DgD9HX7xnrOtC3ylNc3IuCWUx1787277AA= X-Google-Smtp-Source: ABdhPJy9HB2CSWfVKGot2TNTXmz2Xnmi1mQxjHepFnrynKyTEY14rTPdbdhxCfyjThxwhVHJ1lvGxA== X-Received: by 2002:a63:b51:: with SMTP id a17mr37111233pgl.283.1638232772998; Mon, 29 Nov 2021 16:39:32 -0800 (PST) X-Received: from localhost.localdomain ([50.35.70.63]) by smtp.gmail.com with ESMTPSA id v10sm19286119pfu.123.2021.11.29.16.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 16:39:32 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Bret Barkelew , Michael Kubacki Subject: [edk2-devel] [PATCH v1 2/2] ArmPkg: MmCommunicationDxe: Update MM communicate input arguments checks Date: Mon, 29 Nov 2021 16:39:02 -0800 Message-Id: <20211130003902.1884-3-kuqin12@gmail.com> In-Reply-To: <20211130003902.1884-1-kuqin12@gmail.com> References: <20211130003902.1884-1-kuqin12@gmail.com> MIME-Version: 1.0 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,kuqin12@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1638232774; bh=pTPhfb/7qEM5Djuqot78m51l5iHbpqJE9FOK7mpry7k=; h=Cc:Date:From:Reply-To:Subject:To; b=Jm7KJwLdSo37RmZAIA9KBKvJdpxUwBXwZpaPC3FgZSh2c/nmAX74nO7q3aA1nRHuOTV Yy3ypQ3IzRV9lJRP0Kg4EpR3P6MkDJXqfLhC5p6vWguwQ3Q/eAXaFLOvXFhHqe2p3KeJf T2e+me5/mWGa/YwaD4m9GZ2BsFk0wwX/YKM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1638232776399100010 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3751 Current MM communicate routine from ArmPkg would conduct few steps before proceeding with SMC calls. However, some inspection steps are different from PI specification. This patch updated MM communicate input argument inspection routine to match the following PI descriptions: 1. Return code `EFI_INVALID_PARAMETER` represents "the `CommBuffer**` parameters do not refer to the same location in memory". 2. `CommSize` represents "the size of the data buffer being passed in" instead of "the size of the data being used from data buffer". 3. Regarding `MessageLength`, "if the `MessageLength` is zero, or too large for the MM implementation to manage, the MM implementation must update the `MessageLength` to reflect the size of the `Data` buffer that it can tolerate". Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Bret Barkelew Cc: Michael Kubacki Signed-off-by: Kun Qin Reviewed-by: Sami Mujawar --- ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c | 44 ++++++++++++-----= --- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/D= rivers/MmCommunicationDxe/MmCommunication.c index b1e309580988..8a2bd222957f 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -41,15 +41,19 @@ STATIC EFI_HANDLE mMmCommunicateHandle; =20 This function provides a service to send and receive messages from a reg= istered UEFI service. =20 - @param[in] This The EFI_MM_COMMUNICATION_PROTOCOL instanc= e. - @param[in] CommBufferPhysical Physical address of the MM communication = buffer - @param[in] CommBufferVirtual Virtual address of the MM communication b= uffer - @param[in] CommSize The size of the data buffer being passed = in. On exit, the size of data - being returned. Zero if the handler does = not wish to reply with any data. - This parameter is optional and may be NUL= L. + @param[in] This The EFI_MM_COMMUNICATION_PROTOCOL in= stance. + @param[in, out] CommBufferPhysical Physical address of the MM communica= tion buffer + @param[in, out] CommBufferVirtual Virtual address of the MM communicat= ion buffer + @param[in, out] CommSize The size of the data buffer being pa= ssed in. On input, when not + omitted, the buffer should cover EFI= _MM_COMMUNICATE_HEADER and the + value of MessageLength field. On exi= t, the size of data being + returned. Zero if the handler does n= ot wish to reply with any data. + This parameter is optional and may b= e NULL. =20 @retval EFI_SUCCESS The message was successfully posted. - @retval EFI_INVALID_PARAMETER CommBufferPhysical was NULL or CommBuffer= Virtual was NULL. + @retval EFI_INVALID_PARAMETER CommBufferPhysical or CommBufferVirtual w= as NULL, or integer value + pointed by CommSize does not cover EFI_MM= _COMMUNICATE_HEADER and the + value of MessageLength field. @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM implem= entation. If this error is returned, the MessageLen= gth field in the CommBuffer header or the integer p= ointed by @@ -82,10 +86,11 @@ MmCommunication2Communicate ( // // Check parameters // - if (CommBufferVirtual =3D=3D NULL) { + if (CommBufferVirtual =3D=3D NULL || CommBufferPhysical =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 + Status =3D EFI_SUCCESS; CommunicateHeader =3D CommBufferVirtual; // CommBuffer is a mandatory parameter. Hence, Rely on // MessageLength + Header to ascertain the @@ -95,33 +100,38 @@ MmCommunication2Communicate ( sizeof (CommunicateHeader->HeaderGuid) + sizeof (CommunicateHeader->MessageLength); =20 - // If the length of the CommBuffer is 0 then return the expected length. - if (CommSize !=3D 0) { + // If CommSize is not omitted, perform size inspection before proceeding. + if (CommSize !=3D NULL) { // This case can be used by the consumer of this driver to find out the // max size that can be used for allocating CommBuffer. if ((*CommSize =3D=3D 0) || (*CommSize > mNsCommBuffMemRegion.Length)) { *CommSize =3D mNsCommBuffMemRegion.Length; - return EFI_BAD_BUFFER_SIZE; + Status =3D EFI_BAD_BUFFER_SIZE; } // - // CommSize must match MessageLength + sizeof (EFI_MM_COMMUNICATE_HEAD= ER); + // CommSize should cover at least MessageLength + sizeof (EFI_MM_COMMU= NICATE_HEADER); // - if (*CommSize !=3D BufferSize) { - return EFI_INVALID_PARAMETER; + if (*CommSize < BufferSize) { + Status =3D EFI_INVALID_PARAMETER; } } =20 // - // If the buffer size is 0 or greater than what can be tolerated by the = MM + // If the message length is 0 or greater than what can be tolerated by t= he MM // environment then return the expected size. // - if ((BufferSize =3D=3D 0) || + if ((CommunicateHeader->MessageLength =3D=3D 0) || (BufferSize > mNsCommBuffMemRegion.Length)) { CommunicateHeader->MessageLength =3D mNsCommBuffMemRegion.Length - sizeof (CommunicateHeader->HeaderGu= id) - sizeof (CommunicateHeader->MessageL= ength); - return EFI_BAD_BUFFER_SIZE; + Status =3D EFI_BAD_BUFFER_SIZE; + } + + // MessageLength or CommSize check has failed, return here. + if (EFI_ERROR (Status)) { + return Status; } =20 // SMC Function ID --=20 2.32.0.windows.1 -=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 (#84142): https://edk2.groups.io/g/devel/message/84142 Mute This Topic: https://groups.io/mt/87392597/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-