From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 7376E21A09130 for ; Tue, 9 Oct 2018 22:42:11 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Oct 2018 22:42:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,363,1534834800"; d="scan'208";a="98963103" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga002.jf.intel.com with ESMTP; 09 Oct 2018 22:41:00 -0700 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 9 Oct 2018 22:41:00 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX153.amr.corp.intel.com (10.18.125.6) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 9 Oct 2018 22:41:00 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.111]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.183]) with mapi id 14.03.0319.002; Wed, 10 Oct 2018 13:40:58 +0800 From: "Zhu, Yonghong" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [edk2] [Patch] BaseTools: do basic check in FvImage with header size and signature Thread-Index: AQHUV9ED7fZ2O+XtlEqiUO6k+w5hZ6UYB9qA Date: Wed, 10 Oct 2018 05:40:57 +0000 Message-ID: References: <1538210809-19672-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1538210809-19672-1-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] BaseTools: do basic check in FvImage with header size and signature X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Oct 2018 05:42:12 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu Best Regards, Zhu Yonghong -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Yong= hong Zhu Sent: Saturday, September 29, 2018 4:47 PM To: edk2-devel@lists.01.org Cc: Gao, Liming Subject: [edk2] [Patch] BaseTools: do basic check in FvImage with header si= ze and signature From: zhijufan Add some basic check in FvImage with header size and signature. Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1181 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/GenFds/Fv.py | 44 ++++++++++++++++++++------------= ---- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python= /GenFds/Fv.py index 0d005eb..510f283 100644 --- a/BaseTools/Source/Python/GenFds/Fv.py +++ b/BaseTools/Source/Python/GenFds/Fv.py @@ -193,36 +193,40 @@ class FV (FvClassObject): ) =20 # # Write the Fv contents to Buffer # - if os.path.isfile(FvOutputFile): + if os.path.isfile(FvOutputFile) and os.path.getsize(FvOutputFi= le) >=3D 0x48: FvFileObj =3D open(FvOutputFile, 'rb') - GenFdsGlobalVariable.VerboseLogger("\nGenerate %s FV Succe= ssfully" % self.UiFvName) - GenFdsGlobalVariable.SharpCounter =3D 0 - - Buffer.write(FvFileObj.read()) - FvFileObj.seek(0) # PI FvHeader is 0x48 byte FvHeaderBuffer =3D FvFileObj.read(0x48) - # FV alignment position. - FvAlignmentValue =3D 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1= F) - if FvAlignmentValue >=3D 0x400: - if FvAlignmentValue >=3D 0x100000: - if FvAlignmentValue >=3D 0x1000000: - #The max alignment supported by FFS is 16M. - self.FvAlignment =3D "16M" + Signature =3D FvHeaderBuffer[0x28:0x32] + if Signature and Signature.startswith('_FVH'): + GenFdsGlobalVariable.VerboseLogger("\nGenerate %s FV S= uccessfully" % self.UiFvName) + GenFdsGlobalVariable.SharpCounter =3D 0 + + Buffer.write(FvFileObj.read()) + FvFileObj.seek(0) + # FV alignment position. + FvAlignmentValue =3D 1 << (ord(FvHeaderBuffer[0x2E]) &= 0x1F) + if FvAlignmentValue >=3D 0x400: + if FvAlignmentValue >=3D 0x100000: + if FvAlignmentValue >=3D 0x1000000: + #The max alignment supported by FFS is 16M. + self.FvAlignment =3D "16M" + else: + self.FvAlignment =3D str(FvAlignmentValue = / 0x100000) + "M" else: - self.FvAlignment =3D str(FvAlignmentValue / 0x= 100000) + "M" + self.FvAlignment =3D str(FvAlignmentValue / 0x= 400) + "K" else: - self.FvAlignment =3D str(FvAlignmentValue / 0x400)= + "K" + # FvAlignmentValue is less than 1K + self.FvAlignment =3D str (FvAlignmentValue) + FvFileObj.close() + GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper(= ) + 'fv'] =3D FvOutputFile + GenFdsGlobalVariable.LargeFileInFvFlags.pop() else: - # FvAlignmentValue is less than 1K - self.FvAlignment =3D str (FvAlignmentValue) - FvFileObj.close() - GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + = 'fv'] =3D FvOutputFile - GenFdsGlobalVariable.LargeFileInFvFlags.pop() + GenFdsGlobalVariable.ErrorLogger("Invalid FV file %s."= % self.UiFvName) else: GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV= file." %self.UiFvName) return FvOutputFile =20 ## _GetBlockSize() --=20 2.6.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel