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: Star Zeng <star.zeng@intel.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Steven Shi <steven.shi@intel.com>
Subject: [PATCH 08/11] MdeModulePkg/AbsPointer: Don't access key codes when length is wrong
Date: Mon, 15 Oct 2018 14:38:30 +0800	[thread overview]
Message-ID: <20181015063833.61304-9-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20181015063833.61304-1-ruiyu.ni@intel.com>

Per USB HID spec, the buffer holding key codes should at least 3-byte
long.
Today's code assumes that the key codes buffer length is longer than
3-byte and unconditionally accesses the key codes buffer.
It's incorrect.
The patch fixes the issue by returning Device Error when the
length is less than 3-byte.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Steven Shi <steven.shi@intel.com>
---
 .../Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c  | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
index 965195ca34..b4638961d9 100644
--- a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
+++ b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
@@ -813,8 +813,6 @@ OnMouseInterruptComplete (
     return EFI_SUCCESS;
   }
 
-  UsbMouseAbsolutePointerDevice->StateChanged = TRUE;
-
   //
   // Check mouse Data
   // USB HID Specification specifies following data format:
@@ -827,6 +825,12 @@ OnMouseInterruptComplete (
   // 2       0 to 7  Y displacement
   // 3 to n  0 to 7  Device specific (optional)
   //
+  if ((Data != NULL) && (DataLength < 3)) {
+    return EFI_DEVICE_ERROR;
+  }
+
+  UsbMouseAbsolutePointerDevice->StateChanged = TRUE;
+
   UsbMouseAbsolutePointerDevice->State.ActiveButtons = *(UINT8 *) Data & (BIT0 | BIT1 | BIT2);
 
   UsbMouseAbsolutePointerDevice->State.CurrentX =
-- 
2.16.1.windows.1



  parent reply	other threads:[~2018-10-15  6:37 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-15  6:38 [PATCH 00/11] Need to validate data from HW Ruiyu Ni
2018-10-15  6:38 ` [PATCH 01/11] MdeModulePkg/UsbMass: Merge UsbBoot(Read|Write)Blocks(16) Ruiyu Ni
2018-10-16  3:06   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 02/11] MdeModulePkg/UsbMass: Fix integer overflow when BlockSize is 1 Ruiyu Ni
2018-10-16  3:19   ` Zeng, Star
2018-10-16  3:32     ` Ni, Ruiyu
2018-10-15  6:38 ` [PATCH 03/11] MdeModulePkg/UsbBus: Fix out-of-bound read access to descriptors Ruiyu Ni
2018-10-16  3:38   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 04/11] MdeModulePkg/UsbBus: Reject descriptor whose length is bad Ruiyu Ni
2018-10-16  3:42   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 05/11] MdeModulePkg/Usb: Make sure data from HW is no more than expected Ruiyu Ni
2018-10-15 11:29   ` Wu, Hao A
2018-10-16  4:26   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 06/11] SourceLevelDebugPkg/Usb3: Make sure data from HW can fit in buffer Ruiyu Ni
2018-10-15 11:31   ` Wu, Hao A
2018-10-15  6:38 ` [PATCH 07/11] MdeModulePkg/UsbKb: Don't access key codes when length is wrong Ruiyu Ni
2018-10-16  4:52   ` Zeng, Star
2018-10-15  6:38 ` Ruiyu Ni [this message]
2018-10-16  5:01   ` [PATCH 08/11] MdeModulePkg/AbsPointer: " Zeng, Star
2018-10-15  6:38 ` [PATCH 09/11] MdeModulePkg/UsbMouse: " Ruiyu Ni
2018-10-16  5:03   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 10/11] MdeModulePkg/UsbBus: Deny when the string descriptor length is odd Ruiyu Ni
2018-10-16  5:11   ` Zeng, Star
2018-10-15  6:38 ` [PATCH 11/11] MdeModulePkg/Bus/Ufs: Ensure device not return more data than expected Ruiyu Ni
2018-10-16  5:27   ` 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=20181015063833.61304-9-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