From: Ruiyu Ni Date: Thu, 13 Sep 2018 08:09:10 +0000 (+0800) Subject: MdeModulePkg/UsbMouse: Don't access key codes when length is wrong X-Git-Tag: edk2-stable201903~809 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=6c46cbbd5e3e2db7f14c007482e062b90c73c70f MdeModulePkg/UsbMouse: Don't access key codes when length is wrong 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 Cc: Star Zeng Cc: Jiewen Yao Cc: Steven Shi Reviewed-by: Star Zeng --- diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c index 9324994975..f4448bffe6 100644 --- a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c +++ b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c @@ -811,8 +811,6 @@ OnMouseInterruptComplete ( return EFI_SUCCESS; } - UsbMouseDevice->StateChanged = TRUE; - // // Check mouse Data // USB HID Specification specifies following data format: @@ -825,6 +823,12 @@ OnMouseInterruptComplete ( // 2 0 to 7 Y displacement // 3 to n 0 to 7 Device specific (optional) // + if (DataLength < 3) { + return EFI_DEVICE_ERROR; + } + + UsbMouseDevice->StateChanged = TRUE; + UsbMouseDevice->State.LeftButton = (BOOLEAN) ((*(UINT8 *) Data & BIT0) != 0); UsbMouseDevice->State.RightButton = (BOOLEAN) ((*(UINT8 *) Data & BIT1) != 0); UsbMouseDevice->State.RelativeMovementX += *((INT8 *) Data + 1);