From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web09.4026.1634178103545359329 for ; Wed, 13 Oct 2021 19:21:43 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=eY+BSwnV; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: dandan.bi@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10136"; a="208382362" X-IronPort-AV: E=Sophos;i="5.85,371,1624345200"; d="scan'208";a="208382362" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 19:21:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,371,1624345200"; d="scan'208";a="548243804" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by fmsmga004.fm.intel.com with ESMTP; 13 Oct 2021 19:21:42 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Wed, 13 Oct 2021 19:21:42 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12 via Frontend Transport; Wed, 13 Oct 2021 19:21:42 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.12; Wed, 13 Oct 2021 19:21:42 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JY3j1f7h9tU7Go2w0y604wvqIStdrxWIEkZfB5zYWa6BeR1KSQumwswiQVRXh3J3K+fciZQrsr8oBmzb71fx0F4S3hYQ7gwpHA4hDz34C+UOz/SARVYiOrSONlh6NTqVhBLSB6nPZRw3T9fORVV85jE4uHREi1Fwl97uprDYQxS8mLtmQe2j53Tfcd4CBUihVyzj+LZ5HM4zppSqf3eYBreN77qzjrUWaRu+n4jIUUZgMIwuO3o6mI2663m3uyspcEqo3UhRq4Fjh1xpz+TO+R+DefUZcwS0uvfQnbt5mMaXGfVUsb9pUYM9bO5CAMRPPZEbOh6d4TAXT50S49XeIA== 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=GC56xl/DyukcqEmkT8M6zV773G4aBO96RyT9Gl9EBS8=; b=OxMITegBCLAiA2kO0IJt4m2eMP5izU1rE+qvtPkdtMfXlWHqCWCpBu6v/8cXvn89ffw+CGUVX2KUVxmSY3Ckh/zSUmAWDe6LT1twVZ+YR6YCOSp3B1k/rO1FCm1/obIniZs4jx0nVxbI2CL1vAxFHWGoGxie5f4948L8djFEC4b8I6OTyTgIhLWaJzWLNcbr4fecW83EojaZXEV2+5G9i5N9faWY42B3nvrlO5XVWBUv2E2Vqs46pMtd5GuR8z2Qrw+thokWPu3XBWB5a0cq1marUYtmMWrHVdv0QrbAMd6eZ3Y40heS7lpT20iCN2qxe8F5KPkDneVI5IB2fHvY4g== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GC56xl/DyukcqEmkT8M6zV773G4aBO96RyT9Gl9EBS8=; b=eY+BSwnVf6ciY02hva297B3QSpSq6nw67zv/KGwQAWu7q4Kb5v8KZHIrgdvsWEzxlHXNz0jeWCLRF0eXimXGZS/F9zDBlZ5jsCfmDiul5stTYnGZOm/Jg25nFfsO4xpuIG+3eFjl65NswHHclelYQxjJYa9ZozmgC1lpeijxf+k= Received: from DM4PR11MB5453.namprd11.prod.outlook.com (2603:10b6:5:398::15) by DM8PR11MB5717.namprd11.prod.outlook.com (2603:10b6:8:30::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24; Thu, 14 Oct 2021 02:21:40 +0000 Received: from DM4PR11MB5453.namprd11.prod.outlook.com ([fe80::ed4c:25e0:281e:da52]) by DM4PR11MB5453.namprd11.prod.outlook.com ([fe80::ed4c:25e0:281e:da52%2]) with mapi id 15.20.4587.026; Thu, 14 Oct 2021 02:21:40 +0000 From: "Dandan Bi" To: "Wang, Jian J" , "Ma, Hua" , "devel@edk2.groups.io" CC: Liming Gao , "Ni, Ray" Subject: Re: [PATCH v3] MdeModulePkg/Core/Dxe: Acquire a lock when iterating gHandleList Thread-Topic: [PATCH v3] MdeModulePkg/Core/Dxe: Acquire a lock when iterating gHandleList Thread-Index: AQHXwAZj7R6hhY8FPES///8I+sp2xKvQk70AgAEwg7A= Date: Thu, 14 Oct 2021 02:21:40 +0000 Message-ID: References: <837b6a9e5919e51d47fabc133e4b860389e99a15.1634109861.git.hua.ma@intel.com> In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 577f90e4-1989-4bf7-f6a2-08d98eb95b5b x-ms-traffictypediagnostic: DM8PR11MB5717: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: IZXb8k4+mu6GaaY//tnLSlroIgjozNU7U30OqPc6aMM7Ta5dj8B9QWW7ih3NZk6szMCCMBScHKMKnu8LdDL1SwhInMVh9bsa78qnVZEawcQkZAV+FwCKYyqLBx7qx70bgMRCnSxQlHrSPqjs89HJtSeS7twMLZGmUswIUb1OZ5Au+imr8G2EKD9XGiI/W0w4KHtR5JEYWfhkCxa+tdv/JJTS74fJ9v2KH8Vfgj0cCy/huV88+cumu9ivjA68prTK3f2qWJEGBfrTKBZe2FCTIZo2mtemoqfm2FoTwLPgVtodwa0c6eXv6EjRTEWKR6Ul+8ockuUUE8+p3tSH26Ql1chr189Se2PrYqXvvrz3hhmRHMlkX0x2SE0z0kVXuVhKTgnAxLbuVlJkumi9lVQqpMzDjZf5tGTGZic0bZPq4svsoy1BM2VphtynEVFVvhykcfm9GdXtTSy4+jKKRKfYfQhjW8EMOF8+tA+HZpyCKnzsQAtoh743Bk6zC0guptkW7rUCjp0LUPdJNoBtE8BgwRoTfL/NyBWz64012WoV6CgJr3cWXCgowQVI05x+yWYPHcam7vCjhYZg58bp6eCLSEaHq/EX8sf38shaIt4nwHjRM7+AIZYjdZPB5G3PXKhyZUyF9TT8St/fjykf8gt1pUEIV1C0StQUbDTyFaGtECV1UvMCdDEmc4AQD8OVM/zvan8FPmpmm/X/ydTp0UazLM54BBN1gpOAUebKbAMw4DcIB0luIozoIg5cnVtExk73396o/vX7WOxfRGCmruPf9slbrHjBf4a5NNH1OQKhl0lfqtK4Lb7SA0x/T6Ywqqf72nMPXCqdWotUBAYDD614jg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR11MB5453.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(7696005)(86362001)(55016002)(186003)(30864003)(82960400001)(8676002)(71200400001)(9686003)(26005)(83380400001)(6506007)(122000001)(54906003)(66946007)(110136005)(66446008)(966005)(5660300002)(107886003)(4326008)(316002)(8936002)(66476007)(66556008)(52536014)(33656002)(2906002)(76116006)(38070700005)(38100700002)(53546011)(64756008)(508600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?OHz/n9CHTy8U6SU6wYs9rN1cNwhyN8YPEs1KO+kNqwSzLqosebhC26ZBZQe3?= =?us-ascii?Q?6bFYM3ZKMP7h67Io7Kc3fvBfoyeSI4Lasdv4dj+Z8ohcjvPHS6CTixYs/UYJ?= =?us-ascii?Q?XJ5d5WfVMhwzg4NL9I+FzUOqD++MHdY63coz1f1v8n2vuJufNPBg30lAvPgP?= =?us-ascii?Q?SDu6NMTwINfcdpTFRcojb9t7fE+bdoRkk9oO7VfHnGccbMtTBr5Rcvhq5Fa2?= =?us-ascii?Q?5X9JrnZqGwlmggvDS5hYGzMsQCorah03Z9DQBFykqga+mgDsOOBihmSnbg+5?= =?us-ascii?Q?G1TcO3Cs3xPvH3QyhPILLKpyWfwMRBvNtIeqiWtO6Nv+aM/346lupW84UbWi?= =?us-ascii?Q?GNCgMH9YxSJ2VkUaKd7iKcG4x9MLrnHB7Fg/ytMLy5iTxT96EeIoQ8Io02K8?= =?us-ascii?Q?1qi6BAacs71xsRsmg8COouWJROOIOwGFFAnXCTbqrYYikFruUXb2INNZAenf?= =?us-ascii?Q?57qEq75pgRvUJXSAZ4L1mG/BYirHmz8Rh7KvkSfeJ1/pYd5Dx5xhgXP3PE7Q?= =?us-ascii?Q?lJNTuYCIlzVDr4UzQt03hscjjwbapmx8x8op3gZ5ufYnGrUDOxfX0c7kA9XK?= =?us-ascii?Q?84dTGhCylH1wvxYbVXVS3NHI81LBfK2JgQfSE4PoRwQsl7lSrbFJOslyDlig?= =?us-ascii?Q?viOgYPv/BsTXATYZF0ntAozeeIUhwZwjlSxF3IQpDKnA+dJ6HuFkHcP+tyq/?= =?us-ascii?Q?YTHp69pcG35sf5MjfIV+v3AZb9UQ0F2CfqlaTKgIAJEdRfPQL1/vD0+hd7fB?= =?us-ascii?Q?nOUuoSwiYzcMsGhrig9wKAUD2FGYE4How01zJQ3WZu4MqhxDMK2MsGHoAGgR?= =?us-ascii?Q?xBQS98oJMvHr7ofwKLtiIWY28M3Jysx7rAvtbWwftgOYumOSD5Ep5DAfJjKE?= =?us-ascii?Q?gkx6dvZ5Tv0TEUgcxYaAcUT/jFRXp/HL/M/4Kd5SL2Wf9o5Dov4eNfVPAu9I?= =?us-ascii?Q?8mySy8FkADHTX4jdWn2UtYL0VaZo6izY/sqW7zaLW+5pVhqMtFtb7RdVFbUk?= =?us-ascii?Q?8OP6NCHaSe5UbSkv3eZQ75aupxaqfIo6BXppUOZXQ5/tuo9wjCQuL+huY+0q?= =?us-ascii?Q?3W9Rkj+3FNZreXIQXjk3WK4KtKsZzkLTqPownWIGVmbRWOnLFyDMqvMfXLQx?= =?us-ascii?Q?NERbSeL9wdPZmE3LSEuCTMqwreuSML8pOST/6Nc5XBuB1gIyvpasPoitL+2L?= =?us-ascii?Q?wIUx61EIreFzhP2yNV8bwHf23fp9HLBhpapzk3OwaPQnMaxHAA+uzJ9sfUBF?= =?us-ascii?Q?wJKswfricB71AN+ZBMgcKprVzlIGa042NlGTqepFktaOLxevVM+gKm/ESX+o?= =?us-ascii?Q?a9w=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5453.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 577f90e4-1989-4bf7-f6a2-08d98eb95b5b X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Oct 2021 02:21:40.2114 (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: HFBxyBqPJFzaKLiXFF3R87AUqKjEami/29OE9I5DJPSP3xmlnyDLJnAJK216FKbPFTUtdQonLAKa/NGPmgufCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR11MB5717 Return-Path: dandan.bi@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Dandan Bi Thanks, Dandan > -----Original Message----- > From: Wang, Jian J > Sent: Wednesday, October 13, 2021 4:11 PM > To: Ma, Hua ; devel@edk2.groups.io > Cc: Liming Gao ; Bi, Dandan > ; Ni, Ray > Subject: RE: [PATCH v3] MdeModulePkg/Core/Dxe: Acquire a lock when > iterating gHandleList >=20 > Reviewed-by: Jian J Wang >=20 > Regards, > Jian >=20 > > -----Original Message----- > > From: Ma, Hua > > Sent: Wednesday, October 13, 2021 3:45 PM > > To: devel@edk2.groups.io > > Cc: Ma, Hua ; Wang, Jian J ; > > Liming Gao ; Bi, Dandan > > ; Ni, Ray > > Subject: [PATCH v3] MdeModulePkg/Core/Dxe: Acquire a lock when > > iterating gHandleList > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3680 > > > > This patch fixes the following issue: > > > > The global variable gHandleList is a linked list. > > This list is locked when a entry is added or removed from the list, > > but there is no lock when iterating this list in function > > CoreValidateHandle(). > > It can lead to "Handle.c (76): CR has Bad Signature" assertion if the > > iterated entry in the list is just removed by other task during iterati= ng. > > > > Currently some caller functions of CoreValidateHandle() have > > CoreAcquireProtocolLock(), but some caller functions of > > CoreValidateHandle() do not CoreAcquireProtocolLock(). > > Add CoreAcquireProtocolLock() always when CoreValidateHandle() is > > called, Also, A lock check is added in the CoreValidateHandle(). > > > > v3 changes: > > - keep ASSERT_LOCKED(&gProtocolDatabaseLock) in CoreValidateHandle() > > - Call CoreAcquireProtocolLock() before any calling of > > CoreValidateHandle() and CoreReleaseProtocolLock() afterwards > > - Update the commit message > > > > v2 changes: > > - Add lock check and comments in CoreGetProtocolInterface() before > > calling CoreValidateHandle() > > - Update the comments in CoreValidateHandle() header file > > > > v1: https://edk2.groups.io/g/devel/topic/86233569 > > > > Cc: Jian J Wang > > Cc: Liming Gao > > Cc: Dandan Bi > > Cc: Ray Ni > > Signed-off-by: Hua Ma > > --- > > MdeModulePkg/Core/Dxe/Hand/DriverSupport.c | 16 +++++ > > MdeModulePkg/Core/Dxe/Hand/Handle.c | 75 ++++++++++++---------- > > MdeModulePkg/Core/Dxe/Hand/Handle.h | 1 + > > MdeModulePkg/Core/Dxe/Hand/Notify.c | 13 ++-- > > 4 files changed, 64 insertions(+), 41 deletions(-) > > > > diff --git a/MdeModulePkg/Core/Dxe/Hand/DriverSupport.c > > b/MdeModulePkg/Core/Dxe/Hand/DriverSupport.c > > index feabf12faf..12a202417c 100644 > > --- a/MdeModulePkg/Core/Dxe/Hand/DriverSupport.c > > +++ b/MdeModulePkg/Core/Dxe/Hand/DriverSupport.c > > @@ -68,7 +68,12 @@ CoreConnectController ( > > // > > // Make sure ControllerHandle is valid > > // > > + CoreAcquireProtocolLock (); > > + > > Status =3D CoreValidateHandle (ControllerHandle); > > + > > + CoreReleaseProtocolLock (); > > + > > if (EFI_ERROR (Status)) { > > return Status; > > } > > @@ -268,7 +273,12 @@ AddSortedDriverBindingProtocol ( > > // > > // Make sure the DriverBindingHandle is valid > > // > > + CoreAcquireProtocolLock (); > > + > > Status =3D CoreValidateHandle (DriverBindingHandle); > > + > > + CoreReleaseProtocolLock (); > > + > > if (EFI_ERROR (Status)) { > > return; > > } > > @@ -746,8 +756,11 @@ CoreDisconnectController ( > > // > > // Make sure ControllerHandle is valid > > // > > + CoreAcquireProtocolLock (); > > + > > Status =3D CoreValidateHandle (ControllerHandle); > > if (EFI_ERROR (Status)) { > > + CoreReleaseProtocolLock (); > > return Status; > > } > > > > @@ -757,10 +770,13 @@ CoreDisconnectController ( > > if (ChildHandle !=3D NULL) { > > Status =3D CoreValidateHandle (ChildHandle); > > if (EFI_ERROR (Status)) { > > + CoreReleaseProtocolLock (); > > return Status; > > } > > } > > > > + CoreReleaseProtocolLock (); > > + > > Handle =3D ControllerHandle; > > > > // > > diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c > > b/MdeModulePkg/Core/Dxe/Hand/Handle.c > > index 6eccb41ecb..92979281b7 100644 > > --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c > > +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c > > @@ -53,6 +53,7 @@ CoreReleaseProtocolLock ( > > > > /** > > Check whether a handle is a valid EFI_HANDLE > > + The gProtocolDatabaseLock must be owned > > > > @param UserHandle The handle to check > > > > @@ -72,6 +73,8 @@ CoreValidateHandle ( > > return EFI_INVALID_PARAMETER; > > } > > > > + ASSERT_LOCKED(&gProtocolDatabaseLock); > > + > > for (Link =3D gHandleList.BackLink; Link !=3D &gHandleList; Link =3D= Link->BackLink) > { > > Handle =3D CR (Link, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE); > > if (Handle =3D=3D (IHANDLE *) UserHandle) { @@ -720,19 +723,19 @@ > > CoreUninstallProtocolInterface ( > > return EFI_INVALID_PARAMETER; > > } > > > > + // > > + // Lock the protocol database > > + // > > + CoreAcquireProtocolLock (); > > + > > // > > // Check that UserHandle is a valid handle > > // > > Status =3D CoreValidateHandle (UserHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > > > - // > > - // Lock the protocol database > > - // > > - CoreAcquireProtocolLock (); > > - > > // > > // Check that Protocol exists on UserHandle, and Interface matches > > the interface in the database > > // > > @@ -1010,12 +1013,17 @@ CoreOpenProtocol ( > > return EFI_INVALID_PARAMETER; > > } > > > > + // > > + // Lock the protocol database > > + // > > + CoreAcquireProtocolLock (); > > + > > // > > // Check for invalid UserHandle > > // > > Status =3D CoreValidateHandle (UserHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > > > // > > @@ -1025,31 +1033,32 @@ CoreOpenProtocol ( > > case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER : > > Status =3D CoreValidateHandle (ImageHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > Status =3D CoreValidateHandle (ControllerHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > if (UserHandle =3D=3D ControllerHandle) { > > - return EFI_INVALID_PARAMETER; > > + Status =3D EFI_INVALID_PARAMETER; > > + goto Done; > > } > > break; > > case EFI_OPEN_PROTOCOL_BY_DRIVER : > > case EFI_OPEN_PROTOCOL_BY_DRIVER | > EFI_OPEN_PROTOCOL_EXCLUSIVE : > > Status =3D CoreValidateHandle (ImageHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > Status =3D CoreValidateHandle (ControllerHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > break; > > case EFI_OPEN_PROTOCOL_EXCLUSIVE : > > Status =3D CoreValidateHandle (ImageHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > break; > > case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL : > > @@ -1057,13 +1066,10 @@ CoreOpenProtocol ( > > case EFI_OPEN_PROTOCOL_TEST_PROTOCOL : > > break; > > default: > > - return EFI_INVALID_PARAMETER; > > + Status =3D EFI_INVALID_PARAMETER; > > + goto Done; > > } > > > > - // > > - // Lock the protocol database > > - // > > - CoreAcquireProtocolLock (); > > > > // > > // Look at each protocol interface for a match @@ -1246,32 +1252,33 > > @@ CoreCloseProtocol ( > > LIST_ENTRY *Link; > > OPEN_PROTOCOL_DATA *OpenData; > > > > + // > > + // Lock the protocol database > > + // > > + CoreAcquireProtocolLock (); > > + > > // > > // Check for invalid parameters > > // > > Status =3D CoreValidateHandle (UserHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > Status =3D CoreValidateHandle (AgentHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > if (ControllerHandle !=3D NULL) { > > Status =3D CoreValidateHandle (ControllerHandle); > > if (EFI_ERROR (Status)) { > > - return Status; > > + goto Done; > > } > > } > > if (Protocol =3D=3D NULL) { > > - return EFI_INVALID_PARAMETER; > > + Status =3D EFI_INVALID_PARAMETER; > > + goto Done; > > } > > > > - // > > - // Lock the protocol database > > - // > > - CoreAcquireProtocolLock (); > > - > > // > > // Look at each protocol interface for a match > > // > > @@ -1443,13 +1450,6 @@ CoreProtocolsPerHandle ( > > UINTN ProtocolCount; > > EFI_GUID **Buffer; > > > > - Status =3D CoreValidateHandle (UserHandle); > > - if (EFI_ERROR (Status)) { > > - return Status; > > - } > > - > > - Handle =3D (IHANDLE *)UserHandle; > > - > > if (ProtocolBuffer =3D=3D NULL) { > > return EFI_INVALID_PARAMETER; > > } > > @@ -1464,6 +1464,13 @@ CoreProtocolsPerHandle ( > > > > CoreAcquireProtocolLock (); > > > > + Status =3D CoreValidateHandle (UserHandle); if (EFI_ERROR (Status)) > > + { > > + goto Done; > > + } > > + > > + Handle =3D (IHANDLE *)UserHandle; > > + > > for (Link =3D Handle->Protocols.ForwardLink; Link !=3D > > &Handle->Protocols; Link =3D > > Link->ForwardLink) { > > ProtocolCount++; > > } > > diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.h > > b/MdeModulePkg/Core/Dxe/Hand/Handle.h > > index 83eb2b9f3a..3f83e3af15 100644 > > --- a/MdeModulePkg/Core/Dxe/Hand/Handle.h > > +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.h > > @@ -242,6 +242,7 @@ CoreReleaseProtocolLock ( > > > > /** > > Check whether a handle is a valid EFI_HANDLE > > + The gProtocolDatabaseLock must be owned > > > > @param UserHandle The handle to check > > > > diff --git a/MdeModulePkg/Core/Dxe/Hand/Notify.c > > b/MdeModulePkg/Core/Dxe/Hand/Notify.c > > index 553413a350..d05f95207f 100644 > > --- a/MdeModulePkg/Core/Dxe/Hand/Notify.c > > +++ b/MdeModulePkg/Core/Dxe/Hand/Notify.c > > @@ -188,22 +188,21 @@ CoreReinstallProtocolInterface ( > > PROTOCOL_INTERFACE *Prot; > > PROTOCOL_ENTRY *ProtEntry; > > > > - Status =3D CoreValidateHandle (UserHandle); > > - if (EFI_ERROR (Status)) { > > - return Status; > > - } > > - > > if (Protocol =3D=3D NULL) { > > return EFI_INVALID_PARAMETER; > > } > > > > - Handle =3D (IHANDLE *) UserHandle; > > - > > // > > // Lock the protocol database > > // > > CoreAcquireProtocolLock (); > > > > + Status =3D CoreValidateHandle (UserHandle); if (EFI_ERROR (Status)) > > + { > > + goto Done; > > + } > > + > > + Handle =3D (IHANDLE *) UserHandle; > > // > > // Check that Protocol exists on UserHandle, and Interface matches > > the interface in the database > > // > > -- > > 2.32.0.windows.2