From nobody Sat Dec 28 10:01:12 2024 Delivered-To: importer@patchew.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; Authentication-Results: mx.zoho.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 149631722859664.7792601970798; Thu, 1 Jun 2017 04:40:28 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E620A21AE30FD; Thu, 1 Jun 2017 04:39:22 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 DDDD521AE30EC for ; Thu, 1 Jun 2017 04:39:20 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP; 01 Jun 2017 04:40:22 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.1]) by orsmga003.jf.intel.com with ESMTP; 01 Jun 2017 04:40:21 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,279,1493708400"; d="scan'208";a="975531834" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Thu, 1 Jun 2017 19:40:15 +0800 Message-Id: <20170601114016.134288-2-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20170601114016.134288-1-ruiyu.ni@intel.com> References: <20170601114016.134288-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH v2 1/2] MdeModulePkg/UsbBus: Fix system hang when failed to uninstall UsbIo 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: Hao A Wu , Feng Tian , 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" When "reconnect -r" is typed in shell, UsbFreeInterface() is called to uninstall the UsbIo and DevicePath. But When a UsbIo is opened by a driver and that driver rejects to close the UsbIo in Stop(), the uninstall doesn't succeed. But UsbFreeInterface () frees the DevicePath memory without check whether the uninstall succeeds. It leads to the DXE core database contain a DevicePath instance but that instance's memory is freed. Assertion happens when someone calls InstallProtocol(DevicePath) because the InstallProtocol() checks all DevicePath instance to find whether the same one exits in database. We haven't seen any USB device driver which rejects to close UsbIo in Stop(), but it's very likely. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Feng Tian Cc: Star Zeng Cc: Hao A Wu Reviewed-by: Star Zeng to this patch series. --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 43 +++++++++++++++++++-------= ---- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/= Usb/UsbBusDxe/UsbEnumer.c index ea54d37c93..b0e6b835ac 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c @@ -2,7 +2,7 @@ =20 Usb bus enumeration support. =20 -Copyright (c) 2007 - 2014, 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 @@ -53,28 +53,33 @@ UsbGetEndpointDesc ( =20 @param UsbIf The USB interface to free. =20 + @retval EFI_ACCESS_DENIED The interface is still occupied. + @retval EFI_SUCCESS The interface is freed. **/ -VOID +EFI_STATUS UsbFreeInterface ( IN USB_INTERFACE *UsbIf ) { - UsbCloseHostProtoByChild (UsbIf->Device->Bus, UsbIf->Handle); + EFI_STATUS Status; =20 - gBS->UninstallMultipleProtocolInterfaces ( - UsbIf->Handle, - &gEfiDevicePathProtocolGuid, - UsbIf->DevicePath, - &gEfiUsbIoProtocolGuid, - &UsbIf->UsbIo, - NULL - ); + UsbCloseHostProtoByChild (UsbIf->Device->Bus, UsbIf->Handle); =20 - if (UsbIf->DevicePath !=3D NULL) { - FreePool (UsbIf->DevicePath); + Status =3D gBS->UninstallMultipleProtocolInterfaces ( + UsbIf->Handle, + &gEfiDevicePathProtocolGuid, UsbIf->DevicePath, + &gEfiUsbIoProtocolGuid, &UsbIf->UsbIo, + NULL + ); + if (!EFI_ERROR (Status)) { + if (UsbIf->DevicePath !=3D NULL) { + FreePool (UsbIf->DevicePath); + } + FreePool (UsbIf); + } else { + UsbOpenHostProtoByChild (UsbIf->Device->Bus, UsbIf->Handle); } - - FreePool (UsbIf); + return Status; } =20 =20 @@ -525,7 +530,13 @@ UsbRemoveConfig ( =20 Status =3D UsbDisconnectDriver (UsbIf); if (!EFI_ERROR (Status)) { - UsbFreeInterface (UsbIf); + Status =3D UsbFreeInterface (UsbIf); + if (EFI_ERROR (Status)) { + UsbConnectDriver (UsbIf); + } + } + + if (!EFI_ERROR (Status)) { Device->Interfaces[Index] =3D NULL; } else { ReturnStatus =3D Status; --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Dec 28 10:01:12 2024 Delivered-To: importer@patchew.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; Authentication-Results: mx.zoho.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 1496317230324481.64976751741415; Thu, 1 Jun 2017 04:40:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2F34221B0386F; Thu, 1 Jun 2017 04:39:23 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 CD2D521AE30FB for ; Thu, 1 Jun 2017 04:39:21 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP; 01 Jun 2017 04:40:23 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.1]) by orsmga003.jf.intel.com with ESMTP; 01 Jun 2017 04:40:22 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,279,1493708400"; d="scan'208";a="975531840" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Thu, 1 Jun 2017 19:40:16 +0800 Message-Id: <20170601114016.134288-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20170601114016.134288-1-ruiyu.ni@intel.com> References: <20170601114016.134288-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH v2 2/2] MdeModulePkg/UsbBus: Correct debug message 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: 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" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Star Zeng Reviewed-by: Star Zeng to this patch series. --- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c b/MdeModulePkg/Bus= /Usb/UsbBusDxe/UsbUtility.c index 399b7a3b60..75d9b03af0 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c @@ -2,7 +2,7 @@ =20 Wrapper function for usb host controller interface. =20 -Copyright (c) 2007 - 2010, 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 @@ -1364,10 +1364,10 @@ UsbBusRecursivelyConnectWantedUsbIo ( // // Recursively connect the wanted Usb Io handle // - DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d\n"= , (UINT32)UsbGetCurrentTpl ())); + DEBUG ((EFI_D_INFO, "UsbBusRecursivelyConnectWantedUsbIo: TPL befo= re connect is %d\n", (UINT32)UsbGetCurrentTpl ())); Status =3D gBS->ConnectController (UsbIf->Handle, NULL,= NULL, TRUE); UsbIf->IsManaged =3D (BOOLEAN)!EFI_ERROR (Status); - DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n",= (UINT32)UsbGetCurrentTpl())); + DEBUG ((EFI_D_INFO, "UsbBusRecursivelyConnectWantedUsbIo: TPL afte= r connect is %d\n", (UINT32)UsbGetCurrentTpl())); } } } --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel