From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0703.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::703]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7E7158033C for ; Wed, 15 Mar 2017 20:13:04 -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=5zLSXY2jeLg+z3txh3KydAKmempQWgPhIw+2xdnHESQ=; b=kjzPg3Oyb0g1OY2Dm9ItEgdTdAUQaODOZNCq0XC5j0JFihilZj87dp3Rf4xkI5tujFycavCM5DwOHtSuNXWM4DBiWBWuDTuZO608k0FepNPxFGbxRlFxSnofUUV+RCTXGx/aycxIVTcJlIZfL831WOXRQuzEIJcg+NFEaxqW2no= Received: from CS1PR84MB0037.NAMPRD84.PROD.OUTLOOK.COM (10.162.189.143) by CS1PR84MB0039.NAMPRD84.PROD.OUTLOOK.COM (10.162.189.145) 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 03:13:01 +0000 Received: from CS1PR84MB0037.NAMPRD84.PROD.OUTLOOK.COM ([10.162.189.143]) by CS1PR84MB0037.NAMPRD84.PROD.OUTLOOK.COM ([10.162.189.143]) with mapi id 15.01.0961.022; Thu, 16 Mar 2017 03:13:00 +0000 From: "Hegde, Nagaraj P" To: Jiaxin Wu , "edk2-devel@lists.01.org" CC: "Subramanian, Sriram" , Ye Ting , "Fu Siyuan" Thread-Topic: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Config2 Thread-Index: AQHSnfZ0/2pUJVwnaEeKEXdAr1RfraGWyEDw Date: Thu, 16 Mar 2017 03:13:00 +0000 Message-ID: References: <1489628458-16580-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: <1489628458-16580-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.10] x-microsoft-exchange-diagnostics: 1; CS1PR84MB0039; 7:1SS8KyUkGPa7le9l3JTWns6QfVmcVGYOxhD/ZqXqOI+1C5IlWJ7a3rFSyXp92bcZow4/NBeZh8EtbCrqJ4NvIr3xFTfWnrXLdJYDxPiwiWu5wIJ26gw/n71WdQuyxF/FZu84szqg80eNblwHVTpV25HocghrCQQVwzjnL0tP8ofecqO7yHDACksQANuMkNOWNKh0x/gBOMc3iHY6ixkTK6qbfSi7r0QlZ5mVjTTTZKeTgREoiNubUUp4h6uTztzvtkQGkBuxpH3q7muyHRDFhxo/jk5h3XhTneZiL3j38KNGssEG7WPEHN2Bx6JA133JoJbghlR5AtnGKCmO4Fn6xg== x-forefront-antispam-report: SFV:SKI; SCL:-1SFV:NSPM; SFS:(10019020)(6009001)(39450400003)(39410400002)(39860400002)(39840400002)(39850400002)(377454003)(13464003)(66066001)(81166006)(122556002)(2900100001)(8676002)(102836003)(6436002)(305945005)(6506006)(77096006)(6116002)(7736002)(54906002)(6246003)(966004)(4326008)(6306002)(74316002)(38730400002)(53936002)(53376002)(229853002)(55016002)(9686003)(7696004)(2950100002)(50986999)(33656002)(76176999)(5660300001)(54356999)(3846002)(2501003)(189998001)(2906002)(53546007)(3660700001)(86362001)(16799955002)(15188155005)(8936002)(3280700002)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:CS1PR84MB0039; H:CS1PR84MB0037.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; MLV:sfv; LANG:en; x-ms-office365-filtering-correlation-id: cbe30225-0723-4651-28d0-08d46c1a5a1d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:CS1PR84MB0039; 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)(20161123562025)(20161123564025)(20161123558025)(20161123555025)(20161123560025)(6072148); SRVR:CS1PR84MB0039; BCL:0; PCL:0; RULEID:; SRVR:CS1PR84MB0039; 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 03:13:00.1954 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR84MB0039 Subject: Re: [Patch] 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 03:13:04 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Hegde, Nagaraj P -----Original Message----- From: Jiaxin Wu [mailto:jiaxin.wu@intel.com]=20 Sent: Thursday, March 16, 2017 7:11 AM To: edk2-devel@lists.01.org Cc: Hegde, Nagaraj P ; Subramanian, Sriram ; Ye Ting ; Fu Siyuan ; = Wu Jiaxin Subject: [Patch] MdeModulePkg/Ip4Dxe: Add Ip/Netmask pair check for Ip4Conf= ig2 Ip4config2 manual address setting doesn't check the validity of Ip/Netmask = pair, which leads to the invalid combination of Ip and Netmask setting. Thi= s patch is to resolve this 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 | 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/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 availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at http://opens= ource.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=20 + NetGetMaskLength (Netmask)) =3D=3D (IP4_MASK_MAX + 1)) { + return FALSE; + } + + // + // Station address can't be class D or class E address // if ((Type=20 + =3D NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) { + return FALSE; + } + + // + // Station address can't be subnet broadcast/net broadcast address =20 + // 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 availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at http://opens= ource.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..a5191d1 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c @@ -1250,11 +1250,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/Ip4Impl.c b/MdeModu= lePkg/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 availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at http://opens= ource.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 -- 1.9.5.msysgit.1