public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Hao Wu <hao.a.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Hao Wu <hao.a.wu@intel.com>, Ruiyu Ni <ruiyu.ni@intel.com>,
	Star Zeng <star.zeng@intel.com>, Eric Dong <eric.dong@intel.com>
Subject: [PATCH v2 2/2] MdeModulePkg/UdfDxe: Avoid possible loss track of allocated buffer
Date: Thu, 16 Nov 2017 15:47:42 +0800	[thread overview]
Message-ID: <20171116074742.15024-3-hao.a.wu@intel.com> (raw)
In-Reply-To: <20171116074742.15024-1-hao.a.wu@intel.com>

In function FindFileEntry():

Instead of using the function parameter 'FileEntry', use a local
variable to store the buffer allocated for disk read operation.

For the below calling stack:
UdfOpenVolume() -> FindRootDirectory() -> FindFileEntry()

In FindFileEntry(), the call to 'DiskIo->ReadDisk()' is possible (e.g.
media change for a CD/DVD ROM device) to trigger a re-install of the
BlockIO(2) protocol which will further lead to a call of the BindingStop()
& BingdingStart() of the UdfDxe driver.

Meanwhile, for the above listed calling stack, the '**FileEntry'
parameter passed into FindFileEntry() is '&PrivFsData->Root'. 'PrivFsData'
is a driver-managed private data, it will be freed in BindingStop() and
re-allocate in BingdingStart().

In such case, if '*FileEntry' is used to store the allocated buffer, the
information will be lost if 'DiskIo->ReadDisk()' triggers a re-install of
the BlockIO(2) protocol. The subsequent call of the FreePool API:

FreePool (*FileEntry);

will cause issues.

This commit uses a local variable to store the allocated buffer.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Paulo Alcantara <pcacjr@zytor.com>
---
 MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
index e048d95d31..ecc172303e 100644
--- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
+++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
@@ -1615,12 +1615,13 @@ FindFileEntry (
   UINT64              Lsn;
   UINT32              LogicalBlockSize;
   UDF_DESCRIPTOR_TAG  *DescriptorTag;
+  VOID                *ReadBuffer;
 
   Lsn               = GetLongAdLsn (Volume, Icb);
   LogicalBlockSize  = Volume->LogicalVolDesc.LogicalBlockSize;
 
-  *FileEntry = AllocateZeroPool (Volume->FileEntrySize);
-  if (*FileEntry == NULL) {
+  ReadBuffer = AllocateZeroPool (Volume->FileEntrySize);
+  if (ReadBuffer == NULL) {
     return EFI_OUT_OF_RESOURCES;
   }
 
@@ -1632,13 +1633,13 @@ FindFileEntry (
     BlockIo->Media->MediaId,
     MultU64x32 (Lsn, LogicalBlockSize),
     Volume->FileEntrySize,
-    *FileEntry
+    ReadBuffer
     );
   if (EFI_ERROR (Status)) {
     goto Error_Read_Disk_Blk;
   }
 
-  DescriptorTag = *FileEntry;
+  DescriptorTag = ReadBuffer;
 
   //
   // Check if the read extent contains a valid Tag Identifier for the expected
@@ -1650,11 +1651,12 @@ FindFileEntry (
     goto Error_Invalid_Fe;
   }
 
+  *FileEntry = ReadBuffer;
   return EFI_SUCCESS;
 
 Error_Invalid_Fe:
 Error_Read_Disk_Blk:
-  FreePool (*FileEntry);
+  FreePool (ReadBuffer);
 
   return Status;
 }
-- 
2.12.0.windows.1



      parent reply	other threads:[~2017-11-16  7:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-16  7:47 [PATCH v2 0/2] Refine UDF related codes Hao Wu
2017-11-16  7:47 ` [PATCH v2 1/2] MdeModulePkg/PartitionDxe: Merge the discovery of ElTorito into UDF Hao Wu
2017-11-16 22:25   ` Paulo Alcantara
2017-11-16  7:47 ` Hao Wu [this message]

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=20171116074742.15024-3-hao.a.wu@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