From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web10.3014.1585735618495831976 for ; Wed, 01 Apr 2020 03:06:58 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: linux.intel.com, ip: 134.134.136.65, mailfrom: maciej.rabeda@linux.intel.com) IronPort-SDR: Rk3HVsGkY5dw/RJren1Qc78+wc+vdJifV8/qQtBsecPljWFizYqgqV+ZZ95LZYT3pXJX809g1E NWvRswTMBkWg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2020 03:06:57 -0700 IronPort-SDR: QSNw7MPUaTyqEeqEXY3/THpN7qT1L8IknrqgN0kZrMGPCnKFeePv7ro4cdjiC57/ft/fqKnxR4 eSVIPQqLnBCA== X-IronPort-AV: E=Sophos;i="5.72,331,1580803200"; d="scan'208";a="422662008" Received: from mrabeda-mobl.ger.corp.intel.com ([10.213.11.210]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2020 03:06:56 -0700 From: "Maciej Rabeda" To: devel@edk2.groups.io Cc: Ray Ni , Zhichao Gao , Siyuan Fu Subject: [PATCH v2] ShellPkg: Fix 'ping' command Ip4 receive flow. Date: Wed, 1 Apr 2020 12:06:52 +0200 Message-Id: <20200401100652.2049-1-maciej.rabeda@linux.intel.com> X-Mailer: git-send-email 2.24.0.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2032 'ping' command's receive flow utilizes a single Rx token which it attempts to reuse before recycling the previously received packet. This causes a situation where under ICMP traffic, Ping6OnEchoReplyReceived() function will receive an already recycled packet with EFI_SUCCESS token status and finally dereference invalid pointers from RxData structure. Cc: Ray Ni Cc: Zhichao Gao Signed-off-by: Maciej Rabeda Reviewed-by: Siyuan Fu Acked-by: Zhichao Gao --- ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c b/ShellPk= g/Library/UefiShellNetwork1CommandsLib/Ping.c index 23567fa2c1bb..a3fa32515192 100644 --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c @@ -614,6 +614,11 @@ Ping6OnEchoReplyReceived ( =0D ON_EXIT:=0D =0D + //=0D + // Recycle the packet before reusing RxToken=0D + //=0D + gBS->SignalEvent (Private->IpChoice =3D=3D PING_IP_CHOICE_IP6?((EFI_IP6_= RECEIVE_DATA*)Private->RxToken.Packet.RxData)->RecycleSignal:((EFI_IP4_RECE= IVE_DATA*)Private->RxToken.Packet.RxData)->RecycleSignal);=0D +=0D if (Private->RxCount < Private->SendNum) {=0D //=0D // Continue to receive icmp echo reply packets.=0D @@ -632,10 +637,6 @@ ON_EXIT: //=0D Private->Status =3D EFI_SUCCESS;=0D }=0D - //=0D - // Singal to recycle the each rxdata here, not at the end of process.=0D - //=0D - gBS->SignalEvent (Private->IpChoice =3D=3D PING_IP_CHOICE_IP6?((EFI_IP6_= RECEIVE_DATA*)Private->RxToken.Packet.RxData)->RecycleSignal:((EFI_IP4_RECE= IVE_DATA*)Private->RxToken.Packet.RxData)->RecycleSignal);=0D }=0D =0D /**=0D --=20 2.24.0.windows.2