From nobody Sat Nov 2 12:22:56 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 1489544884368773.5963168063861; Tue, 14 Mar 2017 19:28:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2CBAC803EE; Tue, 14 Mar 2017 19:28:03 -0700 (PDT) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 2A9EC803D7 for ; Tue, 14 Mar 2017 19:28:02 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Mar 2017 19:28:01 -0700 Received: from unknown (HELO SHWDEOPENPSI116.ccr.corp.intel.com) ([10.239.9.23]) by orsmga002.jf.intel.com with ESMTP; 14 Mar 2017 19:28:00 -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=1489544882; x=1521080882; h=from:to:cc:subject:date:message-id; bh=V7YWwfBiS+KZM69G+nU0RpqNne23OXHwLxbnu5w2Lb4=; b=eDLFavwT0Ag6hc4JpbG9rJDffeE/qP5M4LEA9VRTQEGug9fQJ1JszJu8 +yzti5SHJqZ/Xe3X0m1o3LhrWHn7hw==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,166,1486454400"; d="scan'208";a="60469216" From: Zhang Lubo To: edk2-devel@lists.01.org Date: Wed, 15 Mar 2017 10:27:59 +0800 Message-Id: <1489544879-24940-1-git-send-email-lubo.zhang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [PATCH V2] NetworkPkg: Fix service binding issue in TCP dxe. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Wu Jiaxin 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" v2: Handle error case in SockCreateChild and fix typo issue when we destroy the socket Sock and its associated protocol control block, we need to first close the parent protocol, then remove the protocol from childHandle and last to free any data structures that allocated in CreateChild. But currently, we free the socket data (Socket ConfigureState) before removing the protocol form the childhandle. So if the up layer perform the driverbing stop to abort tcp session and send the tcp reset packet, it will failed. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zhang Lubo Cc: Wu Jiaxin Cc: Ye Ting Cc: Fu Siyuan Reviewed-by: Fu Siyuan Reviewed-by: Wu Jiaxin Reviewed-by: Ye Ting =20 --- NetworkPkg/TcpDxe/SockImpl.c | 56 +------------------- NetworkPkg/TcpDxe/SockImpl.h | 3 +- NetworkPkg/TcpDxe/SockInterface.c | 108 ++++++++++++++++++++++++++++++++++= +--- NetworkPkg/TcpDxe/TcpDispatcher.c | 19 +------ 4 files changed, 104 insertions(+), 82 deletions(-) diff --git a/NetworkPkg/TcpDxe/SockImpl.c b/NetworkPkg/TcpDxe/SockImpl.c index 4eb42fb..c5fb176 100644 --- a/NetworkPkg/TcpDxe/SockImpl.c +++ b/NetworkPkg/TcpDxe/SockImpl.c @@ -1,9 +1,9 @@ /** @file Implementation of the Socket. =20 - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
=20 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 http://opensource.org/licenses/bsd-license.php. @@ -826,20 +826,12 @@ OnError: VOID SockDestroy ( IN OUT SOCKET *Sock ) { - VOID *SockProtocol; - EFI_GUID *TcpProtocolGuid; - EFI_STATUS Status; - ASSERT (SockStream =3D=3D Sock->Type); =20 - if (Sock->DestroyCallback !=3D NULL) { - Sock->DestroyCallback (Sock, Sock->Context); - } - // // Flush the completion token buffered // by sock and rcv, snd buffer // if (!SOCK_IS_UNCONFIGURED (Sock)) { @@ -870,56 +862,10 @@ SockDestroy ( ); =20 Sock->Parent =3D NULL; } =20 - // - // Set the protocol guid and driver binding handle - // in the light of Sock->SockType - // - if (Sock->IpVersion =3D=3D IP_VERSION_4) { - TcpProtocolGuid =3D &gEfiTcp4ProtocolGuid; - } else { - TcpProtocolGuid =3D &gEfiTcp6ProtocolGuid; - } - - // - // Retrieve the protocol installed on this sock - // - Status =3D gBS->OpenProtocol ( - Sock->SockHandle, - TcpProtocolGuid, - &SockProtocol, - Sock->DriverBinding, - Sock->SockHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - - if (EFI_ERROR (Status)) { - - DEBUG ( - (EFI_D_ERROR, - "SockDestroy: Open protocol installed on socket failed with %r\n", - Status) - ); - - goto FreeSock; - } - - // - // Uninstall the protocol installed on this sock - // in the light of Sock->SockType - // - gBS->UninstallMultipleProtocolInterfaces ( - Sock->SockHandle, - TcpProtocolGuid, - SockProtocol, - NULL - ); - -FreeSock: - FreePool (Sock); } =20 /** Flush the sndBuffer and rcvBuffer of socket. diff --git a/NetworkPkg/TcpDxe/SockImpl.h b/NetworkPkg/TcpDxe/SockImpl.h index 5a067de..80692b1 100644 --- a/NetworkPkg/TcpDxe/SockImpl.h +++ b/NetworkPkg/TcpDxe/SockImpl.h @@ -1,9 +1,9 @@ /** @file The function declaration that provided for Socket Interface. =20 - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
=20 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 http://opensource.org/licenses/bsd-license.php. @@ -15,10 +15,11 @@ =20 #ifndef _SOCK_IMPL_H_ #define _SOCK_IMPL_H_ =20 #include "Socket.h" +#include "TcpMain.h" =20 /** Signal a event with the given status. =20 @param[in] Token The token's event is to be signaled. diff --git a/NetworkPkg/TcpDxe/SockInterface.c b/NetworkPkg/TcpDxe/SockInte= rface.c index 21ce643..b4ba40a 100644 --- a/NetworkPkg/TcpDxe/SockInterface.c +++ b/NetworkPkg/TcpDxe/SockInterface.c @@ -1,9 +1,9 @@ /** @file Interface function of the Socket. =20 - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
=20 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 http://opensource.org/licenses/bsd-license.php. @@ -140,20 +140,37 @@ SockBufferToken ( EFI_STATUS SockDestroyChild ( IN OUT SOCKET *Sock ) { - EFI_STATUS Status; + EFI_STATUS Status; + TCP_PROTO_DATA *ProtoData; + TCP_CB *Tcb; + EFI_GUID *IpProtocolGuid; + EFI_GUID *TcpProtocolGuid; + VOID *SockProtocol; =20 ASSERT ((Sock !=3D NULL) && (Sock->ProtoHandler !=3D NULL)); =20 if (Sock->InDestroy) { return EFI_SUCCESS; } =20 Sock->InDestroy =3D TRUE; =20 + if (Sock->IpVersion =3D=3D IP_VERSION_4) { + IpProtocolGuid =3D &gEfiIp4ProtocolGuid; + TcpProtocolGuid =3D &gEfiTcp4ProtocolGuid; + } else { + IpProtocolGuid =3D &gEfiIp6ProtocolGuid; + TcpProtocolGuid =3D &gEfiTcp6ProtocolGuid; + } + ProtoData =3D (TCP_PROTO_DATA *) Sock->ProtoReserved; + Tcb =3D ProtoData->TcpPcb; + + ASSERT (Tcb !=3D NULL); + Status =3D EfiAcquireLockOrFail (&(Sock->Lock)); if (EFI_ERROR (Status)) { =20 DEBUG ( (EFI_D_ERROR, @@ -163,10 +180,55 @@ SockDestroyChild ( =20 return EFI_ACCESS_DENIED; } =20 // + // Close the IP protocol. + // + gBS->CloseProtocol ( + Tcb->IpInfo->ChildHandle, + IpProtocolGuid, + ProtoData->TcpService->IpIo->Image, + Sock->SockHandle + ); + + if (Sock->DestroyCallback !=3D NULL) { + Sock->DestroyCallback (Sock, Sock->Context); + } + + // + // Retrieve the protocol installed on this sock + // + Status =3D gBS->OpenProtocol ( + Sock->SockHandle, + TcpProtocolGuid, + &SockProtocol, + Sock->DriverBinding, + Sock->SockHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + + if (EFI_ERROR (Status)) { + + DEBUG ( + (EFI_D_ERROR, + "SockDestroyChild: Open protocol installed on socket failed with %r\= n", + Status) + ); + } + + // + // Uninstall the protocol installed on this sock + // + gBS->UninstallMultipleProtocolInterfaces ( + Sock->SockHandle, + TcpProtocolGuid, + SockProtocol, + NULL + ); + + // // force protocol layer to detach the PCB // Status =3D Sock->ProtoHandler (Sock, SOCK_DETACH, NULL); =20 if (EFI_ERROR (Status)) { @@ -211,10 +273,12 @@ SockCreateChild ( IN SOCK_INIT_DATA *SockInitData ) { SOCKET *Sock; EFI_STATUS Status; + VOID *SockProtocol; + EFI_GUID *TcpProtocolGuid; =20 // // create a new socket // Sock =3D SockCreate (SockInitData); @@ -234,13 +298,11 @@ SockCreateChild ( DEBUG ( (EFI_D_ERROR, "SockCreateChild: Get the lock to access socket failed with %r\n", Status) ); - - SockDestroy (Sock); - return NULL; + goto ERROR; } // // inform the protocol layer to attach the socket // with a new protocol control block // @@ -251,16 +313,46 @@ SockCreateChild ( DEBUG ( (EFI_D_ERROR, "SockCreateChild: Protocol failed to attach a socket with %r\n", Status) ); - - SockDestroy (Sock); - Sock =3D NULL; + goto ERROR; } =20 return Sock; + +ERROR: + + if (Sock->DestroyCallback !=3D NULL) { + Sock->DestroyCallback (Sock, Sock->Context); + } + + if (Sock->IpVersion =3D=3D IP_VERSION_4) { + TcpProtocolGuid =3D &gEfiTcp4ProtocolGuid; + } else { + TcpProtocolGuid =3D &gEfiTcp6ProtocolGuid; + } + + gBS->OpenProtocol ( + Sock->SockHandle, + TcpProtocolGuid, + &SockProtocol, + Sock->DriverBinding, + Sock->SockHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + // + // Uninstall the protocol installed on this sock + // + gBS->UninstallMultipleProtocolInterfaces ( + Sock->SockHandle, + TcpProtocolGuid, + SockProtocol, + NULL + ); + SockDestroy (Sock); + return NULL; } =20 /** Configure the specific socket Sock using configuration data ConfigData. =20 diff --git a/NetworkPkg/TcpDxe/TcpDispatcher.c b/NetworkPkg/TcpDxe/TcpDispa= tcher.c index d4bc8ac..9a352b1 100644 --- a/NetworkPkg/TcpDxe/TcpDispatcher.c +++ b/NetworkPkg/TcpDxe/TcpDispatcher.c @@ -1,10 +1,10 @@ /** @file The implementation of a dispatch routine for processing TCP requests. =20 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
=20 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 http://opensource.org/licenses/bsd-license.php. @@ -421,34 +421,17 @@ TcpDetachPcb ( IN OUT SOCKET *Sk ) { TCP_PROTO_DATA *ProtoData; TCP_CB *Tcb; - EFI_GUID *IpProtocolGuid; =20 - if (Sk->IpVersion =3D=3D IP_VERSION_4) { - IpProtocolGuid =3D &gEfiIp4ProtocolGuid; - } else { - IpProtocolGuid =3D &gEfiIp6ProtocolGuid; - } - =20 ProtoData =3D (TCP_PROTO_DATA *) Sk->ProtoReserved; Tcb =3D ProtoData->TcpPcb; =20 ASSERT (Tcb !=3D NULL); =20 TcpFlushPcb (Tcb); - - // - // Close the IP protocol. - // - gBS->CloseProtocol ( - Tcb->IpInfo->ChildHandle, - IpProtocolGuid, - ProtoData->TcpService->IpIo->Image, - Sk->SockHandle - ); =20 IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo); =20 FreePool (Tcb); =20 --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel