From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 89640D80186 for ; Fri, 27 Oct 2023 00:59:31 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=vAUXLQwT/SpUY7L/8SdxkflK/+LyBde06KqITAbXc2s=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698368370; v=1; b=DOItPGigmVjkYuuom4mCtXZel1+QdrFvR21xoPkcx5NJBsMP26shFwswduL66YGCllR1vUqa ghwuAt8Csyjng/+XpqOK72Pm5Ih2XAsgRL401vILCfgyYRBu4GDQ7F/WIHWgj+74w2dWEnzGrPi jTCCGzFPgFQktUY/GGWj9b7M= X-Received: by 127.0.0.2 with SMTP id nUXIYY7687511xvE32ka1vPo; Thu, 26 Oct 2023 17:59:30 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.87089.1698368365478454309 for ; Thu, 26 Oct 2023 17:59:29 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10875"; a="451926113" X-IronPort-AV: E=Sophos;i="6.03,255,1694761200"; d="scan'208";a="451926113" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2023 17:59:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10875"; a="883027068" X-IronPort-AV: E=Sophos;i="6.03,255,1694761200"; d="scan'208";a="883027068" X-Received: from shpfwdbuild003.ccr.corp.intel.com ([10.239.56.82]) by orsmga004.jf.intel.com with ESMTP; 26 Oct 2023 17:59:27 -0700 From: "Xu, Wei6" To: devel@edk2.groups.io Cc: Wei6 Xu , Laszlo Ersek , Ard Biesheuvel , Sami Mujawar , Ray Ni Subject: [edk2-devel] [PATCH v2 1/1] StandaloneMmPkg: Fix some issues in function MmCoreFfsFindMmDriver. Date: Fri, 27 Oct 2023 08:59:20 +0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk 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,wei6.xu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: mB5WuO0INOQAcv1OP4dZhzULx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=DOItPGig; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) 1. The MmCoreFfsFindMmDriver only checks for encapsulated compressed FVs. When an inner FV is uncompressed, StandaloneMmCore will miss the FV and all the MM drivers in the FV will not be dispatched. Add checks for uncompressed inner FV to fix this issue. 2. If FileHeader is an EFI_FFS_FILE_HEADER2, 'FileHeader + 1' will get a wrong section address. Use FfsFindSection to get the section directly, instead of 'FileHeader + 1' to avoid this issue. 3. ScratchBuffer is not freed in the error return path that DstBuffer page allocation fails. Free ScratchBuffer before return with error. Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Ray Ni Signed-off-by: Wei6 Xu --- StandaloneMmPkg/Core/FwVol.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/StandaloneMmPkg/Core/FwVol.c b/StandaloneMmPkg/Core/FwVol.c index 1f6d7714ba97..fb483bd62696 100644 --- a/StandaloneMmPkg/Core/FwVol.c +++ b/StandaloneMmPkg/Core/FwVol.c @@ -104,23 +104,40 @@ MmCoreFfsFindMmDriver ( break;=0D }=0D =0D + //=0D + // Check uncompressed firmware volumes=0D + //=0D Status =3D FfsFindSectionData (=0D - EFI_SECTION_GUID_DEFINED,=0D + EFI_SECTION_FIRMWARE_VOLUME_IMAGE,=0D FileHeader,=0D &SectionData,=0D &SectionDataSize=0D );=0D + if (!EFI_ERROR (Status)) {=0D + if (SectionDataSize > sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {=0D + InnerFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)SectionData;=0D + MmCoreFfsFindMmDriver (InnerFvHeader);=0D + }=0D + }=0D +=0D + //=0D + // Check compressed firmware volumes=0D + //=0D + Status =3D FfsFindSection (=0D + EFI_SECTION_GUID_DEFINED,=0D + FileHeader,=0D + &Section=0D + );=0D if (EFI_ERROR (Status)) {=0D break;=0D }=0D =0D - Section =3D (EFI_COMMON_SECTION_HEADER *)(FileHeader + 1);=0D - Status =3D ExtractGuidedSectionGetInfo (=0D - Section,=0D - &DstBufferSize,=0D - &ScratchBufferSize,=0D - &SectionAttribute=0D - );=0D + Status =3D ExtractGuidedSectionGetInfo (=0D + Section,=0D + &DstBufferSize,=0D + &ScratchBufferSize,=0D + &SectionAttribute=0D + );=0D if (EFI_ERROR (Status)) {=0D break;=0D }=0D @@ -138,6 +155,7 @@ MmCoreFfsFindMmDriver ( //=0D DstBuffer =3D (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (DstBuff= erSize));=0D if (DstBuffer =3D=3D NULL) {=0D + FreePages (ScratchBuffer, EFI_SIZE_TO_PAGES (ScratchBufferSize));=0D return EFI_OUT_OF_RESOURCES;=0D }=0D =0D --=20 2.29.2.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110161): https://edk2.groups.io/g/devel/message/110161 Mute This Topic: https://groups.io/mt/102212658/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-