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>, Paulo Alcantara <pcacjr@zytor.com>,
	Ruiyu Ni <ruiyu.ni@intel.com>, Star Zeng <star.zeng@intel.com>,
	Eric Dong <eric.dong@intel.com>
Subject: [PATCH 1/7] MdeModulePkg/UdfDxe: Add checks to ensure no possible NULL ptr deref
Date: Fri, 15 Sep 2017 12:57:47 +0800	[thread overview]
Message-ID: <20170915045753.588-2-hao.a.wu@intel.com> (raw)
In-Reply-To: <20170915045753.588-1-hao.a.wu@intel.com>

Case 1 - Within DuplicateFid() & DuplicateFe():
The call to AllocateCopyPool() may return NULL.
Add ASSERTs as checks.

Case 2 - Within UdfRead():
Add ASSERT to ensure 'NewFileEntryData' returned from FindFileEntry()
will not be NULL pointer.

Case 3 - Within GetAllocationDescriptorLsn():
The return value of 'GetPdFromLongAd (Volume, ParentIcb)' may be NULL,
and it will be passed into function GetShortAdLsn() which will
dereference it.
Add ASSERT in GetShortAdLsn() as check.

Case 4 - Within ReadFile():
Add ASSERT to ensure 'Data' returned from GetAedAdsData() will not be NULL
pointer.

Case 5 - Within InternalFindFile():
If both 'Parent->FileIdentifierDesc' and 'Icb' are NULL, then possible
NULL pointer dereference will happen in ReadDirectoryEntry().
Add additional check to resolve.

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/File.c                 |  1 +
 MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/File.c b/MdeModulePkg/Universal/Disk/UdfDxe/File.c
index 01361141bb..82db75475b 100644
--- a/MdeModulePkg/Universal/Disk/UdfDxe/File.c
+++ b/MdeModulePkg/Universal/Disk/UdfDxe/File.c
@@ -427,6 +427,7 @@ UdfRead (
     if (EFI_ERROR (Status)) {
       goto Error_Find_Fe;
     }
+    ASSERT (NewFileEntryData != NULL);
 
     if (IS_FE_SYMLINK (NewFileEntryData)) {
       Status = ResolveSymlink (
diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
index 4609580b30..02a73a9eb9 100644
--- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
+++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
@@ -297,6 +297,8 @@ GetShortAdLsn (
   IN UDF_SHORT_ALLOCATION_DESCRIPTOR  *ShortAd
   )
 {
+  ASSERT (PartitionDesc != NULL);
+
   return (UINT64)PartitionDesc->PartitionStartingLocation +
     ShortAd->ExtentPosition;
 }
@@ -480,6 +482,8 @@ DuplicateFid (
   *NewFileIdentifierDesc =
     (UDF_FILE_IDENTIFIER_DESCRIPTOR *)AllocateCopyPool (
       (UINTN) GetFidDescriptorLength (FileIdentifierDesc), FileIdentifierDesc);
+
+  ASSERT (*NewFileIdentifierDesc != NULL);
 }
 
 //
@@ -494,6 +498,8 @@ DuplicateFe (
   )
 {
   *NewFileEntry = AllocateCopyPool (Volume->FileEntrySize, FileEntry);
+
+  ASSERT (*NewFileEntry != NULL);
 }
 
 //
@@ -1028,6 +1034,7 @@ ReadFile (
         if (EFI_ERROR (Status)) {
           goto Error_Get_Aed;
         }
+        ASSERT (Data != NULL);
 
         AdOffset = 0;
         continue;
@@ -1209,6 +1216,13 @@ InternalFindFile (
   VOID                            *CompareFileEntry;
 
   //
+  // Check if both Parent->FileIdentifierDesc and Icb are NULL.
+  //
+  if ((Parent->FileIdentifierDesc == NULL) && (Icb == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
   // Check if parent file is really directory.
   //
   if (!IS_FE_DIRECTORY (Parent->FileEntry)) {
@@ -1220,6 +1234,10 @@ InternalFindFile (
   // FE/EFE and FID descriptors.
   //
   if (StrCmp (FileName, L".") == 0) {
+    if (Parent->FileIdentifierDesc == NULL) {
+      return EFI_INVALID_PARAMETER;
+    }
+
     DuplicateFe (BlockIo, Volume, Parent->FileEntry, &File->FileEntry);
     DuplicateFid (Parent->FileIdentifierDesc, &File->FileIdentifierDesc);
 
-- 
2.12.0.windows.1



  reply	other threads:[~2017-09-15  4:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-15  4:57 [PATCH 0/7] MdeModulePkg/Udf: Code refinements Hao Wu
2017-09-15  4:57 ` Hao Wu [this message]
2017-09-15  4:57 ` [PATCH 2/7] MdeModulePkg/UdfDxe: Fix operands of different size in bitwise OP Hao Wu
2017-09-15  4:57 ` [PATCH 3/7] MdeModulePkg/UdfDxe: Use compare operator for non-boolean comparisons Hao Wu
2017-09-15  4:57 ` [PATCH 4/7] MdeModulePkg/Udf: Refine function description comments Hao Wu
2017-09-15  4:57 ` [PATCH 5/7] MdeModulePkg/UdfDxe: Avoid short (single character) variable name Hao Wu
2017-09-15  4:57 ` [PATCH 6/7] MdeModulePkg/Udf: Avoid declaring and initializing local GUID variable Hao Wu
2017-09-15  4:57 ` [PATCH 7/7] MdeModulePkg/UdfDxe: Refine enum member naming style Hao Wu
2017-09-15 21:47 ` [PATCH 0/7] MdeModulePkg/Udf: Code refinements Paulo Alcantara
2017-09-19  3:30   ` Zeng, Star
2017-09-19  3:36     ` Wu, Hao A

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=20170915045753.588-2-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