From nobody Mon May 6 21:59:20 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+42733+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+42733+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1561356884; cv=none; d=zoho.com; s=zohoarc; b=QjfE9wSoGazHFWVrihiFytMZSvqTLJxbDyF0kysANXwg4BQA2FJAb/cWycAZlyvg5kj6xXXq4vYqRgDr1SxEGCpwWxK+lB2abHqREHPVmOhQJww9vTD6p4nhAflOd2kseSQWv6dEuqIz6YgSQP3K+JgEA+TSIiF/btOGPBXyp4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561356884; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=DAxu/mIm6NFT1uVQh2FrZ1EptP/aQXTJL9nSetJo54I=; b=JWC8XJM292zrz86LP6lxT7FG9n9SP5zVFiFx7jP3XqTI31IQt8ongmPJPQChV81YHDdevxX7rN+DOFmCCbSX+2AGFz9Dy40e3giyJwtFM7qI1KJhNzphvDxvG+qCr4H7BSmkmgyRu4HxTmhYxWQcGAb1f4XzspMO+apX114jFgE= 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+42733+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 156135688469750.30236629547687; Sun, 23 Jun 2019 23:14:44 -0700 (PDT) Return-Path: X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by groups.io with SMTP; Sun, 23 Jun 2019 23:14:43 -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 orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Jun 2019 23:14:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,411,1557212400"; d="scan'208";a="182565673" X-Received: from fieedk001.ccr.corp.intel.com ([10.239.33.119]) by fmsmga001.fm.intel.com with ESMTP; 23 Jun 2019 23:14:41 -0700 From: "Gao, Zhichao" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek , Liming Gao Subject: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Move checksum part for valid microcode data Date: Mon, 24 Jun 2019 14:14:37 +0800 Message-Id: <20190624061437.33744-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=1561356884; bh=5UIZIC4K8WVEDd4Q17QXa5Mfy5ktkI3lg4ord7CFlwU=; h=Cc:Date:From:Reply-To:Subject:To; b=aj/c4cOV4CZxcC3rbf4jcZz5znl+NCpEE7hFfwLluq3uf4+MWHe0TnyftqVL0o03+0w 5XJLqjQ+qBR4SUnBkMsT0JRSUvjGvJhMcXwKy/fZhlGO9HYBxdj3ZbF0qN26BXw89gE2U N2qpAfZEa5cq1s9DCbFpUSIE45u9Wz2kl4U= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1934 Originally, the checksum part would done before verfiy the microcode data. Which meas the checksum would be done for a meaningless data. It would cause a incorrect TotalSize (the size of microcode data), then incorrect checksum and incorrect pointer increasing would happen. To fix this, move the checksum part 1 section in 'if (MicrocodeEntryPoint->HeaderVersion =3D=3D 0x1)' section for a valid microcode data. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Liming Gao Signed-off-by: Zhichao Gao --- UefiCpuPkg/Library/MpInitLib/Microcode.c | 52 ++++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 4763dcfebe..f1a42f2d4e 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 **/ @@ -160,34 +160,34 @@ MicrocodeDetect ( // CorrectMicrocode =3D FALSE; =20 - if (MicrocodeEntryPoint->DataSize =3D=3D 0) { - TotalSize =3D sizeof (CPU_MICROCODE_HEADER) + 2000; - } else { - TotalSize =3D sizeof (CPU_MICROCODE_HEADER) + MicrocodeEntryPoint->D= ataSize; - } + if (MicrocodeEntryPoint->HeaderVersion =3D=3D 0x1) { + if (MicrocodeEntryPoint->DataSize =3D=3D 0) { + TotalSize =3D sizeof (CPU_MICROCODE_HEADER) + 2000; + } else { + TotalSize =3D sizeof (CPU_MICROCODE_HEADER) + MicrocodeEntryPoint-= >DataSize; + } =20 - /// - /// Check overflow and whether TotalSize is aligned with 4 bytes. - /// - if ( ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd || - (TotalSize & 0x3) !=3D 0 - ) { - MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (((UINTN) Microcode= EntryPoint) + SIZE_1KB); - continue; - } + /// + /// Check overflow and whether TotalSize is aligned with 4 bytes. + /// + if ( ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd || + (TotalSize & 0x3) !=3D 0 + ) { + MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (((UINTN) Microco= deEntryPoint) + SIZE_1KB); + continue; + } =20 - // - // Save an in-complete CheckSum32 from CheckSum Part1 for common parts. - // - InCompleteCheckSum32 =3D CalculateSum32 ( - (UINT32 *) MicrocodeEntryPoint, - TotalSize - ); - InCompleteCheckSum32 -=3D MicrocodeEntryPoint->ProcessorSignature.Uint= 32; - InCompleteCheckSum32 -=3D MicrocodeEntryPoint->ProcessorFlags; - InCompleteCheckSum32 -=3D MicrocodeEntryPoint->Checksum; + // + // Save an in-complete CheckSum32 from CheckSum Part1 for common par= ts. + // + InCompleteCheckSum32 =3D CalculateSum32 ( + (UINT32 *) MicrocodeEntryPoint, + TotalSize + ); + InCompleteCheckSum32 -=3D MicrocodeEntryPoint->ProcessorSignature.Ui= nt32; + InCompleteCheckSum32 -=3D MicrocodeEntryPoint->ProcessorFlags; + InCompleteCheckSum32 -=3D MicrocodeEntryPoint->Checksum; =20 - if (MicrocodeEntryPoint->HeaderVersion =3D=3D 0x1) { // // It is the microcode header. It is not the padding data between mi= crocode patches // because the padding data should not include 0x00000001 and it sho= uld be the repeated --=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 (#42733): https://edk2.groups.io/g/devel/message/42733 Mute This Topic: https://groups.io/mt/32189383/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-