From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 BB92B2050A796 for ; Wed, 19 Apr 2017 02:17:25 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Apr 2017 02:17:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,220,1488873600"; d="scan'208";a="958647701" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga003.jf.intel.com with ESMTP; 19 Apr 2017 02:17:23 -0700 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Feng Tian , Jeff Fan , Eric Dong , Michael Turner Date: Wed, 19 Apr 2017 17:17:20 +0800 Message-Id: <20170419091720.25936-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 Subject: [PATCH] MdeModulePkg/UefiBootManagerLib: Avoid buggy USB short-form expanding 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: Wed, 19 Apr 2017 09:17:25 -0000 When a load option points to a physical UsbIo controller, whose device path contains UsbClass or UsbWwid node, old logic unconditionally treats it as a short-form device path and expands it. But the expanding gets the exactly same device path, and the device path is passed to BmGetNextLoadOptionDevicePath() which then passes this device path to BmExpandUsbDevicePath() again. This causes a infinite recursion. The patch avoids the USB short-form expanding when the device path points to a physical UsbIo controller. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Feng Tian Cc: Jeff Fan Cc: Eric Dong Cc: Michael Turner --- MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 43 ++++++++++++++---------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c index aa79c90..d684482 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -1546,26 +1546,35 @@ BmGetNextLoadOptionDevicePath ( // return BmExpandUriDevicePath (FilePath, FullPath); } else { - for (Node = FilePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) { - if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && - ((DevicePathSubType (Node) == MSG_USB_CLASS_DP) || (DevicePathSubType (Node) == MSG_USB_WWID_DP))) { - break; + Node = FilePath; + Status = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid, &Node, &Handle); + if (EFI_ERROR (Status)) { + // + // Only expand the USB WWID/Class device path + // when FilePath doesn't point to a physical UsbIo controller. + // Otherwise, infinite recursion will happen. + // + for (Node = FilePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) { + if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && + ((DevicePathSubType (Node) == MSG_USB_CLASS_DP) || (DevicePathSubType (Node) == MSG_USB_WWID_DP))) { + break; + } } - } - // - // Expand the USB WWID/Class device path - // - if (!IsDevicePathEnd (Node)) { - if (FilePath == Node) { - // - // Boot Option device path starts with USB Class or USB WWID device path. - // For Boot Option device path which doesn't begin with the USB Class or - // USB WWID device path, it's not needed to connect again here. - // - BmConnectUsbShortFormDevicePath (FilePath); + // + // Expand the USB WWID/Class device path + // + if (!IsDevicePathEnd (Node)) { + if (FilePath == Node) { + // + // Boot Option device path starts with USB Class or USB WWID device path. + // For Boot Option device path which doesn't begin with the USB Class or + // USB WWID device path, it's not needed to connect again here. + // + BmConnectUsbShortFormDevicePath (FilePath); + } + return BmExpandUsbDevicePath (FilePath, FullPath, Node); } - return BmExpandUsbDevicePath (FilePath, FullPath, Node); } } -- 2.9.0.windows.1