]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg/BaseCryptLib: Fix potential integer overflow issue.
authorLong Qin <qin.long@intel.com>
Wed, 24 Oct 2018 13:16:42 +0000 (21:16 +0800)
committerLong Qin <qin.long@intel.com>
Wed, 31 Oct 2018 03:07:53 +0000 (11:07 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1275

The LookupFreeMemRegion() in RuntimeMemAllocate.c is used to look-up
free memory region for runtime resource allocation, which was designed
to support runtime authenticated variable service.
The ReqPages in this function is the required pages to be allocated,
which depends on the malloc() call in internal OpenSSL routines. The
direct offset subtractions on ReqPages may bring possible integer
overflow issue.

This patch is to add the extra parameter checks to remove this possible
overflow risk.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Long Qin <qin.long@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c

index 463f2bf8557bfb0036bc0467d9f9b55b24cd7684..92bb9ddccdb9e64998aa0eee7e21d6938cbfaa8e 100644 (file)
@@ -2,7 +2,7 @@
   Light-weight Memory Management Routines for OpenSSL-based Crypto\r
   Library at Runtime Phase.\r
 \r
-Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -141,6 +141,12 @@ LookupFreeMemRegion (
 \r
   StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->LastEmptyPageOffset);\r
   ReqPages       = RT_SIZE_TO_PAGES (AllocationSize);\r
+  if (ReqPages > mRTPageTable->PageCount) {\r
+    //\r
+    // No enough region for object allocation.\r
+    //\r
+    return (UINTN)(-1);\r
+  }\r
 \r
   //\r
   // Look up the free memory region with in current memory map table.\r
@@ -176,6 +182,12 @@ LookupFreeMemRegion (
   // Look up the free memory region from the beginning of the memory table\r
   // until the StartCursorOffset\r
   //\r
+  if (ReqPages > StartPageIndex) {\r
+    //\r
+    // No enough region for object allocation.\r
+    //\r
+    return (UINTN)(-1);\r
+  }\r
   for (Index = 0; Index < (StartPageIndex - ReqPages); ) {\r
     //\r
     // Check Consecutive ReqPages Pages.\r