]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Fix service binding issue in TCP4 and Ip4 dxe.
authorZhang Lubo <lubo.zhang@intel.com>
Thu, 16 Mar 2017 10:03:36 +0000 (18:03 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Fri, 17 Mar 2017 02:14:30 +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 want to send the
tcp reset packet in it's driver binding stop function, it will failed.

The IpInstance destroy state is redundant and may cause
ip transmit failed if up layer want to send ip packet.

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>
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c
MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.h
MdeModulePkg/Universal/Network/Tcp4Dxe/SockInterface.c
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dispatcher.c

index 642e453e020eace3db9b8cfb5ec5e633382dff5d..792db5c173f2ad47a5578e31407ce8279074d73e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The driver binding and service binding protocol for IP4 driver.\r
 \r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
 \r
 This program and the accompanying materials\r
@@ -922,7 +922,6 @@ Ip4ServiceBindingDestroyChild (
   IP4_PROTOCOL              *IpInstance;\r
   EFI_IP4_PROTOCOL          *Ip4;\r
   EFI_TPL                   OldTpl;\r
-  INTN                      State;\r
 \r
   if ((This == NULL) || (ChildHandle == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -960,13 +959,12 @@ Ip4ServiceBindingDestroyChild (
   // when UDP driver is being stopped, it will destroy all\r
   // the IP child it opens.\r
   //\r
-  if (IpInstance->State == IP4_STATE_DESTROY) {\r
+  if (IpInstance->InDestroy) {\r
     gBS->RestoreTPL (OldTpl);\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  State             = IpInstance->State;\r
-  IpInstance->State = IP4_STATE_DESTROY;\r
+  IpInstance->InDestroy = TRUE;\r
 \r
   //\r
   // Close the Managed Network protocol.\r
@@ -1009,6 +1007,7 @@ Ip4ServiceBindingDestroyChild (
                   );\r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
   if (EFI_ERROR (Status)) {\r
+    IpInstance->InDestroy = FALSE;\r
     goto ON_ERROR;\r
   }\r
 \r
@@ -1033,7 +1032,6 @@ Ip4ServiceBindingDestroyChild (
   return EFI_SUCCESS;\r
 \r
 ON_ERROR:\r
-  IpInstance->State = State;\r
   gBS->RestoreTPL (OldTpl);\r
 \r
   return Status;\r
index 5aa3ea137599cde6f4a60cbe6414130d407b0a3f..3cdf8ecaad06f033a2e5381d0f73ef90e6ba2d35 100644 (file)
@@ -550,6 +550,7 @@ Ip4InitProtocol (
   IpInstance->Signature = IP4_PROTOCOL_SIGNATURE;\r
   CopyMem (&IpInstance->Ip4Proto, &mEfiIp4ProtocolTemplete, sizeof (IpInstance->Ip4Proto));\r
   IpInstance->State     = IP4_STATE_UNCONFIGED;\r
+  IpInstance->InDestroy   = FALSE;\r
   IpInstance->Service   = IpSb;\r
 \r
   InitializeListHead (&IpInstance->Link);\r
@@ -936,8 +937,7 @@ EfiIp4Configure (
     Status = Ip4CleanProtocol (IpInstance);\r
 \r
     //\r
-    // Don't change the state if it is DESTROY, consider the following\r
-    // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,\r
+    // Consider the following valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,\r
     // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,\r
     // the unload fails miserably.\r
     //\r
index 7a7ad9d785a15d05cd9213c5e5c384cce255a58e..f6b4047941eb374f33fb0120fad29079a813a9fd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Ip4 internal functions and type defintions.\r
   \r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
 \r
 This program and the accompanying materials\r
@@ -64,12 +64,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 // The state of IP4 protocol. It starts from UNCONFIGED. if it is\r
 // successfully configured, it goes to CONFIGED. if configure NULL\r
-// is called, it becomes UNCONFIGED again. If (partly) destroyed, it\r
-// becomes DESTROY.\r
+// is called, it becomes UNCONFIGED again.\r
 //\r
 #define IP4_STATE_UNCONFIGED    0\r
 #define IP4_STATE_CONFIGED      1\r
-#define IP4_STATE_DESTROY       2\r
 \r
 //\r
 // The state of IP4 service. It starts from UNSTARTED. It transits\r
@@ -136,6 +134,8 @@ struct _IP4_PROTOCOL {
   EFI_HANDLE                Handle;\r
   INTN                      State;\r
 \r
+  BOOLEAN                   InDestroy;                      \r
+\r
   IP4_SERVICE               *Service;\r
   LIST_ENTRY                Link;       // Link to all the IP protocol from the service\r
 \r
index fc7827325f72fb9e4bdc117a8f926e3a2ff76ee5..0476077c2019837884acf0ad99f268326a357bd7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of the Socket.\r
 \r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -717,16 +717,8 @@ SockDestroy (
   IN OUT SOCKET *Sock\r
   )\r
 {\r
-  VOID        *SockProtocol;\r
-  EFI_GUID    *ProtocolGuid;\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
@@ -762,44 +754,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
-  ProtocolGuid = &gEfiTcp4ProtocolGuid;\r
-\r
-  //\r
-  // Retrieve the protocol installed on this sock\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  Sock->SockHandle,\r
-                  ProtocolGuid,\r
-                  &SockProtocol,\r
-                  Sock->DriverBinding,\r
-                  Sock->SockHandle,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-\r
-    DEBUG ((EFI_D_ERROR, "SockDestroy: Open protocol installed "\r
-      "on socket failed with %r\n", Status));\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
-        ProtocolGuid,\r
-        SockProtocol,\r
-        NULL\r
-        );\r
-\r
-FreeSock:\r
   FreePool (Sock);\r
   return ;\r
 }\r
index 4a5a845b0e7d91ce64c854e1564dd6179428b03f..bfd750a8ceee090921d9d562e02c2767ac56379d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Socket implementation header file.\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define _SOCK_IMPL_H_\r
 \r
 #include "Socket.h"\r
+#include "Tcp4Main.h"\r
 \r
 /**\r
   Signal a event with the given status.\r
index a8bdef6802b425bef556e5a1c82895796cb5c5f4..f8b535cf6e7f0ad125a1647bf22e063daca7ff1e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface function of the Socket.\r
 \r
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -144,7 +144,10 @@ SockDestroyChild (
   IN SOCKET *Sock\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS       Status;\r
+  TCP4_PROTO_DATA  *ProtoData;\r
+  TCP_CB           *Tcb;\r
+  VOID             *SockProtocol;\r
 \r
   ASSERT ((Sock != NULL) && (Sock->ProtoHandler != NULL));\r
 \r
@@ -154,6 +157,11 @@ SockDestroyChild (
 \r
   Sock->InDestroy = TRUE;\r
 \r
+  ProtoData = (TCP4_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
@@ -163,6 +171,49 @@ SockDestroyChild (
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
+  //\r
+  // Close the IP protocol.\r
+  //\r
+  gBS->CloseProtocol (\r
+         Tcb->IpInfo->ChildHandle,\r
+         &gEfiIp4ProtocolGuid,\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
+                  &gEfiTcp4ProtocolGuid,\r
+                  &SockProtocol,\r
+                  Sock->DriverBinding,\r
+                  Sock->SockHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    DEBUG ((EFI_D_ERROR, "SockDestroyChild: Open protocol installed "\r
+      "on socket failed with %r\n", Status));\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
+        &gEfiTcp4ProtocolGuid,\r
+        SockProtocol,\r
+        NULL\r
+        );\r
+\r
   //\r
   // force protocol layer to detach the PCB\r
   //\r
@@ -209,6 +260,7 @@ SockCreateChild (
   )\r
 {\r
   SOCKET      *Sock;\r
+  VOID        *SockProtocol;\r
   EFI_STATUS  Status;\r
 \r
   //\r
@@ -229,8 +281,7 @@ SockCreateChild (
     DEBUG ((EFI_D_ERROR, "SockCreateChild: Get the lock to "\r
       "access socket failed with %r\n", Status));\r
 \r
-    SockDestroy (Sock);\r
-    return NULL;\r
+    goto ERROR;\r
   }\r
   //\r
   // inform the protocol layer to attach the socket\r
@@ -243,11 +294,36 @@ SockCreateChild (
     DEBUG ((EFI_D_ERROR, "SockCreateChild: Protocol failed to"\r
       " attach a socket with %r\n", Status));\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
+  gBS->OpenProtocol (\r
+         Sock->SockHandle,\r
+         &gEfiTcp4ProtocolGuid,\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
+        &gEfiTcp4ProtocolGuid,\r
+        SockProtocol,\r
+        NULL\r
+        );\r
+   SockDestroy (Sock);\r
+   return NULL;\r
 }\r
 \r
 \r
index 5b327af721c48ddb7b6db58c3abb3baba3298754..702cae8d6586b89abf8c6ec6684f0c5d57cd97cd 100644 (file)
@@ -2,7 +2,7 @@
   Tcp request dispatcher implementation.\r
 \r
 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -332,16 +332,6 @@ Tcp4DetachPcb (
   ASSERT (Tcb != NULL);\r
 \r
   Tcp4FlushPcb (Tcb);\r
-\r
-  //\r
-  // Close the IP protocol.\r
-  //\r
-  gBS->CloseProtocol (\r
-         Tcb->IpInfo->ChildHandle,\r
-         &gEfiIp4ProtocolGuid,\r
-         ProtoData->TcpService->IpIo->Image,\r
-         Sk->SockHandle\r
-         );\r
   \r
   IpIoRemoveIp (ProtoData->TcpService->IpIo, Tcb->IpInfo);\r
 \r