From nobody Wed Nov 27 00:29:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+42866+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+42866+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1561527126; cv=none; d=zoho.com; s=zohoarc; b=iloVNRjzr59lp5q1q+kFslbEXI0XtrZVE/uC8vWL2o/DaGkwqmcELKSyeuD5XNxzhescH1/PHqR+fWMjSzVkHyybgVBnuxygLY7+sPagZTz2e/k15dOaRJfHTAB+2fDKN9OLgLbId+sU4U6mFsrrDUS3gANsGyKkoV4RJtLyhmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561527126; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=3H2IVOrzbNAarLUhl8I8o6jnNLrHVHQL6ENa76LOc10=; b=KucJd1eXviDwZD6oBotAN7cwz5sA4PbsgaPcYy0gLf7WOC3PwadTl6ofDZFo4JZ5npSzjgbCuZTfaq+YUbhHuuWUaMLWARAtUzEWRTjyxTlYk9l72kz5WS+dd1uYRZzFXVU0syjjkInQD7W+zNjuQc1UOAyKBvYRStqo2qTsegk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+42866+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1561527126989481.3956203065851; Tue, 25 Jun 2019 22:32:06 -0700 (PDT) Return-Path: X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by groups.io with SMTP; Tue, 25 Jun 2019 22:32:03 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jun 2019 22:32:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,418,1557212400"; d="scan'208";a="183051307" X-Received: from fieedk001.ccr.corp.intel.com ([10.239.33.119]) by fmsmga001.fm.intel.com with ESMTP; 25 Jun 2019 22:32:01 -0700 From: "Gao, Zhichao" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek , Liming Gao Subject: [edk2-devel] [PATCH v3] UefiCpuPkg/MpInitLib: MicrocodeDetect: Ensure checked range is valid Date: Wed, 26 Jun 2019 13:31:58 +0800 Message-Id: <20190626053158.6060-1-zhichao.gao@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhichao.gao@intel.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1561527123; bh=+GEZY7n7ozLy/FnnSOD3s703AMcf4ILf5SoEaT7OUfA=; h=Cc:Date:From:Reply-To:Subject:To; b=RcnbocSzIEb2m9VtR73C6HLIT5UJ2X1vBJaMuPnSXwTcC4ImlHlvd7j/TwGoCSNZ406 MQLfOIgit0BPsNYAjArxE25UtbbN98KJUGe77r/CVECid+fZmsbvTOZ73NWNvjZlpl2jH srL30pk50ICQAqUSD1jmYOIOfybE0fzkVJA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1934 0x0 MicrocodeBegin MicrocodeEntry MicrocodeEnd 0xffffffff |--------------|---------------|---------------|---------------| valid TotalSize TotalSize is only valid between 0 and (MicrocodeEnd - MicrocodeEntry). So add '(UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize)' before '((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd' to make sure ((UINTN)MicrocodeEntryPoint + TotalSize) wouldn't overflow. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Liming Gao Signed-off-by: Zhichao Gao Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/Microcode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 4763dcfebe..c30df58e5a 100644 --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c @@ -1,7 +1,7 @@ /** @file Implementation of loading microcode on processors. =20 - Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -167,9 +167,15 @@ MicrocodeDetect ( } =20 /// - /// Check overflow and whether TotalSize is aligned with 4 bytes. + /// 0x0 MicrocodeBegin MicrocodeEntry MicrocodeEnd 0xffff= ffff + /// |--------------|---------------|---------------|---------------| + /// valid TotalSize + /// TotalSize is only valid between 0 and (MicrocodeEnd - MicrocodeEnt= ry). + /// And it should be aligned with 4 bytes. + /// If the TotalSize is invalid skip 1KB the check next entry. /// - if ( ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd || + if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) || + ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd || (TotalSize & 0x3) !=3D 0 ) { MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (((UINTN) Microcode= EntryPoint) + SIZE_1KB); --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#42866): https://edk2.groups.io/g/devel/message/42866 Mute This Topic: https://groups.io/mt/32212210/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-