From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.37931.1669883661579402627 for ; Thu, 01 Dec 2022 00:34:21 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=l/CWHEmp; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: jiewen.yao@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669883661; x=1701419661; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=1Ox+roOpU30pZANC137XJlphzDmQf9dZRch73qPSYmI=; b=l/CWHEmpH3TbluP38ZDzfg9psQm3h8YqK+w7c3YgdRSoPRho2wypIxvZ 29FFDXXJK8JoyBu5NetUKgyrxTJD5kS3anuVTCyo+W6k5L460c0yhHyNU gRpins47LXuFg1QE5gN06pwUriBCeBZs86pt4ctLgg8kPpn95C9qQJmlJ ipu9KrR+p4My0PpDJm4J7RTVn5rjhlqWebg78hngrbi31AfZImJOrfV+m 6zuXPCW9uJqqN64Bb3wlNAfda606ihaNxBdFLL65uqYeP4WWePUvRZfrE c8di8GUObGZBQQexnPVtNZlG9fZEOCLo6YEq99bMnEztW1CImsCWM2rXL Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10547"; a="317485919" X-IronPort-AV: E=Sophos;i="5.96,207,1665471600"; d="scan'208";a="317485919" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2022 00:34:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10547"; a="594981879" X-IronPort-AV: E=Sophos;i="5.96,207,1665471600"; d="scan'208";a="594981879" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga003.jf.intel.com with ESMTP; 01 Dec 2022 00:34:20 -0800 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Thu, 1 Dec 2022 00:34:20 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Thu, 1 Dec 2022 00:34:20 -0800 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (104.47.73.48) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Thu, 1 Dec 2022 00:34:15 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DMr/f+hhFC/pf/r5UWRRheoXJoie5jInzI2lTaIdL5jcU9M8RWhYjrYZGK2i+xtxlQHFVZh366exDTW2CBM83+/70MC/w3vr4+fMGeMl37ppISoZhZqetT9sgM1Frw2MAc0JtrHE8IQDgLtIXbfHS8KYE+jWqyiaMvJGjPavSPK0WB/a0sGi9o0fSIUsKCol8JaLENwCqa+6kEfGMhMIi55e6otUTyZ3nrsFqZBQaOabqvttHwLsyhRtDctk/4661c6rVoHCGfdCKAt1wsvm+Yagz87fnlc2Uv9M94T7QoXSECe7ZNIIgNyxBZ6EAmidUpk4Cty/DjBvTd8qJAwF8g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SuGOUmWFJf6ebGubr66aeWoJUszqpf9WXLa8SZdgfOw=; b=LTmbrLDgh1L8Aq9AZoQCwjBM+04LvTlzyJ7kBk8iIuNG3J6+ts6TtkvRXlKCwhqWM5xErVkjG+SRzGjDd4LfQ8mLZrgnI4L6X2v+JYNjgKoeXd4FVE+P7ywHT0aSCDLv148neDtk71InVhJ7EFlWWKzvz3kLnNcZjjntdwh5+tBB4sj9OpwrG5Jlo6+YQk4rhoqmsrD5ctdByddKAzcbcN04ZTpDSx+Hqrap8TiRoj/P5KDFgjeMETk571O43jjtk7S9BSkRfVsUM15zKqTPOjVMjwDFz49MDXznnNrY0KzDJ3CRIaVRX6I3D0JkrMCY5s6QqIrnDNrzU2151kFGRA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MW4PR11MB5872.namprd11.prod.outlook.com (2603:10b6:303:169::14) by IA1PR11MB7856.namprd11.prod.outlook.com (2603:10b6:208:3f5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.17; Thu, 1 Dec 2022 08:34:13 +0000 Received: from MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::e9dd:f205:1970:4edb]) by MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::e9dd:f205:1970:4edb%9]) with mapi id 15.20.5857.023; Thu, 1 Dec 2022 08:34:13 +0000 From: "Yao, Jiewen" To: "devel@edk2.groups.io" , "xiewenyi2@huawei.com" , "Wang, Jian J" , "Lu, Xiaoyu1" , "Jiang, Guomin" CC: "songdongkuang@huawei.com" , "yizihong@huawei.com" Subject: Re: [edk2-devel] [PATCH EDK2 v1 1/1] CryptoPkg/BaseCryptLib:time overflow Thread-Topic: [edk2-devel] [PATCH EDK2 v1 1/1] CryptoPkg/BaseCryptLib:time overflow Thread-Index: AQHZAK39VswvPNWy2EqWNEfbkDrdf65Yvc0w Date: Thu, 1 Dec 2022 08:34:12 +0000 Message-ID: References: <20221125091148.2405866-1-xiewenyi2@huawei.com> <20221125091148.2405866-2-xiewenyi2@huawei.com> In-Reply-To: <20221125091148.2405866-2-xiewenyi2@huawei.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5872:EE_|IA1PR11MB7856:EE_ x-ms-office365-filtering-correlation-id: 4eded4be-a917-4e54-0a95-08dad376d344 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: KSqRR0ziMLQKRxi4F4HW8yluZZzR50wAVmYudlecIZE8vsMP+T/skhNpn3ZEiBAKwtx9xe4fAJ34O8pf8643KGAUHw+GsJgV+VqBPZJ7abK7zHWlXYzASgDqNszwk3VgstQtYeegIln1nr5jiFbJSvfokFbbjN9rpNdgLmJjH4NUay24ZE7bGv44eLbreXdcAPeWLk+SkseCiE/yU0DaJCBVpyHMXNHDculGQmopbEx3tUAWEUQJLctJkQakZa3Gm50rkWk8eENyyaahWM+9g5xoCaoNbydioNIrwENt61xOdVaCkyhwTKfyJGpEg65Y5kFQ8cDZuVlwR6eYXpNEJGA2pywL62cVITOWV85xo8ukjJzttcOWyf6JSwM0T02WAt4SlVdrZNl0PU4PA5GnCOMT0LFFJKS5oPjSILuTfiPwX9FT9C8ljsg76WOorIe56C9mazLkxArbfv3vXP00nLCahqbaRZdLrA0uyB1wIWc/jZ3GnaHP/yO+xZYjS/mC32rfnAZxk7TEv6q2csNlqQS/eVko2LkxxwqXLm7ndOCfKG1SHSA8tx+aIRYTKVRMCZ3BO1EWqZL2fSY4hzR5WK5NG+MsyYLMQKrEM/2gEUKRFQlhmYZzwNSmLYeVgzK3Nze58ReLY2F4YMvRPMON/omq9/k0e+an85hswp9TP39dB8Qs5emNHft3SpCkRE6/20enEaNp3luYizimZuscq/4bdsyneCmNrF5db0Qv07hsLEJwMW0gd/GP6hLRzaQsaN4QuvzWwkMZiwaNe6xwYg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR11MB5872.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(39860400002)(376002)(366004)(136003)(396003)(451199015)(316002)(66556008)(64756008)(966005)(66946007)(83380400001)(186003)(110136005)(4326008)(6636002)(2906002)(122000001)(66446008)(86362001)(55016003)(8936002)(38100700002)(41300700001)(66476007)(54906003)(8676002)(33656002)(19627235002)(26005)(82960400001)(5660300002)(53546011)(6506007)(7696005)(9686003)(71200400001)(76116006)(66899015)(52536014)(38070700005)(478600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?6UlkizhtugwNUDZYOeZlyLOu8X87y3oc/uj3C1/OfsyH0iDBqy3PIJFR6Qw4?= =?us-ascii?Q?ZgFh/xSKXSP38e8AIQu565Bz0O2ncpkbt9OHbBsqm2w8i7MjveDX5tgccl5e?= =?us-ascii?Q?KCAjy5fTSYFD/G0iZWknJefQ1iB8+wOxg+lZVP/JuWrv4sqoLL+G+nLoA35G?= =?us-ascii?Q?iYG0WCvbfUOhvqPcOukTjpnzQuFRbANKrsB54ZZfxDOzWsEywoU30XZP1L+n?= =?us-ascii?Q?A53WqhhiJOovC39h+O51Q6fpWMEZPNwqiKmO2fTP1c/9uI/xEEKgywvT7tSa?= =?us-ascii?Q?Pm+4Ut83wgWraXxzB8hB7BxPEIkipQfj8wXYXPCJPcURhw7Qjz1AV8fcU2SF?= =?us-ascii?Q?tjGU4ttRVB0yckkQzGO1F+t5AWX0G6wXdmKn/soFQCFNGtOu4R4sB5eKYmIG?= =?us-ascii?Q?9XzXMWIEc4nzY5pjNbyh4e2XKPw9nrFEuahtT2BN2dt3YQv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FnrEeqXfsRjDQJ2SQBTb+UQCkUn2Z?= =?us-ascii?Q?FBlFpavcfroNirI4l7t3TtgQ92vjA54n67QEfxlS+tr4DR7WKxy+KRPqqwka?= =?us-ascii?Q?JxYToH8vO8EJF5KAhFgeAIc0/PugjBAZ3HtK/QX6xLY/c45l6mw9tTYpMJFR?= =?us-ascii?Q?GWthDXtdxbzyv7zpXfOD+Twu/1+zVk5hhBgrAEQO7cAGkNaKr+FYVoa7xAeB?= =?us-ascii?Q?EQUsKP2pEqzho1DVRga9qq+GuH93vdDGOWsQuAkR?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5872.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4eded4be-a917-4e54-0a95-08dad376d344 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Dec 2022 08:34:13.0086 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: dWrCphVLgJkXwKN9ahDPVInEOgIRW+SDAFeyV5pDS98mpv0GCnDbjxuN+BEPTB/MvqWZTHtRzBAuVglD2uI75Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR11MB7856 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thank you! Would you please share what test you have run for this patch, such as UEFI = secure boot? HTTPS boot? > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of > wenyi,xie via groups.io > Sent: Friday, November 25, 2022 5:12 PM > To: devel@edk2.groups.io; Yao, Jiewen ; Wang, Jian > J ; Lu, Xiaoyu1 ; Jiang, > Guomin > Cc: songdongkuang@huawei.com; xiewenyi2@huawei.com; > yizihong@huawei.com > Subject: [edk2-devel] [PATCH EDK2 v1 1/1] CryptoPkg/BaseCryptLib:time > overflow >=20 > From: Zihong Yi >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4167 >=20 > In CrtLibSupport.h, time_t is defined as INT32, and its maximum value > is 2147483647. That is, the corresponding maximum timestamp is > 2038-01-19 11:14:07. Therefore, overflow occurs when the test time > exceeds 2038-01-19 11:14:07. So change the type of time_t to INT64 and > also change the type of variables in function gmtime which calculated > with time_t. >=20 > Cc: Jiewen Yao > Cc: Jian J Wang > Cc: Xiaoyu Lu > Cc: Guomin Jiang > Signed-off-by: Zihong Yi > --- > CryptoPkg/Library/Include/CrtLibSupport.h | 2 +- > CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c | 51 > ++++++++++++++------ > 2 files changed, 38 insertions(+), 15 deletions(-) >=20 > diff --git a/CryptoPkg/Library/Include/CrtLibSupport.h > b/CryptoPkg/Library/Include/CrtLibSupport.h > index 5072c343da57..94b0e6b6014f 100644 > --- a/CryptoPkg/Library/Include/CrtLibSupport.h > +++ b/CryptoPkg/Library/Include/CrtLibSupport.h > @@ -109,7 +109,7 @@ typedef UINTN off_t; > typedef UINTN u_int; > typedef INTN ptrdiff_t; > typedef INTN ssize_t; > -typedef INT32 time_t; > +typedef INT64 time_t; > typedef UINT8 __uint8_t; > typedef UINT8 sa_family_t; > typedef UINT8 u_char; > diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c > b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c > index bf8a5325817f..3ed64375d0ff 100644 > --- a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c > +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c > @@ -15,7 +15,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > // -- Time Management Routines -- > // >=20 > -#define IsLeap(y) (((y) % 4) =3D=3D 0 && (((y) % 100) !=3D 0 || ((y) % = 400) =3D=3D 0)) > #define SECSPERMIN (60) > #define SECSPERHOUR (60 * 60) > #define SECSPERDAY (24 * SECSPERHOUR) > @@ -60,6 +59,26 @@ UINTN CumulativeDays[2][14] =3D { > } > }; >=20 > +/* Check the year is leap or not. */ > +// BOOLEAN IsLeap( > +// INTN timer > +// ) > +BOOLEAN > +IsLeap ( > + time_t timer > + ) > +{ > + INT64 Remainder1; > + INT64 Remainder2; > + INT64 Remainder3; > + > + DivS64x64Remainder (timer, 4, &Remainder1); > + DivS64x64Remainder (timer, 100, &Remainder2); > + DivS64x64Remainder (timer, 400, &Remainder3); > + > + return (Remainder1 =3D=3D 0 && (Remainder2 !=3D 0 || Remainder3 =3D=3D= 0)); > +} > + > /* Get the system time as seconds elapsed since midnight, January 1, 197= 0. > */ > // INTN time( > // INTN *timer > @@ -117,12 +136,13 @@ gmtime ( > ) > { > struct tm *GmTime; > - UINT16 DayNo; > - UINT32 DayRemainder; > + UINT64 DayNo; > + UINT64 DayRemainder; > time_t Year; > time_t YearNo; > - UINT16 TotalDays; > - UINT16 MonthNo; > + UINT32 TotalDays; > + UINT32 MonthNo; > + INT64 Remainder; >=20 > if (timer =3D=3D NULL) { > return NULL; > @@ -135,18 +155,21 @@ gmtime ( >=20 > ZeroMem ((VOID *)GmTime, (UINTN)sizeof (struct tm)); >=20 > - DayNo =3D (UINT16)(*timer / SECSPERDAY); > - DayRemainder =3D (UINT32)(*timer % SECSPERDAY); > + DayNo =3D (UINT64)DivS64x64Remainder (*timer, SECSPERDAY, > &Remainder); > + DayRemainder =3D (UINT64)Remainder; >=20 > - GmTime->tm_sec =3D (int)(DayRemainder % SECSPERMIN); > - GmTime->tm_min =3D (int)((DayRemainder % SECSPERHOUR) / > SECSPERMIN); > - GmTime->tm_hour =3D (int)(DayRemainder / SECSPERHOUR); > - GmTime->tm_wday =3D (int)((DayNo + 4) % 7); > + DivS64x64Remainder (DayRemainder, SECSPERMIN, &Remainder); > + GmTime->tm_sec =3D (int)Remainder; > + DivS64x64Remainder (DayRemainder, SECSPERHOUR, &Remainder); > + GmTime->tm_min =3D (int)DivS64x64Remainder (Remainder, SECSPERMIN, > NULL); > + GmTime->tm_hour =3D (int)DivS64x64Remainder (DayRemainder, > SECSPERHOUR, NULL); > + DivS64x64Remainder ((DayNo + 4), 7, &Remainder); > + GmTime->tm_wday =3D (int)Remainder; >=20 > for (Year =3D 1970, YearNo =3D 0; DayNo > 0; Year++) { > - TotalDays =3D (UINT16)(IsLeap (Year) ? 366 : 365); > + TotalDays =3D (UINT32)(IsLeap (Year) ? 366 : 365); > if (DayNo >=3D TotalDays) { > - DayNo =3D (UINT16)(DayNo - TotalDays); > + DayNo =3D (UINT64)(DayNo - TotalDays); > YearNo++; > } else { > break; > @@ -158,7 +181,7 @@ gmtime ( >=20 > for (MonthNo =3D 12; MonthNo > 1; MonthNo--) { > if (DayNo >=3D CumulativeDays[IsLeap (Year)][MonthNo]) { > - DayNo =3D (UINT16)(DayNo - (UINT16)(CumulativeDays[IsLeap > (Year)][MonthNo])); > + DayNo =3D (UINT64)(DayNo - (UINT32)(CumulativeDays[IsLeap > (Year)][MonthNo])); > break; > } > } > -- > 2.20.1.windows.1 >=20 >=20 >=20 >=20 >=20