public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Jiewen Yao <jiewen.yao@intel.com>,
	Star Zeng <star.zeng@intel.com>, Hao A Wu <hao.a.wu@intel.com>
Subject: [PATCH v2 05/12] MdeModulePkg/Usb: Make sure data from HW is no more than expected
Date: Tue, 16 Oct 2018 13:43:28 +0800	[thread overview]
Message-ID: <20181016054335.47460-6-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20181016054335.47460-1-ruiyu.ni@intel.com>

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 9 ++++++---
 MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c | 7 ++++---
 MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 9 ++++++---
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
index fea6f47f4c..168280be81 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c
@@ -1009,9 +1009,12 @@ EhcMonitorAsyncRequests (
     ProcBuf = NULL;
 
     if (Urb->Result == EFI_USB_NOERROR) {
-      ASSERT (Urb->Completed <= Urb->DataLen);
-
-      ProcBuf = AllocatePool (Urb->Completed);
+      //
+      // Make sure the data received from HW is no more than expected.
+      //
+      if (Urb->Completed <= Urb->DataLen) {
+        ProcBuf = AllocatePool (Urb->Completed);
+      }
 
       if (ProcBuf == NULL) {
         EhcUpdateAsyncRequest (Ehc, Urb);
diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c b/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
index 90f010c998..f7510f3ec0 100644
--- a/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
+++ b/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
@@ -2,7 +2,7 @@
 
   The EHCI register operation routines.
 
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 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
@@ -1001,11 +1001,12 @@ UhciMonitorAsyncReqList (
 
     //
     // Copy the data to temporary buffer if there are some
-    // data transferred. We may have zero-length packet
+    // data transferred. We may have zero-length packet.
+    // Make sure the data received from HW is no more than expected.
     //
     Data = NULL;
 
-    if (QhResult.Complete != 0) {
+    if ((QhResult.Complete != 0) && (QhResult.Complete <= AsyncReq->DataLen)) {
       Data = AllocatePool (QhResult.Complete);
 
       if (Data == NULL) {
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index 6a2ef4cd5d..166c44bf5e 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -1556,9 +1556,12 @@ XhcMonitorAsyncRequests (
     //
     ProcBuf = NULL;
     if (Urb->Result == EFI_USB_NOERROR) {
-      ASSERT (Urb->Completed <= Urb->DataLen);
-
-      ProcBuf = AllocateZeroPool (Urb->Completed);
+      //
+      // Make sure the data received from HW is no more than expected.
+      //
+      if (Urb->Completed <= Urb->DataLen) {
+        ProcBuf = AllocateZeroPool (Urb->Completed);
+      }
 
       if (ProcBuf == NULL) {
         XhcUpdateAsyncRequest (Xhc, Urb);
-- 
2.16.1.windows.1



  parent reply	other threads:[~2018-10-16  5:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-16  5:43 [PATCH v2 00/12] Need to validate data from HW Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 01/12] MdeModulePkg/UsbMass: Merge UsbBoot(Read|Write)Blocks(16) Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 02/12] MdeModulePkg/UsbMass: Fix integer overflow when BlockSize is 1 Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 03/12] MdeModulePkg/UsbBus: Fix out-of-bound read access to descriptors Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 04/12] MdeModulePkg/UsbBus: Reject descriptor whose length is bad Ruiyu Ni
2018-10-16  5:43 ` Ruiyu Ni [this message]
2018-10-16  5:43 ` [PATCH v2 06/12] SourceLevelDebugPkg/Usb3: Make sure data from HW can fit in buffer Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 07/12] MdeModulePkg/UsbKb: Don't access key codes when length is wrong Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 08/12] MdeModulePkg/AbsPointer: " Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 09/12] MdeModulePkg/UsbMouse: " Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 10/12] MdeModulePkg/UsbBus: Deny when the string descriptor length is odd Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 11/12] MdeModulePkg/Bus/Ufs: Ensure device not return more data than expected Ruiyu Ni
2018-10-16  5:43 ` [PATCH v2 12/12] MdeModulePkg/UsbMass: Reject device whose block size is 0 or > 64K Ruiyu Ni
2018-10-17  2:43 ` [PATCH v2 00/12] Need to validate data from HW Zeng, Star
2018-10-17  2:46   ` Zeng, Star

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181016054335.47460-6-ruiyu.ni@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox