From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=michael.d.kinney@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 5BFC12035BB1E for ; Fri, 17 Nov 2017 10:15:00 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Nov 2017 10:19:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,410,1505804400"; d="scan'208";a="2820436" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.241.98.51]) by fmsmga004.fm.intel.com with ESMTP; 17 Nov 2017 10:19:09 -0800 From: Michael D Kinney To: edk2-devel@lists.01.org Cc: Star Zeng , Eric Dong Date: Fri, 17 Nov 2017 10:19:05 -0800 Message-Id: <20171117181906.14380-2-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.14.2.windows.3 In-Reply-To: <20171117181906.14380-1-michael.d.kinney@intel.com> References: <20171117181906.14380-1-michael.d.kinney@intel.com> Subject: [Patch V4 1/2] MdeModulePkg/UsbBusDxe: Add UsbControlTransfer() error check X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Nov 2017 18:15:00 -0000 https://bugzilla.tianocore.org/show_bug.cgi?id=767 The USB I/O Protocol function ControlTransfer() has a DataLength parameter that specifies the size of the Data buffer. The UsbBusDxe module implements the USB I/O Protocol using the services of the USB2 Host Controller Protocol. The DataLength parameter in the USB2 Host Controller Protocol ControlTransfer() service is an IN OUT parameter so the number of bytes actually transferred is returned. Since the USB I/O Protocol ControlTransfer() service can not return the number of bytes actually transferred, the only option if the number of bytes actually transferred is less than the number of bytes requested is to return EFI_DEVICE_ERROR. The change fixes an issue with a USB mass storage device that responds with 0 bytes to the Get MAX LUN command. Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c index 78220222f6..7c58fe8d36 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c @@ -2,7 +2,7 @@ Usb Bus Driver Binding and Bus IO Protocol. -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
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 @@ -76,6 +76,7 @@ UsbIoControlTransfer ( USB_ENDPOINT_DESC *EpDesc; EFI_TPL OldTpl; EFI_STATUS Status; + UINTN RequestedDataLength; if (UsbStatus == NULL) { return EFI_INVALID_PARAMETER; @@ -86,6 +87,7 @@ UsbIoControlTransfer ( UsbIf = USB_INTERFACE_FROM_USBIO (This); Dev = UsbIf->Device; + RequestedDataLength = DataLength; Status = UsbHcControlTransfer ( Dev->Bus, Dev->Address, @@ -99,6 +101,18 @@ UsbIoControlTransfer ( &Dev->Translator, UsbStatus ); + // + // If the request completed sucessfully and the Direction of the request is + // EfiUsbDataIn or EfiUsbDataOut, then make sure the actual number of bytes + // transfered is the same as the number of bytes requested. If a different + // number of bytes were transfered, then return EFI_DEVICE_ERROR. + // + if (!EFI_ERROR (Status)) { + if (Direction != EfiUsbNoData && DataLength != RequestedDataLength) { + Status = EFI_DEVICE_ERROR; + goto ON_EXIT; + } + } if (EFI_ERROR (Status) || (*UsbStatus != EFI_USB_NOERROR)) { // -- 2.14.2.windows.3