From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 33905211F887C for ; Mon, 2 Jul 2018 01:37:52 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jul 2018 01:37:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,298,1526367600"; d="scan'208";a="61641419" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by FMSMGA003.fm.intel.com with ESMTP; 02 Jul 2018 01:37:43 -0700 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 2 Jul 2018 01:37:43 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 2 Jul 2018 01:37:43 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.51]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.87]) with mapi id 14.03.0319.002; Mon, 2 Jul 2018 16:37:41 +0800 From: "Wu, Jiaxin" To: Gary Lin CC: "Ye, Ting" , "edk2-devel@lists.01.org" , "Fu, Siyuan" Thread-Topic: [edk2] [Patch v2] NetworkPkg/HttpDxe: Fix the bug when parsing HTTP(S) message body. Thread-Index: AQHUEasin5WRhEXpy0mLFSBpO+wzoaR6zbAAgACV75CAAAULYP//p+UAgACJKUA= Date: Mon, 2 Jul 2018 08:37:41 +0000 Message-ID: <895558F6EA4E3B41AC93A00D163B72741645B508@SHSMSX103.ccr.corp.intel.com> References: <20180702021930.11488-1-Jiaxin.wu@intel.com> <20180702041720.smrkzrpt5ucpqoa3@GaryWorkstation> <895558F6EA4E3B41AC93A00D163B72741645B3C0@SHSMSX103.ccr.corp.intel.com> <895558F6EA4E3B41AC93A00D163B72741645B3FF@SHSMSX103.ccr.corp.intel.com> <20180702081640.moebxgydtiyulecs@GaryWorkstation> In-Reply-To: <20180702081640.moebxgydtiyulecs@GaryWorkstation> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjE0NmY1ZmEtMjc5My00YTc2LWEzNjQtNGRmNzIxODBmYzc2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiYjlBc1BmcHhhazNyNkUweFM3VlwvMWhcL2Fza2hBUWJiTVFIbjNsSmFIZ0NraVNtUUJabzFEUEJSMTQ1bmFPem5UIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch v2] NetworkPkg/HttpDxe: Fix the bug when parsing HTTP(S) message body. 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: , X-List-Received-Date: Mon, 02 Jul 2018 08:37:53 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Sorry, I can't access below google link:(. It will be better to share us th= e steps to reproduce the issue. I don't know whether the below two files ar= e enough to reproduce the issue, but you can share it to me first, then I w= ill try that. > bootx64.efi: 1208528 bytes > grub.efi: 1057792 bytes BTW, the issue only happened after applying this patches?=20 Thanks, Jiaxin =20 > -----Original Message----- > From: Gary Lin [mailto:glin@suse.com] > Sent: Monday, July 2, 2018 4:17 PM > To: Wu, Jiaxin > Cc: Ye, Ting ; edk2-devel@lists.01.org; Fu, Siyuan > > Subject: Re: [edk2] [Patch v2] NetworkPkg/HttpDxe: Fix the bug when > parsing HTTP(S) message body. >=20 > On Mon, Jul 02, 2018 at 05:34:29AM +0000, Wu, Jiaxin wrote: > > Hi Gary, > > > > Thanks the verification, in my part, HTTPS works well. Can you send me > > the failure wireshark packet/full debug message? > > > > (correct the typo) > > > Per my test, HTTPS worked for firmware -> bootx64.efi(shim.efi), and > shim failed to fetch grub2. >=20 > Here is the packets captured by wireshark: > https://drive.google.com/open?id=3D11UMRtkq521My3VNY75MeKDL8AFI12Rz > E >=20 > From the log, the second connection did start but end suddenly after a > few packet transmissions. >=20 > For reference, here are the sizes of bootx64.efi and grub.efi: >=20 > bootx64.efi: 1208528 bytes > grub.efi: 1057792 bytes >=20 > Gary Lin >=20 > > Thanks, > > Jiaxin > > > > > > > > > > > -----Original Message----- > > > > From: Gary Lin [mailto:glin@suse.com] > > > > Sent: Monday, July 2, 2018 12:17 PM > > > > To: Wu, Jiaxin > > > > Cc: edk2-devel@lists.01.org; Ye, Ting ; Fu, Siyu= an > > > > > > > > Subject: Re: [edk2] [Patch v2] NetworkPkg/HttpDxe: Fix the bug when > > > > parsing HTTP(S) message body. > > > > > > > > On Mon, Jul 02, 2018 at 10:19:30AM +0800, Jiaxin Wu wrote: > > > > > *v2: Resolve the conflict commit. > > > > > > > > > > HttpBodyParserCallback function is to parse the HTTP(S) message > body so > > > > as to > > > > > confirm whether there is the next message header. But it doesn't > record > > > > the > > > > > parsing message data/length correctly. > > > > > > > > > > This patch is refine the parsing logic so as to fix the potential= failure. > > > > > > > > > Hi Jiaxin, > > > > > > > > After applying this patch, shim failed to fetch grub.efi through th= e > > > > HTTPS connection. It got EFI_BAD_BUFFER_SIZE from HTTP->Response() > > > and > > > > I > > > > found several error messages in the OVMF log: > > > > > > > > TcpInput: Discard a packet > > > > TcpSendIpPacket: No appropriate IpSender. > > > > > > > > This only happened with HTTPS. If I replace the HTTPS URL in > dhcpd.conf > > > with > > > > the HTTP URL, it works as expected. > > > > > > > > Gary Lin > > > > > > > > > Cc: Ye Ting > > > > > Cc: Fu Siyuan > > > > > Contributed-under: TianoCore Contribution Agreement 1.0 > > > > > Signed-off-by: Wu Jiaxin > > > > > Reviewed-by: Fu Siyuan > > > > > --- > > > > > NetworkPkg/HttpDxe/HttpImpl.c | 112 +++++++++++++++++-------- > ----- > > > -- > > > > - > > > > > NetworkPkg/HttpDxe/HttpProto.c | 10 +++ > > > > > NetworkPkg/HttpDxe/HttpProto.h | 10 +++ > > > > > 3 files changed, 77 insertions(+), 55 deletions(-) > > > > > > > > > > diff --git a/NetworkPkg/HttpDxe/HttpImpl.c > > > > b/NetworkPkg/HttpDxe/HttpImpl.c > > > > > index f70e116f38..57a3712c23 100644 > > > > > --- a/NetworkPkg/HttpDxe/HttpImpl.c > > > > > +++ b/NetworkPkg/HttpDxe/HttpImpl.c > > > > > @@ -914,10 +914,11 @@ HttpBodyParserCallback ( > > > > > IN CHAR8 *Data, > > > > > IN UINTN Length, > > > > > IN VOID *Context > > > > > ) > > > > > { > > > > > + HTTP_CALLBACK_DATA *CallbackData; > > > > > HTTP_TOKEN_WRAP *Wrap; > > > > > UINTN BodyLength; > > > > > CHAR8 *Body; > > > > > > > > > > if (EventType !=3D BodyParseEventOnComplete) { > > > > > @@ -926,25 +927,22 @@ HttpBodyParserCallback ( > > > > > > > > > > if (Data =3D=3D NULL || Length !=3D 0 || Context =3D=3D NULL) = { > > > > > return EFI_SUCCESS; > > > > > } > > > > > > > > > > - Wrap =3D (HTTP_TOKEN_WRAP *) Context; > > > > > - Body =3D Wrap->HttpToken->Message->Body; > > > > > - BodyLength =3D Wrap->HttpToken->Message->BodyLength; > > > > > + CallbackData =3D (HTTP_CALLBACK_DATA *) Context; > > > > > + > > > > > + Wrap =3D (HTTP_TOKEN_WRAP *) (CallbackData->Wrap); > > > > > + Body =3D CallbackData->ParseData; > > > > > + BodyLength =3D CallbackData->ParseDataLength; > > > > > + > > > > > if (Data < Body + BodyLength) { > > > > > Wrap->HttpInstance->NextMsg =3D Data; > > > > > } else { > > > > > Wrap->HttpInstance->NextMsg =3D NULL; > > > > > } > > > > > > > > > > - > > > > > - // > > > > > - // Free Tx4Token or Tx6Token since already received corrspondi= ng > > > HTTP > > > > response. > > > > > - // > > > > > - FreePool (Wrap); > > > > > - > > > > > return EFI_SUCCESS; > > > > > } > > > > > > > > > > /** > > > > > The work function of EfiHttpResponse(). > > > > > @@ -1189,33 +1187,43 @@ HttpResponseWorker ( > > > > > HttpInstance->Method, > > > > > HttpMsg->Data.Response->StatusCode, > > > > > HttpMsg->HeaderCount, > > > > > HttpMsg->Headers, > > > > > HttpBodyParserCallback, > > > > > - (VOID *) ValueInItem, > > > > > + (VOID *) (&HttpInstance->CallbackData), > > > > > &HttpInstance->MsgParser > > > > > ); > > > > > if (EFI_ERROR (Status)) { > > > > > goto Error2; > > > > > } > > > > > > > > > > // > > > > > // Check whether we received a complete HTTP message. > > > > > // > > > > > if (HttpInstance->CacheBody !=3D NULL) { > > > > > + // > > > > > + // Record the CallbackData data. > > > > > + // > > > > > + HttpInstance->CallbackData.Wrap =3D (VOID *) Wrap; > > > > > + HttpInstance->CallbackData.ParseData =3D (VOID *) HttpIn= stance- > > > > >CacheBody; > > > > > + HttpInstance->CallbackData.ParseDataLength =3D HttpInsta= nce- > > > > >CacheLen; > > > > > + > > > > > + // > > > > > + // Parse message with CallbackData data. > > > > > + // > > > > > Status =3D HttpParseMessageBody (HttpInstance->MsgParser= , > > > > HttpInstance->CacheLen, HttpInstance->CacheBody); > > > > > if (EFI_ERROR (Status)) { > > > > > goto Error2; > > > > > } > > > > > + } > > > > > > > > > > - if (HttpIsMessageComplete (HttpInstance->MsgParser)) { > > > > > - // > > > > > - // Free the MsgParse since we already have a full HTTP= message. > > > > > - // > > > > > - HttpFreeMsgParser (HttpInstance->MsgParser); > > > > > - HttpInstance->MsgParser =3D NULL; > > > > > - } > > > > > + if (HttpIsMessageComplete (HttpInstance->MsgParser)) { > > > > > + // > > > > > + // Free the MsgParse since we already have a full HTTP m= essage. > > > > > + // > > > > > + HttpFreeMsgParser (HttpInstance->MsgParser); > > > > > + HttpInstance->MsgParser =3D NULL; > > > > > } > > > > > } > > > > > > > > > > if ((HttpMsg->Body =3D=3D NULL) || (HttpMsg->BodyLength =3D= =3D 0)) { > > > > > Status =3D EFI_SUCCESS; > > > > > @@ -1330,16 +1338,30 @@ HttpResponseWorker ( > > > > > if (EFI_ERROR (Status)) { > > > > > goto Error2; > > > > > } > > > > > > > > > > // > > > > > - // Check whether we receive a complete HTTP message. > > > > > + // Process the received the body packet. > > > > > + // > > > > > + HttpMsg->BodyLength =3D MIN (Fragment.Len, (UINT32) HttpMsg- > > > > >BodyLength); > > > > > + > > > > > + CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg- > >BodyLength); > > > > > + > > > > > + // > > > > > + // Record the CallbackData data. > > > > > + // > > > > > + HttpInstance->CallbackData.Wrap =3D (VOID *) Wrap; > > > > > + HttpInstance->CallbackData.ParseData =3D HttpMsg->Body; > > > > > + HttpInstance->CallbackData.ParseDataLength =3D HttpMsg- > > > >BodyLength; > > > > > + > > > > > + // > > > > > + // Parse Body with CallbackData data. > > > > > // > > > > > Status =3D HttpParseMessageBody ( > > > > > HttpInstance->MsgParser, > > > > > - (UINTN) Fragment.Len, > > > > > - (CHAR8 *) Fragment.Bulk > > > > > + HttpMsg->BodyLength, > > > > > + HttpMsg->Body > > > > > ); > > > > > if (EFI_ERROR (Status)) { > > > > > goto Error2; > > > > > } > > > > > > > > > > @@ -1350,51 +1372,31 @@ HttpResponseWorker ( > > > > > HttpFreeMsgParser (HttpInstance->MsgParser); > > > > > HttpInstance->MsgParser =3D NULL; > > > > > } > > > > > > > > > > // > > > > > - // We receive part of header of next HTTP msg. > > > > > + // Check whether there is the next message header in the > HttpMsg- > > > > >Body. > > > > > // > > > > > if (HttpInstance->NextMsg !=3D NULL) { > > > > > - HttpMsg->BodyLength =3D MIN ((UINTN) HttpInstance->NextMsg= - > > > > (UINTN) Fragment.Bulk, HttpMsg->BodyLength); > > > > > - CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg- > >BodyLength); > > > > > - > > > > > - HttpInstance->CacheLen =3D Fragment.Len - HttpMsg->BodyLen= gth; > > > > > - if (HttpInstance->CacheLen !=3D 0) { > > > > > - if (HttpInstance->CacheBody !=3D NULL) { > > > > > - FreePool (HttpInstance->CacheBody); > > > > > - } > > > > > - > > > > > - HttpInstance->CacheBody =3D AllocateZeroPool (HttpInstan= ce- > > > > >CacheLen); > > > > > - if (HttpInstance->CacheBody =3D=3D NULL) { > > > > > - Status =3D EFI_OUT_OF_RESOURCES; > > > > > - goto Error2; > > > > > - } > > > > > - > > > > > - CopyMem (HttpInstance->CacheBody, Fragment.Bulk + > HttpMsg- > > > > >BodyLength, HttpInstance->CacheLen); > > > > > - HttpInstance->CacheOffset =3D 0; > > > > > + HttpMsg->BodyLength =3D HttpInstance->NextMsg - (CHAR8 *) > > > > HttpMsg->Body; > > > > > + } > > > > > > > > > > - HttpInstance->NextMsg =3D HttpInstance->CacheBody + ((UI= NTN) > > > > HttpInstance->NextMsg - (UINTN) (Fragment.Bulk + HttpMsg- > > > >BodyLength)); > > > > > + HttpInstance->CacheLen =3D Fragment.Len - HttpMsg->BodyLengt= h; > > > > > + if (HttpInstance->CacheLen !=3D 0) { > > > > > + if (HttpInstance->CacheBody !=3D NULL) { > > > > > + FreePool (HttpInstance->CacheBody); > > > > > } > > > > > - } else { > > > > > - HttpMsg->BodyLength =3D MIN (Fragment.Len, (UINT32) HttpMs= g- > > > > >BodyLength); > > > > > - CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg- > >BodyLength); > > > > > - HttpInstance->CacheLen =3D Fragment.Len - HttpMsg->BodyLen= gth; > > > > > - if (HttpInstance->CacheLen !=3D 0) { > > > > > - if (HttpInstance->CacheBody !=3D NULL) { > > > > > - FreePool (HttpInstance->CacheBody); > > > > > - } > > > > > - > > > > > - HttpInstance->CacheBody =3D AllocateZeroPool (HttpInstan= ce- > > > > >CacheLen); > > > > > - if (HttpInstance->CacheBody =3D=3D NULL) { > > > > > - Status =3D EFI_OUT_OF_RESOURCES; > > > > > - goto Error2; > > > > > - } > > > > > > > > > > - CopyMem (HttpInstance->CacheBody, Fragment.Bulk + > HttpMsg- > > > > >BodyLength, HttpInstance->CacheLen); > > > > > - HttpInstance->CacheOffset =3D 0; > > > > > + HttpInstance->CacheBody =3D AllocateZeroPool (HttpInstance= - > > > > >CacheLen); > > > > > + if (HttpInstance->CacheBody =3D=3D NULL) { > > > > > + Status =3D EFI_OUT_OF_RESOURCES; > > > > > + goto Error2; > > > > > } > > > > > + > > > > > + CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg- > > > > >BodyLength, HttpInstance->CacheLen); > > > > > + HttpInstance->CacheOffset =3D 0; > > > > > + HttpInstance->NextMsg =3D HttpInstance->CacheBody; > > > > > } > > > > > > > > > > if (Fragment.Bulk !=3D NULL) { > > > > > FreePool (Fragment.Bulk); > > > > > Fragment.Bulk =3D NULL; > > > > > diff --git a/NetworkPkg/HttpDxe/HttpProto.c > > > > b/NetworkPkg/HttpDxe/HttpProto.c > > > > > index 5356cd35c0..94f89f5665 100644 > > > > > --- a/NetworkPkg/HttpDxe/HttpProto.c > > > > > +++ b/NetworkPkg/HttpDxe/HttpProto.c > > > > > @@ -195,10 +195,20 @@ HttpTcpReceiveNotifyDpc ( > > > > > Length =3D (UINTN) Wrap- > > > > >TcpWrap.Rx6Data.FragmentTable[0].FragmentLength; > > > > > } else { > > > > > Length =3D (UINTN) Wrap- > > > > >TcpWrap.Rx4Data.FragmentTable[0].FragmentLength; > > > > > } > > > > > > > > > > + // > > > > > + // Record the CallbackData data. > > > > > + // > > > > > + HttpInstance->CallbackData.Wrap =3D (VOID *) Wrap; > > > > > + HttpInstance->CallbackData.ParseData =3D Wrap->HttpToken- > >Message- > > > > >Body; > > > > > + HttpInstance->CallbackData.ParseDataLength =3D Length; > > > > > + > > > > > + // > > > > > + // Parse Body with CallbackData data. > > > > > + // > > > > > Status =3D HttpParseMessageBody ( > > > > > HttpInstance->MsgParser, > > > > > Length, > > > > > Wrap->HttpToken->Message->Body > > > > > ); > > > > > diff --git a/NetworkPkg/HttpDxe/HttpProto.h > > > > b/NetworkPkg/HttpDxe/HttpProto.h > > > > > index cc6c1eb566..fa57dbfd39 100644 > > > > > --- a/NetworkPkg/HttpDxe/HttpProto.h > > > > > +++ b/NetworkPkg/HttpDxe/HttpProto.h > > > > > @@ -89,10 +89,19 @@ typedef struct { > > > > > EFI_TLS_CONNECTION_END ConnectionEnd; > > > > > EFI_TLS_VERIFY VerifyMethod; > > > > > EFI_TLS_SESSION_STATE SessionState; > > > > > } TLS_CONFIG_DATA; > > > > > > > > > > +// > > > > > +// Callback data for HTTP_PARSER_CALLBACK() > > > > > +// > > > > > +typedef struct { > > > > > + UINTN ParseDataLength; > > > > > + VOID *ParseData; > > > > > + VOID *Wrap; > > > > > +} HTTP_CALLBACK_DATA; > > > > > + > > > > > typedef struct _HTTP_PROTOCOL { > > > > > UINT32 Signature; > > > > > EFI_HTTP_PROTOCOL Http; > > > > > EFI_HANDLE Handle; > > > > > HTTP_SERVICE *Service; > > > > > @@ -147,10 +156,11 @@ typedef struct _HTTP_PROTOCOL { > > > > > > > > > > // > > > > > // HTTP message-body parser. > > > > > // > > > > > VOID *MsgParser; > > > > > + HTTP_CALLBACK_DATA CallbackData; > > > > > > > > > > EFI_HTTP_VERSION HttpVersion; > > > > > UINT32 TimeOutMillisec; > > > > > BOOLEAN LocalAddressIsIPv6; > > > > > > > > > > -- > > > > > 2.17.1.windows.2 > > > > > > > > > > _______________________________________________ > > > > > edk2-devel mailing list > > > > > edk2-devel@lists.01.org > > > > > https://lists.01.org/mailman/listinfo/edk2-devel > > > > > > > > _______________________________________________ > > > edk2-devel mailing list > > > edk2-devel@lists.01.org > > > https://lists.01.org/mailman/listinfo/edk2-devel > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > >