From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by mx.groups.io with SMTP id smtpd.web10.5917.1659085377200996226 for ; Fri, 29 Jul 2022 02:02:57 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=q7AlVnPT; spf=pass (domain: gmail.com, ip: 209.85.219.173, mailfrom: aladyshev22@gmail.com) Received: by mail-yb1-f173.google.com with SMTP id o15so7133833yba.10 for ; Fri, 29 Jul 2022 02:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=gYXBsiK82XA1A+wfRzuVjqCEr19g9/A7ATmCrtofGQI=; b=q7AlVnPToToeQhUoKXdm/XnuCBdyE7KNsVVfOSxwP0PnH4TDixxwDVFfRGxXfv+uYQ vni5JS3mOFaf0JgbR7uubZuu+7wGCSMIJlIGi+idi5oLow1/z6AxThnepCJUxMCWnJN9 ZaOq1gb/K/7OQPudH9UWoiJVivszNm7e4zAE9cqRFq7D+vmfMkjymG9xiGHMkzRlz4v1 +YKHJYfwUKejEErd3TwV0dEAfUh8xnMcI6Nan41i6mKLZBDz3PkGqg1xWQoongIAXDfA c58egUtv5OCJ+GRT19BQKkFvqtNPQxmn5LikaG9or1XAtQcKhYRcX+zgPuLxluVN790x WHEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=gYXBsiK82XA1A+wfRzuVjqCEr19g9/A7ATmCrtofGQI=; b=oqzXoEMHhseZBr8imAniyb5fRrOVorvel5qJCP7pVbb4MSmuqQPdOp+XV+oR8E2kq0 Es6HRELKyk3U75Fqlv/uggpQ14uYuIPr7197g96P5LQZWmEWk10lyy7B2+5hjTBrjv8S kpkRoz7133ITvSxHvsW9+jIb9yx3GS4ZWqmcWtMwsMYcK6LKU0TfQRRywUOWv3qfGPjK kQPvNpSVeIzUx88KhO80/gvwdG1NQmWZdiQEV+Vs49GnpfWXpUGnw+D6K5mNJU0phNZZ dfKfVTyWA3HHzrIGTOPUZsr/pdEaWhfxlnXbA8foQdmHsXW65UOFda5n2e4bgz4IPBRj lkwA== X-Gm-Message-State: ACgBeo1hx4b4elC2C0fcj3/8Lttf1SsAqYChYSftN4t5fgm2hEKvC/AE eKgP0RDiBYmWXt0YiGg5uV05JXogR2dsDXR3kec= X-Google-Smtp-Source: AA6agR4g4R0BBAJyn6TtqTeRLtGaeYRx6toxQYU80X5shFVTQyALvdgh1aMhjlb/8qK0ddyD45NgDm6dVGIme/xBLlU= X-Received: by 2002:a5b:804:0:b0:670:7de2:5fde with SMTP id x4-20020a5b0804000000b006707de25fdemr1641620ybp.43.1659085376356; Fri, 29 Jul 2022 02:02:56 -0700 (PDT) MIME-Version: 1.0 References: <20220719134435.8054-1-aladyshev22@gmail.com> In-Reply-To: From: "Konstantin Aladyshev" Date: Fri, 29 Jul 2022 12:02:44 +0300 Message-ID: Subject: Re: [edk2-devel] [PATCH] BaseTools/VolInfo: Correct buffer for GenCrc32 tool To: "Chen, Christine" Cc: "devel@edk2.groups.io" , "Feng, Bob C" , "Gao, Liming" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Christine! I think the GenCrc32 usage is different because it just prepends the data with the CRC32 value leaving the main data unmodified, opposed to all of the encryption utilities that change the data itself. Therefore in the case of the GenCrc32 produced section it is possible to get the main data just by the 'DataOffset' field. Here is the definition of the EFI_GUIDED_SECTION_PROCESSING_REQUIRED flag from the PI specification: ``` EFI_GUIDED_SECTION_ PROCESSING_REQUIRED: Set to 1 if the section requires processing to obtain meaningful data from the section contents. Processing would be required, for example, if the section contents were encrypted or compressed. If the EFI_GUIDED_SECTION_PROCESSING_REQUIRED bit is cleared to zero, it is possible to retrieve the section=E2=80=99s contents without processing in t= he absence of an associated instance of the EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL (DXE) or EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI (PEI).. In this case, the beginning of the encapsulated section stream is indicated by the value of DataOffset ``` So in the case of encryption utilities like LzmaCompress/TianoCompress/BrotliCompress/... we set EFI_GUIDED_SECTION_PROCESSING_REQUIRED=3D1 and DataOffset points to the very start of data right after the EFI_GUID_DEFINED_SECTION header. But in the case of GenCrc32 we can just set EFI_GUIDED_SECTION_PROCESSING_REQUIRED=3D0 and point DataOffset to the (EFI_GUID_DEFINED_SECTION + 4 bytes). Best regards, Konstantin Aladyshev On Fri, Jul 29, 2022 at 7:02 AM Chen, Christine wrot= e: > > Hi Konstantin, this is really an issue need to be solved. > > When GenSec tool uses the guidtools to encode the section, it differentia= tes how GenCrc32 is used from other tools.. > > GenSec defines a CRC32_SECTION_HEADER structure for GenCrc32, and calcula= te the DataOffset of the Section with this header. > > However other guidtools just use the EFI_GUID_DEFINED_SECTION header and = calculate the DataOffset with it. > > > > =E2=80=9C > > typedef struct { > > EFI_GUID_DEFINED_SECTION GuidSectionHeader; > > UINT32 CRC32Checksum; > > } CRC32_SECTION_HEADER; > > > > Crc32GuidSect->GuidSectionHeader.DataOffset =3D sizeof (CRC32_SECTION_HE= ADER); > > > > =E2=80=9D > > Personally think that is the root cause of the 4 bytes issue. > > > > I do not know why the GenCrc32 usage is different from other tools in ori= gin design. > > Propose to solve this issue from GenSec side to keep all the guidtool wit= h same function. > > > > Thanks, > > Christine > > > > > -----Original Message----- > > > From: devel@edk2.groups.io On Behalf Of > > > Konstantin Aladyshev > > > Sent: Tuesday, July 19, 2022 9:45 PM > > > To: devel@edk2.groups.io > > > Cc: Feng, Bob C ; Gao, Liming > > > ; Chen, Christine ; > > > Konstantin Aladyshev > > > Subject: [edk2-devel] [PATCH] BaseTools/VolInfo: Correct buffer for > > > GenCrc32 tool > > > > > > If the guided section was encoded with GenCrc32 tool the resulting > > > 'EFI_GUID_DEFINED_SECTION.DataOffset' field points to the start of the > > > meaningfull data that follows the CRC32 value. > > > But if we want to decode the section with GenCrc32 tool we need to prov= ide > > > a buffer that includes the CRC32 value itself. > > > > > > Signed-off-by: Konstantin Aladyshev > > > --- > > > BaseTools/Source/C/VolInfo/VolInfo.c | 7 +++++++ > > > 1 file changed, 7 insertions(+) > > > > > > diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c > > > b/BaseTools/Source/C/VolInfo/VolInfo.c > > > index f450796f9c..47a8f80f46 100644 > > > --- a/BaseTools/Source/C/VolInfo/VolInfo.c > > > +++ b/BaseTools/Source/C/VolInfo/VolInfo.c > > > @@ -1999,6 +1999,13 @@ Returns: > > > ); free (ExtractionTool); + if (!CompareGuid = (+ EfiGuid,+ > > > &gEfiCrc32GuidedSectionExtractionProtocolGuid+ )+ = ) {+ > > > DataOffset -=3D 4;+ } Status =3D PutFileImage = ( ToolInputFile,-- > > > 2.25.1 > > > > > > > > > > > > -=3D-=3D-=3D-=3D-=3D-=3D > > > Groups.io Links: You receive all messages sent to this group. > > > View/Reply Online (#91530): https://edk2.groups.io/g/devel/message/9153= 0 > > > Mute This Topic: https://groups.io/mt/92482555/4546272 > > > Group Owner: devel+owner@edk2.groups.io > > > Unsubscribe: https://edk2.groups.io/g/devel/unsub [yuwei.chen@intel.com= ] > > > -=3D-=3D-=3D-=3D-=3D-=3D > > > > >