From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0730.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe4a::730]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 558348036B for ; Thu, 16 Mar 2017 01:31:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=HPEnterprise.onmicrosoft.com; s=selector1-hpe-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=A5TH6LAC/Ai2D5yTQbKKi+5aZG1l4rK1YatjzAfo9aU=; b=gLdtnfesIBxMZFMuqpB40y80LmF4KvjM/A+Rm7qrsltQP49UZyle/vXa3SLsQouuf/iLiQvB/cMfNi7JF4AFmicpl0PYkNqhVpVOnLt//D6aMyu4zGgXzErVHesxCtUXIcWhBqELf+5eAIyVas/lhllAm9MRf6+PbbPHH189vUk= Received: from DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM (10.162.192.143) by DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM (10.162.192.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.961.17; Thu, 16 Mar 2017 08:31:35 +0000 Received: from DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM ([10.162.192.143]) by DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM ([10.162.192.143]) with mapi id 15.01.0961.022; Thu, 16 Mar 2017 08:31:33 +0000 From: "Subramanian, Sriram" To: Jiaxin Wu , "edk2-devel@lists.01.org" CC: "Hegde, Nagaraj P" , Ye Ting , Fu Siyuan Thread-Topic: [PATCH v2] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2 Thread-Index: AQHSnhj31uyCQZeg9U+lbFBNizeE6qGXHwLg Date: Thu, 16 Mar 2017 08:31:33 +0000 Message-ID: References: <1489643256-42736-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: <1489643256-42736-1-git-send-email-jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [15.219.195.12] x-microsoft-exchange-diagnostics: 1; DF4PR84MB0041; 7:LNdvxoP5+Vew2pqrBNtVVg8cXqkbp6Dv/RGFxGP/TcBN7+h5UKdP2+V6sAYdIEyr9I10tc8yFu87rUo7ZrhVS9fdi65kzaWQCfkNEL+9/fyPa5ZuqT6QDvTSTrJclLz3D+ga5DQGaanhKjaUyZiFha6bX8KJEuJbrXqiyWCeW2Ah3WZIFdPAorQY5qZniB0QRwFZvZLsC675oHzRWyF07hOvsrdT8i4AROiRgohDaOK0x6GZsJHk47bVYpnSBAo/Vauu9TMXGqZuegZwPmyCSTwID3zKNP9Jubgdm6bvNX3NUdm+kTXAVn0N8fbu5WXMGkk8lKqb2jq6wE3/Q9y91g== x-forefront-antispam-report: SFV:SKI; SCL:-1SFV:NSPM; SFS:(10019020)(6009001)(39850400002)(39860400002)(39410400002)(39450400003)(39840400002)(13464003)(377454003)(9686003)(2906002)(53936002)(122556002)(33656002)(966004)(6246003)(81166006)(3280700002)(3660700001)(86362001)(8936002)(6506006)(77096006)(305945005)(6436002)(53546007)(575784001)(55016002)(6306002)(8676002)(54906002)(7736002)(2501003)(7696004)(4326008)(66066001)(74316002)(54356999)(50986999)(76176999)(6116002)(2950100002)(3846002)(38730400002)(53376002)(102836003)(229853002)(189998001)(15188155005)(5660300001)(2900100001)(16799955002)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:DF4PR84MB0041; H:DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; MLV:sfv; LANG:en; x-ms-office365-filtering-correlation-id: 8aead2c4-247c-476b-7c79-08d46c46da87 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:DF4PR84MB0041; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(227479698468861)(200054503718035)(162533806227266)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123558025)(20161123562025)(20161123564025)(6072148); SRVR:DF4PR84MB0041; BCL:0; PCL:0; RULEID:; SRVR:DF4PR84MB0041; x-forefront-prvs: 024847EE92 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2017 08:31:33.4811 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0041 Subject: Re: [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: , X-List-Received-Date: Thu, 16 Mar 2017 08:31:36 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Sriram Subramanian -----Original Message----- From: Jiaxin Wu [mailto:jiaxin.wu@intel.com]=20 Sent: Thursday, March 16, 2017 11:18 AM To: edk2-devel@lists.01.org Cc: Hegde, Nagaraj P ; Subramanian, Sriram ; Ye Ting ; Fu Siyuan ; = Wu Jiaxin Subject: [PATCH v2] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4C= onfig2 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 --- 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 operationa= l 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