public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] Refine UDF related codes
@ 2017-11-14  7:51 Hao Wu
  2017-11-14  7:51 ` [PATCH 1/2] MdeModulePkg/PartitionDxe: Merge the discovery of ElTorito into UDF Hao Wu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hao Wu @ 2017-11-14  7:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Paulo Alcantara, Ruiyu Ni, Star Zeng, Eric Dong

The series will do the following refinements:
a. Merge the discovery of the El Torito feature on CD/DVD media into the
   detect of UDF;
b. Avoid possible loss track of the allocated buffer pointer in UdfDxe.

Cc: Paulo Alcantara <pcacjr@zytor.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>

Hao Wu (2):
  MdeModulePkg/PartitionDxe: Merge the discovery of ElTorito into UDF
  MdeModulePkg/UdfDxe: Avoid possible loss track of allocated buffer

 MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c      |  7 +++----
 MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c            | 17 +++++++++++++++++
 MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c | 12 +++++++-----
 3 files changed, 27 insertions(+), 9 deletions(-)

-- 
2.12.0.windows.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] MdeModulePkg/PartitionDxe: Merge the discovery of ElTorito into UDF
  2017-11-14  7:51 [PATCH 0/2] Refine UDF related codes Hao Wu
@ 2017-11-14  7:51 ` Hao Wu
  2017-11-14  7:51 ` [PATCH 2/2] MdeModulePkg/UdfDxe: Avoid possible loss track of allocated buffer Hao Wu
  2017-11-14 16:00 ` [PATCH 0/2] Refine UDF related codes Paulo Alcantara
  2 siblings, 0 replies; 4+ messages in thread
From: Hao Wu @ 2017-11-14  7:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Paulo Alcantara, Ruiyu Ni, Star Zeng, Eric Dong

In order to create all of the children (El Torito standard and UDF) for
a CD/DVD media in an entry of the PartitionDriverBindingStart(), this
commit merges the discovery of the El Torito feature
(PartitionInstallElToritoChildHandles) into function
PartitionInstallUdfChildHandles.

Cc: Paulo Alcantara <pcacjr@zytor.com>
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>
---
 MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c |  7 +++----
 MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c       | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
index f6030e0897..603abfe55a 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
@@ -43,7 +43,6 @@ EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {
 //
 PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {
   PartitionInstallGptChildHandles,
-  PartitionInstallElToritoChildHandles,
   PartitionInstallMbrChildHandles,
   PartitionInstallUdfChildHandles,
   NULL
@@ -306,9 +305,9 @@ PartitionDriverBindingStart (
   if (BlockIo->Media->MediaPresent ||
       (BlockIo->Media->RemovableMedia && !BlockIo->Media->LogicalPartition)) {
     //
-    // Try for GPT, then El Torito, then UDF, and then legacy MBR partition
-    // types. If the media supports a given partition type install child handles
-    // to represent the partitions described by the media.
+    // Try for GPT, then legacy MBR partition types, and then UDF and El Torito.
+    // If the media supports a given partition type install child handles to
+    // represent the partitions described by the media.
     //
     Routine = &mPartitionDetectRoutineTable[0];
     while (*Routine != NULL) {
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
index 7eee748958..f6f0ff37d8 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
@@ -704,6 +704,23 @@ PartitionInstallUdfChildHandles (
   }
 
   //
+  // Detect El Torito feature first.
+  // And always continue to search for UDF.
+  //
+  Status = PartitionInstallElToritoChildHandles (
+             This,
+             Handle,
+             DiskIo,
+             DiskIo2,
+             BlockIo,
+             BlockIo2,
+             DevicePath
+             );
+  if (!EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_INFO, "PartitionDxe: El Torito standard found on handle 0x%p.\n", Handle));
+  }
+
+  //
   // Search for an UDF file system on block device
   //
   Status = FindUdfFileSystem (BlockIo, DiskIo, &StartingLBA, &EndingLBA);
-- 
2.12.0.windows.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] MdeModulePkg/UdfDxe: Avoid possible loss track of allocated buffer
  2017-11-14  7:51 [PATCH 0/2] Refine UDF related codes Hao Wu
  2017-11-14  7:51 ` [PATCH 1/2] MdeModulePkg/PartitionDxe: Merge the discovery of ElTorito into UDF Hao Wu
@ 2017-11-14  7:51 ` Hao Wu
  2017-11-14 16:00 ` [PATCH 0/2] Refine UDF related codes Paulo Alcantara
  2 siblings, 0 replies; 4+ messages in thread
From: Hao Wu @ 2017-11-14  7:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Paulo Alcantara, Ruiyu Ni, Star Zeng, Eric Dong

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: Paulo Alcantara <pcacjr@zytor.com>
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>
---
 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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Refine UDF related codes
  2017-11-14  7:51 [PATCH 0/2] Refine UDF related codes Hao Wu
  2017-11-14  7:51 ` [PATCH 1/2] MdeModulePkg/PartitionDxe: Merge the discovery of ElTorito into UDF Hao Wu
  2017-11-14  7:51 ` [PATCH 2/2] MdeModulePkg/UdfDxe: Avoid possible loss track of allocated buffer Hao Wu
@ 2017-11-14 16:00 ` Paulo Alcantara
  2 siblings, 0 replies; 4+ messages in thread
From: Paulo Alcantara @ 2017-11-14 16:00 UTC (permalink / raw)
  To: Hao Wu, edk2-devel; +Cc: Ruiyu Ni, Star Zeng, Eric Dong

Hi Hao,

On 14/11/2017 05:51, Hao Wu wrote:
> The series will do the following refinements:
> a. Merge the discovery of the El Torito feature on CD/DVD media into the
>     detect of UDF;
> b. Avoid possible loss track of the allocated buffer pointer in UdfDxe.
> 
> Cc: Paulo Alcantara <pcacjr@zytor.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> 
> Hao Wu (2):
>    MdeModulePkg/PartitionDxe: Merge the discovery of ElTorito into UDF
>    MdeModulePkg/UdfDxe: Avoid possible loss track of allocated buffer
> 
>   MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c      |  7 +++----
>   MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c            | 17 +++++++++++++++++
>   MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c | 12 +++++++-----
>   3 files changed, 27 insertions(+), 9 deletions(-)
> 

Looks good to me. Thanks for fixing and testing it!

Reviewed-by: Paulo Alcantara <pcacjr@zytor.com>

Paulo


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-14 15:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-14  7:51 [PATCH 0/2] Refine UDF related codes Hao Wu
2017-11-14  7:51 ` [PATCH 1/2] MdeModulePkg/PartitionDxe: Merge the discovery of ElTorito into UDF Hao Wu
2017-11-14  7:51 ` [PATCH 2/2] MdeModulePkg/UdfDxe: Avoid possible loss track of allocated buffer Hao Wu
2017-11-14 16:00 ` [PATCH 0/2] Refine UDF related codes Paulo Alcantara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox