From nobody Mon Apr 29 19:39:20 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 1508125050185310.3000402709239; Sun, 15 Oct 2017 20:37:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4F890202E614B; Sun, 15 Oct 2017 20:33:53 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 40AF121F38832 for ; Sun, 15 Oct 2017 20:33:52 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Oct 2017 20:37:26 -0700 Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga001.fm.intel.com with ESMTP; 15 Oct 2017 20:37:25 -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=134.134.136.24; helo=mga09.intel.com; envelope-from=dandan.bi@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,385,1503385200"; d="scan'208";a="1206160320" From: Dandan Bi To: edk2-devel@lists.01.org Date: Mon, 16 Oct 2017 11:37:08 +0800 Message-Id: <1508125028-85644-1-git-send-email-dandan.bi@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [patch] Security/OpalHii.c: Handle NULL Request or Request with no elements 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: , Cc: Eric Dong , Chao Zhang 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" According to UEFI spec, for the ExtractConfig function in EFI_HII_CONFIG_ACCESS_PROTOCOL,If a NULL is passed in for the Request field or if a ConfigHdr is passed in with no request elements, all of the settings being abstracted by this function will be returned in the Results field. The implementation of ExtractConfig function in OpalHii.c misses to handle above cases.This patch is to do the enhancements. Cc: Chao Zhang Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi Reviewed-by: Eric Dong --- SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c | 46 ++++++++++++++++++++++= +++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c b/SecurityPkg/T= cg/Opal/OpalPasswordDxe/OpalHii.c index 4881e72..e3bde42 100644 --- a/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c +++ b/SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c @@ -1278,10 +1278,16 @@ ExtractConfig( EFI_STRING *Progress, EFI_STRING *Results ) { EFI_STATUS Status; + EFI_STRING ConfigRequest; + EFI_STRING ConfigRequestHdr; + UINTN BufferSize; + UINTN Size; + BOOLEAN AllocatedRequest; + EFI_HANDLE DriverHandle; =20 // // Check for valid parameters // if (Progress =3D=3D NULL || Results =3D=3D NULL) { @@ -1292,22 +1298,60 @@ ExtractConfig( if ((Request !=3D NULL) && !HiiIsConfigHdrMatch (Request, &gHiiSetupVariableGuid, OpalPasswordSto= rageName)) { return EFI_NOT_FOUND; } =20 + AllocatedRequest =3D FALSE; + BufferSize =3D sizeof (OPAL_HII_CONFIGURATION); + ConfigRequest =3D Request; + if ((Request =3D=3D NULL) || (StrStr (Request, L"OFFSET") =3D=3D NULL)) { + // + // Request has no request element, construct full request string. + // Allocate and fill a buffer large enough to hold the tem= plate + // followed by "&OFFSET=3D0&WIDTH=3DWWWWWWWWWWWWWWWW" followed by a Nu= ll-terminator + // + DriverHandle =3D HiiGetDriverImageHandleCB(); + ConfigRequestHdr =3D HiiConstructConfigHdr (&gHiiSetupVariableGuid, Op= alPasswordStorageName, DriverHandle); + Size =3D (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); + ConfigRequest =3D AllocateZeroPool (Size); + if (ConfigRequest =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + AllocatedRequest =3D TRUE; + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=3D0&WIDTH=3D%016LX", C= onfigRequestHdr, (UINT64)BufferSize); + FreePool (ConfigRequestHdr); + } + // // Convert Buffer Data to by helper function BlockToConfig(= ) // Status =3D gHiiConfigRouting->BlockToConfig( gHiiConfigRouting, - Request, + ConfigRequest, (UINT8*)&gHiiConfiguration, sizeof(OPAL_HII_CONFIGURATION), Results, Progress ); =20 + // + // Free the allocated config request string. + // + if (AllocatedRequest) { + FreePool (ConfigRequest); + ConfigRequest =3D NULL; + } + + // + // Set Progress string to the original request string. + // + if (Request =3D=3D NULL) { + *Progress =3D NULL; + } else if (StrStr (Request, L"OFFSET") =3D=3D NULL) { + *Progress =3D Request + StrLen (Request); + } + return (Status); } =20 =20 /** --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel