public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Xu, Wei6" <wei6.xu@intel.com>
To: devel@edk2.groups.io
Cc: Wei6 Xu <wei6.xu@intel.com>, Laszlo Ersek <lersek@redhat.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>, Ray Ni <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH v2 1/1] StandaloneMmPkg: Fix some issues in function MmCoreFfsFindMmDriver.
Date: Fri, 27 Oct 2023 08:59:20 +0800	[thread overview]
Message-ID: <a5eae2a433c40e99bdd6b087e50c5360a2f32a68.1698341782.git.wei6.xu@intel.com> (raw)
In-Reply-To: <cover.1698341782.git.wei6.xu@intel.com>

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 <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
---
 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;
     }
 
+    //
+    // Check uncompressed firmware volumes
+    //
     Status = FfsFindSectionData (
-               EFI_SECTION_GUID_DEFINED,
+               EFI_SECTION_FIRMWARE_VOLUME_IMAGE,
                FileHeader,
                &SectionData,
                &SectionDataSize
                );
+    if (!EFI_ERROR (Status)) {
+      if (SectionDataSize > sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {
+        InnerFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)SectionData;
+        MmCoreFfsFindMmDriver (InnerFvHeader);
+      }
+    }
+
+    //
+    // Check compressed firmware volumes
+    //
+    Status = FfsFindSection (
+               EFI_SECTION_GUID_DEFINED,
+               FileHeader,
+               &Section
+               );
     if (EFI_ERROR (Status)) {
       break;
     }
 
-    Section = (EFI_COMMON_SECTION_HEADER *)(FileHeader + 1);
-    Status  = ExtractGuidedSectionGetInfo (
-                Section,
-                &DstBufferSize,
-                &ScratchBufferSize,
-                &SectionAttribute
-                );
+    Status = ExtractGuidedSectionGetInfo (
+               Section,
+               &DstBufferSize,
+               &ScratchBufferSize,
+               &SectionAttribute
+               );
     if (EFI_ERROR (Status)) {
       break;
     }
@@ -138,6 +155,7 @@ MmCoreFfsFindMmDriver (
     //
     DstBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));
     if (DstBuffer == NULL) {
+      FreePages (ScratchBuffer, EFI_SIZE_TO_PAGES (ScratchBufferSize));
       return EFI_OUT_OF_RESOURCES;
     }
 
-- 
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]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2023-10-27  0:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-27  0:59 [edk2-devel] [PATCH v2 0/1] StandaloneMmCore finds drivers in uncompressed inner fv Xu, Wei6
2023-10-27  0:59 ` Xu, Wei6 [this message]
2023-10-27  5:49 ` Ni, Ray
2023-10-28 11:08   ` Laszlo Ersek
2023-10-30  7:53     ` Xu, Wei6

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a5eae2a433c40e99bdd6b087e50c5360a2f32a68.1698341782.git.wei6.xu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox