From nobody Wed May 14 16:50:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1510804685273301.2269255686126; Wed, 15 Nov 2017 19:58:05 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 68EFB21B00DEE; Wed, 15 Nov 2017 19:53:53 -0800 (PST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 0F7FD21B00DC4 for ; Wed, 15 Nov 2017 19:53:52 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2017 19:58:00 -0800 Received: from mdkinney-mobl2.amr.corp.intel.com ([10.241.98.51]) by fmsmga002.fm.intel.com with ESMTP; 15 Nov 2017 19:58:00 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=michael.d.kinney@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,402,1505804400"; d="scan'208";a="1244699918" From: Michael D Kinney To: edk2-devel@lists.01.org Date: Wed, 15 Nov 2017 19:57:54 -0800 Message-Id: <20171116035755.12448-2-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.14.2.windows.3 In-Reply-To: <20171116035755.12448-1-michael.d.kinney@intel.com> References: <20171116035755.12448-1-michael.d.kinney@intel.com> Subject: [edk2] [Patch V3 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: , Cc: Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.tianocore.org/show_bug.cgi?id=3D767 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 @@ =20 Usb Bus Driver Binding and Bus IO Protocol. =20 -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; =20 if (UsbStatus =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -86,6 +87,7 @@ UsbIoControlTransfer ( UsbIf =3D USB_INTERFACE_FROM_USBIO (This); Dev =3D UsbIf->Device; =20 + RequestedDataLength =3D DataLength; Status =3D 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 by= tes + // transfered is the same as the number of bytes requested. If a differ= ent + // number of bytes were transfered, then return EFI_DEVICE_ERROR. + // + if (!EFI_ERROR (Status)) { + if (Direction !=3D EfiUsbNoData && DataLength !=3D RequestedDataLength= ) { + Status =3D EFI_DEVICE_ERROR; + goto ON_EXIT; + } + } =20 if (EFI_ERROR (Status) || (*UsbStatus !=3D EFI_USB_NOERROR)) { // --=20 2.14.2.windows.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel