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 1D15EAC090A for ; Fri, 1 Mar 2024 03:05:49 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Ro+igoYlaVlwG0Lngcqcob3xESa8KPn+ommytBsAyvQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: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=1709262348; v=1; b=U5+28INA8OSrjAkkEP/e2+K09nR6AhvcSjr5AP4DHbyRJaCliCWjum0Luw1FpxnMIiYEUpB0 cINgpFjYg2ZvLKQ1gxe1bXkK7Ftoo62R3Tiue/0QSWQbvm5cirMGbPhnN4bKRobZNq4YAmyFH+t /KZmLFlv+MANbmSoR7rjN9No= X-Received: by 127.0.0.2 with SMTP id 154DYY7687511xewNrtWUFY5; Thu, 29 Feb 2024 19:05:48 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by mx.groups.io with SMTP id smtpd.web10.14105.1709262340273339436 for ; Thu, 29 Feb 2024 19:05:48 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10999"; a="3955941" X-IronPort-AV: E=Sophos;i="6.06,194,1705392000"; d="scan'208";a="3955941" X-Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Feb 2024 19:05:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,194,1705392000"; d="scan'208";a="8181920" X-Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Feb 2024 19:05:46 -0800 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Liming Gao , Jiaxin Wu , Ray Ni , Laszlo Ersek , Ard Biesheuvel , Sami Mujawar Subject: [edk2-devel] [PATCH v3 4/4] StandaloneMmPkg: Disallow unregister MMI handler in other MMI handler Date: Fri, 1 Mar 2024 11:01:33 +0800 Message-Id: <20240301030133.628-5-zhiguang.liu@intel.com> In-Reply-To: <20240301030133.628-1-zhiguang.liu@intel.com> References: <20240301030133.628-1-zhiguang.liu@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,zhiguang.liu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: teHoDXavSiWSl1vjmJXbTesMx7686176AA= 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=U5+28INA; 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 In last patch, we add code support to unregister MMI handler inside itself. However, the code doesn't support unregister MMI handler insider other MMI handler. While this is not a must-have usage. So add check to disallow unregister MMI handler in other MMI handler. Cc: Liming Gao Cc: Jiaxin Wu Cc: Ray Ni Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Ray Ni Signed-off-by: Zhiguang Liu --- StandaloneMmPkg/Core/Mmi.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/StandaloneMmPkg/Core/Mmi.c b/StandaloneMmPkg/Core/Mmi.c index c1a1d76e85..9e52072bf7 100644 --- a/StandaloneMmPkg/Core/Mmi.c +++ b/StandaloneMmPkg/Core/Mmi.c @@ -36,8 +36,9 @@ typedef struct { MMI_ENTRY *MmiEntry; } MMI_HANDLER; -LIST_ENTRY mRootMmiHandlerList = INITIALIZE_LIST_HEAD_VARIABLE (mRootMmiHandlerList); -LIST_ENTRY mMmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mMmiEntryList); +LIST_ENTRY mRootMmiHandlerList = INITIALIZE_LIST_HEAD_VARIABLE (mRootMmiHandlerList); +LIST_ENTRY mMmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mMmiEntryList); +MMI_HANDLER *mCurrentMmiHandler = NULL; /** Finds the MMI entry for the requested handler type. @@ -161,13 +162,19 @@ MmiManage ( // get next node before handler is executed, since LIST_ENTRY that // Link points to may be freed if unregister MMI handler. // - Link = Link->ForwardLink; - Status = MmiHandler->Handler ( - (EFI_HANDLE)MmiHandler, - Context, - CommBuffer, - CommBufferSize - ); + Link = Link->ForwardLink; + // + // Assign gCurrentMmiHandle before calling the MMI handler and + // set to NULL when it returns. + // + mCurrentMmiHandler = MmiHandler; + Status = MmiHandler->Handler ( + (EFI_HANDLE)MmiHandler, + Context, + CommBuffer, + CommBufferSize + ); + mCurrentMmiHandler = NULL; switch (Status) { case EFI_INTERRUPT_PENDING: @@ -314,6 +321,13 @@ MmiHandlerUnRegister ( return EFI_INVALID_PARAMETER; } + // + // Do not allow to unregister MMI Handler inside other MMI Handler + // + if ((mCurrentMmiHandler != NULL) && (mCurrentMmiHandler != MmiHandler)) { + return EFI_INVALID_PARAMETER; + } + MmiEntry = MmiHandler->MmiEntry; RemoveEntryList (&MmiHandler->Link); -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116206): https://edk2.groups.io/g/devel/message/116206 Mute This Topic: https://groups.io/mt/104657669/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-