From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2699A211799D6 for ; Mon, 15 Oct 2018 22:42:36 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Oct 2018 22:42:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,387,1534834800"; d="scan'208";a="81760210" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.11]) by orsmga008.jf.intel.com with ESMTP; 15 Oct 2018 22:42:34 -0700 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Star Zeng , Jiewen Yao , Steven Shi Date: Tue, 16 Oct 2018 13:43:32 +0800 Message-Id: <20181016054335.47460-10-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 In-Reply-To: <20181016054335.47460-1-ruiyu.ni@intel.com> References: <20181016054335.47460-1-ruiyu.ni@intel.com> Subject: [PATCH v2 09/12] MdeModulePkg/UsbMouse: Don't access key codes when length is wrong X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Oct 2018 05:42:36 -0000 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 --- MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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); -- 2.16.1.windows.1