public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2
@ 2017-03-16  1:40 Jiaxin Wu
  2017-03-16  3:13 ` Hegde, Nagaraj P
  0 siblings, 1 reply; 4+ messages in thread
From: Jiaxin Wu @ 2017-03-16  1:40 UTC (permalink / raw)
  To: edk2-devel
  Cc: Hegde Nagaraj P, Subramanian Sriram, Ye Ting, Fu Siyuan,
	Wu Jiaxin

Ip4config2 manual address setting doesn't check the validity
of Ip/Netmask pair, which leads to the invalid combination of
Ip and Netmask setting. This patch is to resolve this issue.

Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Cc: Subramanian Sriram <sriram-s@hpe.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c  | 62 +++++++++++++++++++++-
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h  | 21 +++++++-
 .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c      |  5 +-
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c    | 62 +---------------------
 4 files changed, 86 insertions(+), 64 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
index 004a8bc..7c7d182 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
@@ -1,8 +1,8 @@
 /** @file
 
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -265,5 +265,65 @@ Ip4NtohHead (
   Head->Src       = NTOHL (Head->Src);
   Head->Dst       = NTOHL (Head->Dst);
 
   return Head;
 }
+
+
+/**
+  Validate that Ip/Netmask pair is OK to be used as station
+  address. Only continuous netmasks are supported. and check
+  that StationAddress is a unicast address on the newtwork.
+
+  @param[in]  Ip                 The IP address to validate.
+  @param[in]  Netmask            The netmaks of the IP.
+
+  @retval TRUE                   The Ip/Netmask pair is valid.
+  @retval FALSE                  The Ip/Netmask pair is invalid.
+
+**/
+BOOLEAN
+Ip4StationAddressValid (
+  IN IP4_ADDR               Ip,
+  IN IP4_ADDR               Netmask
+  )
+{
+  IP4_ADDR                  NetBrdcastMask;
+  INTN                      Len;
+  INTN                      Type;
+
+  //
+  // Only support the station address with 0.0.0.0/0 to enable DHCP client.
+  //
+  if (Netmask == IP4_ALLZERO_ADDRESS) {
+    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
+  }
+
+  //
+  // Only support the continuous net masks
+  //
+  if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
+    return FALSE;
+  }
+
+  //
+  // Station address can't be class D or class E address
+  //
+  if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
+    return FALSE;
+  }
+
+  //
+  // Station address can't be subnet broadcast/net broadcast address
+  //
+  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
+    return FALSE;
+  }
+
+  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
+
+  if (Ip == (Ip | ~NetBrdcastMask)) {
+    return FALSE;
+  }
+
+  return TRUE;
+}
\ No newline at end of file
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
index d38857c..9689f37 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
@@ -1,9 +1,9 @@
 /** @file
   Common definition for IP4.
   
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -199,6 +199,25 @@ Ip4GetMulticastMac (
 IP4_HEAD *
 Ip4NtohHead (
   IN IP4_HEAD           *Head
   );
 
+
+/**
+  Validate that Ip/Netmask pair is OK to be used as station
+  address. Only continuous netmasks are supported. and check
+  that StationAddress is a unicast address on the newtwork.
+
+  @param[in]  Ip                 The IP address to validate.
+  @param[in]  Netmask            The netmaks of the IP.
+
+  @retval TRUE                   The Ip/Netmask pair is valid.
+  @retval FALSE                  The Ip/Netmask pair is invalid.
+
+**/
+BOOLEAN
+Ip4StationAddressValid (
+  IN IP4_ADDR               Ip,
+  IN IP4_ADDR               Netmask
+  );
+
 #endif
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
index 6c7ac68..a5191d1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
@@ -1250,11 +1250,14 @@ Ip4Config2SetMaunualAddress (
   NewAddress = *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data);
 
   StationAddress = EFI_NTOHL (NewAddress.Address);
   SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);
 
-  if (NetGetMaskLength (SubnetMask) == IP4_MASK_NUM) {
+  //
+  // Check whether the StationAddress/SubnetMask pair is valid.
+  //
+  if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {
     return EFI_INVALID_PARAMETER;
   }
 
   //
   // Store the new data, and init the DataItem status to EFI_NOT_READY because
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
index 91f1a67..5aa3ea1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
@@ -1,8 +1,8 @@
 /** @file
 
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -808,70 +808,10 @@ Ip4CleanProtocol (
   return EFI_SUCCESS;
 }
 
 
 /**
-  Validate that Ip/Netmask pair is OK to be used as station
-  address. Only continuous netmasks are supported. and check
-  that StationAddress is a unicast address on the newtwork.
-
-  @param[in]  Ip                 The IP address to validate.
-  @param[in]  Netmask            The netmaks of the IP.
-
-  @retval TRUE                   The Ip/Netmask pair is valid.
-  @retval FALSE                  The Ip/Netmask pair is invalid.
-
-**/
-BOOLEAN
-Ip4StationAddressValid (
-  IN IP4_ADDR               Ip,
-  IN IP4_ADDR               Netmask
-  )
-{
-  IP4_ADDR                  NetBrdcastMask;
-  INTN                      Len;
-  INTN                      Type;
-
-  //
-  // Only support the station address with 0.0.0.0/0 to enable DHCP client.
-  //
-  if (Netmask == IP4_ALLZERO_ADDRESS) {
-    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
-  }
-
-  //
-  // Only support the continuous net masks
-  //
-  if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
-    return FALSE;
-  }
-
-  //
-  // Station address can't be class D or class E address
-  //
-  if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
-    return FALSE;
-  }
-
-  //
-  // Station address can't be subnet broadcast/net broadcast address
-  //
-  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
-    return FALSE;
-  }
-
-  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
-
-  if (Ip == (Ip | ~NetBrdcastMask)) {
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-
-/**
   Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
 
   The Configure() function is used to set, change, or reset the operational
   parameters and filter settings for this EFI IPv4 Protocol instance. Until these
   parameters have been set, no network traffic can be sent or received by this
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2
  2017-03-16  1:40 [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2 Jiaxin Wu
@ 2017-03-16  3:13 ` Hegde, Nagaraj P
  2017-03-16  4:39   ` Hegde, Nagaraj P
  0 siblings, 1 reply; 4+ messages in thread
From: Hegde, Nagaraj P @ 2017-03-16  3:13 UTC (permalink / raw)
  To: Jiaxin Wu, edk2-devel@lists.01.org
  Cc: Subramanian, Sriram, Ye Ting, Fu Siyuan

Reviewed-by: Hegde, Nagaraj P <nagaraj-p.hegde@hpe.com>

-----Original Message-----
From: Jiaxin Wu [mailto:jiaxin.wu@intel.com] 
Sent: Thursday, March 16, 2017 7:11 AM
To: edk2-devel@lists.01.org
Cc: Hegde, Nagaraj P <nagaraj-p.hegde@hpe.com>; Subramanian, Sriram <sriram-s@hpe.com>; Ye Ting <ting.ye@intel.com>; Fu Siyuan <siyuan.fu@intel.com>; Wu Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2

Ip4config2 manual address setting doesn't check the validity of Ip/Netmask pair, which leads to the invalid combination of Ip and Netmask setting. This patch is to resolve this issue.

Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Cc: Subramanian Sriram <sriram-s@hpe.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c  | 62 +++++++++++++++++++++-  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h  | 21 +++++++-
 .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c      |  5 +-
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c    | 62 +---------------------
 4 files changed, 86 insertions(+), 64 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
index 004a8bc..7c7d182 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
@@ -1,8 +1,8 @@
 /** @file
 
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at  http://opensource.org/licenses/bsd-license.php
 
@@ -265,5 +265,65 @@ Ip4NtohHead (
   Head->Src       = NTOHL (Head->Src);
   Head->Dst       = NTOHL (Head->Dst);
 
   return Head;
 }
+
+
+/**
+  Validate that Ip/Netmask pair is OK to be used as station
+  address. Only continuous netmasks are supported. and check
+  that StationAddress is a unicast address on the newtwork.
+
+  @param[in]  Ip                 The IP address to validate.
+  @param[in]  Netmask            The netmaks of the IP.
+
+  @retval TRUE                   The Ip/Netmask pair is valid.
+  @retval FALSE                  The Ip/Netmask pair is invalid.
+
+**/
+BOOLEAN
+Ip4StationAddressValid (
+  IN IP4_ADDR               Ip,
+  IN IP4_ADDR               Netmask
+  )
+{
+  IP4_ADDR                  NetBrdcastMask;
+  INTN                      Len;
+  INTN                      Type;
+
+  //
+  // Only support the station address with 0.0.0.0/0 to enable DHCP client.
+  //
+  if (Netmask == IP4_ALLZERO_ADDRESS) {
+    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);  }
+
+  //
+  // Only support the continuous net masks  //  if ((Len = 
+ NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
+    return FALSE;
+  }
+
+  //
+  // Station address can't be class D or class E address  //  if ((Type 
+ = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
+    return FALSE;
+  }
+
+  //
+  // Station address can't be subnet broadcast/net broadcast address  
+ //  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
+    return FALSE;
+  }
+
+  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
+
+  if (Ip == (Ip | ~NetBrdcastMask)) {
+    return FALSE;
+  }
+
+  return TRUE;
+}
\ No newline at end of file
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
index d38857c..9689f37 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
@@ -1,9 +1,9 @@
 /** @file
   Common definition for IP4.
   
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at  http://opensource.org/licenses/bsd-license.php
 
@@ -199,6 +199,25 @@ Ip4GetMulticastMac (  IP4_HEAD *  Ip4NtohHead (
   IN IP4_HEAD           *Head
   );
 
+
+/**
+  Validate that Ip/Netmask pair is OK to be used as station
+  address. Only continuous netmasks are supported. and check
+  that StationAddress is a unicast address on the newtwork.
+
+  @param[in]  Ip                 The IP address to validate.
+  @param[in]  Netmask            The netmaks of the IP.
+
+  @retval TRUE                   The Ip/Netmask pair is valid.
+  @retval FALSE                  The Ip/Netmask pair is invalid.
+
+**/
+BOOLEAN
+Ip4StationAddressValid (
+  IN IP4_ADDR               Ip,
+  IN IP4_ADDR               Netmask
+  );
+
 #endif
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
index 6c7ac68..a5191d1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
@@ -1250,11 +1250,14 @@ Ip4Config2SetMaunualAddress (
   NewAddress = *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data);
 
   StationAddress = EFI_NTOHL (NewAddress.Address);
   SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);
 
-  if (NetGetMaskLength (SubnetMask) == IP4_MASK_NUM) {
+  //
+  // Check whether the StationAddress/SubnetMask pair is valid.
+  //
+  if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {
     return EFI_INVALID_PARAMETER;
   }
 
   //
   // Store the new data, and init the DataItem status to EFI_NOT_READY because diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
index 91f1a67..5aa3ea1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
@@ -1,8 +1,8 @@
 /** @file
 
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at  http://opensource.org/licenses/bsd-license.php
 
@@ -808,70 +808,10 @@ Ip4CleanProtocol (
   return EFI_SUCCESS;
 }
 
 
 /**
-  Validate that Ip/Netmask pair is OK to be used as station
-  address. Only continuous netmasks are supported. and check
-  that StationAddress is a unicast address on the newtwork.
-
-  @param[in]  Ip                 The IP address to validate.
-  @param[in]  Netmask            The netmaks of the IP.
-
-  @retval TRUE                   The Ip/Netmask pair is valid.
-  @retval FALSE                  The Ip/Netmask pair is invalid.
-
-**/
-BOOLEAN
-Ip4StationAddressValid (
-  IN IP4_ADDR               Ip,
-  IN IP4_ADDR               Netmask
-  )
-{
-  IP4_ADDR                  NetBrdcastMask;
-  INTN                      Len;
-  INTN                      Type;
-
-  //
-  // Only support the station address with 0.0.0.0/0 to enable DHCP client.
-  //
-  if (Netmask == IP4_ALLZERO_ADDRESS) {
-    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
-  }
-
-  //
-  // Only support the continuous net masks
-  //
-  if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
-    return FALSE;
-  }
-
-  //
-  // Station address can't be class D or class E address
-  //
-  if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
-    return FALSE;
-  }
-
-  //
-  // Station address can't be subnet broadcast/net broadcast address
-  //
-  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
-    return FALSE;
-  }
-
-  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
-
-  if (Ip == (Ip | ~NetBrdcastMask)) {
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-
-/**
   Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
 
   The Configure() function is used to set, change, or reset the operational
   parameters and filter settings for this EFI IPv4 Protocol instance. Until these
   parameters have been set, no network traffic can be sent or received by this
--
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2
  2017-03-16  3:13 ` Hegde, Nagaraj P
@ 2017-03-16  4:39   ` Hegde, Nagaraj P
  2017-03-16  5:24     ` Wu, Jiaxin
  0 siblings, 1 reply; 4+ messages in thread
From: Hegde, Nagaraj P @ 2017-03-16  4:39 UTC (permalink / raw)
  To: Jiaxin Wu, edk2-devel@lists.01.org; +Cc: Ye Ting, Fu Siyuan

We need to handle the case of DHCP server serving with a subnet of  0.0.0.0. When we set the Policy to Dhcp, we enter into Ip4Config2OnPolicyChanged, which calls Ip4StartAutoConfig. Here we configure DHCP and we queue up Ip4Config2OnDhcp4Complete to be called once DHCP is complete. In Ip4Config2OnDhcp4Complete, we call Ip4Config2SetDefaultIf, which calls Ip4Config2SetDefaultAddr, where we call Ip4SetAddress. Ip4SetAddress has a similar check as Ip4Config2SetMaunualAddress:

  Len = NetGetMaskLength (SubnetMask);
  if (Len == IP4_MASK_NUM) {
    return EFI_INVALID_PARAMETER;
  }

Shouldn't this also be updated? 

Regards,
Nagaraj.

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Hegde, Nagaraj P
Sent: Thursday, March 16, 2017 8:43 AM
To: Jiaxin Wu <jiaxin.wu@intel.com>; edk2-devel@lists.01.org
Cc: Ye Ting <ting.ye@intel.com>; Fu Siyuan <siyuan.fu@intel.com>
Subject: Re: [edk2] [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2

Reviewed-by: Hegde, Nagaraj P <nagaraj-p.hegde@hpe.com>

-----Original Message-----
From: Jiaxin Wu [mailto:jiaxin.wu@intel.com]
Sent: Thursday, March 16, 2017 7:11 AM
To: edk2-devel@lists.01.org
Cc: Hegde, Nagaraj P <nagaraj-p.hegde@hpe.com>; Subramanian, Sriram <sriram-s@hpe.com>; Ye Ting <ting.ye@intel.com>; Fu Siyuan <siyuan.fu@intel.com>; Wu Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2

Ip4config2 manual address setting doesn't check the validity of Ip/Netmask pair, which leads to the invalid combination of Ip and Netmask setting. This patch is to resolve this issue.

Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Cc: Subramanian Sriram <sriram-s@hpe.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c  | 62 +++++++++++++++++++++-  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h  | 21 +++++++-
 .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c      |  5 +-
 MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c    | 62 +---------------------
 4 files changed, 86 insertions(+), 64 deletions(-)

diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
index 004a8bc..7c7d182 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
@@ -1,8 +1,8 @@
 /** @file
 
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at  http://opensource.org/licenses/bsd-license.php
 
@@ -265,5 +265,65 @@ Ip4NtohHead (
   Head->Src       = NTOHL (Head->Src);
   Head->Dst       = NTOHL (Head->Dst);
 
   return Head;
 }
+
+
+/**
+  Validate that Ip/Netmask pair is OK to be used as station
+  address. Only continuous netmasks are supported. and check
+  that StationAddress is a unicast address on the newtwork.
+
+  @param[in]  Ip                 The IP address to validate.
+  @param[in]  Netmask            The netmaks of the IP.
+
+  @retval TRUE                   The Ip/Netmask pair is valid.
+  @retval FALSE                  The Ip/Netmask pair is invalid.
+
+**/
+BOOLEAN
+Ip4StationAddressValid (
+  IN IP4_ADDR               Ip,
+  IN IP4_ADDR               Netmask
+  )
+{
+  IP4_ADDR                  NetBrdcastMask;
+  INTN                      Len;
+  INTN                      Type;
+
+  //
+  // Only support the station address with 0.0.0.0/0 to enable DHCP client.
+  //
+  if (Netmask == IP4_ALLZERO_ADDRESS) {
+    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);  }
+
+  //
+  // Only support the continuous net masks  //  if ((Len = 
+ NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
+    return FALSE;
+  }
+
+  //
+  // Station address can't be class D or class E address  //  if ((Type 
+ = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
+    return FALSE;
+  }
+
+  //
+  // Station address can't be subnet broadcast/net broadcast address //  
+ if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
+    return FALSE;
+  }
+
+  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
+
+  if (Ip == (Ip | ~NetBrdcastMask)) {
+    return FALSE;
+  }
+
+  return TRUE;
+}
\ No newline at end of file
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
index d38857c..9689f37 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
@@ -1,9 +1,9 @@
 /** @file
   Common definition for IP4.
   
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at  http://opensource.org/licenses/bsd-license.php
 
@@ -199,6 +199,25 @@ Ip4GetMulticastMac (  IP4_HEAD *  Ip4NtohHead (
   IN IP4_HEAD           *Head
   );
 
+
+/**
+  Validate that Ip/Netmask pair is OK to be used as station
+  address. Only continuous netmasks are supported. and check
+  that StationAddress is a unicast address on the newtwork.
+
+  @param[in]  Ip                 The IP address to validate.
+  @param[in]  Netmask            The netmaks of the IP.
+
+  @retval TRUE                   The Ip/Netmask pair is valid.
+  @retval FALSE                  The Ip/Netmask pair is invalid.
+
+**/
+BOOLEAN
+Ip4StationAddressValid (
+  IN IP4_ADDR               Ip,
+  IN IP4_ADDR               Netmask
+  );
+
 #endif
diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
index 6c7ac68..a5191d1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
@@ -1250,11 +1250,14 @@ Ip4Config2SetMaunualAddress (
   NewAddress = *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data);
 
   StationAddress = EFI_NTOHL (NewAddress.Address);
   SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);
 
-  if (NetGetMaskLength (SubnetMask) == IP4_MASK_NUM) {
+  //
+  // Check whether the StationAddress/SubnetMask pair is valid.
+  //
+  if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {
     return EFI_INVALID_PARAMETER;
   }
 
   //
   // Store the new data, and init the DataItem status to EFI_NOT_READY because diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
index 91f1a67..5aa3ea1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
@@ -1,8 +1,8 @@
 /** @file
 
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at  http://opensource.org/licenses/bsd-license.php
 
@@ -808,70 +808,10 @@ Ip4CleanProtocol (
   return EFI_SUCCESS;
 }
 
 
 /**
-  Validate that Ip/Netmask pair is OK to be used as station
-  address. Only continuous netmasks are supported. and check
-  that StationAddress is a unicast address on the newtwork.
-
-  @param[in]  Ip                 The IP address to validate.
-  @param[in]  Netmask            The netmaks of the IP.
-
-  @retval TRUE                   The Ip/Netmask pair is valid.
-  @retval FALSE                  The Ip/Netmask pair is invalid.
-
-**/
-BOOLEAN
-Ip4StationAddressValid (
-  IN IP4_ADDR               Ip,
-  IN IP4_ADDR               Netmask
-  )
-{
-  IP4_ADDR                  NetBrdcastMask;
-  INTN                      Len;
-  INTN                      Type;
-
-  //
-  // Only support the station address with 0.0.0.0/0 to enable DHCP client.
-  //
-  if (Netmask == IP4_ALLZERO_ADDRESS) {
-    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
-  }
-
-  //
-  // Only support the continuous net masks
-  //
-  if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
-    return FALSE;
-  }
-
-  //
-  // Station address can't be class D or class E address
-  //
-  if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
-    return FALSE;
-  }
-
-  //
-  // Station address can't be subnet broadcast/net broadcast address
-  //
-  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
-    return FALSE;
-  }
-
-  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
-
-  if (Ip == (Ip | ~NetBrdcastMask)) {
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-
-/**
   Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.
 
   The Configure() function is used to set, change, or reset the operational
   parameters and filter settings for this EFI IPv4 Protocol instance. Until these
   parameters have been set, no network traffic can be sent or received by this
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2
  2017-03-16  4:39   ` Hegde, Nagaraj P
@ 2017-03-16  5:24     ` Wu, Jiaxin
  0 siblings, 0 replies; 4+ messages in thread
From: Wu, Jiaxin @ 2017-03-16  5:24 UTC (permalink / raw)
  To: Hegde, Nagaraj P, edk2-devel@lists.01.org; +Cc: Ye, Ting, Fu, Siyuan

Nagaraj,

You are right, but I'd like to update the patch to check it in Ip4Config2SetDefaultIf instead of Ip4SetAddress to avoid the previous interface free operation. After that, the  check in Ip4SetAddress is needless. 

Thanks,
Jiaxin


> -----Original Message-----
> From: Hegde, Nagaraj P [mailto:nagaraj-p.hegde@hpe.com]
> Sent: Thursday, March 16, 2017 12:40 PM
> To: Wu, Jiaxin <jiaxin.wu@intel.com>; edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>
> Subject: RE: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for
> Ip4Config2
> 
> We need to handle the case of DHCP server serving with a subnet of  0.0.0.0.
> When we set the Policy to Dhcp, we enter into Ip4Config2OnPolicyChanged,
> which calls Ip4StartAutoConfig. Here we configure DHCP and we queue up
> Ip4Config2OnDhcp4Complete to be called once DHCP is complete. In
> Ip4Config2OnDhcp4Complete, we call Ip4Config2SetDefaultIf, which calls
> Ip4Config2SetDefaultAddr, where we call Ip4SetAddress. Ip4SetAddress has
> a similar check as Ip4Config2SetMaunualAddress:
> 
>   Len = NetGetMaskLength (SubnetMask);
>   if (Len == IP4_MASK_NUM) {
>     return EFI_INVALID_PARAMETER;
>   }
> 
> Shouldn't this also be updated?
> 
> Regards,
> Nagaraj.
> 
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Hegde, Nagaraj P
> Sent: Thursday, March 16, 2017 8:43 AM
> To: Jiaxin Wu <jiaxin.wu@intel.com>; edk2-devel@lists.01.org
> Cc: Ye Ting <ting.ye@intel.com>; Fu Siyuan <siyuan.fu@intel.com>
> Subject: Re: [edk2] [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair
> check for Ip4Config2
> 
> Reviewed-by: Hegde, Nagaraj P <nagaraj-p.hegde@hpe.com>
> 
> -----Original Message-----
> From: Jiaxin Wu [mailto:jiaxin.wu@intel.com]
> Sent: Thursday, March 16, 2017 7:11 AM
> To: edk2-devel@lists.01.org
> Cc: Hegde, Nagaraj P <nagaraj-p.hegde@hpe.com>; Subramanian, Sriram
> <sriram-s@hpe.com>; Ye Ting <ting.ye@intel.com>; Fu Siyuan
> <siyuan.fu@intel.com>; Wu Jiaxin <jiaxin.wu@intel.com>
> Subject: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for
> Ip4Config2
> 
> Ip4config2 manual address setting doesn't check the validity of Ip/Netmask
> pair, which leads to the invalid combination of Ip and Netmask setting. This
> patch is to resolve this issue.
> 
> Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
> Cc: Subramanian Sriram <sriram-s@hpe.com>
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Fu Siyuan <siyuan.fu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
> ---
>  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c  | 62
> +++++++++++++++++++++-
> MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h  | 21 +++++++-
>  .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c      |  5 +-
>  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c    | 62 +-----------------
> ----
>  4 files changed, 86 insertions(+), 64 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
> b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
> index 004a8bc..7c7d182 100644
> --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
> +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
> @@ -1,8 +1,8 @@
>  /** @file
> 
> -Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
>  This program and the accompanying materials  are licensed and made
> available under the terms and conditions of the BSD License  which
> accompanies this distribution.  The full text of the license may be found at
> http://opensource.org/licenses/bsd-license.php
> 
> @@ -265,5 +265,65 @@ Ip4NtohHead (
>    Head->Src       = NTOHL (Head->Src);
>    Head->Dst       = NTOHL (Head->Dst);
> 
>    return Head;
>  }
> +
> +
> +/**
> +  Validate that Ip/Netmask pair is OK to be used as station
> +  address. Only continuous netmasks are supported. and check
> +  that StationAddress is a unicast address on the newtwork.
> +
> +  @param[in]  Ip                 The IP address to validate.
> +  @param[in]  Netmask            The netmaks of the IP.
> +
> +  @retval TRUE                   The Ip/Netmask pair is valid.
> +  @retval FALSE                  The Ip/Netmask pair is invalid.
> +
> +**/
> +BOOLEAN
> +Ip4StationAddressValid (
> +  IN IP4_ADDR               Ip,
> +  IN IP4_ADDR               Netmask
> +  )
> +{
> +  IP4_ADDR                  NetBrdcastMask;
> +  INTN                      Len;
> +  INTN                      Type;
> +
> +  //
> +  // Only support the station address with 0.0.0.0/0 to enable DHCP client.
> +  //
> +  if (Netmask == IP4_ALLZERO_ADDRESS) {
> +    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);  }
> +
> +  //
> +  // Only support the continuous net masks  //  if ((Len =
> + NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
> +    return FALSE;
> +  }
> +
> +  //
> +  // Station address can't be class D or class E address  //  if ((Type
> + = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
> +    return FALSE;
> +  }
> +
> +  //
> +  // Station address can't be subnet broadcast/net broadcast address //
> + if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
> +    return FALSE;
> +  }
> +
> +  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
> +
> +  if (Ip == (Ip | ~NetBrdcastMask)) {
> +    return FALSE;
> +  }
> +
> +  return TRUE;
> +}
> \ No newline at end of file
> diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
> b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
> index d38857c..9689f37 100644
> --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
> +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
> @@ -1,9 +1,9 @@
>  /** @file
>    Common definition for IP4.
> 
> -Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
>  This program and the accompanying materials  are licensed and made
> available under the terms and conditions of the BSD License  which
> accompanies this distribution.  The full text of the license may be found at
> http://opensource.org/licenses/bsd-license.php
> 
> @@ -199,6 +199,25 @@ Ip4GetMulticastMac (  IP4_HEAD *  Ip4NtohHead (
>    IN IP4_HEAD           *Head
>    );
> 
> +
> +/**
> +  Validate that Ip/Netmask pair is OK to be used as station
> +  address. Only continuous netmasks are supported. and check
> +  that StationAddress is a unicast address on the newtwork.
> +
> +  @param[in]  Ip                 The IP address to validate.
> +  @param[in]  Netmask            The netmaks of the IP.
> +
> +  @retval TRUE                   The Ip/Netmask pair is valid.
> +  @retval FALSE                  The Ip/Netmask pair is invalid.
> +
> +**/
> +BOOLEAN
> +Ip4StationAddressValid (
> +  IN IP4_ADDR               Ip,
> +  IN IP4_ADDR               Netmask
> +  );
> +
>  #endif
> diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
> b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
> index 6c7ac68..a5191d1 100644
> --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
> +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c
> @@ -1250,11 +1250,14 @@ Ip4Config2SetMaunualAddress (
>    NewAddress = *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data);
> 
>    StationAddress = EFI_NTOHL (NewAddress.Address);
>    SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);
> 
> -  if (NetGetMaskLength (SubnetMask) == IP4_MASK_NUM) {
> +  //
> +  // Check whether the StationAddress/SubnetMask pair is valid.
> +  //
> +  if (!Ip4StationAddressValid (StationAddress, SubnetMask)) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
>    //
>    // Store the new data, and init the DataItem status to EFI_NOT_READY
> because diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
> b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
> index 91f1a67..5aa3ea1 100644
> --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
> +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
> @@ -1,8 +1,8 @@
>  /** @file
> 
> -Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
>  This program and the accompanying materials  are licensed and made
> available under the terms and conditions of the BSD License  which
> accompanies this distribution.  The full text of the license may be found at
> http://opensource.org/licenses/bsd-license.php
> 
> @@ -808,70 +808,10 @@ Ip4CleanProtocol (
>    return EFI_SUCCESS;
>  }
> 
> 
>  /**
> -  Validate that Ip/Netmask pair is OK to be used as station
> -  address. Only continuous netmasks are supported. and check
> -  that StationAddress is a unicast address on the newtwork.
> -
> -  @param[in]  Ip                 The IP address to validate.
> -  @param[in]  Netmask            The netmaks of the IP.
> -
> -  @retval TRUE                   The Ip/Netmask pair is valid.
> -  @retval FALSE                  The Ip/Netmask pair is invalid.
> -
> -**/
> -BOOLEAN
> -Ip4StationAddressValid (
> -  IN IP4_ADDR               Ip,
> -  IN IP4_ADDR               Netmask
> -  )
> -{
> -  IP4_ADDR                  NetBrdcastMask;
> -  INTN                      Len;
> -  INTN                      Type;
> -
> -  //
> -  // Only support the station address with 0.0.0.0/0 to enable DHCP client.
> -  //
> -  if (Netmask == IP4_ALLZERO_ADDRESS) {
> -    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
> -  }
> -
> -  //
> -  // Only support the continuous net masks
> -  //
> -  if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {
> -    return FALSE;
> -  }
> -
> -  //
> -  // Station address can't be class D or class E address
> -  //
> -  if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {
> -    return FALSE;
> -  }
> -
> -  //
> -  // Station address can't be subnet broadcast/net broadcast address
> -  //
> -  if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {
> -    return FALSE;
> -  }
> -
> -  NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];
> -
> -  if (Ip == (Ip | ~NetBrdcastMask)) {
> -    return FALSE;
> -  }
> -
> -  return TRUE;
> -}
> -
> -
> -/**
>    Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver
> instance.
> 
>    The Configure() function is used to set, change, or reset the operational
>    parameters and filter settings for this EFI IPv4 Protocol instance. Until these
>    parameters have been set, no network traffic can be sent or received by
> this
> --
> 1.9.5.msysgit.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-16  5:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-16  1:40 [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2 Jiaxin Wu
2017-03-16  3:13 ` Hegde, Nagaraj P
2017-03-16  4:39   ` Hegde, Nagaraj P
2017-03-16  5:24     ` Wu, Jiaxin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox