]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Fix service binding issue in TCP dxe.
authorZhang Lubo <lubo.zhang@intel.com>
Thu, 16 Mar 2017 09:52:51 +0000 (17:52 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Fri, 17 Mar 2017 02:14:37 +0000 (10:14 +0800)
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 <lubo.zhang@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
NetworkPkg/TcpDxe/SockImpl.c
NetworkPkg/TcpDxe/SockImpl.h
NetworkPkg/TcpDxe/SockInterface.c
NetworkPkg/TcpDxe/TcpDispatcher.c

index 4eb42fb868f43c5f23a6d30f8b50e54b393ccca4..c5fb1762551d88e4ab480c89df5e1de1e5f47cf3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of the Socket.\r
 \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -828,16 +828,8 @@ SockDestroy (
   IN OUT SOCKET *Sock\r
   )\r
 {\r
-  VOID        *SockProtocol;\r
-  EFI_GUID    *TcpProtocolGuid;\r
-  EFI_STATUS  Status;\r
-\r
   ASSERT (SockStream == Sock->Type);\r
 \r
-  if (Sock->DestroyCallback != NULL) {\r
-    Sock->DestroyCallback (Sock, Sock->Context);\r
-  }\r
-\r
   //\r
   // Flush the completion token buffered\r
   // by sock and rcv, snd buffer\r
@@ -872,52 +864,6 @@ SockDestroy (
     Sock->Parent = NULL;\r
   }\r
 \r
-  //\r
-  // Set the protocol guid and driver binding handle\r
-  // in the light of Sock->SockType\r
-  //\r
-  if (Sock->IpVersion == IP_VERSION_4) {\r
-    TcpProtocolGuid = &gEfiTcp4ProtocolGuid;\r
-  } else {\r
-    TcpProtocolGuid = &gEfiTcp6ProtocolGuid;\r
-  }\r
-\r
-  //\r
-  // Retrieve the protocol installed on this sock\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  Sock->SockHandle,\r
-                  TcpProtocolGuid,\r
-                  &SockProtocol,\r
-                  Sock->DriverBinding,\r
-                  Sock->SockHandle,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-\r
-    DEBUG (\r
-      (EFI_D_ERROR,\r
-      "SockDestroy: Open protocol installed on socket failed with %r\n",\r
-      Status)\r
-      );\r
-\r
-    goto FreeSock;\r
-  }\r
-\r
-  //\r
-  // Uninstall the protocol installed on this sock\r
-  // in the light of Sock->SockType\r
-  //\r
-  gBS->UninstallMultipleProtocolInterfaces (\r
-        Sock->SockHandle,\r
-        TcpProtocolGuid,\r
-        SockProtocol,\r
-        NULL\r
-        );\r
-\r
-FreeSock:\r
-\r
   FreePool (Sock);\r
 }\r
 \r
index 5a067deb41944697e6867c7c787a00052bd50c4e..80692b161eff95ac8f3df028aa64735984917116 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The function declaration that provided for Socket Interface.\r
 \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -17,6 +17,7 @@
 #define _SOCK_IMPL_H_\r
 \r
 #include "Socket.h"\r
+#include "TcpMain.h"\r
 \r
 /**\r
   Signal a event with the given status.\r
index 21ce643a5481b62b6439408b4f8002ccca3d6b61..b4ba40afcef620f9e6889c5866f10b4c9408aae4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface function of the Socket.\r
 \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -142,7 +142,12 @@ SockDestroyChild (
   IN OUT SOCKET *Sock\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS       Status;\r
+  TCP_PROTO_DATA   *ProtoData;\r
+  TCP_CB           *Tcb;\r
+  EFI_GUID         *IpProtocolGuid;\r
+  EFI_GUID         *TcpProtocolGuid;\r
+  VOID             *SockProtocol;\r
 \r
   ASSERT ((Sock != NULL) && (Sock->ProtoHandler != NULL));\r
 \r
@@ -152,6 +157,18 @@ SockDestroyChild (
 \r
   Sock->InDestroy = TRUE;\r
 \r
+  if (Sock->IpVersion == IP_VERSION_4) {\r
+    IpProtocolGuid = &gEfiIp4ProtocolGuid;\r
+    TcpProtocolGuid = &gEfiTcp4ProtocolGuid;\r
+  } else {\r
+    IpProtocolGuid = &gEfiIp6ProtocolGuid;\r
+    TcpProtocolGuid = &gEfiTcp6ProtocolGuid;\r
+  }\r
+  ProtoData = (TCP_PROTO_DATA *) Sock->ProtoReserved;\r
+  Tcb       = ProtoData->TcpPcb;\r
+\r
+  ASSERT (Tcb != NULL);\r
+\r
   Status            = EfiAcquireLockOrFail (&(Sock->Lock));\r
   if (EFI_ERROR (Status)) {\r
 \r
@@ -164,6 +181,51 @@ SockDestroyChild (
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
+  //\r
+  // Close the IP protocol.\r
+  //\r
+  gBS->CloseProtocol (\r
+         Tcb->IpInfo->ChildHandle,\r
+         IpProtocolGuid,\r
+         ProtoData->TcpService->IpIo->Image,\r
+         Sock->SockHandle\r
+         );\r
+\r
+  if (Sock->DestroyCallback != NULL) {\r
+    Sock->DestroyCallback (Sock, Sock->Context);\r
+  }\r
+\r
+  //\r
+  // Retrieve the protocol installed on this sock\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Sock->SockHandle,\r
+                  TcpProtocolGuid,\r
+                  &SockProtocol,\r
+                  Sock->DriverBinding,\r
+                  Sock->SockHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "SockDestroyChild: Open protocol installed on socket failed with %r\n",\r
+      Status)\r
+      );\r
+  }\r
+\r
+  //\r
+  // Uninstall the protocol installed on this sock\r
+  //\r
+  gBS->UninstallMultipleProtocolInterfaces (\r
+        Sock->SockHandle,\r
+        TcpProtocolGuid,\r
+        SockProtocol,\r
+        NULL\r
+        );\r
+\r
   //\r
   // force protocol layer to detach the PCB\r
   //\r
@@ -213,6 +275,8 @@ SockCreateChild (
 {\r
   SOCKET      *Sock;\r
   EFI_STATUS  Status;\r
+  VOID        *SockProtocol;\r
+  EFI_GUID    *TcpProtocolGuid;\r
 \r
   //\r
   // create a new socket\r
@@ -236,9 +300,7 @@ SockCreateChild (
       "SockCreateChild: Get the lock to access socket failed with %r\n",\r
       Status)\r
       );\r
-\r
-    SockDestroy (Sock);\r
-    return NULL;\r
+    goto ERROR;\r
   }\r
   //\r
   // inform the protocol layer to attach the socket\r
@@ -253,12 +315,42 @@ SockCreateChild (
       "SockCreateChild: Protocol failed to attach a socket with %r\n",\r
       Status)\r
       );\r
-\r
-    SockDestroy (Sock);\r
-    Sock = NULL;\r
+    goto ERROR;\r
   }\r
 \r
   return Sock;\r
+\r
+ERROR:\r
+\r
+  if (Sock->DestroyCallback != NULL) {\r
+    Sock->DestroyCallback (Sock, Sock->Context);\r
+  }\r
+\r
+  if (Sock->IpVersion == IP_VERSION_4) {\r
+    TcpProtocolGuid = &gEfiTcp4ProtocolGuid;\r
+  } else {\r
+    TcpProtocolGuid = &gEfiTcp6ProtocolGuid;\r
+  }\r
+\r
+  gBS->OpenProtocol (\r
+         Sock->SockHandle,\r
+         TcpProtocolGuid,\r
+         &SockProtocol,\r
+         Sock->DriverBinding,\r
+         Sock->SockHandle,\r
+         EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+         );\r
+  //\r
+  // Uninstall the protocol installed on this sock\r
+  //\r
+  gBS->UninstallMultipleProtocolInterfaces (\r
+        Sock->SockHandle,\r
+        TcpProtocolGuid,\r
+        SockProtocol,\r
+        NULL\r
+        );\r
+   SockDestroy (Sock);\r
+   return NULL;\r
 }\r
 \r
 /**\r
index d4bc8ace5597604a0b6e0279efdaa64289690307..9a352b1531e1d85899fedc3d976313fbbb4f79c4 100644 (file)
@@ -2,7 +2,7 @@
   The implementation of a dispatch routine for processing TCP requests.\r
 \r
   (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -423,30 +423,13 @@ TcpDetachPcb (
 {\r
   TCP_PROTO_DATA   *ProtoData;\r
   TCP_CB           *Tcb;\r
-  EFI_GUID         *IpProtocolGuid;\r
 \r
-  if (Sk->IpVersion == IP_VERSION_4) {\r
-    IpProtocolGuid = &gEfiIp4ProtocolGuid;\r
-  } else {\r
-    IpProtocolGuid = &gEfiIp6ProtocolGuid;\r
-  }\r
-  \r
   ProtoData = (TCP_PROTO_DATA *) Sk->ProtoReserved;\r
   Tcb       = ProtoData->TcpPcb;\r
 \r
   ASSERT (Tcb != NULL);\r
 \r
   TcpFlushPcb (Tcb);\r
-\r
-  //\r
-  // Close the IP protocol.\r
-  //\r
-  gBS->CloseProtocol (\r
-         Tcb->IpInfo->ChildHandle,\r
-         IpProtocolGuid,\r
-         ProtoData->TcpService->IpIo->Image,\r
-         Sk->SockHandle\r
-         );\r
   \r
   IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo);\r
 \r