Re: [edk2-devel] [PATCH v3 4/4] StandaloneMmPkg: Disallow unregister MMI handler in other MMI handler
On 3/1/24 04:01, Zhiguang Liu wrote: > 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 (>Link); Reviewed-by: Laszlo Ersek -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116241): https://edk2.groups.io/g/devel/message/116241 Mute This Topic: https://groups.io/mt/104657669/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v3 4/4] StandaloneMmPkg: Disallow unregister MMI handler in other MMI handler
Reviewed-by: Ray Ni Thanks, Ray > -Original Message- > From: Liu, Zhiguang > Sent: Friday, March 1, 2024 11:02 AM > To: devel@edk2.groups.io > Cc: Liu, Zhiguang ; Liming Gao > ; Wu, Jiaxin ; Ni, Ray > ; Laszlo Ersek ; Ard Biesheuvel > ; Sami Mujawar > Subject: [PATCH v3 4/4] StandaloneMmPkg: Disallow unregister MMI handler > in other MMI handler > > 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 (>Link); > -- > 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116209): https://edk2.groups.io/g/devel/message/116209 Mute This Topic: https://groups.io/mt/104657669/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-
[edk2-devel] [PATCH v3 4/4] StandaloneMmPkg: Disallow unregister MMI handler in other MMI handler
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 (>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/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-