From nobody Sun May 5 04:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1512457174463299.08083551572554; Mon, 4 Dec 2017 22:59:34 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DB32F20356265; Mon, 4 Dec 2017 22:55:02 -0800 (PST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 94F6F20356261 for ; Mon, 4 Dec 2017 22:55:01 -0800 (PST) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2017 22:59:32 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.96]) by orsmga008.jf.intel.com with ESMTP; 04 Dec 2017 22:59:30 -0800 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,363,1508828400"; d="scan'208";a="157575" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 5 Dec 2017 14:59:19 +0800 Message-Id: <1512457162-9296-2-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com> References: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 1/4] NetworkPkg/DnsDxe: Remove the unnecessary if condition check in DNS.Config 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 , Wang Fan , 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" Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- NetworkPkg/DnsDxe/DnsProtocol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NetworkPkg/DnsDxe/DnsProtocol.c b/NetworkPkg/DnsDxe/DnsProtoco= l.c index bd189ae..7435607 100644 --- a/NetworkPkg/DnsDxe/DnsProtocol.c +++ b/NetworkPkg/DnsDxe/DnsProtocol.c @@ -254,11 +254,11 @@ Dns4Configure ( Status =3D Dns4CopyConfigure (&Instance->Dns4CfgData, DnsConfigData); if (EFI_ERROR (Status)) { goto ON_EXIT; } =20 - if (DnsConfigData->DnsServerListCount =3D=3D 0 || DnsConfigData->DnsSe= rverList =3D=3D NULL) { + if (DnsConfigData->DnsServerListCount =3D=3D 0) { gBS->RestoreTPL (OldTpl);=20 =20 // // The DNS instance will retrieve DNS server from DHCP Server // @@ -1076,11 +1076,11 @@ Dns6Configure ( Status =3D Dns6CopyConfigure (&Instance->Dns6CfgData, DnsConfigData); if (EFI_ERROR (Status)) { goto ON_EXIT; } =20 - if (DnsConfigData->DnsServerCount =3D=3D 0 || DnsConfigData->DnsServer= List =3D=3D NULL) { + if (DnsConfigData->DnsServerCount =3D=3D 0) { gBS->RestoreTPL (OldTpl); =20 // //The DNS instance will retrieve DNS server from DHCP Server. // --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 04:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1512457176649792.5940331614977; Mon, 4 Dec 2017 22:59:36 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2A9452035626A; Mon, 4 Dec 2017 22:55:05 -0800 (PST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 CD02B20356253 for ; Mon, 4 Dec 2017 22:55:03 -0800 (PST) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2017 22:59:34 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.96]) by orsmga008.jf.intel.com with ESMTP; 04 Dec 2017 22:59:32 -0800 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,363,1508828400"; d="scan'208";a="157586" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 5 Dec 2017 14:59:20 +0800 Message-Id: <1512457162-9296-3-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com> References: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 2/4] NetworkPkg/DnsDxe: Update RetryCount/RetryInterval to comply with UEFI spec. 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 , Wang Fan , 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" According to UEFI spec: "Retry number if no response received after RetryInterval. If zero, use the parameter configured through Dns.Configure() interface." "Minimum interval of retry is 2 second. If the retry interval is less than 2 second, then use the 2 second. If zero, use the parameter configured through Dns.Configure() interface." For both DNS.HostNameToIp and DNS.GeneralLookUp, the value of RetryCount / RetryInterval need to be updated to comply with UEFI spec. Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- NetworkPkg/DnsDxe/DnsDriver.h | 4 +- NetworkPkg/DnsDxe/DnsImpl.c | 4 +- NetworkPkg/DnsDxe/DnsImpl.h | 5 +- NetworkPkg/DnsDxe/DnsProtocol.c | 102 ++++++++++++++++++++++++------------= ---- 4 files changed, 67 insertions(+), 48 deletions(-) diff --git a/NetworkPkg/DnsDxe/DnsDriver.h b/NetworkPkg/DnsDxe/DnsDriver.h index 6632bb2..49f6a1d 100644 --- a/NetworkPkg/DnsDxe/DnsDriver.h +++ b/NetworkPkg/DnsDxe/DnsDriver.h @@ -1,9 +1,9 @@ /** @file The header files of the driver binding and service binding protocol for Dn= sDxe driver. =20 -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 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 @@ -87,12 +87,10 @@ struct _DNS_INSTANCE { EFI_IP_ADDRESS SessionDnsServer; =20 NET_MAP Dns4TxTokens; NET_MAP Dns6TxTokens; =20 - UINT32 MaxRetry; - UDP_IO *UdpIo; }; =20 typedef struct { EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c index ea3d27d..7c236a0 100644 --- a/NetworkPkg/DnsDxe/DnsImpl.c +++ b/NetworkPkg/DnsDxe/DnsImpl.c @@ -1946,11 +1946,11 @@ DnsOnTimerRetransmit ( =20 // // Retransmit the packet if haven't reach the maxmium retry count, // otherwise exit the transfer. // - if (++Dns4TokenEntry->Token->RetryCount < Instance->MaxRetry) { + if (++Dns4TokenEntry->RetryCounting <=3D Dns4TokenEntry->Token->Re= tryCount) { DnsRetransmit (Instance, (NET_BUF *)ItemNetMap->Value); EntryNetMap =3D EntryNetMap->ForwardLink; } else { // // Maximum retries reached, clean the Token up. @@ -1990,11 +1990,11 @@ DnsOnTimerRetransmit ( =20 // // Retransmit the packet if haven't reach the maxmium retry count, // otherwise exit the transfer. // - if (++Dns6TokenEntry->Token->RetryCount < Instance->MaxRetry) { + if (++Dns6TokenEntry->RetryCounting <=3D Dns6TokenEntry->Token->Re= tryCount) { DnsRetransmit (Instance, (NET_BUF *) ItemNetMap->Value); EntryNetMap =3D EntryNetMap->ForwardLink; } else { // // Maximum retries reached, clean the Token up. diff --git a/NetworkPkg/DnsDxe/DnsImpl.h b/NetworkPkg/DnsDxe/DnsImpl.h index 5fa7f24..3c6296c 100644 --- a/NetworkPkg/DnsDxe/DnsImpl.h +++ b/NetworkPkg/DnsDxe/DnsImpl.h @@ -1,9 +1,9 @@ /** @file DnsDxe support functions implementation. =20 -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 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 @@ -84,11 +84,10 @@ extern EFI_DNS6_PROTOCOL mDns6Protocol; #define DNS_STATE_UNCONFIGED 0 #define DNS_STATE_CONFIGED 1 #define DNS_STATE_DESTROY 2 =20 #define DNS_DEFAULT_TIMEOUT 2 -#define DNS_DEFAULT_RETRY 3 =20 #define DNS_TIME_TO_GETMAP 5 =20 #pragma pack(1) =20 @@ -113,18 +112,20 @@ typedef struct { LIST_ENTRY AllServerLink; EFI_IPv6_ADDRESS Dns6ServerIp; =20 } DNS6_SERVER_IP; =20 typedef struct { + UINT32 RetryCounting; UINT32 PacketToLive; CHAR16 *QueryHostName; EFI_IPv4_ADDRESS QueryIpAddress; BOOLEAN GeneralLookUp; EFI_DNS4_COMPLETION_TOKEN *Token; } DNS4_TOKEN_ENTRY; =20 typedef struct { + UINT32 RetryCounting; UINT32 PacketToLive; CHAR16 *QueryHostName; EFI_IPv6_ADDRESS QueryIpAddress; BOOLEAN GeneralLookUp; EFI_DNS6_COMPLETION_TOKEN *Token; diff --git a/NetworkPkg/DnsDxe/DnsProtocol.c b/NetworkPkg/DnsDxe/DnsProtoco= l.c index 7435607..df737dc 100644 --- a/NetworkPkg/DnsDxe/DnsProtocol.c +++ b/NetworkPkg/DnsDxe/DnsProtocol.c @@ -221,12 +221,10 @@ Dns4Configure ( // if (!NetMapIsEmpty(&Instance->Dns4TxTokens)) { Dns4InstanceCancelToken(Instance, NULL); } =20 - Instance->MaxRetry =3D 0; - if (Instance->UdpIo !=3D NULL){ UdpIoCleanIo (Instance->UdpIo); } =20 if (Instance->Dns4CfgData.DnsServerList !=3D NULL) { @@ -375,28 +373,34 @@ Dns4HostNameToIp ( =20 Instance =3D DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This); =20 ConfigData =3D &(Instance->Dns4CfgData); =20 - Instance->MaxRetry =3D ConfigData->RetryCount; - =20 - Token->Status =3D EFI_NOT_READY; - Token->RetryCount =3D 0; - Token->RetryInterval =3D ConfigData->RetryInterval; - if (Instance->State !=3D DNS_STATE_CONFIGED) { Status =3D EFI_NOT_STARTED; goto ON_EXIT; } =20 + Token->Status =3D EFI_NOT_READY; + // - // Check the MaxRetry and RetryInterval values. + // If zero, use the parameter configured through Dns.Configure() interfa= ce. // - if (Instance->MaxRetry =3D=3D 0) { - Instance->MaxRetry =3D DNS_DEFAULT_RETRY; + if (Token->RetryCount =3D=3D 0) { + Token->RetryCount =3D ConfigData->RetryCount; } =20 + // + // If zero, use the parameter configured through Dns.Configure() interfa= ce. + // + if (Token->RetryInterval =3D=3D 0) { + Token->RetryInterval =3D ConfigData->RetryInterval; + } + =20 + // + // Minimum interval of retry is 2 second. If the retry interval is less = than 2 second, then use the 2 second.=20 + // if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) { Token->RetryInterval =3D DNS_DEFAULT_TIMEOUT; } =20 // @@ -618,29 +622,35 @@ Dns4GeneralLookUp ( OldTpl =3D gBS->RaiseTPL (TPL_CALLBACK); =20 Instance =3D DNS_INSTANCE_FROM_THIS_PROTOCOL4 (This); =20 ConfigData =3D &(Instance->Dns4CfgData); - =20 - Instance->MaxRetry =3D ConfigData->RetryCount; - =20 - Token->Status =3D EFI_NOT_READY; - Token->RetryCount =3D 0; - Token->RetryInterval =3D ConfigData->RetryInterval; =20 if (Instance->State !=3D DNS_STATE_CONFIGED) { Status =3D EFI_NOT_STARTED; goto ON_EXIT; } =20 + Token->Status =3D EFI_NOT_READY; + =20 + // + // If zero, use the parameter configured through Dns.Configure() interfa= ce. // - // Check the MaxRetry and RetryInterval values. + if (Token->RetryCount =3D=3D 0) { + Token->RetryCount =3D ConfigData->RetryCount; + } + =20 + // + // If zero, use the parameter configured through Dns.Configure() interfa= ce. // - if (Instance->MaxRetry =3D=3D 0) { - Instance->MaxRetry =3D DNS_DEFAULT_RETRY; + if (Token->RetryInterval =3D=3D 0) { + Token->RetryInterval =3D ConfigData->RetryInterval; } =20 + // + // Minimum interval of retry is 2 second. If the retry interval is less = than 2 second, then use the 2 second.=20 + // if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) { Token->RetryInterval =3D DNS_DEFAULT_TIMEOUT; } =20 // @@ -1050,12 +1060,10 @@ Dns6Configure ( // if (!NetMapIsEmpty(&Instance->Dns6TxTokens)) { Dns6InstanceCancelToken(Instance, NULL); } =20 - Instance->MaxRetry =3D 0; - if (Instance->UdpIo !=3D NULL){ UdpIoCleanIo (Instance->UdpIo); } =20 if (Instance->Dns6CfgData.DnsServerList !=3D NULL) { @@ -1201,32 +1209,38 @@ Dns6HostNameToIp ( OldTpl =3D gBS->RaiseTPL (TPL_CALLBACK); =20 Instance =3D DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This); =20 ConfigData =3D &(Instance->Dns6CfgData); - =20 - Instance->MaxRetry =3D ConfigData->RetryCount; - - Token->Status =3D EFI_NOT_READY; - Token->RetryCount =3D 0; - Token->RetryInterval =3D ConfigData->RetryInterval; =20 if (Instance->State !=3D DNS_STATE_CONFIGED) { Status =3D EFI_NOT_STARTED; goto ON_EXIT; } =20 + Token->Status =3D EFI_NOT_READY; + // - // Check the MaxRetry and RetryInterval values. + // If zero, use the parameter configured through Dns.Configure() interfa= ce. // - if (Instance->MaxRetry =3D=3D 0) { - Instance->MaxRetry =3D DNS_DEFAULT_RETRY; + if (Token->RetryCount =3D=3D 0) { + Token->RetryCount =3D ConfigData->RetryCount; } =20 + // + // If zero, use the parameter configured through Dns.Configure() interfa= ce. + // + if (Token->RetryInterval =3D=3D 0) { + Token->RetryInterval =3D ConfigData->RetryInterval; + } + =20 + // + // Minimum interval of retry is 2 second. If the retry interval is less = than 2 second, then use the 2 second.=20 + // if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) { Token->RetryInterval =3D DNS_DEFAULT_TIMEOUT; - }=20 + } =20 // // Check cache // if (ConfigData->EnableDnsCache) { @@ -1449,29 +1463,35 @@ Dns6GeneralLookUp ( OldTpl =3D gBS->RaiseTPL (TPL_CALLBACK); =20 Instance =3D DNS_INSTANCE_FROM_THIS_PROTOCOL6 (This); =20 ConfigData =3D &(Instance->Dns6CfgData); - =20 - Instance->MaxRetry =3D ConfigData->RetryCount; - =20 - Token->Status =3D EFI_NOT_READY; - Token->RetryCount =3D 0; - Token->RetryInterval =3D ConfigData->RetryInterval; =20 if (Instance->State !=3D DNS_STATE_CONFIGED) { Status =3D EFI_NOT_STARTED; goto ON_EXIT; } =20 + Token->Status =3D EFI_NOT_READY; + =20 // - // Check the MaxRetry and RetryInterval values. + // If zero, use the parameter configured through Dns.Configure() interfa= ce. // - if (Instance->MaxRetry =3D=3D 0) { - Instance->MaxRetry =3D DNS_DEFAULT_RETRY; + if (Token->RetryCount =3D=3D 0) { + Token->RetryCount =3D ConfigData->RetryCount; + } + =20 + // + // If zero, use the parameter configured through Dns.Configure() interfa= ce. + // + if (Token->RetryInterval =3D=3D 0) { + Token->RetryInterval =3D ConfigData->RetryInterval; } =20 + // + // Minimum interval of retry is 2 second. If the retry interval is less = than 2 second, then use the 2 second.=20 + // if (Token->RetryInterval < DNS_DEFAULT_TIMEOUT) { Token->RetryInterval =3D DNS_DEFAULT_TIMEOUT; } =20 // --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 04:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1512457180300576.5773805482745; Mon, 4 Dec 2017 22:59:40 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 856C22035626E; Mon, 4 Dec 2017 22:55:06 -0800 (PST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 678402035625F for ; Mon, 4 Dec 2017 22:55:05 -0800 (PST) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2017 22:59:36 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.96]) by orsmga008.jf.intel.com with ESMTP; 04 Dec 2017 22:59:34 -0800 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,363,1508828400"; d="scan'208";a="157595" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 5 Dec 2017 14:59:21 +0800 Message-Id: <1512457162-9296-4-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com> References: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 3/4] NetworkPkg/DnsDxe: Fix the potential memory leak issue. 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 , Wang Fan , 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" Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- NetworkPkg/DnsDxe/DnsImpl.c | 131 ++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 121 insertions(+), 10 deletions(-) diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c index 7c236a0..7057bfb 100644 --- a/NetworkPkg/DnsDxe/DnsImpl.c +++ b/NetworkPkg/DnsDxe/DnsImpl.c @@ -790,10 +790,14 @@ UpdateDns4Cache ( if (DeleteFlag) { // // Delete matching DNS Cache entry // RemoveEntryList (&Item->AllCacheLink); + + FreePool (Item->DnsCache.HostName); + FreePool (Item->DnsCache.IpAddress); + FreePool (Item); =20 return EFI_SUCCESS; } else if (Override) { // // Update this one @@ -817,17 +821,20 @@ UpdateDns4Cache ( =20 InitializeListHead (&NewDnsCache->AllCacheLink); =20 NewDnsCache->DnsCache.HostName =3D AllocatePool (StrSize (DnsCacheEntry.= HostName)); if (NewDnsCache->DnsCache.HostName =3D=3D NULL) {=20 + FreePool (NewDnsCache); return EFI_OUT_OF_RESOURCES; } =20 CopyMem (NewDnsCache->DnsCache.HostName, DnsCacheEntry.HostName, StrSize= (DnsCacheEntry.HostName)); =20 NewDnsCache->DnsCache.IpAddress =3D AllocatePool (sizeof (EFI_IPv4_ADDRE= SS)); - if (NewDnsCache->DnsCache.IpAddress =3D=3D NULL) {=20 + if (NewDnsCache->DnsCache.IpAddress =3D=3D NULL) { + FreePool (NewDnsCache->DnsCache.HostName); + FreePool (NewDnsCache); return EFI_OUT_OF_RESOURCES; } =20 CopyMem (NewDnsCache->DnsCache.IpAddress, DnsCacheEntry.IpAddress, sizeo= f (EFI_IPv4_ADDRESS)); =20 @@ -882,10 +889,14 @@ UpdateDns6Cache ( // // Delete matching DNS Cache entry // RemoveEntryList (&Item->AllCacheLink); =20 + FreePool (Item->DnsCache.HostName); + FreePool (Item->DnsCache.IpAddress); + FreePool (Item); + =20 return EFI_SUCCESS; } else if (Override) { // // Update this one // @@ -908,17 +919,20 @@ UpdateDns6Cache ( =20 InitializeListHead (&NewDnsCache->AllCacheLink); =20 NewDnsCache->DnsCache.HostName =3D AllocatePool (StrSize (DnsCacheEntry.= HostName)); if (NewDnsCache->DnsCache.HostName =3D=3D NULL) {=20 + FreePool (NewDnsCache); return EFI_OUT_OF_RESOURCES; } =20 CopyMem (NewDnsCache->DnsCache.HostName, DnsCacheEntry.HostName, StrSize= (DnsCacheEntry.HostName)); =20 NewDnsCache->DnsCache.IpAddress =3D AllocatePool (sizeof (EFI_IPv6_ADDRE= SS)); - if (NewDnsCache->DnsCache.IpAddress =3D=3D NULL) {=20 + if (NewDnsCache->DnsCache.IpAddress =3D=3D NULL) { + FreePool (NewDnsCache->DnsCache.HostName); + FreePool (NewDnsCache); return EFI_OUT_OF_RESOURCES; } =20 CopyMem (NewDnsCache->DnsCache.IpAddress, DnsCacheEntry.IpAddress, sizeo= f (EFI_IPv6_ADDRESS)); =20 @@ -1254,31 +1268,31 @@ ParseDnsResponse ( =20 if (Dns4TokenEntry->GeneralLookUp) { // // It's the GeneralLookUp querying. // - Dns4TokenEntry->Token->RspData.GLookupData =3D AllocatePool (sizeof = (DNS_RESOURCE_RECORD)); + Dns4TokenEntry->Token->RspData.GLookupData =3D AllocateZeroPool (siz= eof (DNS_RESOURCE_RECORD)); if (Dns4TokenEntry->Token->RspData.GLookupData =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - Dns4TokenEntry->Token->RspData.GLookupData->RRList =3D AllocatePool = (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); + Dns4TokenEntry->Token->RspData.GLookupData->RRList =3D AllocateZeroP= ool (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); if (Dns4TokenEntry->Token->RspData.GLookupData->RRList =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } } else { // // It's not the GeneralLookUp querying. Check the Query type. // if (QuerySection->Type =3D=3D DNS_TYPE_A) { - Dns4TokenEntry->Token->RspData.H2AData =3D AllocatePool (sizeof (D= NS_HOST_TO_ADDR_DATA)); + Dns4TokenEntry->Token->RspData.H2AData =3D AllocateZeroPool (sizeo= f (DNS_HOST_TO_ADDR_DATA)); if (Dns4TokenEntry->Token->RspData.H2AData =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - Dns4TokenEntry->Token->RspData.H2AData->IpList =3D AllocatePool (D= nsHeader->AnswersNum * sizeof (EFI_IPv4_ADDRESS)); + Dns4TokenEntry->Token->RspData.H2AData->IpList =3D AllocateZeroPoo= l (DnsHeader->AnswersNum * sizeof (EFI_IPv4_ADDRESS)); if (Dns4TokenEntry->Token->RspData.H2AData->IpList =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } } else { @@ -1291,31 +1305,31 @@ ParseDnsResponse ( =20 if (Dns6TokenEntry->GeneralLookUp) { // // It's the GeneralLookUp querying. // - Dns6TokenEntry->Token->RspData.GLookupData =3D AllocatePool (sizeof = (DNS_RESOURCE_RECORD)); + Dns6TokenEntry->Token->RspData.GLookupData =3D AllocateZeroPool (siz= eof (DNS_RESOURCE_RECORD)); if (Dns6TokenEntry->Token->RspData.GLookupData =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - Dns6TokenEntry->Token->RspData.GLookupData->RRList =3D AllocatePool = (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); + Dns6TokenEntry->Token->RspData.GLookupData->RRList =3D AllocateZeroP= ool (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); if (Dns6TokenEntry->Token->RspData.GLookupData->RRList =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } } else { // // It's not the GeneralLookUp querying. Check the Query type. // if (QuerySection->Type =3D=3D DNS_TYPE_AAAA) { - Dns6TokenEntry->Token->RspData.H2AData =3D AllocatePool (sizeof (D= NS6_HOST_TO_ADDR_DATA)); + Dns6TokenEntry->Token->RspData.H2AData =3D AllocateZeroPool (sizeo= f (DNS6_HOST_TO_ADDR_DATA)); if (Dns6TokenEntry->Token->RspData.H2AData =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - Dns6TokenEntry->Token->RspData.H2AData->IpList =3D AllocatePool (D= nsHeader->AnswersNum * sizeof (EFI_IPv6_ADDRESS)); + Dns6TokenEntry->Token->RspData.H2AData->IpList =3D AllocateZeroPoo= l (DnsHeader->AnswersNum * sizeof (EFI_IPv6_ADDRESS)); if (Dns6TokenEntry->Token->RspData.H2AData->IpList =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } } else { @@ -1601,10 +1615,101 @@ ON_COMPLETE: DispatchDpc (); } } =20 ON_EXIT: + // + // Free the allocated buffer if error happen. + // + if (EFI_ERROR (Status)) { + if (Dns4TokenEntry !=3D NULL) { + if (Dns4TokenEntry->GeneralLookUp) { + if (Dns4TokenEntry->Token->RspData.GLookupData !=3D NULL) { + if (Dns4TokenEntry->Token->RspData.GLookupData->RRList !=3D NULL= ) { + while (RRCount !=3D 0) { + RRCount --; + if (Dns4TokenEntry->Token->RspData.GLookupData->RRList[RRCou= nt].QName !=3D NULL) { + FreePool (Dns4TokenEntry->Token->RspData.GLookupData->RRLi= st[RRCount].QName); + } + + if (Dns4TokenEntry->Token->RspData.GLookupData->RRList[RRCou= nt].RData !=3D NULL) { + FreePool (Dns4TokenEntry->Token->RspData.GLookupData->RRLi= st[RRCount].RData); + } + } + =20 + FreePool (Dns4TokenEntry->Token->RspData.GLookupData->RRList); + } + =20 + FreePool (Dns4TokenEntry->Token->RspData.GLookupData); + } + } else { + if (QuerySection->Type =3D=3D DNS_TYPE_A && Dns4TokenEntry->Token-= >RspData.H2AData !=3D NULL) { + if (Dns4TokenEntry->Token->RspData.H2AData->IpList !=3D NULL) { + FreePool (Dns4TokenEntry->Token->RspData.H2AData->IpList); + } + =20 + FreePool (Dns4TokenEntry->Token->RspData.H2AData); + } + } + } + + if (Dns6TokenEntry !=3D NULL) { + if (Dns6TokenEntry->GeneralLookUp) { + if (Dns6TokenEntry->Token->RspData.GLookupData !=3D NULL) { + if (Dns6TokenEntry->Token->RspData.GLookupData->RRList !=3D NULL= ) { + while (RRCount !=3D 0) { + RRCount --; + if (Dns6TokenEntry->Token->RspData.GLookupData->RRList[RRCou= nt].QName !=3D NULL) { + FreePool (Dns6TokenEntry->Token->RspData.GLookupData->RRLi= st[RRCount].QName); + } + + if (Dns6TokenEntry->Token->RspData.GLookupData->RRList[RRCou= nt].RData !=3D NULL) { + FreePool (Dns6TokenEntry->Token->RspData.GLookupData->RRLi= st[RRCount].RData); + } + } + =20 + FreePool (Dns6TokenEntry->Token->RspData.GLookupData->RRList); + } + =20 + FreePool (Dns6TokenEntry->Token->RspData.GLookupData); + } + } else { + if (QuerySection->Type =3D=3D DNS_TYPE_AAAA && Dns6TokenEntry->Tok= en->RspData.H2AData !=3D NULL) { + if (Dns6TokenEntry->Token->RspData.H2AData->IpList !=3D NULL) { + FreePool (Dns6TokenEntry->Token->RspData.H2AData->IpList); + } + =20 + FreePool (Dns6TokenEntry->Token->RspData.H2AData); + } + } + } + + if (Dns4CacheEntry !=3D NULL) { + if (Dns4CacheEntry->HostName !=3D NULL) { + FreePool (Dns4CacheEntry->HostName); + } + + if (Dns4CacheEntry->IpAddress !=3D NULL) { + FreePool (Dns4CacheEntry->IpAddress); + } + + FreePool (Dns4CacheEntry); + } + + if (Dns6CacheEntry !=3D NULL) { + if (Dns6CacheEntry->HostName !=3D NULL) { + FreePool (Dns6CacheEntry->HostName); + } + + if (Dns6CacheEntry->IpAddress !=3D NULL) { + FreePool (Dns6CacheEntry->IpAddress); + } + + FreePool (Dns6CacheEntry); + } =20 + } + =20 gBS->RestoreTPL (OldTpl); return Status; } =20 /** @@ -2051,10 +2156,13 @@ DnsOnTimerUpdate ( Entry =3D mDriverData->Dns4CacheList.ForwardLink; while (Entry !=3D &mDriverData->Dns4CacheList) { Item4 =3D NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink); if (Item4->DnsCache.Timeout =3D=3D 0) { RemoveEntryList (&Item4->AllCacheLink); + FreePool (Item4->DnsCache.HostName); + FreePool (Item4->DnsCache.IpAddress); + FreePool (Item4); Entry =3D mDriverData->Dns4CacheList.ForwardLink; } else { Entry =3D Entry->ForwardLink; } } @@ -2070,10 +2178,13 @@ DnsOnTimerUpdate ( Entry =3D mDriverData->Dns6CacheList.ForwardLink; while (Entry !=3D &mDriverData->Dns6CacheList) { Item6 =3D NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink); if (Item6->DnsCache.Timeout =3D=3D 0) { RemoveEntryList (&Item6->AllCacheLink); + FreePool (Item6->DnsCache.HostName); + FreePool (Item6->DnsCache.IpAddress); + FreePool (Item6); Entry =3D mDriverData->Dns6CacheList.ForwardLink; } else { Entry =3D Entry->ForwardLink; } } --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 04:51:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1512457182824877.9112087113524; Mon, 4 Dec 2017 22:59:42 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BE10620356269; Mon, 4 Dec 2017 22:55:07 -0800 (PST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 E795E20356268 for ; Mon, 4 Dec 2017 22:55:06 -0800 (PST) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2017 22:59:37 -0800 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.96]) by orsmga008.jf.intel.com with ESMTP; 04 Dec 2017 22:59:36 -0800 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,363,1508828400"; d="scan'208";a="157599" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 5 Dec 2017 14:59:22 +0800 Message-Id: <1512457162-9296-5-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com> References: <1512457162-9296-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 4/4] NetworkPkg/DnsDxe: Avoid to access the freed memory buffer. 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 , Wang Fan , 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" The HostNameToIp() is a asynchronous function, so the caller may free the HostName buffer immediately once HostNameToIp() is returned. Then DNS driver may access the freed memory buffer later. This patch is to fix above issue. Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- NetworkPkg/DnsDxe/DnsProtocol.c | 69 +++++++++++++++++++++++--------------= ---- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/NetworkPkg/DnsDxe/DnsProtocol.c b/NetworkPkg/DnsDxe/DnsProtoco= l.c index df737dc..1fcaabd 100644 --- a/NetworkPkg/DnsDxe/DnsProtocol.c +++ b/NetworkPkg/DnsDxe/DnsProtocol.c @@ -462,13 +462,19 @@ Dns4HostNameToIp ( Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } =20 TokenEntry->PacketToLive =3D Token->RetryInterval; - TokenEntry->QueryHostName =3D HostName; TokenEntry->Token =3D Token; - + TokenEntry->QueryHostName =3D AllocateZeroPool (StrSize (HostName)); + if (TokenEntry->QueryHostName =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + =20 + CopyMem (TokenEntry->QueryHostName, HostName, StrSize (HostName)); + =20 // // Construct QName. // QueryName =3D NetLibCreateDnsQName (TokenEntry->QueryHostName); if (QueryName =3D=3D NULL) { @@ -478,49 +484,48 @@ Dns4HostNameToIp ( =20 // // Construct DNS Query Packet. // Status =3D ConstructDNSQuery (Instance, QueryName, DNS_TYPE_A, DNS_CLASS= _INET, &Packet); - if (EFI_ERROR (Status)) { - if (TokenEntry !=3D NULL) { - FreePool (TokenEntry); - } - =20 + if (EFI_ERROR (Status)) {=20 goto ON_EXIT; } =20 ASSERT (Packet !=3D NULL); =20 // // Save the token into the Dns4TxTokens map. // Status =3D NetMapInsertTail (&Instance->Dns4TxTokens, TokenEntry, Packet= ); if (EFI_ERROR (Status)) { - if (TokenEntry !=3D NULL) { - FreePool (TokenEntry); - } - =20 - NetbufFree (Packet); - =20 goto ON_EXIT; } =20 // // Dns Query Ip // Status =3D DoDnsQuery (Instance, Packet); if (EFI_ERROR (Status)) { Dns4RemoveTokenEntry (&Instance->Dns4TxTokens, TokenEntry); + } + =20 +ON_EXIT: =20 + if (EFI_ERROR (Status)) { if (TokenEntry !=3D NULL) { + if (TokenEntry->QueryHostName !=3D NULL) { + FreePool (TokenEntry->QueryHostName); + } + =20 FreePool (TokenEntry); } =20 - NetbufFree (Packet); + if (Packet !=3D NULL) { + NetbufFree (Packet); + } } =20 -ON_EXIT: if (QueryName !=3D NULL) { FreePool (QueryName); } =20 gBS->RestoreTPL (OldTpl); @@ -1299,13 +1304,18 @@ Dns6HostNameToIp ( Status =3D EFI_OUT_OF_RESOURCES; goto ON_EXIT; } =20 TokenEntry->PacketToLive =3D Token->RetryInterval; - TokenEntry->QueryHostName =3D HostName; TokenEntry->Token =3D Token; - + TokenEntry->QueryHostName =3D AllocateZeroPool (StrSize (HostName)); + if (TokenEntry->QueryHostName =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + =20 + CopyMem (TokenEntry->QueryHostName, HostName, StrSize (HostName)); =20 // // Construct QName. // QueryName =3D NetLibCreateDnsQName (TokenEntry->QueryHostName); @@ -1317,48 +1327,47 @@ Dns6HostNameToIp ( // // Construct DNS Query Packet. // Status =3D ConstructDNSQuery (Instance, QueryName, DNS_TYPE_AAAA, DNS_CL= ASS_INET, &Packet); if (EFI_ERROR (Status)) { - if (TokenEntry !=3D NULL) { - FreePool (TokenEntry); - } - =20 goto ON_EXIT; } =20 ASSERT (Packet !=3D NULL); =20 // // Save the token into the Dns6TxTokens map. // Status =3D NetMapInsertTail (&Instance->Dns6TxTokens, TokenEntry, Packet= ); if (EFI_ERROR (Status)) { - if (TokenEntry !=3D NULL) { - FreePool (TokenEntry); - } - =20 - NetbufFree (Packet); - =20 goto ON_EXIT; } =20 // // Dns Query Ip // Status =3D DoDnsQuery (Instance, Packet); if (EFI_ERROR (Status)) { Dns6RemoveTokenEntry (&Instance->Dns6TxTokens, TokenEntry); - =20 + } + =20 +ON_EXIT: + + if (EFI_ERROR (Status)) { if (TokenEntry !=3D NULL) { + if (TokenEntry->QueryHostName !=3D NULL) { + FreePool (TokenEntry->QueryHostName); + } + =20 FreePool (TokenEntry); } =20 - NetbufFree (Packet); + if (Packet !=3D NULL) { + NetbufFree (Packet); + } } =20 -ON_EXIT: if (QueryName !=3D NULL) { FreePool (QueryName); } =20 gBS->RestoreTPL (OldTpl); --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel