]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/IpIoLib: Check the input parameters before use them.
authorFu Siyuan <siyuan.fu@intel.com>
Wed, 13 Dec 2017 08:06:42 +0000 (16:06 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Fri, 22 Dec 2017 05:45:25 +0000 (13:45 +0800)
This patch updates the DxeIpIoLib to check the input parameters before using.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
MdeModulePkg/Include/Library/IpIoLib.h
MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c

index bae7113407cb6abf074fed7e7c86f3cd13dd7d80..463bf95b499a51f310b25fe83103a3f6bb393285 100644 (file)
@@ -359,8 +359,9 @@ IpIoDestroy (
 \r
   @param[in, out]  IpIo            The pointer to the IP_IO instance that needs to stop.\r
 \r
-  @retval          EFI_SUCCESS     The IP_IO instance stopped successfully.\r
-  @retval          Others          Anrror condition occurred.\r
+  @retval          EFI_SUCCESS            The IP_IO instance stopped successfully.\r
+  @retval          EFI_INVALID_PARAMETER  Invalid input parameter.\r
+  @retval          Others                 Anrror condition occurred.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -381,12 +382,13 @@ IpIoStop (
   @param[in]       OpenData           The configuration data and callbacks for\r
                                       the IP_IO instance.\r
 \r
-  @retval          EFI_SUCCESS        The IP_IO instance opened with OpenData\r
-                                      successfully.\r
-  @retval          EFI_ACCESS_DENIED  The IP_IO instance is configured; avoid  \r
-                                      reopening it.\r
-  @retval          EFI_UNSUPPORTED    IPv4 RawData mode is no supported.\r
-  @retval          Others             An error condition occurred.\r
+  @retval          EFI_SUCCESS            The IP_IO instance opened with OpenData\r
+                                          successfully.\r
+  @retval          EFI_ACCESS_DENIED      The IP_IO instance is configured, avoid to \r
+                                          reopen it.\r
+  @retval          EFI_UNSUPPORTED        IPv4 RawData mode is no supported.\r
+  @retval          EFI_INVALID_PARAMETER  Invalid input parameter.\r
+  @retval          Others                 Error condition occurred.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -522,7 +524,7 @@ IpIoRemoveIp (
   @param[in]       Src               The local IP address.\r
 \r
   @return The pointer to the IP protocol can be used for sending purpose and its local\r
-          address is the same with Src.\r
+          address is the same with Src. NULL if failed.\r
 \r
 **/\r
 IP_IO_IP_INFO *\r
index 1436da777af662a209ef3057d028e938bc52eda0..a06c0b6a4752cdea4fb78e20ce6d74006275999e 100644 (file)
@@ -283,15 +283,22 @@ IpIoIcmpv4Handler (
   UINT8                Type;\r
   UINT8                Code;\r
   UINT32               TrimBytes;\r
-\r
+  \r
+  ASSERT (IpIo != NULL);\r
+  ASSERT (Pkt != NULL);\r
+  ASSERT (Session != NULL);\r
   ASSERT (IpIo->IpVersion == IP_VERSION_4);\r
-\r
-  IcmpHdr = NET_PROTO_HDR (Pkt, IP4_ICMP_ERROR_HEAD);\r
-  IpHdr   = (EFI_IP4_HEADER *) (&IcmpHdr->IpHead);\r
-\r
+  \r
   //\r
   // Check the ICMP packet length.\r
   //\r
+  if (Pkt->TotalSize < sizeof (IP4_ICMP_ERROR_HEAD)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  \r
+  IcmpHdr = NET_PROTO_HDR (Pkt, IP4_ICMP_ERROR_HEAD);\r
+  IpHdr   = (EFI_IP4_HEADER *) (&IcmpHdr->IpHead);\r
+\r
   if (Pkt->TotalSize < ICMP_ERRLEN (IpHdr)) {\r
 \r
     return EFI_ABORTED;\r
@@ -421,6 +428,9 @@ IpIoIcmpv6Handler (
   UINT32               TrimBytes;\r
   BOOLEAN              Flag;\r
 \r
+  ASSERT (IpIo != NULL);\r
+  ASSERT (Pkt != NULL);\r
+  ASSERT (Session != NULL);\r
   ASSERT (IpIo->IpVersion == IP_VERSION_6);\r
 \r
   //\r
@@ -1043,6 +1053,7 @@ IpIoListenHandlerDpc (
   }\r
 \r
   if (IpIo->IpVersion == IP_VERSION_4) {\r
+    ASSERT (RxData->Ip4RxData.Header != NULL);\r
     if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress))) {\r
       //\r
       // The source address is a broadcast address, discard it.\r
@@ -1066,6 +1077,11 @@ IpIoListenHandlerDpc (
       goto CleanUp;\r
     }\r
 \r
+    //\r
+    // The fragment should always be valid for non-zero length packet.\r
+    //\r
+    ASSERT (RxData->Ip4RxData.FragmentCount != 0);\r
+\r
     //\r
     // Create a netbuffer representing IPv4 packet\r
     //\r
@@ -1090,7 +1106,7 @@ IpIoListenHandlerDpc (
     Session.IpHdrLen       = RxData->Ip4RxData.HeaderLength;\r
     Session.IpVersion      = IP_VERSION_4;\r
   } else {\r
-\r
+    ASSERT (RxData->Ip6RxData.Header != NULL);\r
     if (!NetIp6IsValidUnicast(&RxData->Ip6RxData.Header->SourceAddress)) {\r
       goto CleanUp;\r
     }\r
@@ -1102,6 +1118,11 @@ IpIoListenHandlerDpc (
       goto CleanUp;\r
     }\r
     \r
+    //\r
+    // The fragment should always be valid for non-zero length packet.\r
+    //\r
+    ASSERT (RxData->Ip6RxData.FragmentCount != 0);\r
+    \r
     //\r
     // Create a netbuffer representing IPv6 packet\r
     //\r
@@ -1287,12 +1308,13 @@ ReleaseIpIo:
   @param[in]       OpenData           The configuration data and callbacks for\r
                                       the IP_IO instance.\r
 \r
-  @retval          EFI_SUCCESS        The IP_IO instance opened with OpenData\r
-                                      successfully.\r
-  @retval          EFI_ACCESS_DENIED  The IP_IO instance is configured, avoid to \r
-                                      reopen it.\r
-  @retval          EFI_UNSUPPORTED    IPv4 RawData mode is no supported.\r
-  @retval          Others             Error condition occurred.\r
+  @retval          EFI_SUCCESS            The IP_IO instance opened with OpenData\r
+                                          successfully.\r
+  @retval          EFI_ACCESS_DENIED      The IP_IO instance is configured, avoid to \r
+                                          reopen it.\r
+  @retval          EFI_UNSUPPORTED        IPv4 RawData mode is no supported.\r
+  @retval          EFI_INVALID_PARAMETER  Invalid input parameter.\r
+  @retval          Others                 Error condition occurred.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1305,6 +1327,10 @@ IpIoOpen (
   EFI_STATUS        Status;\r
   UINT8             IpVersion;\r
 \r
+  if (IpIo == NULL || OpenData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   if (IpIo->IsConfigured) {\r
     return EFI_ACCESS_DENIED;\r
   }\r
@@ -1416,8 +1442,9 @@ ErrorExit:
 \r
   @param[in, out]  IpIo            Pointer to the IP_IO instance that needs to stop.\r
 \r
-  @retval          EFI_SUCCESS     The IP_IO instance stopped successfully.\r
-  @retval          Others          Error condition occurred.\r
+  @retval          EFI_SUCCESS            The IP_IO instance stopped successfully.\r
+  @retval          EFI_INVALID_PARAMETER  Invalid input parameter.\r
+  @retval          Others                 Error condition occurred.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1430,6 +1457,10 @@ IpIoStop (
   IP_IO_IP_INFO     *IpInfo;\r
   UINT8             IpVersion;\r
 \r
+  if (IpIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   if (!IpIo->IsConfigured) {\r
     return EFI_SUCCESS;\r
   }\r
@@ -1957,6 +1988,10 @@ IpIoRemoveIp (
 {\r
 \r
   UINT8               IpVersion;\r
+  \r
+  if (IpIo == NULL || IpInfo == NULL) {\r
+    return;\r
+  }\r
 \r
   ASSERT (IpInfo->RefCnt > 0);\r
 \r
@@ -2021,7 +2056,7 @@ IpIoRemoveIp (
   @param[in]       Src               The local IP address.\r
 \r
   @return Pointer to the IP protocol can be used for sending purpose and its local\r
-          address is the same with Src.\r
+          address is the same with Src. NULL if failed.\r
 \r
 **/\r
 IP_IO_IP_INFO *\r
@@ -2037,7 +2072,13 @@ IpIoFindSender (
   LIST_ENTRY      *IpInfoEntry;\r
   IP_IO_IP_INFO   *IpInfo;\r
 \r
-  ASSERT ((IpVersion == IP_VERSION_4) || (IpVersion == IP_VERSION_6));  \r
+  if (IpIo == NULL || Src == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  if ((IpVersion != IP_VERSION_4) && (IpVersion != IP_VERSION_6)) {\r
+    return NULL;\r
+  }\r
 \r
   NET_LIST_FOR_EACH (IpIoEntry, &mActiveIpIoList) {\r
     IpIoPtr = NET_LIST_USER_STRUCT (IpIoEntry, IP_IO, Entry);\r