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.65; helo=mga03.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 DCF212034C5DD for ; Wed, 22 Nov 2017 17:34:27 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Nov 2017 17:38:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,438,1505804400"; d="scan'208";a="10915494" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 22 Nov 2017 17:38:44 -0800 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 22 Nov 2017 17:38:44 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 22 Nov 2017 17:38:43 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.152]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.213]) with mapi id 14.03.0319.002; Thu, 23 Nov 2017 09:38:41 +0800 From: "Wu, Hao A" To: "Wang, Jian J" , "edk2-devel@lists.01.org" CC: "Zeng, Star" , "Dong, Eric" Thread-Topic: [PATCH] MdeModulePkg/Core: Fix potential array overflow Thread-Index: AQHTY/dI1sE9RkKRD06NV2zkTrrI2qMhL6Eg Date: Thu, 23 Nov 2017 01:38:41 +0000 Message-ID: References: <20171123010613.8908-1-jian.j.wang@intel.com> In-Reply-To: <20171123010613.8908-1-jian.j.wang@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdeModulePkg/Core: Fix potential array overflow 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, 23 Nov 2017 01:34:28 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Hao Wu Best Regards, Hao Wu > -----Original Message----- > From: Wang, Jian J > Sent: Thursday, November 23, 2017 9:06 AM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A; Zeng, Star; Dong, Eric > Subject: [PATCH] MdeModulePkg/Core: Fix potential array overflow >=20 > In the method DumpGuardedMemoryBitmap() and SetAllGuardPages(), the > code > didn't check if the global mMapLevel is legal value or not, which leaves > a logic hole causing potential array overflow in code followed. >=20 > This patch adds sanity check before any array reference in those methods. >=20 > Cc: Wu Hao > Cc: Star Zeng > Cc: Eric Dong > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 4 +++- > MdeModulePkg/Core/PiSmmCore/HeapGuard.c | 8 ++++++-- > 2 files changed, 9 insertions(+), 3 deletions(-) >=20 > diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c > b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c > index 30a73fc04d..3a829854af 100644 > --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c > +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c > @@ -1110,7 +1110,9 @@ DumpGuardedMemoryBitmap ( > CHAR8 *Ruler1; > CHAR8 *Ruler2; >=20 > - if (mGuardedMemoryMap =3D=3D 0) { > + if (mGuardedMemoryMap =3D=3D 0 || > + mMapLevel =3D=3D 0 || > + mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) { > return; > } >=20 > diff --git a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c > b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c > index 7dbbf79dc0..1d5fb8cdb5 100644 > --- a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c > +++ b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c > @@ -1170,7 +1170,9 @@ SetAllGuardPages ( > UINTN Index; > BOOLEAN OnGuarding; >=20 > - if (mGuardedMemoryMap =3D=3D 0) { > + if (mGuardedMemoryMap =3D=3D 0 || > + mMapLevel =3D=3D 0 || > + mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) { > return; > } >=20 > @@ -1329,7 +1331,9 @@ DumpGuardedMemoryBitmap ( > CHAR8 *Ruler1; > CHAR8 *Ruler2; >=20 > - if (mGuardedMemoryMap =3D=3D 0) { > + if (mGuardedMemoryMap =3D=3D 0 || > + mMapLevel =3D=3D 0 || > + mMapLevel > GUARDED_HEAP_MAP_TABLE_DEPTH) { > return; > } >=20 > -- > 2.14.1.windows.1