From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 3A18BAC1016 for ; Mon, 22 Jan 2024 09:53:01 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=SVyYSRk4RaeecMyM7mm9JiBT3ak8HZz/d4LLEW7Zgvw=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1705917180; v=1; b=hhS4TW/sCPubxbNhJfyoQ9z/Om+yGQGnVCWNxNDB2wH9sIlRcBDD8K+TXJvwctDKtoDjreJc k/Apk9i/A8PcAfb261F0tdHxnDDESOL/Odyon6DwFpC1dlxDbKP/Dgsk+FBfPOBigyfPaGvyyWb 7skCg6zI7/yoBO/jf3KH+Q64= X-Received: by 127.0.0.2 with SMTP id fnKhYY7687511xVbjxv4GEln; Mon, 22 Jan 2024 01:53:00 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.69970.1705917179856456592 for ; Mon, 22 Jan 2024 01:53:00 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10960"; a="465424613" X-IronPort-AV: E=Sophos;i="6.05,211,1701158400"; d="scan'208";a="465424613" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 01:52:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10960"; a="735094011" X-IronPort-AV: E=Sophos;i="6.05,211,1701158400"; d="scan'208";a="735094011" X-Received: from zjin7-devs.sh.intel.com ([10.239.154.113]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 01:52:55 -0800 From: "Zhi Jin" To: devel@edk2.groups.io Cc: Zhi Jin , Liming Gao , Ray Ni , Michael D Kinney Subject: [edk2-devel] [PATCH v2 1/2] MdeModulePkg: Remove the handle validation check in CoreGetProtocolInterface Date: Mon, 22 Jan 2024 17:53:22 +0800 Message-Id: <20240122095323.1824627-1-zhi.jin@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,zhi.jin@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 1zitHvPdo74ID8TFkCLkNnDCx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="hhS4TW/s"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io CoreGetProtocolInterface() is called by CoreOpenProtocol(), CoreCloseProtocol() and CoreOpenProtocolInformation(). Before CoreOpenProtocol() calls CoreGetProtocolInterface(), the input parameter UserHandle has been already checked for validation. So does CoreCloseProtocol(). Removing the handle validation check in CoreGetProtocolInterface() could improve the performance, as CoreOpenProtocol() is called very frequently. To ensure the assumption that the caller of CoreGetProtocolInterface() must pass in a valid UserHandle that is checked with CoreValidateHandle(), add the parameter check in CoreOpenProtocolInformation(), and declare CoreGetProtocolInterface() as static. v1 -> v2: 1. Update the description of UserHandle to state that the caller must pass in a valid UserHandle that is checked with CoreValidateHandle(). 2. Declare CoreGetProtocolInterface() as static. Cc: Liming Gao Cc: Ray Ni Cc: Michael D Kinney Signed-off-by: Zhi Jin --- MdeModulePkg/Core/Dxe/Hand/Handle.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index 51e5b5d3b3..24e4fbf5f3 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -918,28 +918,25 @@ CoreUninstallMultipleProtocolInterfaces ( Locate a certain GUID protocol interface in a Handle's protocols. @param UserHandle The handle to obtain the protocol interface on + The caller must pass in a valid UserHandle that + is checked with CoreValidateHandle(). @param Protocol The GUID of the protocol @return The requested protocol interface for the handle **/ +STATIC PROTOCOL_INTERFACE * CoreGetProtocolInterface ( IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol ) { - EFI_STATUS Status; PROTOCOL_ENTRY *ProtEntry; PROTOCOL_INTERFACE *Prot; IHANDLE *Handle; LIST_ENTRY *Link; - Status = CoreValidateHandle (UserHandle); - if (EFI_ERROR (Status)) { - return NULL; - } - Handle = (IHANDLE *)UserHandle; // @@ -1392,6 +1389,15 @@ CoreOpenProtocolInformation ( // CoreAcquireProtocolLock (); + // + // Check for invalid UserHandle + // + Status = CoreValidateHandle (UserHandle); + if (EFI_ERROR (Status)) { + Status = EFI_NOT_FOUND; + goto Done; + } + // // Look at each protocol interface for a match // -- 2.39.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114137): https://edk2.groups.io/g/devel/message/114137 Mute This Topic: https://groups.io/mt/103883257/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-