]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UdfDxe: Avoid possible use of already-freed data
authorHao Wu <hao.a.wu@intel.com>
Tue, 16 Oct 2018 05:09:43 +0000 (13:09 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 23 Oct 2018 06:25:04 +0000 (14:25 +0800)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1255

For function ReadFile():

If the line

  Status = GetAedAdsData (
   ...
   );

is reached multiple times during the 'for' loop, freeing the data pointed
by variable 'Data' may potentially lead to variable 'Ad' referencing the
already-freed data.

After calling function GetAllocationDescriptor(), 'Data' and 'Ad' may
point to the same memory (with some possible offset). Hence, this commit
will move the FreePool() call backwards to ensure the data will no longer
be used.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Paulo Alcantara <palcantara@suse.de>
Acked-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c

index cabb599695aaa684476263e108d2a2315e83ab48..b9ebddfe6293ad8a353297168acf390f2aa3657f 100644 (file)
@@ -1078,6 +1078,7 @@ ReadFile (
   EFI_STATUS              Status;\r
   UINT32                  LogicalBlockSize;\r
   VOID                    *Data;\r
+  VOID                    *DataBak;\r
   UINT64                  Length;\r
   VOID                    *Ad;\r
   UINT64                  AdOffset;\r
@@ -1218,12 +1219,7 @@ ReadFile (
       // Descriptor and its extents (ADs).\r
       //\r
       if (GET_EXTENT_FLAGS (RecordingFlags, Ad) == ExtentIsNextExtent) {\r
-        if (!DoFreeAed) {\r
-          DoFreeAed = TRUE;\r
-        } else {\r
-          FreePool (Data);\r
-        }\r
-\r
+        DataBak = Data;\r
         Status = GetAedAdsData (\r
           BlockIo,\r
           DiskIo,\r
@@ -1234,6 +1230,13 @@ ReadFile (
           &Data,\r
           &Length\r
           );\r
+\r
+        if (!DoFreeAed) {\r
+          DoFreeAed = TRUE;\r
+        } else {\r
+          FreePool (DataBak);\r
+        }\r
+\r
         if (EFI_ERROR (Status)) {\r
           goto Error_Get_Aed;\r
         }\r