From nobody Sat Nov 2 12:32:22 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 1489643261999443.9617201762584; Wed, 15 Mar 2017 22:47:41 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CE4728032F; Wed, 15 Mar 2017 22:47:39 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 4CB878032B for ; Wed, 15 Mar 2017 22:47:39 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP; 15 Mar 2017 22:47:39 -0700 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.130]) by orsmga004.jf.intel.com with ESMTP; 15 Mar 2017 22:47:37 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,170,1486454400"; d="scan'208";a="67862763" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Thu, 16 Mar 2017 13:47:36 +0800 Message-Id: <1489643256-42736-1-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [PATCH v2] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 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: * Add the check in Ip4Config2SetDefaultIf to avoid the DHCP configuration case. Ip4config2 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 the issue. Cc: Hegde Nagaraj P Cc: Subramanian Sriram Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Sriram Subramanian --- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c | 62 ++++++++++++++++++= +++- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h | 21 +++++++- .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c | 12 ++++- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c | 8 +-- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c | 62 +-----------------= ---- 5 files changed, 94 insertions(+), 71 deletions(-) diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c b/MdeModuleP= kg/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 =20 -Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
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 =20 @@ -265,5 +265,65 @@ Ip4NtohHead ( Head->Src =3D NTOHL (Head->Src); Head->Dst =3D NTOHL (Head->Dst); =20 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 =3D=3D IP4_ALLZERO_ADDRESS) { + return (BOOLEAN) (Ip =3D=3D IP4_ALLZERO_ADDRESS); + } + + // + // Only support the continuous net masks + // + if ((Len =3D NetGetMaskLength (Netmask)) =3D=3D (IP4_MASK_MAX + 1)) { + return FALSE; + } + + // + // Station address can't be class D or class E address + // + if ((Type =3D NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) { + return FALSE; + } + + // + // Station address can't be subnet broadcast/net broadcast address + // + if ((Ip =3D=3D (Ip & Netmask)) || (Ip =3D=3D (Ip | ~Netmask))) { + return FALSE; + } + + NetBrdcastMask =3D gIp4AllMasks[MIN (Len, Type << 3)]; + + if (Ip =3D=3D (Ip | ~NetBrdcastMask)) { + return FALSE; + } + + return TRUE; +} \ No newline at end of file diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h b/MdeModuleP= kg/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. =20 -Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
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 =20 @@ -199,6 +199,25 @@ Ip4GetMulticastMac ( IP4_HEAD * Ip4NtohHead ( IN IP4_HEAD *Head ); =20 + +/** + 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/MdeMo= dulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c index 6c7ac68..f4dfbb6 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c @@ -607,10 +607,17 @@ Ip4Config2SetDefaultIf ( EFI_STATUS Status; IP4_SERVICE *IpSb; =20 IpSb =3D IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance); =20 + // + // Check whether the StationAddress/SubnetMask pair is valid. + // + if (!Ip4StationAddressValid (StationAddress, SubnetMask)) { + return EFI_INVALID_PARAMETER; + } + Status =3D Ip4Config2SetDefaultAddr (IpSb, StationAddress, SubnetMask); if (EFI_ERROR (Status)) { return Status; } =20 @@ -1250,11 +1257,14 @@ Ip4Config2SetMaunualAddress ( NewAddress =3D *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data); =20 StationAddress =3D EFI_NTOHL (NewAddress.Address); SubnetMask =3D EFI_NTOHL (NewAddress.SubnetMask); =20 - if (NetGetMaskLength (SubnetMask) =3D=3D IP4_MASK_NUM) { + // + // Check whether the StationAddress/SubnetMask pair is valid. + // + if (!Ip4StationAddressValid (StationAddress, SubnetMask)) { return EFI_INVALID_PARAMETER; } =20 // // Store the new data, and init the DataItem status to EFI_NOT_READY bec= ause diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c b/MdeModulePkg/U= niversal/Network/Ip4Dxe/Ip4If.c index b0cc6a3..7512a00 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c @@ -1,9 +1,9 @@ /** @file Implement IP4 pesudo interface. =20 -Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
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 =20 @@ -558,19 +558,13 @@ Ip4SetAddress ( IN IP4_ADDR SubnetMask ) { EFI_ARP_CONFIG_DATA ArpConfig; EFI_STATUS Status; - INTN Len; =20 NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE); =20 - Len =3D NetGetMaskLength (SubnetMask); - if (Len =3D=3D IP4_MASK_NUM) { - return EFI_INVALID_PARAMETER; - } - // // Set the ip/netmask, then compute the subnet broadcast // and network broadcast for easy access. When computing // nework broadcast, the subnet mask is most like longer // than the default netmask (not subneted) as defined in 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 =20 -Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
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 =20 @@ -808,70 +808,10 @@ Ip4CleanProtocol ( return EFI_SUCCESS; } =20 =20 /** - 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 =3D=3D IP4_ALLZERO_ADDRESS) { - return (BOOLEAN) (Ip =3D=3D IP4_ALLZERO_ADDRESS); - } - - // - // Only support the continuous net masks - // - if ((Len =3D NetGetMaskLength (Netmask)) =3D=3D (IP4_MASK_MAX + 1)) { - return FALSE; - } - - // - // Station address can't be class D or class E address - // - if ((Type =3D NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) { - return FALSE; - } - - // - // Station address can't be subnet broadcast/net broadcast address - // - if ((Ip =3D=3D (Ip & Netmask)) || (Ip =3D=3D (Ip | ~Netmask))) { - return FALSE; - } - - NetBrdcastMask =3D gIp4AllMasks[MIN (Len, Type << 3)]; - - if (Ip =3D=3D (Ip | ~NetBrdcastMask)) { - return FALSE; - } - - return TRUE; -} - - -/** Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver= instance. =20 The Configure() function is used to set, change, or reset the operational parameters and filter settings for this EFI IPv4 Protocol instance. Unti= l these parameters have been set, no network traffic can be sent or received by = this --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel