public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jian J Wang <jian.j.wang@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Bi Dandan <dandan.bi@intel.com>
Subject: [PATCH 3/3] IntelFrameworkModulePkg: Fix misuses of AllocateCopyPool
Date: Fri,  3 Nov 2017 12:57:59 +0800	[thread overview]
Message-ID: <20171103045759.26508-4-jian.j.wang@intel.com> (raw)
In-Reply-To: <20171103045759.26508-1-jian.j.wang@intel.com>

AllocateCopyPool(AllocationSize, *Buffer) will copy "AllocationSize" bytes of
memory from old "Buffer" to new allocated one. If "AllocationSize" is bigger
than size of "Buffer", heap memory overflow occurs during copy.

The solution is to allocate pool first then copy the necessary bytes to new
memory. This can avoid copying extra bytes from unknown memory range.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Bi Dandan <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
---
 IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
index 125c49db5e..b844224068 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
@@ -480,7 +480,9 @@ AddIdToMacDeviceList (
   } else {
     mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;
     if (mMacDeviceList.CurListLen != 0) {
-      TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList);
+      TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);
+      ASSERT (TempDeviceList != NULL);
+      CopyMem (TempDeviceList, mMacDeviceList.NodeList, sizeof (MENU_INFO_ITEM) * mMacDeviceList.CurListLen);
     } else {
       TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);
     }
-- 
2.14.1.windows.1



      parent reply	other threads:[~2017-11-03  4:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03  4:57 [PATCH 0/3] Fix misuses of AllocateCopyPool Jian J Wang
2017-11-03  4:57 ` [PATCH 1/3] MdeModulePkg: " Jian J Wang
2017-11-03  9:14   ` Zeng, Star
2017-11-06  0:49     ` Wang, Jian J
2017-11-03  4:57 ` [PATCH 2/3] ShellPkg: " Jian J Wang
2017-11-03  8:22   ` Ni, Ruiyu
2017-11-03 11:43     ` Jim.Dailey
2017-11-06  0:55       ` Wang, Jian J
2017-11-06  0:35     ` Wang, Jian J
2017-11-03  4:57 ` Jian J Wang [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=20171103045759.26508-4-jian.j.wang@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