From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 B89E8820A1 for ; Wed, 8 Feb 2017 01:17:36 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 527FD3A7698; Wed, 8 Feb 2017 09:17:37 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-31.phx2.redhat.com [10.3.116.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16A406D241; Wed, 8 Feb 2017 09:17:35 +0000 (UTC) To: "Wang, Sunny (HPS SW)" , Ruiyu Ni , "edk2-devel@lists.01.org" References: <20170207025345.599532-1-ruiyu.ni@intel.com> Cc: Jeff Fan From: Laszlo Ersek Message-ID: <4c038ec5-b8a2-2f47-afd8-a58a349464de@redhat.com> Date: Wed, 8 Feb 2017 10:17:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Feb 2017 09:17:37 +0000 (UTC) Subject: Re: [PATCH] MdeModulePkg/UefiBootManagerLib: Initialize Handle before using it X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Feb 2017 09:17:36 -0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 02/08/17 09:13, Wang, Sunny (HPS SW) wrote: > Looks good to me. > Reviewed-by: Sunny Wang > > However, I saw the other potential issue below. If you also think the > potential issue is valid, you can fix this in the other patch. > We need to consider the case where MDEPKG_NDEBUG is defined. We're > using ASSERT_EFI_ERROR to handle the error status from > LocateDevicePath() in the following code block, which contains > potential bug that we still use uninitialized Handle for the case > where LocateDevicePath returns error status. > > Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle); > ASSERT_EFI_ERROR (Status); I think that Ray made a sufficient argument in the commit message why the assertion was correct -- it is indeed an assertion, and not error checking. Since the function is called when the Handle supports BlockIo or SimpleFileSystem, when there is no SimpleFileSystem installed on the Handle, BlockIo should be installed on the Handle. Perhaps the wording could be clarified, as in: ... BlockIo is *guaranteed* to be installed on the Handle. Just my two cents anyway. Laszlo > > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiyu Ni > Sent: Tuesday, February 07, 2017 10:54 AM > To: edk2-devel@lists.01.org > Cc: Jeff Fan > Subject: [edk2] [PATCH] MdeModulePkg/UefiBootManagerLib: Initialize Handle before using it > > BmExpandMediaDevicePath contains a bug that it uses the uninitialized Handle. > > Since the function is called when the Handle supports BlockIo or SimpleFileSystem, when there is no SimpleFileSystem installed on the Handle, BlockIo should be installed on the Handle. > The fix initializes the Handle by locating the BlockIo protocol from the device path. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ruiyu Ni > Cc: Jeff Fan > --- > MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > index 75bd5dc..9f99122 100644 > --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > @@ -991,9 +991,13 @@ BmExpandMediaDevicePath ( > return FileBuffer; > } > > + Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, > + &TempDevicePath, &Handle); ASSERT_EFI_ERROR (Status); > + > // > // For device boot option only pointing to the removable device handle, > - // should make sure all its children handles (its child partion or media handles) are created and connected. > + // should make sure all its children handles (its child partion or > + media handles) // are created and connected. > // > gBS->ConnectController (Handle, NULL, NULL, TRUE); > > @@ -1004,8 +1008,6 @@ BmExpandMediaDevicePath ( > // returned. After the Block IO protocol is reinstalled, subsequent > // Block IO read/write will success. > // > - Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle); > - ASSERT_EFI_ERROR (Status); > Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo); > ASSERT_EFI_ERROR (Status); > Buffer = AllocatePool (BlockIo->Media->BlockSize); > -- > 2.9.0.windows.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel >