From nobody Fri Nov 1 00:59:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1525858599975913.6843260557675; Wed, 9 May 2018 02:36:39 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AFC3B203B85AF; Wed, 9 May 2018 02:36:38 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 85D90203B859B for ; Wed, 9 May 2018 02:36:37 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 02:36:37 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.4]) by fmsmga006.fm.intel.com with ESMTP; 09 May 2018 02:36:36 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,381,1520924400"; d="scan'208";a="227067910" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 9 May 2018 17:36:37 +0800 Message-Id: <20180509093637.306480-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 Subject: [edk2] [PATCH] MdePkg/SmmPeriodicSmiLib: Get Periodic SMI Context More Robustly X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The PeriodicSmiDispatchFunction() in SmmPeriodicSmiLib may assert with "Bad CR signature". Currently, the SetActivePeriodicSmiLibraryHandler() function (invoked at the beginning of the PeriodicSmiDispatchFunction() function) attempts to locate the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure pointer for the current periodic SMI from a given EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT (RegiserContext) structure pointer (using the CR macro). The RegisterContext structure pointer passed to the PeriodicSmiDispatchFunction() is assumed to point to the same RegisterContext structure address given to the SmmPeriodicTimerDispatch2 protocol Register() API in PeriodicSmiEnable(). However, certain SmmPeriodicTimerDispatch2 implementation may copy the RegisterContext to a local buffer and pass that address as the context to PeriodicSmiDispatchFunction() in which case usage of the CR macro to find the parent structure base fails. The patch uses the LookupPeriodicSmiLibraryHandler() function to find the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure pointer. This works even in this scenario since the DispatchHandle returned from the SmmPeriodicTimerDispatch2 Register() function uniquely identifies that registration. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Michael D Kinney Cc: Liming Gao Reviewed-by: Liming Gao --- .../Library/SmmPeriodicSmiLib/SmmPeriodicSmiLib.c | 38 +++++++++---------= ---- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/MdePkg/Library/SmmPeriodicSmiLib/SmmPeriodicSmiLib.c b/MdePkg/= Library/SmmPeriodicSmiLib/SmmPeriodicSmiLib.c index 2016af60d8..ca6967c9be 100644 --- a/MdePkg/Library/SmmPeriodicSmiLib/SmmPeriodicSmiLib.c +++ b/MdePkg/Library/SmmPeriodicSmiLib/SmmPeriodicSmiLib.c @@ -1,7 +1,7 @@ /** @file SMM Periodic SMI Library. =20 - Copyright (c) 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -144,19 +144,6 @@ typedef struct { UINT64 ElapsedTime; } PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT; =20 -/** - Macro that returns a pointer to a PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT=20 - structure based on a pointer to a RegisterContext field. - -**/ -#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_REGISTER_CONTEXT(a) \ - CR ( \ - a, \ - PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT, \ - RegisterContext, \ - PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE \ - ) - /** Macro that returns a pointer to a PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT=20 structure based on a pointer to a Link field. @@ -280,26 +267,31 @@ LookupPeriodicSmiLibraryHandler ( =20 /** Internal worker function that sets that active periodic SMI handler base= d on=20 - the Context used when the periodic SMI handler was registered with the=20 - SMM Periodic Timer Dispatch 2 Protocol. If Context is NULL, then the=20 + the DispatchHandle that was returned when the periodic SMI handler was e= nabled + with PeriodicSmiEnable(). If DispatchHandle is NULL, then the=20 state is updated to show that there is not active periodic SMI handler. A pointer to the active PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure=20 is returned. - =20 - @retval NULL Context is NULL. + + @param [in] DispatchHandle DispatchHandle that was returned when the per= iodic + SMI handler was enabled with PeriodicSmiEnabl= e(). + This is an optional parameter that may be NUL= L. + If this parameter is NULL, then the state is = updated + to show that there is not active periodic SMI= handler. + @retval NULL DispatchHandle is NULL. @retval other Pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT - associated with Context. + associated with DispatchHandle. =20 **/ PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * SetActivePeriodicSmiLibraryHandler ( - IN CONST VOID *Context OPTIONAL + IN EFI_HANDLE DispatchHandle OPTIONAL ) { - if (Context =3D=3D NULL) { + if (DispatchHandle =3D=3D NULL) { gActivePeriodicSmiLibraryHandler =3D NULL; } else { - gActivePeriodicSmiLibraryHandler =3D PERIODIC_SMI_LIBRARY_HANDLER_CONT= EXT_FROM_REGISTER_CONTEXT (Context); + gActivePeriodicSmiLibraryHandler =3D LookupPeriodicSmiLibraryHandler (= DispatchHandle); } return gActivePeriodicSmiLibraryHandler; } @@ -798,7 +790,7 @@ PeriodicSmiDispatchFunction ( // // Set the active periodic SMI handler // =20 - PeriodicSmiLibraryHandler =3D SetActivePeriodicSmiLibraryHandler (Contex= t); + PeriodicSmiLibraryHandler =3D SetActivePeriodicSmiLibraryHandler (Dispat= chHandle); if (PeriodicSmiLibraryHandler =3D=3D NULL) { return EFI_NOT_FOUND; } --=20 2.16.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel