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 815CF940FA2 for ; Wed, 28 Feb 2024 02:28:21 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=owFa6sVqtK0k/N5MCu5pemmRF5c3T4RJW77Uk/i8hJo=; 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=1709087300; v=1; b=jL4OEqzIFQny/OjXo9fG76BtRk7oWIllxS/93y7/A2qktCX9ny0xx5i3B2LVsEMk0oXSWSZx dA4x9XIkNIJasYvGEL5oGbCPnWgI1SSeHgdc2ts/Q/3xsYbWVXqhZ+6gg387S9zT3Ym5/Sh2EoU KfrXD/417myI5b2enY2rW9kk= X-Received: by 127.0.0.2 with SMTP id AyJTYY7687511xV8gznI9pXu; Tue, 27 Feb 2024 18:28:20 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by mx.groups.io with SMTP id smtpd.web11.4428.1709087295523770648 for ; Tue, 27 Feb 2024 18:28:19 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="7285783" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="7285783" X-Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 18:28:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11893873" X-Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 18:28:16 -0800 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Liming Gao , Jiaxin Wu , Ray Ni , Laszlo Ersek Subject: [edk2-devel] [PATCH v2 2/4] MdeModulePkg/SMM: Disallow unregister SMI handler in other SMI handler Date: Wed, 28 Feb 2024 10:27:48 +0800 Message-Id: <20240228022750.873-3-zhiguang.liu@intel.com> In-Reply-To: <20240228022750.873-1-zhiguang.liu@intel.com> References: <20240228022750.873-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: 0e2FJKaUJYjmMD4uGDWEZQ7Zx7686176AA= 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=jL4OEqzI; 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 SMI handler inside itself. However, the code doesn't support unregister SMI handler insider other SMI handler. While this is not a must-have usage. So add check to disallow unregister SMI handler in other SMI handler. Cc: Liming Gao Cc: Jiaxin Wu Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Zhiguang Liu --- MdeModulePkg/Core/PiSmmCore/Smi.c | 32 +++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/Core/PiSmmCore/Smi.c b/MdeModulePkg/Core/PiSmmCore/Smi.c index 3489c130fd..1bfbc635fc 100644 --- a/MdeModulePkg/Core/PiSmmCore/Smi.c +++ b/MdeModulePkg/Core/PiSmmCore/Smi.c @@ -8,7 +8,8 @@ #include "PiSmmCore.h" -LIST_ENTRY mSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryList); +SMI_HANDLER *gCurrentSmiHandler = NULL; +LIST_ENTRY mSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryList); SMI_ENTRY mRootSmiEntry = { SMI_ENTRY_SIGNATURE, @@ -142,13 +143,18 @@ SmiManage ( // Link points to may be freed if unregister SMI handler. // Link = Link->ForwardLink; - - Status = SmiHandler->Handler ( - (EFI_HANDLE)SmiHandler, - Context, - CommBuffer, - CommBufferSize - ); + // + // Assign gCurrentSmiHandle before calling the SMI handler and + // set to NULL when it returns. + // + gCurrentSmiHandler = SmiHandler; + Status = SmiHandler->Handler ( + (EFI_HANDLE)SmiHandler, + Context, + CommBuffer, + CommBufferSize + ); + gCurrentSmiHandler = NULL; switch (Status) { case EFI_INTERRUPT_PENDING: @@ -328,6 +334,16 @@ SmiHandlerUnRegister ( return EFI_INVALID_PARAMETER; } + // + // Check if unregister SMI handler inside a SMI Handler + // + if (gCurrentSmiHandler != NULL) { + // + // Only allow to unregister SMI Handler inside itself. + // + ASSERT (gCurrentSmiHandler == SmiHandler); + } + SmiEntry = SmiHandler->SmiEntry; RemoveEntryList (&SmiHandler->Link); -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116073): https://edk2.groups.io/g/devel/message/116073 Mute This Topic: https://groups.io/mt/104616993/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-