From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mx.groups.io with SMTP id smtpd.web08.35270.1629176930115813727 for ; Mon, 16 Aug 2021 22:08:50 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IgCcgUtg; spf=pass (domain: gmail.com, ip: 209.85.214.182, mailfrom: kuqin12@gmail.com) Received: by mail-pl1-f182.google.com with SMTP id u15so8028719plg.13 for ; Mon, 16 Aug 2021 22:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Sb9ntsIp7DPEFAfV/H5La0wS9onjslyYvFpprpWPylo=; b=IgCcgUtglBrG7GuUgRpicLbrs8rLYKBbiBbIGMwR2Futp27M4Z/Aemw0qhJmmafo6J FcPBm5PwUYOApyYzA8Uej4VWFPgTpWsn34wzoDS2X3KxMZEFnj2Rf0vNxdPwQoLdjswr dwlounsKHpzkbbYHcp79EuDy4AsPPf3aofXVq+4XUVa72wAcJEa7HK4XwY2TDUnd5t3k 6OK6jn/sRgC/5CK2gQHMN3o3cQ6xQfweJEgcrYWu5PSzi7yH/mJQKuDeudhmnYZhUo+Y bG/K+B1SjHv0WHKvdbKjO2p010VP6Epueu81WQpERnwMKc2lXjMCq1t6N6aZZBKNSfxf 431w== 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=Sb9ntsIp7DPEFAfV/H5La0wS9onjslyYvFpprpWPylo=; b=VWSVD3DueTcze7KoiDuzUROGM4HUYMaMgeVr+44/QapxOt27Szgph0UBXxGcQ1lXQz Hxu1O1kgApurIm0haxQ1Bg5AtSMPnOnN87MutGiVom+b1w5YbGcFp04N2lIbTLDv0nAn T+6NWy+DiidBZG3O78ys6BCtf9QJxAXMS9TCsW+SnH7PKuDTlJQGZwjAdqtptO8iNPv/ IFzgsIvc8jBWDUuC4kItVoTrd143uAvUvlRTnl3mzeFtskGAkjhyuokQv7Y6yJR/0hAT XoiwMZIsJg4StzhwqFidoVlfhQw9YofGkoj9RBKnIFILGG0q+aOg4DPW13uEqYUK0Yq2 lvDA== X-Gm-Message-State: AOAM532XecdiMShdd7ombFsAGnbb2AsbObCyUbwO0rM8BjkUFEWW6I65 XUYH/NVFH91PnxL9cpckzMbHI0tVjE03lg== X-Google-Smtp-Source: ABdhPJz2sBwbvfK1+rOAyTm2x7QzBN8x0kyy5pJ/DJpVdnx+vLOo4PWB/ibKHGYXzCPOQvlkKlqD6Q== X-Received: by 2002:a17:90a:4306:: with SMTP id q6mr1691839pjg.202.1629176929283; Mon, 16 Aug 2021 22:08:49 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([50.35.88.161]) by smtp.gmail.com with ESMTPSA id i5sm737965pjk.47.2021.08.16.22.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 22:08:48 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Eric Dong , Ray Ni Subject: [PATCH v3 5/7] MdeModulePkg: PiSmmCore: Added parser of new MM communicate header Date: Mon, 16 Aug 2021 22:08:05 -0700 Message-Id: <20210817050807.766-6-kuqin12@gmail.com> X-Mailer: git-send-email 2.32.0.windows.1 In-Reply-To: <20210817050807.766-1-kuqin12@gmail.com> References: <20210817050807.766-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3398 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3430 MM communicate protocols are expanded with EFI_MM_COMMUNICATE_HEADER_V3 structure that cooperates with updated field types and flexible array. The PiSmmCore implementation is updated to detect and process incoming data accordingly. Two checks are also performed to prevent legacy communicate data or unsupported data is fed into MM core under agreed header guid. Cc: Jian J Wang Cc: Hao A Wu Cc: Eric Dong Cc: Ray Ni Signed-off-by: Kun Qin --- Notes: v3: - Newly added MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 42 +++++++++++++++----- MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf | 1 + 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c index cfa9922cbdb5..63ac2b5fcbbd 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c @@ -646,12 +646,16 @@ SmmEntryPoint ( IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext ) { - EFI_STATUS Status; - EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader; - BOOLEAN InLegacyBoot; - BOOLEAN IsOverlapped; - VOID *CommunicationBuffer; - UINTN BufferSize; + EFI_STATUS Status; + EFI_MM_COMMUNICATE_HEADER_V3 *CommunicateHeader; + EFI_SMM_COMMUNICATE_HEADER *LegacyCommunicateHeader; + BOOLEAN InLegacyBoot; + BOOLEAN IsOverlapped; + VOID *CommunicationBuffer; + UINTN BufferSize; + EFI_GUID *CommGuid; + VOID *CommData; + UINTN CommHeaderSize; // // Update SMST with contents of the SmmEntryContext structure @@ -707,19 +711,35 @@ SmmEntryPoint ( gSmmCorePrivate->CommunicationBuffer = NULL; gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED; } else { - CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer; - BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); + CommGuid = &((EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicationBuffer)->HeaderGuid; + // + // Check if the signature matches EFI_MM_COMMUNICATE_HEADER_V3 definition + // + if (CompareGuid (CommGuid, &gCommunicateHeaderV3Guid)) { + CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicationBuffer; + ASSERT (CommunicateHeader->Signature == EFI_MM_COMMUNICATE_HEADER_V3_SIGNATURE); + ASSERT (CommunicateHeader->Version <= EFI_MM_COMMUNICATE_HEADER_V3_VERSION); + CommGuid = &CommunicateHeader->MessageGuid; + CommData = CommunicateHeader->MessageData; + CommHeaderSize = sizeof (EFI_MM_COMMUNICATE_HEADER_V3); + } else { + LegacyCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer; + CommGuid = &LegacyCommunicateHeader->HeaderGuid; + CommData = LegacyCommunicateHeader->Data; + CommHeaderSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); + } + BufferSize -= CommHeaderSize; Status = SmiManage ( - &CommunicateHeader->HeaderGuid, + CommGuid, NULL, - CommunicateHeader->Data, + CommData, &BufferSize ); // // Update CommunicationBuffer, BufferSize and ReturnStatus // Communicate service finished, reset the pointer to CommBuffer to NULL // - gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); + gSmmCorePrivate->BufferSize = BufferSize + CommHeaderSize; gSmmCorePrivate->CommunicationBuffer = NULL; gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND; } diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf index c8bfae3860fc..5a0929a45e19 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf @@ -118,6 +118,7 @@ [Guids] gSmiHandlerProfileGuid gEdkiiEndOfS3ResumeGuid ## SOMETIMES_PRODUCES ## GUID # Install protocol gEdkiiS3SmmInitDoneGuid ## SOMETIMES_PRODUCES ## GUID # Install protocol + gCommunicateHeaderV3Guid ## CONSUMES ## GUID # Communicate header [UserExtensions.TianoCore."ExtraFiles"] PiSmmCoreExtra.uni -- 2.32.0.windows.1