From nobody Mon Apr 29 18:19:37 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 1513846595882993.3798362315846; Thu, 21 Dec 2017 00:56:35 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 34E22222447CF; Thu, 21 Dec 2017 00:51:46 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 F2943221ED75B for ; Thu, 21 Dec 2017 00:51:44 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2017 00:56:33 -0800 Received: from sfu5-mobl.ccr.corp.intel.com ([10.239.192.229]) by fmsmga006.fm.intel.com with ESMTP; 21 Dec 2017 00:56: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=192.55.52.88; helo=mga01.intel.com; envelope-from=siyuan.fu@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.45,435,1508828400"; d="scan'208";a="188903691" From: Fu Siyuan To: edk2-devel@lists.01.org Date: Thu, 21 Dec 2017 16:56:18 +0800 Message-Id: <20171221085618.12408-1-siyuan.fu@intel.com> X-Mailer: git-send-email 2.13.0.windows.1 Subject: [edk2] [Patch V2] MdeModulePkg/IpIoLib: add more error handling code to DxeIpIoLib. 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 , Wang Fan , 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" V2 update: Add missing "Status =3D" when call GetModeData() In DxeIpIo, there are several places not check the returned value of called= functions. This patch is to add the error handling to these functions. Cc: Ye Ting Cc: Wu Jiaxin Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan --- MdeModulePkg/Include/Library/IpIoLib.h | 4 +- MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c | 95 +++++++++++++++++-------= ---- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/MdeModulePkg/Include/Library/IpIoLib.h b/MdeModulePkg/Include/= Library/IpIoLib.h index aab0c68059..a8496f729d 100644 --- a/MdeModulePkg/Include/Library/IpIoLib.h +++ b/MdeModulePkg/Include/Library/IpIoLib.h @@ -2,7 +2,7 @@ This library is only intended to be used by UEFI network stack modules. It provides the combined IpIo layer on the EFI IP4 Protocol and EFI IP6 = protocol. =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 availabl= e under=20 the terms and conditions of the BSD License that accompanies this distribu= tion. =20 The full text of the license may be found at @@ -426,7 +426,7 @@ IpIoSend ( IN IP_IO_IP_INFO *Sender OPTIONAL, IN VOID *Context OPTIONAL, IN VOID *NotifyData OPTIONAL, - IN EFI_IP_ADDRESS *Dest, + IN EFI_IP_ADDRESS *Dest OPTIONAL, IN IP_IO_OVERRIDE *OverrideData OPTIONAL ); =20 diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c b/MdeModulePkg/Li= brary/DxeIpIoLib/DxeIpIoLib.c index abc07fb0ff..ae0199f58f 100644 --- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c +++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c @@ -2,7 +2,7 @@ IpIo Library. =20 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
-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 @@ -234,24 +234,25 @@ IpIoCloseProtocolDestroyIpChild ( // // Close the previously openned IP protocol. // - gBS->CloseProtocol ( - ChildHandle, - IpProtocolGuid, - ImageHandle, - ControllerHandle - ); + Status =3D gBS->CloseProtocol ( + ChildHandle, + IpProtocolGuid, + ImageHandle, + ControllerHandle + ); + if (EFI_ERROR (Status)) { + return Status; + } =20 // // Destroy the IP child. // - Status =3D NetLibDestroyServiceChild ( - ControllerHandle, - ImageHandle, - ServiceBindingGuid, - ChildHandle - ); - - return Status; + return NetLibDestroyServiceChild ( + ControllerHandle, + ImageHandle, + ServiceBindingGuid, + ChildHandle + ); } =20 /** @@ -377,8 +378,14 @@ IpIoIcmpv4Handler ( TrimBytes =3D (UINT32) (PayLoadHdr - (UINT8 *) IcmpHdr); =20 NetbufTrim (Pkt, TrimBytes, TRUE); - - IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdCo= ntext); + =20 + // + // If the input packet has invalid format, and TrimBytes is larger than=20 + // the packet size, the NetbufTrim might trim the packet to zero. + // + if (Pkt->TotalSize !=3D 0) { + IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->Rcvd= Context); + } =20 return EFI_SUCCESS; =20 } @@ -539,7 +546,13 @@ IpIoIcmpv6Handler ( =20 NetbufTrim (Pkt, TrimBytes, TRUE); =20 - IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdCo= ntext); + // + // If the input packet has invalid format, and TrimBytes is larger than=20 + // the packet size, the NetbufTrim might trim the packet to zero. + // + if (Pkt->TotalSize !=3D 0) { + IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->Rcvd= Context); + } =20 return EFI_SUCCESS; } @@ -1540,7 +1553,7 @@ IpIoSend ( IN IP_IO_IP_INFO *Sender OPTIONAL, IN VOID *Context OPTIONAL, IN VOID *NotifyData OPTIONAL, - IN EFI_IP_ADDRESS *Dest, + IN EFI_IP_ADDRESS *Dest OPTIONAL, IN IP_IO_OVERRIDE *OverrideData OPTIONAL ) { @@ -1791,19 +1804,23 @@ IpIoConfigIp ( } =20 if (IpConfigData !=3D NULL) { - if (IpInfo->IpVersion =3D=3D IP_VERSION_4){ + if (IpInfo->IpVersion =3D=3D IP_VERSION_4) { =20 if (((EFI_IP4_CONFIG_DATA *) IpConfigData)->UseDefaultAddress) { - Ip.Ip4->GetModeData ( - Ip.Ip4,=20 - &Ip4ModeData,=20 - NULL,=20 - NULL - ); + Status =3D Ip.Ip4->GetModeData ( + Ip.Ip4,=20 + &Ip4ModeData,=20 + NULL,=20 + NULL + ); + if (EFI_ERROR (Status)) { + Ip.Ip4->Configure (Ip.Ip4, NULL); + goto OnExit; + } =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); - } + } =20 CopyMem ( &IpInfo->Addr.Addr,=20 @@ -1820,16 +1837,20 @@ IpIoConfigIp ( Ip.Ip4, &IpInfo->DummyRcvToken.Ip4Token ); - if (EFI_ERROR (Status)) { - Ip.Ip4->Configure (Ip.Ip4, NULL); - } - } else { - Ip.Ip6->GetModeData ( - Ip.Ip6, - &Ip6ModeData, - NULL, - NULL - ); + if (EFI_ERROR (Status)) { + Ip.Ip4->Configure (Ip.Ip4, NULL); + } + } else { + Status =3D Ip.Ip6->GetModeData ( + Ip.Ip6, + &Ip6ModeData, + NULL, + NULL + ); + if (EFI_ERROR (Status)) { + Ip.Ip6->Configure (Ip.Ip6, NULL); + goto OnExit; + } =20 if (Ip6ModeData.IsConfigured) { CopyMem ( --=20 2.13.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel