From nobody Sat Apr 27 20:51:09 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 1515554195322202.1914983207363; Tue, 9 Jan 2018 19:16:35 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4BEA02236BAA0; Tue, 9 Jan 2018 19:11:22 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 C8824222EDCE2 for ; Tue, 9 Jan 2018 19:11:20 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2018 19:16:32 -0800 Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.33]) by fmsmga002.fm.intel.com with ESMTP; 09 Jan 2018 19:16: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=192.55.52.43; helo=mga05.intel.com; envelope-from=fan.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,337,1511856000"; d="scan'208";a="8879736" From: Wang Fan To: edk2-devel@lists.01.org Date: Wed, 10 Jan 2018 11:16:27 +0800 Message-Id: <1515554188-2560-2-git-send-email-fan.wang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1515554188-2560-1-git-send-email-fan.wang@intel.com> References: <1515554188-2560-1-git-send-email-fan.wang@intel.com> Subject: [edk2] [Patch 1/2] MdeModulePkg: Freed the received packet buffer if it is not expected. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Jiaxin Wu 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" * When the packet is not normal packet or icmp error packet, the code does not recycle it by signal RecycleSignal event, and this will result some memory leak. This patch is to fix this issue. Cc: Jiaxin Wu Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan Reviewed-by: Fu Siyuan --- MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c b/MdeModulePkg/Li= brary/DxeIpIoLib/DxeIpIoLib.c index a06c0b6..c7bc1aa 100644 --- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c +++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c @@ -1037,16 +1037,26 @@ IpIoListenHandlerDpc ( // The reception is actively aborted by the consumer, directly return. // return; } =20 - if (((EFI_SUCCESS !=3D Status) && (EFI_ICMP_ERROR !=3D Status)) || (NULL= =3D=3D RxData)) { + if ((EFI_SUCCESS !=3D Status) && (EFI_ICMP_ERROR !=3D Status)) { // - // @bug Only process the normal packets and the icmp error packets, if= RxData is NULL - // @bug with Status =3D=3D EFI_SUCCESS or EFI_ICMP_ERROR, just resume = the receive although - // @bug this should be a bug of the low layer (IP). + // Only process the normal packets and the icmp error packets. // + if (RxData !=3D NULL) { + goto CleanUp; + } else { + goto Resume; + } + } + + // + // if RxData is NULL with Status =3D=3D EFI_SUCCESS or EFI_ICMP_ERROR, t= his should be a code issue in the low layer (IP). + // + ASSERT (RxData !=3D NULL); + if (RxData =3D=3D NULL) { goto Resume; } =20 if (NULL =3D=3D IpIo->PktRcvdNotify) { goto CleanUp; --=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 Sat Apr 27 20:51:09 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 1515554197759728.4901144287631; Tue, 9 Jan 2018 19:16:37 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B28052236BAAB; Tue, 9 Jan 2018 19:11:24 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 EDD57222EDCE2 for ; Tue, 9 Jan 2018 19:11:22 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2018 19:16:34 -0800 Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.33]) by fmsmga002.fm.intel.com with ESMTP; 09 Jan 2018 19:16:33 -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=192.55.52.43; helo=mga05.intel.com; envelope-from=fan.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,337,1511856000"; d="scan'208";a="8879746" From: Wang Fan To: edk2-devel@lists.01.org Date: Wed, 10 Jan 2018 11:16:28 +0800 Message-Id: <1515554188-2560-3-git-send-email-fan.wang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1515554188-2560-1-git-send-email-fan.wang@intel.com> References: <1515554188-2560-1-git-send-email-fan.wang@intel.com> Subject: [edk2] [Patch 2/2] MdeModulePkg: Did some code enhancement for DxeIpIpLib. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Jiaxin Wu 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" * In DxeIpIo, there are several places use ASSERT() to check input parameters without and descriptions or error handling. This patch fixed this issue. * Fixed some incorrect descriptions in code commence. * Remove unneeded Exit tag in function IpIoOpen and IpIoConfigIp. * Add EFIAPI tag for function IpIoRefreshNeighbor. Cc: Jiaxin Wu Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan Reviewed-by: Fu Siyuan --- MdeModulePkg/Include/Library/IpIoLib.h | 21 +++++++++-- MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c | 52 ++++++++++++++++++------= ---- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/MdeModulePkg/Include/Library/IpIoLib.h b/MdeModulePkg/Include/= Library/IpIoLib.h index 463bf95..61653b0 100644 --- a/MdeModulePkg/Include/Library/IpIoLib.h +++ b/MdeModulePkg/Include/Library/IpIoLib.h @@ -308,10 +308,12 @@ typedef struct _IP_IO_IP_INFO { UINT8 IpVersion; } IP_IO_IP_INFO; =20 /** Create a new IP_IO instance. + + If IpVersion is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). =20 This function uses IP4/IP6 service binding protocol in Controller to cre= ate an IP4/IP6 child (aka IP4/IP6 instance). =20 @param[in] Image The image handle of the driver or applicat= ion that @@ -351,10 +353,12 @@ IpIoDestroy ( IN OUT IP_IO *IpIo ); =20 /** Stop an IP_IO instance. + + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). =20 This function is paired with IpIoOpen(). The IP_IO will be unconfigured,= and all pending send/receive tokens will be canceled. =20 @param[in, out] IpIo The pointer to the IP_IO instance that = needs to stop. @@ -370,11 +374,13 @@ IpIoStop ( IN OUT IP_IO *IpIo ); =20 /** Open an IP_IO instance for use. - =20 + + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). + This function is called after IpIoCreate(). It is used for configuring t= he IP instance and register the callbacks and their context data for sending a= nd receiving IP packets. =20 @param[in, out] IpIo The pointer to an IP_IO instance tha= t needs @@ -399,11 +405,11 @@ IpIoOpen ( ); =20 /** Send out an IP packet. =20 - This function is called after IpIoOpen(). The data to be sent are wrappe= d in + This function is called after IpIoOpen(). The data to be sent is wrapped= in Pkt. The IP instance wrapped in IpIo is used for sending by default but = can be overriden by Sender. Other sending configs, like source address and gate= way address etc., are specified in OverrideData. =20 @param[in, out] IpIo Pointer to an IP_IO instance used= for sending IP @@ -437,10 +443,13 @@ IpIoSend ( ); =20 /** Cancel the IP transmit token that wraps this Packet. =20 + If IpIo is NULL, then ASSERT(). + If Packet is NULL, then ASSERT(). + @param[in] IpIo The pointer to the IP_IO instance. @param[in] Packet The pointer to the packet of NET_BUF t= o cancel. =20 **/ VOID @@ -450,10 +459,13 @@ IpIoCancelTxToken ( IN VOID *Packet ); =20 /** Add a new IP instance for sending data. + + If IpIo is NULL, then ASSERT(). + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). =20 The function is used to add the IP_IO to the IP_IO sending list. The cal= ler can later use IpIoFindSender() to get the IP_IO and call IpIoSend() to s= end data. =20 @@ -471,10 +483,12 @@ IpIoAddIp ( =20 /** Configure the IP instance of this IpInfo and start the receiving if IpCo= nfigData is not NULL. =20 + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). + @param[in, out] IpInfo The pointer to the IP_IO_IP_INFO instan= ce. @param[in, out] IpConfigData The IP4 or IP6 configure data used to c= onfigure=20 the IP instance. If NULL, the IP instan= ce is reset. If UseDefaultAddress is set to TRUE, an= d the configure operation succeeds, the default address= information @@ -493,10 +507,12 @@ IpIoConfigIp ( ); =20 /** Destroy an IP instance maintained in IpIo->IpList for sending purpose. + + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). =20 =20 This function pairs with IpIoAddIp(). The IpInfo is previously created by IpIoAddIp(). The IP_IO_IP_INFO::RefCnt is decremented and the IP instance will be dstroyed if the RefCnt is zero. =20 @@ -584,10 +600,11 @@ IpIoGetIcmpErrStatus ( @retval EFI_UNSUPPORTED IP version is IPv4, which doesn't sup= port neighbor cache refresh. @retval EFI_OUT_OF_RESOURCES Failed due to resource limitations. =20 **/ EFI_STATUS +EFIAPI IpIoRefreshNeighbor ( IN IP_IO *IpIo, IN EFI_IP_ADDRESS *Neighbor, IN UINT32 Timeout =20 ); diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c b/MdeModulePkg/Li= brary/DxeIpIoLib/DxeIpIoLib.c index c7bc1aa..0c6681d 100644 --- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c +++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c @@ -1,10 +1,10 @@ /** @file IpIo Library. =20 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
-Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2018, 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 @@ -632,12 +632,12 @@ IpIoExtFree ( @param[in] Context Pointer to the context. @param[in] NotifyData Pointer to the notify data. @param[in] Dest Pointer to the destination IP addr= ess. @param[in] Override Pointer to the overriden IP_IO dat= a. =20 - @return Pointer to the data structure created to wrap the packet. If NUL= L, - @return resource limit occurred. + @return Pointer to the data structure created to wrap the packet. If any= error occurs,=20 + then return NULL. =20 **/ IP_IO_SEND_ENTRY * IpIoCreateSndEntry ( IN OUT IP_IO *IpIo, @@ -1073,11 +1073,11 @@ IpIoListenHandlerDpc ( if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) !=3D 0) && (IpIo->SubnetMask !=3D 0) && IP4_NET_EQUAL (IpIo->StationIp, EFI_NTOHL (((EFI_IP4_RECEIVE_DATA = *) RxData)->Header->SourceAddress), IpIo->SubnetMask) && !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->He= ader->SourceAddress), IpIo->SubnetMask)) { // - // The source address is not zero and it's not a unicast IP address,= discard it. + // The source address doesn't match StationIp and it's not a unicast= IP address, discard it. // goto CleanUp; } =20 if (RxData->Ip4RxData.DataLength =3D=3D 0) { @@ -1219,10 +1219,12 @@ IpIoListenHandler ( } =20 =20 /** Create a new IP_IO instance. + + If IpVersion is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). =20 This function uses IP4/IP6 service binding protocol in Controller to cre= ate an IP4/IP6 child (aka IP4/IP6 instance). =20 @param[in] Image The image handle of the driver or applicat= ion that @@ -1284,11 +1286,11 @@ IpIoCreate ( Status =3D IpIoCreateIpChildOpenProtocol ( Controller, Image, &IpIo->ChildHandle, IpVersion, =20 - (VOID **)&(IpIo->Ip) + (VOID **) & (IpIo->Ip) ); if (EFI_ERROR (Status)) { goto ReleaseIpIo; } =20 @@ -1306,11 +1308,13 @@ ReleaseIpIo: } =20 =20 /** Open an IP_IO instance for use. - =20 + + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). + This function is called after IpIoCreate(). It is used for configuring t= he IP instance and register the callbacks and their context data for sending a= nd receiving IP packets. =20 @param[in, out] IpIo Pointer to an IP_IO instance that ne= eds @@ -1417,11 +1421,11 @@ IpIoOpen ( IpIo->Ip.Ip4, &(IpIo->RcvToken.Ip4Token) ); if (EFI_ERROR (Status)) { IpIo->Ip.Ip4->Configure (IpIo->Ip.Ip4, NULL); - goto ErrorExit; + return Status; } =20 } else { =20 IpIo->Protocol =3D OpenData->IpConfigData.Ip6CfgData.DefaultProtocol; @@ -1429,25 +1433,25 @@ IpIoOpen ( IpIo->Ip.Ip6, &(IpIo->RcvToken.Ip6Token) ); if (EFI_ERROR (Status)) { IpIo->Ip.Ip6->Configure (IpIo->Ip.Ip6, NULL); - goto ErrorExit; + return Status; } } =20 IpIo->IsConfigured =3D TRUE; InsertTailList (&mActiveIpIoList, &IpIo->Entry); =20 -ErrorExit: - return Status; } =20 =20 /** Stop an IP_IO instance. + + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). =20 This function is paired with IpIoOpen(). The IP_IO will be unconfigured = and all the pending send/receive tokens will be canceled. =20 @param[in, out] IpIo Pointer to the IP_IO instance that need= s to stop. @@ -1575,11 +1579,11 @@ IpIoDestroy ( =20 =20 /** Send out an IP packet. =20 - This function is called after IpIoOpen(). The data to be sent are wrappe= d in + This function is called after IpIoOpen(). The data to be sent is wrapped= in Pkt. The IP instance wrapped in IpIo is used for sending by default but = can be overriden by Sender. Other sending configs, like source address and gate= way address etc., are specified in OverrideData. =20 @param[in, out] IpIo Pointer to an IP_IO instance used= for sending IP @@ -1662,10 +1666,13 @@ IpIoSend ( =20 =20 /** Cancel the IP transmit token which wraps this Packet. =20 + If IpIo is NULL, then ASSERT(). + If Packet is NULL, then ASSERT(). + @param[in] IpIo Pointer to the IP_IO instance. @param[in] Packet Pointer to the packet of NET_BUF to ca= ncel. =20 **/ VOID @@ -1708,10 +1715,13 @@ IpIoCancelTxToken ( } =20 =20 /** Add a new IP instance for sending data. + + If IpIo is NULL, then ASSERT(). + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). =20 The function is used to add the IP_IO to the IP_IO sending list. The cal= ler can later use IpIoFindSender() to get the IP_IO and call IpIoSend() to s= end data. =20 @@ -1735,10 +1745,11 @@ IpIoAddIp ( =20 IpInfo =3D AllocatePool (sizeof (IP_IO_IP_INFO)); if (IpInfo =3D=3D NULL) { return NULL; } + ASSERT ((IpInfo->IpVersion =3D=3D IP_VERSION_4) || (IpInfo->IpVersion = =3D=3D IP_VERSION_6)); =20 // // Init this IpInfo, set the Addr and SubnetMask to 0 before we configur= e the IP // instance. // @@ -1810,10 +1821,13 @@ ReleaseIpInfo: =20 /** Configure the IP instance of this IpInfo and start the receiving if IpCo= nfigData is not NULL. =20 + If IpInfo is NULL, then ASSERT(). + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). + @param[in, out] IpInfo Pointer to the IP_IO_IP_INFO instance. @param[in, out] IpConfigData The IP configure data used to configure= the IP instance, if NULL the IP instance is re= set. If UseDefaultAddress is set to TRUE, and t= he configure operation succeeds, the default address= information @@ -1859,11 +1873,11 @@ IpIoConfigIp ( } else { Status =3D Ip.Ip6->Configure (Ip.Ip6, IpConfigData); } =20 if (EFI_ERROR (Status)) { - goto OnExit; + return Status; } =20 if (IpConfigData !=3D NULL) { if (IpInfo->IpVersion =3D=3D IP_VERSION_4) { =20 @@ -1874,11 +1888,11 @@ IpIoConfigIp ( NULL,=20 NULL ); if (EFI_ERROR (Status)) { Ip.Ip4->Configure (Ip.Ip4, NULL); - goto OnExit; + return Status; } =20 IP4_COPY_ADDRESS (&((EFI_IP4_CONFIG_DATA*) IpConfigData)->StationA= ddress, &Ip4ModeData.ConfigData.StationAddress); IP4_COPY_ADDRESS (&((EFI_IP4_CONFIG_DATA*) IpConfigData)->SubnetMa= sk, &Ip4ModeData.ConfigData.SubnetMask); } @@ -1908,11 +1922,11 @@ IpIoConfigIp ( NULL, NULL ); if (EFI_ERROR (Status)) { Ip.Ip6->Configure (Ip.Ip6, NULL); - goto OnExit; + return Status; } =20 if (Ip6ModeData.IsConfigured) { CopyMem ( &((EFI_IP6_CONFIG_DATA *) IpConfigData)->StationAddress, @@ -1944,11 +1958,11 @@ IpIoConfigIp ( FreePool (Ip6ModeData.IcmpTypeList); } =20 } else { Status =3D EFI_NO_MAPPING; - goto OnExit; + return Status; }=20 =20 CopyMem ( &IpInfo->Addr,=20 &Ip6ModeData.ConfigData.StationAddress,=20 @@ -1969,19 +1983,19 @@ IpIoConfigIp ( // ZeroMem (&IpInfo->Addr, sizeof (IpInfo->Addr)); ZeroMem (&IpInfo->PreMask, sizeof (IpInfo->PreMask)); } =20 -OnExit: - return Status; } =20 =20 /** Destroy an IP instance maintained in IpIo->IpList for sending purpose. + + If Ip version is not IP_VERSION_4 or IP_VERSION_6, then ASSERT(). =20 This function pairs with IpIoAddIp(). The IpInfo is previously created by IpIoAddIp(). The IP_IO_IP_INFO::RefCnt is decremented and the IP instance will be dstroyed if the RefCnt is zero. =20 @@ -2110,12 +2124,11 @@ IpIoFindSender ( =20 if (EFI_IP6_EQUAL (&IpInfo->Addr.v6, &Src->v6)) { *IpIo =3D IpIoPtr; return IpInfo; =20 } - } =20 - + } } } =20 // // No match. @@ -2258,10 +2271,11 @@ IpIoGetIcmpErrStatus ( @retval EFI_UNSUPPORTED IP version is IPv4, which doesn't sup= port neighbor cache refresh. @retval EFI_OUT_OF_RESOURCES Failed due to resource limit. =20 **/ EFI_STATUS +EFIAPI IpIoRefreshNeighbor ( IN IP_IO *IpIo, IN EFI_IP_ADDRESS *Neighbor, IN UINT32 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