From nobody Sun Feb 8 19:02:51 2026 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+86071+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+86071+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1643139560; cv=none; d=zohomail.com; s=zohoarc; b=cMMJ+RiRctvoS6EzZ0O7NFDUBjYvTAZQJQUtgEp3MThxpLsyB/EiGOATRkrEL28CvGMdtu35knagi90/ONtI3GG3rBWzGmJWPGtgJOzDEqNaeNaSBUbf7XS8cRHVhnCaoHZFx82nlemknkRbnxb3zYml84cWGNK/MhitZUb6tFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643139560; 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=qxFobrFgyqoRbGczfbg/yZkIfYzc3tp27VlwvhTflAk=; b=X25E4JS+/T6SlYJozGDem0NmxI1G1IQfkLn/PKkT9+oO/+yfSKu5xVLJNXcRpXi4Tszae/PUW88z6+t61VrHknnpX9boxrki55OtflohfiO8oAGwuVXMi14Ymwv+GtTN0BaFXXwV7RSofQEuimj4jfksHFk0rJl9humKMcaapFs= 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+86071+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 1643139560709654.2468990434907; Tue, 25 Jan 2022 11:39:20 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Q4P3YY1788612xdVarOq8M51; Tue, 25 Jan 2022 11:39:20 -0800 X-Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mx.groups.io with SMTP id smtpd.web12.1945.1643139559444445864 for ; Tue, 25 Jan 2022 11:39:19 -0800 X-Received: by mail-pl1-f173.google.com with SMTP id x11so14574553plg.6 for ; Tue, 25 Jan 2022 11:39:19 -0800 (PST) X-Gm-Message-State: WpEBTOd6ZxwEXj2OHXLFzf3Ex1787277AA= X-Google-Smtp-Source: ABdhPJysYZ7RKSd6QbTD20rDghcHfwBSo2MIxuw4WIS5GzgLzyfNZqWyGhm90YfDOuBh1d9Gaj9goQ== X-Received: by 2002:a17:902:dad1:b0:14b:5094:9076 with SMTP id q17-20020a170902dad100b0014b50949076mr10538008plx.22.1643139558944; Tue, 25 Jan 2022 11:39:18 -0800 (PST) X-Received: from gem-name-lb-02.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id v8sm1036929pju.51.2022.01.25.11.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 11:39:18 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Bret Barkelew , Michael Kubacki , Sami Mujawar Subject: [edk2-devel] [PATCH v3 6/6] ArmPkg: MmCommunicationDxe: Update MM communicate `MessageLength` check Date: Tue, 25 Jan 2022 11:39:09 -0800 Message-Id: <20220125193909.491-7-kuqin12@gmail.com> In-Reply-To: <20220125193909.491-1-kuqin12@gmail.com> References: <20220125193909.491-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=1643139560; bh=CYWAnssUrK76S4sCQYccL/63VwvDvv+JuX6AcJRBUdg=; h=Cc:Date:From:Reply-To:Subject:To; b=PZiVBgvH3ddtoR2/cDZY36/AN17Wsby6vx3McaFa8YcrF14pAl9YKjyoqFzfbbFP4Kl 0MEsoEDr2njDonIoKQ1Ozoys/Y/jlm6Pu/g/5dL41dCgT86+vSXcSu3YYYR6B0d5++DON fk7Wfeny5SE6JZemz8yplOamNI6b4pCNGBk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1643139562402100026 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 checks prior to proceeding with SMC calls. However, the inspection step is different from PI specification. This patch updated MM communicate input argument inspection routine to assure that "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", as described by `EFI_MM_COMMUNICATION_PROTOCOL.Communicate()` section in PI specification. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Bret Barkelew Cc: Michael Kubacki Cc: Sami Mujawar Signed-off-by: Kun Qin Reviewed-by: Sami Mujawar --- Notes: v2: - Splitting patch into 4 of 4 [Ard] - Uncrustify style update =20 v3: - Added cc entry and reviewed-by tag [Sami] ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/D= rivers/MmCommunicationDxe/MmCommunication.c index 2f89b7c5b6c4..85d9034555f0 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -92,6 +92,7 @@ MmCommunication2Communicate ( 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 @@ -109,28 +110,33 @@ MmCommunication2Communicate ( (*CommSize > mNsCommBuffMemRegion.Length)) { *CommSize =3D mNsCommBuffMemRegion.Length; - return EFI_BAD_BUFFER_SIZE; + Status =3D EFI_BAD_BUFFER_SIZE; } =20 // // CommSize should cover at least MessageLength + sizeof (EFI_MM_COMMU= NICATE_HEADER); // if (*CommSize < BufferSize) { - return EFI_INVALID_PARAMETER; + 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.34.1.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 (#86071): https://edk2.groups.io/g/devel/message/86071 Mute This Topic: https://groups.io/mt/88680225/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-