From nobody Sun Apr 28 23:19:24 2024 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 1510942755071153.10359133589668; Fri, 17 Nov 2017 10:19:15 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8610C21B00DD4; Fri, 17 Nov 2017 10:15:01 -0800 (PST) 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 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 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=192.55.52.93; helo=mga11.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,410,1505804400"; d="scan'208";a="2820436" From: Michael D Kinney To: edk2-devel@lists.01.org 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: [edk2] [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: , 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 Reviewed-by: Star Zeng --- 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 From nobody Sun Apr 28 23:19:24 2024 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 1510942757734127.41755290069045; Fri, 17 Nov 2017 10:19:17 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C1AA821B00DE2; Fri, 17 Nov 2017 10:15:01 -0800 (PST) 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 A3ABA2035BB1E 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 Received: from mdkinney-mobl2.amr.corp.intel.com ([10.241.98.51]) by fmsmga004.fm.intel.com with ESMTP; 17 Nov 2017 10:19:11 -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=192.55.52.93; helo=mga11.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,410,1505804400"; d="scan'208";a="2820444" From: Michael D Kinney To: edk2-devel@lists.01.org Date: Fri, 17 Nov 2017 10:19:06 -0800 Message-Id: <20171117181906.14380-3-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: [edk2] [Patch V4 2/2] MdeModulePkg/UsbMassStorageDxe: Check Get Max LUN status/value 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 If a USB Mass Storage device does not support the Get Max LUN command, then the USB I/O Protocol ControlTransfer() service may return an error. If an error is returned for this command, then assume that the device does not support multiple LUNs and return a maximum LUN value of 0. The USB Mass Storage Class Specification states that a maximum LUN value larger than 0x0F is invalid. Add a check to make sure this maximum LUN value is in this valid range, and if it is not, then assume that the device does not support multiple LUNs and return a maximum LUN value of 0. This change improves compatibility with USB FLASH drives that do not support the Get Max LUN command or return an invalid maximum LUN value. Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney Reviewed-by: Star Zeng --- .../Bus/Usb/UsbMassStorageDxe/UsbMassBot.c | 22 ++++++++++++++++++= ---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c b/MdeModul= ePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c index 4bb7222b89..477bfa7952 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c @@ -2,7 +2,7 @@ Implementation of the USB mass storage Bulk-Only Transport protocol, according to USB Mass Storage Class Bulk-Only Transport, Revision 1.0. =20 -Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 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 @@ -552,8 +552,10 @@ UsbBotGetMaxLun ( UINT32 Result; UINT32 Timeout; =20 - ASSERT (Context); - =20 + if (Context =3D=3D NULL || MaxLun =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + UsbBot =3D (USB_BOT_PROTOCOL *) Context; =20 // @@ -576,8 +578,20 @@ UsbBotGetMaxLun ( 1, &Result ); + if (EFI_ERROR (Status) || *MaxLun > USB_BOT_MAX_LUN) { + // + // If the Get LUN request returns an error or the MaxLun is larger than + // the maximum LUN value (0x0f) supported by the USB Mass Storage Class + // Bulk-Only Transport Spec, then set MaxLun to 0. + // + // This improves compatibility with USB FLASH drives that have a singl= e LUN + // and either do not return a max LUN value or return an invalid maxim= um LUN + // value. + // + *MaxLun =3D 0; + } =20 - return Status; + return EFI_SUCCESS; } =20 /** --=20 2.14.2.windows.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel