From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on072c.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe41::72c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 573BB1A1E0E for ; Sun, 18 Sep 2016 23:00:53 -0700 (PDT) Received: from CS1PR84MB0037.NAMPRD84.PROD.OUTLOOK.COM (10.162.189.143) by CS1PR84MB0040.NAMPRD84.PROD.OUTLOOK.COM (10.162.189.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.629.8; Mon, 19 Sep 2016 06:00:51 +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.0629.006; Mon, 19 Sep 2016 06:00:51 +0000 From: "Hegde, Nagaraj P" To: Jiaxin Wu , "edk2-devel@lists.01.org" CC: Fu Siyuan , Ye Ting Thread-Topic: [Patch] NetworkPkg: Correct the DNS token return status by RCODE Thread-Index: AQHSDlOwub660JsGqEOf+gDV2RY2IqCAWVQw Date: Mon, 19 Sep 2016 06:00:51 +0000 Message-ID: References: <1473835550-58760-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: <1473835550-58760-1-git-send-email-jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=nagaraj-p.hegde@hpe.com; x-originating-ip: [15.219.195.6] x-ms-office365-filtering-correlation-id: b0b10a6b-9112-40bc-0e45-08d3e0524f86 x-microsoft-exchange-diagnostics: 1; CS1PR84MB0040; 6:x5JtJsGVq67VUADtXmEr98vR2zfMy2CQZfNSqDMbtp4wc+8VIwj2utf3VhECx6xIp1gnalqhs48CO2Vt6+tcxu7Q+j/8CHGjMN4zCcR+UHzIdzp1nIDe6dc0sH+xM1R4uAIJoDa0lw2iohucY7qgMpt8Dd+b4iCQoiEm/WeiVqqUl0qSJaK8VME1Hii689JKYLGwYZGS2Cj9j9+RFYQPr2HwjrA/VD7T0trInKNVRR8AXKr5w/RHe3MzI1g3BLFmqb30IIAdQmvxyMmyOsMhkwybicfDedJu4W20zo8H2fww06mHmHh29hHpdhriK55VTbujwBK1Hjnb9LYdQnaxWA==; 5:Q822JJt8AfcnTvB7PCsQaGwQ1uj3PAt/7xPmBhNv8FohhTVCaW/JfPwQOTlcKXVPuKCL6pyY+BBjO+GN1RLS+H+151C1iNo2zmZG7WWVncuoKvidmu+i6pBkIDgPK0dCQ7xDK4IeJBrXjtEz70VzXQ==; 24:h1TnOYYOXxUfX4LIG6SQV4zBC+5QnMRHydOKNjlfIu/ybQyF0FGAf8OhRiCdIGmwLRN6G08RIGJma5ELsodqdj2KyUBaNuncx50UeCVxNXA=; 7:Ubs7IiClQ1B4hJLaNJPbBCmArdEIpxzRc2HWBy0lAhC3CmE8Y+3PeTvoqjrT7/5TOndfDHeul9KCVwNzF9+vw1no3t1pn1ZL0Faq0puLDguOvYTqWfMnDB9JG9cr/OFLzbuT4r1U/q51uNvU1hn6IPlxg58WnYMFqoVUsyv3ivY/IfZkVnnd+ARrg3BUu9Am79DVPUEjwfO5mZsg5acFINtOTHWb12x5exu+0joPOvavNsQJPQCU64IktTWa/EnMxyQf4fpm+bDu+GIDcMGvUwZsLLhItXsFt07+7pu1bYQWsFRix6BLI9W6C+i17a0Z x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CS1PR84MB0040; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(227479698468861)(150554046322364)(162533806227266)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:CS1PR84MB0040; BCL:0; PCL:0; RULEID:; SRVR:CS1PR84MB0040; x-forefront-prvs: 0070A8666B x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(13464003)(377454003)(199003)(189002)(2900100001)(99286002)(106356001)(68736007)(33656002)(10400500002)(106116001)(586003)(105586002)(77096005)(4326007)(2950100001)(102836003)(6116002)(122556002)(3846002)(87936001)(66066001)(5001770100001)(81156014)(7846002)(11100500001)(86362001)(74316002)(2501003)(189998001)(81166006)(101416001)(9686002)(3280700002)(8676002)(7696004)(8936002)(19580395003)(76176999)(92566002)(5002640100001)(305945005)(54356999)(19580405001)(50986999)(3660700001)(5660300001)(2906002)(97736004)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:CS1PR84MB0040; H:CS1PR84MB0037.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: hpe.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2016 06:00:51.3485 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR84MB0040 Subject: Re: [Patch] NetworkPkg: Correct the DNS token return status by RCODE X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Sep 2016 06:00:53 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Tested-by: Hegde Nagaraj P -----Original Message----- From: Jiaxin Wu [mailto:jiaxin.wu@intel.com]=20 Sent: Wednesday, September 14, 2016 12:16 PM To: edk2-devel@lists.01.org Cc: Hegde, Nagaraj P ; Fu Siyuan ; Ye Ting Subject: [Patch] NetworkPkg: Correct the DNS token return status by RCODE When HostNameToIp() and GeneralLookUp() are called with a invalid host name, RCODE (4 bit field is set as part of responses) error will returned in packet to identify the domain name referenced in the query does not exist. So, EFI_NOT_FOUND should be returned directly. Current implementation only check the RCODE in successful condition. Need update the code for more error check according to RFC 1035 4.1.1 section. Cc: Hegde Nagaraj P Cc: Fu Siyuan Cc: Ye Ting Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu --- NetworkPkg/DnsDxe/DnsImpl.c | 104 +++++++++++++++++-----------------------= ---- 1 file changed, 40 insertions(+), 64 deletions(-) diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c index cfaa4c7..3f3b756 100644 --- a/NetworkPkg/DnsDxe/DnsImpl.c +++ b/NetworkPkg/DnsDxe/DnsImpl.c @@ -1230,12 +1230,20 @@ ParseDnsResponse ( // // Continue Check Some Errors. // if (DnsHeader->Flags.Bits.RCode !=3D DNS_FLAGS_RCODE_NO_ERROR || DnsHead= er->AnswersNum < 1 || \ DnsHeader->Flags.Bits.QR !=3D DNS_FLAGS_QR_RESPONSE) { - Status =3D EFI_ABORTED; - goto ON_EXIT; + // + // The domain name referenced in the query does not exist. + // + if (DnsHeader->Flags.Bits.RCode =3D=3D DNS_FLAGS_RCODE_NAME_ERROR) { + Status =3D EFI_NOT_FOUND;=20 + } else { + Status =3D EFI_DEVICE_ERROR; + } + =20 + goto ON_COMPLETE; } =20 // // Do some buffer allocations. // @@ -1404,27 +1412,12 @@ ParseDnsResponse ( =20 HostAddr4 =3D Dns4TokenEntry->Token->RspData.H2AData->IpList; AnswerData =3D (UINT8 *) AnswerSection + sizeof (*AnswerSection); CopyMem (&HostAddr4[IpCount], AnswerData, sizeof (EFI_IPv4_ADDRESS= )); =20 - // - // Update DNS cache dynamically. - // - if (Dns4CacheEntry !=3D NULL) { - if (Dns4CacheEntry->HostName !=3D NULL) { - FreePool (Dns4CacheEntry->HostName); - } - - if (Dns4CacheEntry->IpAddress !=3D NULL) { - FreePool (Dns4CacheEntry->IpAddress); - } - =20 - FreePool (Dns4CacheEntry); - } - //=20 - // Allocate new CacheEntry pool. + // Allocate new CacheEntry pool to update DNS cache dynamically. // Dns4CacheEntry =3D AllocateZeroPool (sizeof (EFI_DNS4_CACHE_ENTRY)= ); if (Dns4CacheEntry =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; @@ -1446,11 +1439,23 @@ ParseDnsResponse ( Dns4CacheEntry->Timeout =3D MIN (CNameTtl, AnswerSection->Ttl); } else { Dns4CacheEntry->Timeout =3D MAX (CNameTtl, AnswerSection->Ttl); } =20 - UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4Ca= cheEntry); =20 + UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE, *Dns4Ca= cheEntry); + + //=20 + // Free allocated CacheEntry pool. + // + FreePool (Dns4CacheEntry->HostName); + Dns4CacheEntry->HostName =3D NULL; + =20 + FreePool (Dns4CacheEntry->IpAddress); + Dns4CacheEntry->IpAddress =3D NULL; + + FreePool (Dns4CacheEntry); + Dns4CacheEntry =3D NULL; =20 IpCount ++; Status =3D EFI_SUCCESS; break; case DNS_TYPE_AAAA: @@ -1461,27 +1466,12 @@ ParseDnsResponse ( =20 HostAddr6 =3D Dns6TokenEntry->Token->RspData.H2AData->IpList; AnswerData =3D (UINT8 *) AnswerSection + sizeof (*AnswerSection); CopyMem (&HostAddr6[IpCount], AnswerData, sizeof (EFI_IPv6_ADDRESS= )); =20 - // - // Update DNS cache dynamically. - // - if (Dns6CacheEntry !=3D NULL) { - if (Dns6CacheEntry->HostName !=3D NULL) { - FreePool (Dns6CacheEntry->HostName); - } - - if (Dns6CacheEntry->IpAddress !=3D NULL) { - FreePool (Dns6CacheEntry->IpAddress); - } - =20 - FreePool (Dns6CacheEntry); - } - //=20 - // Allocate new CacheEntry pool. + // Allocate new CacheEntry pool to update DNS cache dynamically. // Dns6CacheEntry =3D AllocateZeroPool (sizeof (EFI_DNS6_CACHE_ENTRY)= ); if (Dns6CacheEntry =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; @@ -1503,11 +1493,23 @@ ParseDnsResponse ( Dns6CacheEntry->Timeout =3D MIN (CNameTtl, AnswerSection->Ttl); } else { Dns6CacheEntry->Timeout =3D MAX (CNameTtl, AnswerSection->Ttl); } =20 - UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6Ca= cheEntry); =20 + UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE, *Dns6Ca= cheEntry); + + //=20 + // Free allocated CacheEntry pool. + // + FreePool (Dns6CacheEntry->HostName); + Dns6CacheEntry->HostName =3D NULL; + =20 + FreePool (Dns6CacheEntry->IpAddress); + Dns6CacheEntry->IpAddress =3D NULL; + + FreePool (Dns6CacheEntry); + Dns6CacheEntry =3D NULL; =20 IpCount ++; Status =3D EFI_SUCCESS; break; case DNS_TYPE_CNAME: @@ -1556,11 +1558,12 @@ ParseDnsResponse ( Status =3D EFI_UNSUPPORTED; goto ON_EXIT; } } } - + =20 +ON_COMPLETE: // // Parsing is complete, free the sending packet and signal Event here. // if (Item !=3D NULL && Item->Value !=3D NULL) { NetbufFree ((NET_BUF *) (Item->Value)); @@ -1582,37 +1585,10 @@ ParseDnsResponse ( gBS->SignalEvent (Dns6TokenEntry->Token->Event); DispatchDpc (); } } =20 - //=20 - // Free allocated CacheEntry pool. - // - if (Dns4CacheEntry !=3D NULL) { - if (Dns4CacheEntry->HostName !=3D NULL) { - FreePool (Dns4CacheEntry->HostName); - } - - if (Dns4CacheEntry->IpAddress !=3D NULL) { - FreePool (Dns4CacheEntry->IpAddress); - } - - FreePool (Dns4CacheEntry); - } - =20 - if (Dns6CacheEntry !=3D NULL) { - if (Dns6CacheEntry->HostName !=3D NULL) { - FreePool (Dns6CacheEntry->HostName); - } - - if (Dns6CacheEntry->IpAddress !=3D NULL) { - FreePool (Dns6CacheEntry->IpAddress); - } - =20 - FreePool (Dns6CacheEntry); - } - ON_EXIT: gBS->RestoreTPL (OldTpl); return Status; } =20 --=20 1.9.5.msysgit.1