From nobody Sun Apr 28 01:00:06 2024 Delivered-To: importer@patchew.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; Authentication-Results: mx.zoho.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 1495021165498566.9670552378024; Wed, 17 May 2017 04:39:25 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 48BF821A0708A; Wed, 17 May 2017 04:39:22 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 6512721A16E5F for ; Wed, 17 May 2017 04:39:21 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2017 04:39:21 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.15]) by orsmga003.jf.intel.com with ESMTP; 17 May 2017 04:39:20 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,354,1491289200"; d="scan'208";a="969399175" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 17 May 2017 19:39:17 +0800 Message-Id: <20170517113917.172084-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 Subject: [edk2] [PATCH] MdeModulePkg/BDS: Fix a buffer overflow bug 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: , 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" KeyOption points to a buffer holding the content of Key####. So its size is smaller than EFI_BOOT_MANAGER_KEY_OPTION. Old code to assign value to KeyOption->OptionNumber modifies the memory outside of the KeyOption buffer. The patch fixes this bug. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Steven Shi --- MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModule= Pkg/Library/UefiBootManagerLib/BmHotkey.c index 0f2e677c8a..431be0d8d6 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c @@ -167,7 +167,10 @@ BmCollectKeyOptions ( if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) { GetEfiGlobalVariable2 (Name, (VOID**) &KeyOption, &KeyOptionSize); ASSERT (KeyOption !=3D NULL); - KeyOption->OptionNumber =3D OptionNumber; + // + // Be careful!! KeyOption points to a buffer smaller than EFI_BOOT_MAN= AGER_KEY_OPTION. + // Do not access KeyOption->OptionNumber. + // if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) { Param->KeyOptions =3D ReallocatePool ( Param->KeyOptionCount * sizeof (EFI_BOOT_MANAG= ER_KEY_OPTION), @@ -179,12 +182,13 @@ BmCollectKeyOptions ( // Insert the key option in order // for (Index =3D 0; Index < Param->KeyOptionCount; Index++) { - if (KeyOption->OptionNumber < Param->KeyOptions[Index].OptionNumbe= r) { + if (OptionNumber < Param->KeyOptions[Index].OptionNumber) { break; } } CopyMem (&Param->KeyOptions[Index + 1], &Param->KeyOptions[Index], (= Param->KeyOptionCount - Index) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION)); CopyMem (&Param->KeyOptions[Index], KeyOption, BmSizeOfKeyOption (Ke= yOption)); + Param->KeyOptions[Index].OptionNumber =3D OptionNumber; Param->KeyOptionCount++; } FreePool (KeyOption); --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel