From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.2425.1582801337989162158 for ; Thu, 27 Feb 2020 03:02:18 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: linux.intel.com, ip: 134.134.136.20, mailfrom: maciej.rabeda@linux.intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2020 03:02:17 -0800 X-IronPort-AV: E=Sophos;i="5.70,491,1574150400"; d="scan'208";a="242011768" Received: from mrabeda-mobl.ger.corp.intel.com ([10.102.8.43]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 27 Feb 2020 03:02:16 -0800 From: "Maciej Rabeda" To: devel@edk2.groups.io Cc: Ray Ni , Zhichao Gao Subject: [PATCH v1] ShellPkg: Fix 'ping' command Ip4 receive flow. Date: Thu, 27 Feb 2020 12:02:12 +0100 Message-Id: <20200227110212.1070-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 --- 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