From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web12.5122.1634112679723915863 for ; Wed, 13 Oct 2021 01:11:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=qlH2lzF1; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: jian.j.wang@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10135"; a="226150686" X-IronPort-AV: E=Sophos;i="5.85,370,1624345200"; d="scan'208";a="226150686" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 01:11:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,370,1624345200"; d="scan'208";a="491353307" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga008.jf.intel.com with ESMTP; 13 Oct 2021 01:11:18 -0700 Received: from fmsmsx605.amr.corp.intel.com (10.18.126.85) by fmsmsx604.amr.corp.intel.com (10.18.126.84) 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 01:11:17 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx605.amr.corp.intel.com (10.18.126.85) 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 01:11:17 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.171) 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.2242.12; Wed, 13 Oct 2021 01:11:17 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MJ1dFmr1AhpYv/k8sfYeke8EqX1WcOsBBjnOWSEZ+mMRQBLHB49bpzjrRzvuHqhtCe9mNLLrXudDDdISI6XTRArU1yxUOpT2TrP5s2RRQIuWCTjnen6lIcISfkz41gY9GKr6hGN2AZ6E7In62Del1WUb5YcyQPzp9zsckivFd2I0K4Hqm1pnX0gKXqGCqq2awa5VryEzKYRaALYPKJEDrBEd9dIWI57sjfKDWPhAJhq+bm6L5O7y02lgfFYXxd2wksIEO/BFDiZN/U7g6WU/f/47H+oUicVhLp9e5UDKB7YF1a4As03lezxOHxPWUXC840VK6WiL4E6gxA6v/pSiRA== 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=8rgVJkWQrT7mSgmbephg6/asr7BWflVARO+jMPk1POg=; b=jxJL+XIfgihEaN1pio0IErhMoRK75vJm2z7oRxj4ZTsxm9OBohIOcp5XoxHBCbyCEBGXtaenI44wbQtEnqfiEA1I6D6t4ouoyp5aznpsUxO+TnFxfzyAZlmoAHPg1e6kIf4xXEQWK0HdjlXQuouv+mJx1lrSEsgDaZOdU+/fBb7Fr95fbf2cPeDiiIXB1InHCTLdBpwAegP2VXyM5+Lqu0/wE9kHa4Hip9TzO7I9ky2YH4SqOm5hXBy1iX079Tcl7yBK5NIKeVhlBv7Ng4RRu0/wOMwHWcQY1lxv1USjbY3V1ft6H/uN/2ce35kbiNVdhLNHntGB5NICypV9L6WYRg== 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=8rgVJkWQrT7mSgmbephg6/asr7BWflVARO+jMPk1POg=; b=qlH2lzF11KyAk35t5BTNLNCH59yr35jhvvvzoeyQvi1510tlULq3+7ISe1xxrYhz45vZbCWz2GjQ8VkWr62glHPHGQUO7svrl4iassG/ZhpzFnhvzzzkQwoZ8ifnTdoeFXCLgG680zTz/FuEuG6544BUTekYMAZ15A8RireNG00= Received: from CO1PR11MB4945.namprd11.prod.outlook.com (2603:10b6:303:9c::8) by MWHPR11MB1791.namprd11.prod.outlook.com (2603:10b6:300:10f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Wed, 13 Oct 2021 08:11:16 +0000 Received: from CO1PR11MB4945.namprd11.prod.outlook.com ([fe80::752d:e1b:2ca:978f]) by CO1PR11MB4945.namprd11.prod.outlook.com ([fe80::752d:e1b:2ca:978f%9]) with mapi id 15.20.4608.016; Wed, 13 Oct 2021 08:11:16 +0000 From: "Wang, Jian J" 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 Thread-Topic: [PATCH v3] MdeModulePkg/Core/Dxe: Acquire a lock when iterating gHandleList Thread-Index: AQHXwAZj1WZ13i5m3UmmyOYBS602IKvQk6zg Date: Wed, 13 Oct 2021 08:11:16 +0000 Message-ID: References: <837b6a9e5919e51d47fabc133e4b860389e99a15.1634109861.git.hua.ma@intel.com> In-Reply-To: <837b6a9e5919e51d47fabc133e4b860389e99a15.1634109861.git.hua.ma@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-reaction: no-action dlp-version: 11.6.200.16 dlp-product: dlpe-windows 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: d4648c0d-6963-47d0-2746-08d98e2107ac x-ms-traffictypediagnostic: MWHPR11MB1791: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +5FAODbpCezjDpZc31grNofsSNLDOH+Yja08jUtsLtJGzydy86/0fzJPKV85xIQIc2ZC3Uteeu4tbdAMTAUWl/uHB5zVroRmAZkyf2EXdQQkd6ytrapwnhR7t5qOSP7btZnuRb/oTb1MGFoY2H39Rwiq7yvARafZvoY6LIDQP3RWs/YsUm1e0EpfDtX0si0R2Ws9j4pK43AOiEfUMjVhErLXc/l826gnLmjZLb3HOFac7IRSnYh87B/8O5NTpSdj3SarYP5UsiuHM5c29sdFLojB9hLtvyB24mvPkNzWIDMzV5ZgnOMnxUakYCMt1T4QxYzU61Lys6tcBvWCvegGmlX5IPZr9LSg2NMZCd1udZ+rFiRXF4nrCUjHrX97BRIhxF9uQn/lzKFjLEEOL5Bq4XXdDV4+/QWsRxMQZwEMq1N3a2jpXWTxBnFuuR04FtG07DBDfPeAOv3XTalt0TksbGx0UsI4F9hepcy5bA5VU1ozVO5W6z3qK0bfl/iiAp6U0WSE4P8OkYL2RiMG40+M9fTNXvBhXtZHm+U335xjfibcv8q6YArB2uI4HwKS0jFT1m2BRNlN50a2hfjohWCxUQwQ9d2zWpvKxULtFrarO1I/gOXQ8X87iqALUhihVEYxg4deMPyX/Ygrfnd967t/xyOn7qCiJy+EFWxVSnAg/5KY/tuwJmqQhjloN/myrndav9clPgH1hNv33BZeC2TI+xnFuqKNolFPDBiaXQ4mUqX28OLqbxwiPTcgvZ+o4jEJc1D1wPkfiTHM+jv8DdeYpsKLSQlwkX5N8YCbY+rW72YqKLMsWnm29NlosjFpD13mNGDIUNbluHUGhslwtCyN+Q== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4945.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(66446008)(66556008)(64756008)(66476007)(26005)(66946007)(186003)(76116006)(38100700002)(122000001)(7696005)(5660300002)(2906002)(52536014)(53546011)(6506007)(82960400001)(9686003)(33656002)(55016002)(8676002)(83380400001)(508600001)(8936002)(966005)(71200400001)(4326008)(110136005)(54906003)(316002)(86362001)(107886003)(38070700005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?WmnVibrJLBZoHiaPNQIMMwh7Ssl3aI+VOlY7HN0sJp+IRf3g27Z0+aZtU4BH?= =?us-ascii?Q?3DsWVGGjxrDvFfc5nGg/ozrHV6PHvPNUJz1c0CEf0QUI11VVWflF53o4DNg0?= =?us-ascii?Q?IoU/yqbsg6MeLn6d+Zsla2UWdEMcHmFUiPB6vbjP9ZC/sMqu0DEKKiAsNouh?= =?us-ascii?Q?NhSOh4ejQxzutESjl7yIVhOFdxnhF3W2/hUq+EXlY89Ez0r+zpnZwF3GogF7?= =?us-ascii?Q?Qgij+3mTCUWJgAW0zqacDG0jtUawA976353y/Ta7DUJe/lL1+5unTDvwhrJI?= =?us-ascii?Q?iAKROtuJTIjQQlWQ4OmyhcJnE74+PonkEY0NrVlj48OJ0xepoA547TG9NSZ4?= =?us-ascii?Q?KhrS55tP6mSN0eNSrAJf9pLAALdHhVozVGCtAudZxoyyjnP0Y7pzy5AEoI1H?= =?us-ascii?Q?L8dQqF53YBv6cZmblLYm7RdqAzu3CvVF0FGFlAVFTYQ4bM6M+OiOQFVraYGx?= =?us-ascii?Q?GrM6038sIVblfgc22KXLZI+4BWB1k6LXwEV3+/YKVgiO5Td/FOeUGaQIjmD6?= =?us-ascii?Q?w1gJRMLTJ4GPIrWArTQyXUr8QvquBX8fY0qd9uaNbgE02pJ/3BC8CsyZ88P6?= =?us-ascii?Q?juRjsbk+L5uKBtynveZIQEZX1jSzbnHDk1kVPVNvYUyzQwr5GNl/Q5H7IDqk?= =?us-ascii?Q?RnlC+3ktfOcJ/5YmaDC10h7UR2RAD/1t18qKPbxFwpwDIH+BAfbwu97gTmDB?= =?us-ascii?Q?ajhRDkHN2w0aM80z864ykabS5a81DDz19LY/ipc6Ysii4H3+ZI1mYopxOID0?= =?us-ascii?Q?o6ncymI6UFxQ23VOFQrhe08J9DnZ2VDMSyxHR/KqKBcdOfruDTUiFFTtriMv?= =?us-ascii?Q?KSvUOQTzoQQLSFgqxPOKc2C5TpYPO5X5x1TdR09snHCyf51e1e2X49Gcwq6Q?= =?us-ascii?Q?9L3R6oqrx4I+6E73AS/1bX0lfOYUJqyDQQoJgOrrcFkgTq59KfszV6+i6qkv?= =?us-ascii?Q?aqJaXzwRC07fwxt2xNFfk0km0SigJ/uG199vaRRhSO8dT+oypmkY5yB0ISbu?= =?us-ascii?Q?LiTWtOb6Lp0K9LQpLB5WOaJ8ssV6qjNXFniPKMfFqXmxIAUif3HA6cVNlcwW?= =?us-ascii?Q?2gRZSZQ+vo6IoeytJmxJguiR1PHldWYFtc/YYWgI/HyR8nKQWWcFtpF1MigK?= =?us-ascii?Q?RmRymabX6gXNa92fShNipiW5gLIFNfNH9vnRuarOp5Z9Qd7cEQpmzqE2b1JJ?= =?us-ascii?Q?3PwMUuN9KoMIlHDgPDsy5WLw10tHlkv1BrqdrTSW15VlvjO+MQMmwqd8NmwJ?= =?us-ascii?Q?Lm15goViY2xWH9M5Kwcdmoc04VbDhT9gYNItnCmCi0qsIp90tRv05sRcxKu6?= =?us-ascii?Q?X4qLZSgkigkxUMdxGBJVtktz?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4945.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4648c0d-6963-47d0-2746-08d98e2107ac X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Oct 2021 08:11:16.2298 (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: lVGnPxtC27V353zyVFKYHROynygderyCRa2oP94o+phe56qKyK4PC1oy+CixE99vaK7Z5hjqrEQUe9jfwCdfDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1791 Return-Path: jian.j.wang@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jian J Wang Regards, Jian > -----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 >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3680 >=20 > This patch fixes the following issue: >=20 > 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 iterating= . >=20 > 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(). >=20 > v3 changes: > - keep ASSERT_LOCKED(&gProtocolDatabaseLock) in CoreValidateHandle() > - Call CoreAcquireProtocolLock() before any calling of > CoreValidateHandle() and CoreReleaseProtocolLock() afterwards > - Update the commit message >=20 > v2 changes: > - Add lock check and comments in CoreGetProtocolInterface() before > calling CoreValidateHandle() > - Update the comments in CoreValidateHandle() header file >=20 > v1: https://edk2.groups.io/g/devel/topic/86233569 >=20 > 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(-) >=20 > 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; > } >=20 > @@ -757,10 +770,13 @@ CoreDisconnectController ( > if (ChildHandle !=3D NULL) { > Status =3D CoreValidateHandle (ChildHandle); > if (EFI_ERROR (Status)) { > + CoreReleaseProtocolLock (); > return Status; > } > } >=20 > + CoreReleaseProtocolLock (); > + > Handle =3D ControllerHandle; >=20 > // > 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 ( >=20 > /** > Check whether a handle is a valid EFI_HANDLE > + The gProtocolDatabaseLock must be owned >=20 > @param UserHandle The handle to check >=20 > @@ -72,6 +73,8 @@ CoreValidateHandle ( > return EFI_INVALID_PARAMETER; > } >=20 > + ASSERT_LOCKED(&gProtocolDatabaseLock); > + > for (Link =3D gHandleList.BackLink; Link !=3D &gHandleList; Link =3D L= ink->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; > } >=20 > + // > + // Lock the protocol database > + // > + CoreAcquireProtocolLock (); > + > // > // Check that UserHandle is a valid handle > // > Status =3D CoreValidateHandle (UserHandle); > if (EFI_ERROR (Status)) { > - return Status; > + goto Done; > } >=20 > - // > - // 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; > } >=20 > + // > + // Lock the protocol database > + // > + CoreAcquireProtocolLock (); > + > // > // Check for invalid UserHandle > // > Status =3D CoreValidateHandle (UserHandle); > if (EFI_ERROR (Status)) { > - return Status; > + goto Done; > } >=20 > // > @@ -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; > } >=20 > - // > - // Lock the protocol database > - // > - CoreAcquireProtocolLock (); >=20 > // > // Look at each protocol interface for a match > @@ -1246,32 +1252,33 @@ CoreCloseProtocol ( > LIST_ENTRY *Link; > OPEN_PROTOCOL_DATA *OpenData; >=20 > + // > + // 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; > } >=20 > - // > - // Lock the protocol database > - // > - CoreAcquireProtocolLock (); > - > // > // Look at each protocol interface for a match > // > @@ -1443,13 +1450,6 @@ CoreProtocolsPerHandle ( > UINTN ProtocolCount; > EFI_GUID **Buffer; >=20 > - 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 ( >=20 > CoreAcquireProtocolLock (); >=20 > + Status =3D CoreValidateHandle (UserHandle); > + if (EFI_ERROR (Status)) { > + goto Done; > + } > + > + Handle =3D (IHANDLE *)UserHandle; > + > for (Link =3D Handle->Protocols.ForwardLink; Link !=3D &Handle->Protoc= ols; 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 ( >=20 > /** > Check whether a handle is a valid EFI_HANDLE > + The gProtocolDatabaseLock must be owned >=20 > @param UserHandle The handle to check >=20 > 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; >=20 > - Status =3D CoreValidateHandle (UserHandle); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > if (Protocol =3D=3D NULL) { > return EFI_INVALID_PARAMETER; > } >=20 > - Handle =3D (IHANDLE *) UserHandle; > - > // > // Lock the protocol database > // > CoreAcquireProtocolLock (); >=20 > + 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