CryptoPkg/BaseCryptLib: Fix potential integer overflow issue.

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>
This commit is contained in:
Long Qin 2018-10-24 21:16:42 +08:00
parent beabfd5800
commit 269f3b5180
1 changed files with 13 additions and 1 deletions

View File

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