From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.139]) by mx.groups.io with SMTP id smtpd.web12.432.1581547574508008274 for ; Wed, 12 Feb 2020 14:46:14 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=CltX0Nr2; spf=pass (domain: microsoft.com, ip: 40.107.243.139, mailfrom: bret.barkelew@microsoft.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X6/TvrR21Gxg+GWZaoAYiaaCRJPRDYB18nlySj65bzxtpit0gAe/oogf9nb2dgF/cpWvlLgQZaEFAFisWdJMUdk0KsFjeUHt7GT+7PpQK2t2x5lEYLL9Gx+yGw+gJZP/baqVoTPUJJCC3oXcI7oycFyT3ps6fR5j04rqvoH3r7W+Pdbiw/O4wxsGCSQFz8S/9sClYxCf4UiV0jKCQ1PBuo1v5zu4xOqU2uSAIF/Zb0/UMJHbuGhf8M0xdmFbPbCYoAlGlk5yObeKraRMN8QjWvq9EqsuCoAFCyVEYsZprQ8kcbgaO966BZPLIK7HFIpRwxG4CeotAhkFrHlPEtOJMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L/IF/EC29ftzMM/i0LNSW+q2iM5VZYK6F3E0UHnahhM=; b=iNPQ79PDTFEKsJm2ZUqhqogwqszX3YHZCJRO833Eu4DifzkbcPQSqsKICg3jSU4OClLOMO55NXz/fLWkuLvXb1+TOYMldlbBQWYIIRDSpi3NMWGTUQvdW844u1vs55U+FzDWVW/kBxPiHFPNRE3s8nyGBCUy+maCujBRaNCLlZv9wp5KxDE2hgcZkBF40ZToDKj91VnTADs7Oj62Am9LBY12HPy3EipwgB6aobnT2dc51Eh2UxzJcz1qpu0afC7s+L1gG98MW/+R7EyEfvTBjay7HewiWZzIMVAWjXiUS6Jo+A0jygn0Nes/gRuUqjOht+A5PQrRvq/eKYiiBvxaqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L/IF/EC29ftzMM/i0LNSW+q2iM5VZYK6F3E0UHnahhM=; b=CltX0Nr2ZSRaGispLK+LZPNSSuRXL5H1dc1HwPWRl6yQzW9D3Zz0Hjntnz0mD49Z1B5AUJC4Fq2tLsUJDfC3sX3kaQsfM21uyTGd+z0SJ5Yn9+wZ3IhvTp3KKZYLnfInY/f+xNIy5C2aFX17TEli8+WiFLedNZw+LuutwOfECE0= Received: from CY4PR21MB0743.namprd21.prod.outlook.com (10.173.189.9) by CY4PR21MB0133.namprd21.prod.outlook.com (10.173.189.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.5; Wed, 12 Feb 2020 22:46:12 +0000 Received: from CY4PR21MB0743.namprd21.prod.outlook.com ([fe80::9118:22ef:23c:d0ab]) by CY4PR21MB0743.namprd21.prod.outlook.com ([fe80::9118:22ef:23c:d0ab%8]) with mapi id 15.20.2750.000; Wed, 12 Feb 2020 22:46:12 +0000 From: "Bret Barkelew" To: "Kinney, Michael D" , "devel@edk2.groups.io" CC: Liming Gao , Sean Brogan Subject: Re: [EXTERNAL] [Patch] MdePkg/BaseSafeIntLib: Fix VS20xx IA32 link failures Thread-Topic: [EXTERNAL] [Patch] MdePkg/BaseSafeIntLib: Fix VS20xx IA32 link failures Thread-Index: AQHV4fYY2/lN6Xcpt0CyEHb/Patj6KgYKGyp Date: Wed, 12 Feb 2020 22:46:12 +0000 Message-ID: References: <20200212224511.27164-1-michael.d.kinney@intel.com> In-Reply-To: <20200212224511.27164-1-michael.d.kinney@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2020-02-12T22:45:49.7620250Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Privileged authentication-results: spf=none (sender IP is ) smtp.mailfrom=Bret.Barkelew@microsoft.com; x-originating-ip: [2001:4898:80e8:3:94ee:4f79:9831:b3b9] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 621b86d5-e4a3-4671-64c8-08d7b00d5c86 x-ms-traffictypediagnostic: CY4PR21MB0133:|CY4PR21MB0133:|CY4PR21MB0133: x-ms-exchange-transport-forked: True x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0311124FA9 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(4636009)(39860400002)(136003)(366004)(396003)(346002)(376002)(189003)(199004)(33656002)(52536014)(71200400001)(5660300002)(7696005)(186003)(81166006)(8676002)(81156014)(110136005)(8936002)(478600001)(8990500004)(4326008)(9686003)(107886003)(54906003)(55016002)(316002)(6506007)(86362001)(53546011)(2906002)(91956017)(966005)(66946007)(66556008)(10290500003)(64756008)(66476007)(66446008)(76116006);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR21MB0133;H:CY4PR21MB0743.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2wyHYo+ePz+7+um6emMyFdZKsLvc8q5Ns+YmVpz04PyAQmlCrPKLZGVi7Y1N1fbppru9wKF0XlqRvXXP8fOfeObDqEF66X25hZvdReFrpUfsYyAkHfbN9Wy5R9MFiyainDDXXlzocz3h8kw0vnTmUx0nJFFFCEk/DyZ6C6s7qEBkyUEWTiGkzQ2yFYceYYy/D5s9wCu+GVFURFGTeRS1ZTbiNSAFsnt3hL8gVNlFSsTDyVtsP+dmCgrJz9WcYiHT4R5rMLVIztLTtpXhArnmdJzddIyz/zAyiNloMp3DaTPGCHB+D74sOclApnlM6iI5fBKOp5JzUGQ5q1IOuGf7mJnGOiTLFinu6E9/rEDuU8At1v0/JN/pJ4Xh+9vBieNFt0Fhks7o4fhPQIvjquyFVSek0lFZNIO8ar6Vk1HcK691rgf6P3YTTlPvv9CzZCUsTqonKrsoO5wfVqLyXYb+2bftWYDJgKK0axZq4eXPHKGrzTvH7Ix7lQO/O+eUw2OFTh3ADwONrCUuB5lzodU3Og== x-ms-exchange-antispam-messagedata: rLgyigYH+hRvm8n15U+2E8qohOlnNP1jJRMTj5JQ8eq6Jkc/QN28VcMavqsjx5kDSKH2anZP1wQjPqP2JDza89Bu56vcBvYDE2Cc2KanLFvLRMbGMM+SZ/xZmT84BjlZBe/n8BZ3pgzgG3h5tPDSLyNKbuPUuHe1Yzv00UHPpjtn7KqHeGYzXSnFo77S+ELo6GQ7OrogscRJWjw+kcRNLA== MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 621b86d5-e4a3-4671-64c8-08d7b00d5c86 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Feb 2020 22:46:12.8130 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 9nvU/WRLkyt26R1DJqRtYF/MDCv8cbYZbFsAFJX9GSr42/dkOdcduYmgtP46+7StEoZCihzJrA7e7bmWX4DNKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR21MB0133 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_CY4PR21MB07430BB7BC3536EAFA421654EF1B0CY4PR21MB0743namp_" --_000_CY4PR21MB07430BB7BC3536EAFA421654EF1B0CY4PR21MB0743namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bret Barkelew - Bret ________________________________ From: Michael D Kinney Sent: Wednesday, February 12, 2020 2:45:11 PM To: devel@edk2.groups.io Cc: Liming Gao ; Sean Brogan ; Bret Barkelew Subject: [EXTERNAL] [Patch] MdePkg/BaseSafeIntLib: Fix VS20xx IA32 link fai= lures https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugzill= a.tianocore.org%2Fshow_bug.cgi%3Fid%3D2525&data=3D02%7C01%7CBret.Barkel= ew%40microsoft.com%7C42f4119d0b1e4cb0fa0e08d7b00d3970%7C72f988bf86f141af91a= b2d7cd011db47%7C1%7C0%7C637171443157049083&sdata=3DwhRKJqlUj7Hq%2F%2BGt= PO2ofn97iKwfKXV93RmYCair5l0%3D&reserved=3D0 SafeUint64Mult() looks for 64-bit overflows and performs several 32-bit multiples with 64-bit results to check for all possible overflow conditions. IA32 builds using VS20xx with optimizations enabled are producing a reference to the _allmull intrinsic. The fix is to use MultU64x64() instead of '*' for these operations. These are safe because the inputs are guaranteed to have the upper 32-bits clear, which means MultU64x64() can never overflow with those inputs. Cc: Liming Gao Cc: Sean Brogan Cc: Bret Barkelew Signed-off-by: Michael D Kinney --- MdePkg/Library/BaseSafeIntLib/SafeIntLib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c b/MdePkg/Library/Ba= seSafeIntLib/SafeIntLib.c index 0f6be6e064..eec8ac1ffd 100644 --- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c +++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c @@ -3380,14 +3380,14 @@ SafeUint64Mult ( // // a * d must be less than 2^32 or there would be bits set in the hi= gh 64-bits // - ProductAD =3D (((UINT64)DwordA) *(UINT64)DwordD); + ProductAD =3D MultU64x64 ((UINT64)DwordA, (UINT64)DwordD); if ((ProductAD & 0xffffffff00000000) =3D=3D 0) { DwordB =3D (UINT32)Multiplicand; // // b * c must be less than 2^32 or there would be bits set in the = high 64-bits // - ProductBC =3D (((UINT64)DwordB) *(UINT64)DwordC); + ProductBC =3D MultU64x64 ((UINT64)DwordB, (UINT64)DwordC); if ((ProductBC & 0xffffffff00000000) =3D=3D 0) { // // now sum them all up checking for overflow. @@ -3397,7 +3397,7 @@ SafeUint64Mult ( // // b * d // - ProductBD =3D (((UINT64)DwordB) *(UINT64)DwordD); + ProductBD =3D MultU64x64 ((UINT64)DwordB, (UINT64)DwordD); if (!RETURN_ERROR (SafeUint64Add (UnsignedResult, ProductBD, &= UnsignedResult))) { *Result =3D UnsignedResult; -- 2.21.0.windows.1 --_000_CY4PR21MB07430BB7BC3536EAFA421654EF1B0CY4PR21MB0743namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Reviewed-by: Bret Barkelew <bret.barkelew@microso= ft.com>

 

- Bret

 


From: Michael D Kinney <= michael.d.kinney@intel.com>
Sent: Wednesday, February 12, 2020 2:45:11 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Liming Gao <liming.gao@intel.com>; Sean Brogan <sean.br= ogan@microsoft.com>; Bret Barkelew <Bret.Barkelew@microsoft.com> Subject: [EXTERNAL] [Patch] MdePkg/BaseSafeIntLib: Fix VS20xx IA32 l= ink failures
 
https://nam06.safelinks.protection.outlook.com/?url= =3Dhttps%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2525&amp;= data=3D02%7C01%7CBret.Barkelew%40microsoft.com%7C42f4119d0b1e4cb0fa0e08d7b0= 0d3970%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637171443157049083&= amp;sdata=3DwhRKJqlUj7Hq%2F%2BGtPO2ofn97iKwfKXV93RmYCair5l0%3D&amp;rese= rved=3D0

SafeUint64Mult() looks for 64-bit overflows and performs
several 32-bit multiples with 64-bit results to check for
all possible overflow conditions.  IA32 builds using VS20xx
with optimizations enabled are producing a reference to
the _allmull intrinsic.

The fix is to use MultU64x64() instead of '*' for
these operations.  These are safe because the inputs
are guaranteed to have the upper 32-bits clear, which
means MultU64x64() can never overflow with those inputs.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
---
 MdePkg/Library/BaseSafeIntLib/SafeIntLib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c b/MdePkg/Library/Ba= seSafeIntLib/SafeIntLib.c
index 0f6be6e064..eec8ac1ffd 100644
--- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
+++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
@@ -3380,14 +3380,14 @@ SafeUint64Mult (
       //
       // a * d must be less than 2^32 or the= re would be bits set in the high 64-bits
       //
-      ProductAD =3D (((UINT64)DwordA) *(UINT64)Dw= ordD);
+      ProductAD =3D MultU64x64 ((UINT64)Dword= A, (UINT64)DwordD);
       if ((ProductAD & 0xffffffff0000000= 0) =3D=3D 0) {
         DwordB =3D (UINT32)Multipl= icand;
 
         //
         // b * c must be less than= 2^32 or there would be bits set in the high 64-bits
         //
-        ProductBC =3D (((UINT64)DwordB)= *(UINT64)DwordC);
+        ProductBC =3D MultU64x64 ((= UINT64)DwordB, (UINT64)DwordC);
         if ((ProductBC & 0xfff= fffff00000000) =3D=3D 0) {
           //
           // now sum the= m all up checking for overflow.
@@ -3397,7 +3397,7 @@ SafeUint64Mult (
             //=
             //= b * d
             //=
-            Product= BD =3D (((UINT64)DwordB) *(UINT64)DwordD);
+            Pro= ductBD =3D MultU64x64 ((UINT64)DwordB, (UINT64)DwordD);
 
             if= (!RETURN_ERROR (SafeUint64Add (UnsignedResult, ProductBD, &UnsignedRes= ult))) {
            &nb= sp;  *Result =3D UnsignedResult;
--
2.21.0.windows.1

--_000_CY4PR21MB07430BB7BC3536EAFA421654EF1B0CY4PR21MB0743namp_--