From nobody Thu May 2 19:22:12 2024 Delivered-To: importer@patchew.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; Authentication-Results: mx.zoho.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 1491898729990372.78697357809756; Tue, 11 Apr 2017 01:18:49 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CF77E21DFA7AF; Tue, 11 Apr 2017 01:18:29 -0700 (PDT) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 0DB5C2095C3B7 for ; Tue, 11 Apr 2017 01:18:28 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Apr 2017 01:17:22 -0700 Received: from tiano01.ccr.corp.intel.com ([10.239.9.111]) by orsmga002.jf.intel.com with ESMTP; 11 Apr 2017 01:17:21 -0700 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491898709; x=1523434709; h=from:to:cc:subject:date:message-id; bh=AadTIPZCxjpxZhn7cBEjkqD095dbFRcmgQ8CRCvRB9k=; b=qKtY+t/l11wArp5pWh3ohU3YZ5Ahcb7SpFFudIeRTf5/oH/1BHphHjS1 s7/z/DmvrrACnhPP40JqHf4q6/ZSbA==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,184,1488873600"; d="scan'208";a="72454791" From: hesschen To: edk2-devel@lists.01.org Date: Tue, 11 Apr 2017 16:17:19 +0800 Message-Id: <1491898639-450600-1-git-send-email-hesheng.chen@intel.com> X-Mailer: git-send-email 2.7.2.windows.1 Subject: [edk2] [patch] BaseTools/ECC: Add a new checkpoint X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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" Add a new checkpoint to check if the SMM communication parameter has a correct buffer type. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: hesschen Reviewed-by: Yonghong Zhu --- BaseTools/Source/Python/Ecc/Check.py | 141 +++++++++++++++++++++++= ++++ BaseTools/Source/Python/Ecc/Configuration.py | 7 +- BaseTools/Source/Python/Ecc/EccToolError.py | 6 +- BaseTools/Source/Python/Ecc/config.ini | 7 ++ 4 files changed, 159 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/Ecc/Check.py b/BaseTools/Source/Python= /Ecc/Check.py index 062120c..5864758 100644 --- a/BaseTools/Source/Python/Ecc/Check.py +++ b/BaseTools/Source/Python/Ecc/Check.py @@ -41,6 +41,134 @@ class Check(object): self.DeclAndDataTypeCheck() self.FunctionLayoutCheck() self.NamingConventionCheck() + self.SmmCommParaCheck() + + def SmmCommParaCheck(self): + self.SmmCommParaCheckBufferType() + + + # Check if SMM communication function has correct parameter type + # 1. Get function calling with instance./->Communicate() interface + # and make sure the protocol instance is of type EFI_SMM_COMMUNICATION= _PROTOCOL. + # 2. Find the origin of the 2nd parameter of Communicate() interface, = if - + # a. it is a local buffer on stack + # report error. + # b. it is a global buffer, check the driver that holds the global = buffer is of type DXE_RUNTIME_DRIVER + # report success. + # c. it is a buffer by AllocatePage/AllocatePool (may be wrapped by= nested function calls), + # check the EFI_MEMORY_TYPE to be EfiRuntimeServicesCode,EfiRunt= imeServicesData, + # EfiACPIMemoryNVS or EfiReservedMemoryType + # report success. + # d. it is a buffer located via EFI_SYSTEM_TABLE.ConfigurationTable= (may be wrapped by nested function calls) + # report warning to indicate human code review. + # e. it is a buffer from other kind of pointers (may need to trace = into nested function calls to locate), + # repeat checks in a.b.c and d. + def SmmCommParaCheckBufferType(self): + if EccGlobalData.gConfig.SmmCommParaCheckBufferType =3D=3D '1' or = EccGlobalData.gConfig.SmmCommParaCheckAll =3D=3D '1': + EdkLogger.quiet("Checking SMM communication parameter type ...= ") + # Get all EFI_SMM_COMMUNICATION_PROTOCOL interface + CommApiList =3D [] + for IdentifierTable in EccGlobalData.gIdentifierTableList: + SqlCommand =3D """select ID, Name, BelongsToFile from %s + where Modifier =3D 'EFI_SMM_COMMUNICATION_= PROTOCOL*' """ % (IdentifierTable) + RecordSet =3D EccGlobalData.gDb.TblFile.Exec(SqlCommand) + if RecordSet: + for Record in RecordSet: + if Record[1] not in CommApiList: + CommApiList.append(Record[1]) + # For each interface, check the second parameter + for CommApi in CommApiList: + for IdentifierTable in EccGlobalData.gIdentifierTableList: + SqlCommand =3D """select ID, Name, Value, BelongsToFil= e, StartLine from %s + where Name =3D '%s->Communicate' and Model =3D %s""" \ + % (IdentifierTable, CommApi, MODEL_IDENTIFIER_FUNCTION= _CALLING) + RecordSet =3D EccGlobalData.gDb.TblFile.Exec(SqlComman= d) + if RecordSet: + # print IdentifierTable + for Record in RecordSet: + # Get the second parameter for Communicate fun= ction + SecondPara =3D Record[2].split(',')[1].strip() + SecondParaIndex =3D None + if SecondPara.startswith('&'): + SecondPara =3D SecondPara[1:] + if SecondPara.endswith(']'): + SecondParaIndex =3D SecondPara[SecondPara.= find('[') + 1:-1] + SecondPara =3D SecondPara[:SecondPara.find= ('[')] + # Get the ID + Id =3D Record[0] + # Get the BelongsToFile + BelongsToFile =3D Record[3] + # Get the source file path + SqlCommand =3D """select FullPath from File wh= ere ID =3D %s""" % BelongsToFile + NewRecordSet =3D EccGlobalData.gDb.TblFile.Exe= c(SqlCommand) + FullPath =3D NewRecordSet[0][0] + # Get the line no of function calling + StartLine =3D Record[4] + # Get the module type + SqlCommand =3D """select Value3 from INF where= BelongsToFile =3D (select ID from File + where Path =3D (select Path fr= om File where ID =3D %s) and Model =3D 1011) + and Value2 =3D 'MODULE_TYPE'""= " % BelongsToFile + NewRecordSet =3D EccGlobalData.gDb.TblFile.Exe= c(SqlCommand) + ModuleType =3D NewRecordSet[0][0] if NewRecord= Set else None + + # print BelongsToFile, FullPath, StartLine, Mo= duleType, SecondPara + + Value =3D FindPara(FullPath, SecondPara, Start= Line) + # Find the value of the parameter + if Value: + if 'AllocatePage' in Value \ + or 'AllocatePool' in Value \ + or 'AllocateRuntimePool' in Value \ + or 'AllocateZeroPool' in Value: + pass + else: + if '->' in Value: + if not EccGlobalData.gException.Is= Exception( + ERROR_SMM_COMM_PARA_CHECK_B= UFFER_TYPE, Value): + EccGlobalData.gDb.TblReport.In= sert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, + = OtherMsg=3D"Please review the buffer type" + = + "is correct or not. If it is correct" + + = " please add [%s] to exception list" + = % Value, + = BelongsToTable=3DIdentifierTable, + = BelongsToItem=3DId) + else: + if not EccGlobalData.gException.Is= Exception( + ERROR_SMM_COMM_PARA_CHECK_B= UFFER_TYPE, Value): + EccGlobalData.gDb.TblReport.In= sert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, + = OtherMsg=3D"Please review the buffer type" + = + "is correct or not. If it is correct" + + = " please add [%s] to exception list" + = % Value, + = BelongsToTable=3DIdentifierTable, + = BelongsToItem=3DId) + + + # Not find the value of the parameter + else: + SqlCommand =3D """select ID, Modifier, Nam= e, Value, Model, BelongsToFunction from %s + where Name =3D '%s' and St= artLine < %s order by StartLine DESC""" \ + % (IdentifierTable, Second= Para, StartLine) + NewRecordSet =3D EccGlobalData.gDb.TblFile= .Exec(SqlCommand) + if NewRecordSet: + Value =3D NewRecordSet[0][1] + if 'AllocatePage' in Value \ + or 'AllocatePool' in Value \ + or 'AllocateRuntimePool' in Value \ + or 'AllocateZeroPool' in Value: + pass + else: + if not EccGlobalData.gException.Is= Exception( + ERROR_SMM_COMM_PARA_CHECK_BUFF= ER_TYPE, Value): + EccGlobalData.gDb.TblReport.In= sert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, + = OtherMsg=3D"Please review the buffer type" + = + "is correct or not. If it is correct" + + = " please add [%s] to exception list" + = % Value, + = BelongsToTable=3DIdentifierTable, + = BelongsToItem=3DId) + else: + pass =20 # Check UNI files def UniCheck(self): @@ -1261,6 +1389,19 @@ class Check(object): if not EccGlobalData.gException.IsException(ERROR_NAMI= NG_CONVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, Record[1]): EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CO= NVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, OtherMsg=3D"The variable name [%s= ] does not follow the rules" % (Record[1]), BelongsToTable=3DFileTable, Bel= ongsToItem=3DRecord[0]) =20 +def FindPara(FilePath, Para, CallingLine): + Lines =3D open(FilePath).readlines() + Line =3D '' + for Index in range(CallingLine - 1, 0, -1): + # Find the nearest statement for Para + Line =3D Lines[Index].strip() + if Line.startswith('%s =3D ' % Para): + Line =3D Line.strip() + return Line + break + + return '' + ## # # This acts like the main() function for the script, unless it is 'import'= ed into another diff --git a/BaseTools/Source/Python/Ecc/Configuration.py b/BaseTools/Sourc= e/Python/Ecc/Configuration.py index 5262b68..b523858 100644 --- a/BaseTools/Source/Python/Ecc/Configuration.py +++ b/BaseTools/Source/Python/Ecc/Configuration.py @@ -1,7 +1,7 @@ ## @file # This file is used to define class Configuration # -# Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2017, 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 @@ -256,6 +256,11 @@ class Configuration(object): # Check PCD whether defined the prompt, help in the DEC file and l= ocalized information in the associated UNI file. self.UniCheckPCDInfo =3D 1 =20 + # Check SMM communication function parameter + self.SmmCommParaCheckAll =3D 0 + # Check if the EFI_SMM_COMMUNICATION_PROTOCOL parameter buffer typ= e is Reserved / ACPI NVS or UEFI RT code/data + self.SmmCommParaCheckBufferType =3D -1 + # # The check points in this section are reserved # diff --git a/BaseTools/Source/Python/Ecc/EccToolError.py b/BaseTools/Source= /Python/Ecc/EccToolError.py index 1eae9d1..1d51da3 100644 --- a/BaseTools/Source/Python/Ecc/EccToolError.py +++ b/BaseTools/Source/Python/Ecc/EccToolError.py @@ -1,7 +1,7 @@ ## @file # Standardized Error Hanlding infrastructures. # -# Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2017, 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 @@ -105,6 +105,8 @@ ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED =3D 10022 =20 ERROR_SPELLING_CHECK_ALL =3D 11000 =20 +ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE =3D 12001 + gEccErrorMessage =3D { ERROR_GENERAL_CHECK_ALL : "", ERROR_GENERAL_CHECK_NO_TAB : "'TAB' character is not allowed in source= code, please replace each 'TAB' with two spaces", @@ -198,5 +200,7 @@ gEccErrorMessage =3D { ERROR_META_DATA_FILE_CHECK_FORMAT_PCD : "Wrong Pcd Format used in Modu= le file", ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED : "Not defined LibraryC= lass used in the Module file.", ERROR_SPELLING_CHECK_ALL : "", + + ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE : "SMM communication function ma= y use wrong parameter type", } =20 diff --git a/BaseTools/Source/Python/Ecc/config.ini b/BaseTools/Source/Pyth= on/Ecc/config.ini index e97c718..9a431bf 100644 --- a/BaseTools/Source/Python/Ecc/config.ini +++ b/BaseTools/Source/Python/Ecc/config.ini @@ -262,6 +262,13 @@ UniCheckPCDInfo =3D 1 GeneralCheckUni =3D -1 =20 # +# SMM Communicate Function Parameter Checking +# +SmmCommParaCheckAll =3D 0 +# Check if the EFI_SMM_COMMUNICATION_PROTOCOL parameter buffer type is Res= erved / ACPI NVS or UEFI RT code/data +SmmCommParaCheckBufferType =3D 1 + +# # The check points in this section are reserved # # GotoStatementCheckAll =3D 0 --=20 2.7.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel