From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7B26C220D4BFE for ; Wed, 15 Nov 2017 23:43:49 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2017 23:47:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,402,1505804400"; d="scan'208";a="2419353" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by FMSMGA003.fm.intel.com with ESMTP; 15 Nov 2017 23:47:57 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Ruiyu Ni , Star Zeng , Eric Dong Date: Thu, 16 Nov 2017 15:47:42 +0800 Message-Id: <20171116074742.15024-3-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171116074742.15024-1-hao.a.wu@intel.com> References: <20171116074742.15024-1-hao.a.wu@intel.com> Subject: [PATCH v2 2/2] MdeModulePkg/UdfDxe: Avoid possible loss track of allocated buffer X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Nov 2017 07:43:49 -0000 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 Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Paulo Alcantara --- 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