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 D72A6D80144 for ; Wed, 28 Feb 2024 08:45:20 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=7mhqJpXCV5NFHvUTrDwQJw4Ul4Q9v/3SnOMPac05CsQ=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1709109919; v=1; b=iu8N/CZnDOUN6TRyxTx1TOdpuUGKYmmWbGE3F5ot988YgBqsJoAqHNF8op/PdRaXcUQr03Sp /ShO00V5ndlBitoCirWRH/xCupVoX9BGEsrWNfA6W+Z1F6LdhkV6yUeeptvBvYX/gmDq0soXzjo H76lJABqNDvHljoxAK7wRfbA= X-Received: by 127.0.0.2 with SMTP id oy4PYY7687511xXRuZ2q60Uz; Wed, 28 Feb 2024 00:45:19 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.9182.1709109918883003007 for ; Wed, 28 Feb 2024 00:45:19 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175--ewTnz0KPJKvxkpD8JHs7w-1; Wed, 28 Feb 2024 03:45:16 -0500 X-MC-Unique: -ewTnz0KPJKvxkpD8JHs7w-1 X-Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 690D4108BE0A; Wed, 28 Feb 2024 08:45:16 +0000 (UTC) X-Received: from [10.39.193.212] (unknown [10.39.193.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A27262166B33; Wed, 28 Feb 2024 08:45:15 +0000 (UTC) Message-ID: <7e5bff6c-04b0-4c91-3fa1-514e10e14481@redhat.com> Date: Wed, 28 Feb 2024 09:45:14 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v2 2/4] MdeModulePkg/SMM: Disallow unregister SMI handler in other SMI handler To: devel@edk2.groups.io, zhiguang.liu@intel.com Cc: Liming Gao , Jiaxin Wu , Ray Ni References: <20240228022750.873-1-zhiguang.liu@intel.com> <20240228022750.873-3-zhiguang.liu@intel.com> From: "Laszlo Ersek" In-Reply-To: <20240228022750.873-3-zhiguang.liu@intel.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: rpIPAGnQ5jJbklvWTbbU02RCx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="iu8N/CZn"; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none) On 2/28/24 03:27, Zhiguang Liu wrote: > 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. >=20 > 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(-) >=20 > diff --git a/MdeModulePkg/Core/PiSmmCore/Smi.c b/MdeModulePkg/Core/PiSmmC= ore/Smi.c > index 3489c130fd..1bfbc635fc 100644 > --- a/MdeModulePkg/Core/PiSmmCore/Smi.c > +++ b/MdeModulePkg/Core/PiSmmCore/Smi.c > @@ -8,7 +8,8 @@ > =20 > #include "PiSmmCore.h" > =20 > -LIST_ENTRY mSmiEntryList =3D INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryLi= st); > +SMI_HANDLER *gCurrentSmiHandler =3D NULL; > +LIST_ENTRY mSmiEntryList =3D INITIALIZE_LIST_HEAD_VARIABLE (mSmi= EntryList); > =20 > SMI_ENTRY mRootSmiEntry =3D { > SMI_ENTRY_SIGNATURE, > @@ -142,13 +143,18 @@ SmiManage ( > // Link points to may be freed if unregister SMI handler. > // > Link =3D Link->ForwardLink; > - > - Status =3D SmiHandler->Handler ( > - (EFI_HANDLE)SmiHandler, > - Context, > - CommBuffer, > - CommBufferSize > - ); > + // > + // Assign gCurrentSmiHandle before calling the SMI handler and > + // set to NULL when it returns. > + // > + gCurrentSmiHandler =3D SmiHandler; > + Status =3D SmiHandler->Handler ( > + (EFI_HANDLE)SmiHandler, > + Context, > + CommBuffer, > + CommBufferSize > + ); > + gCurrentSmiHandler =3D NULL; > =20 > switch (Status) { > case EFI_INTERRUPT_PENDING: > @@ -328,6 +334,16 @@ SmiHandlerUnRegister ( > return EFI_INVALID_PARAMETER; > } > =20 > + // > + // Check if unregister SMI handler inside a SMI Handler > + // > + if (gCurrentSmiHandler !=3D NULL) { > + // > + // Only allow to unregister SMI Handler inside itself. > + // > + ASSERT (gCurrentSmiHandler =3D=3D SmiHandler); > + } > + > SmiEntry =3D SmiHandler->SmiEntry; > =20 > RemoveEntryList (&SmiHandler->Link); (1) Why not: if ((gCurrentSmiHandler !=3D NULL) && (gCurrentSmiHandler !=3D SmiHandler= )) { return EFI_INVALID_PARAMETER; } ? (2) Why do we call the new global variable "gCurrentSmiHandler" rather than= "mCurrentSmiHandler"? Thanks Laszlo -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116101): https://edk2.groups.io/g/devel/message/116101 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-