From nobody Sun Apr 28 04:45:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511399178929169.13040971937164; Wed, 22 Nov 2017 17:06:18 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CE5A42035BB1F; Wed, 22 Nov 2017 17:02:00 -0800 (PST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 C586A220C163B for ; Wed, 22 Nov 2017 17:01:59 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Nov 2017 17:06:16 -0800 Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.52]) by fmsmga006.fm.intel.com with ESMTP; 22 Nov 2017 17:06:15 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,438,1505804400"; d="scan'208";a="179520420" From: Jian J Wang To: edk2-devel@lists.01.org Date: Thu, 23 Nov 2017 09:06:13 +0800 Message-Id: <20171123010613.8908-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.14.1.windows.1 Subject: [edk2] [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: , Cc: Wu Hao , Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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. This patch adds sanity check before any array reference in those methods. Cc: Wu Hao Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang Reviewed-by: Hao Wu --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 4 +++- MdeModulePkg/Core/PiSmmCore/HeapGuard.c | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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/Pi= SmmCore/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 --=20 2.14.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel