From: "Jan Beulich" Subject: Re: [PATCH for-4.5 V6 13/14] Fix freeing of uninitialized pointer Date: Wed, 24 Sep 2014 10:07:50 +0100 Message-ID: <5422A606020000780003819D@mail.emea.novell.com> References: <1411534992-27443-1-git-send-email-roy.franz@linaro.org> <1411534992-27443-14-git-send-email-roy.franz@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1411534992-27443-14-git-send-email-roy.franz@linaro.org> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Roy Franz Cc: keir@xen.org, ian.campbell@citrix.com, tim@xen.org, xen-devel@lists.xen.org, stefano.stabellini@citrix.com, fu.wei@linaro.org List-Id: xen-devel@lists.xenproject.org >>> On 24.09.14 at 07:03, wrote: > The only valid response from the LocateHandle() call is EFI_BUFFER_TOO_SMALL, > so exit if we get anything else. We pass a 0 size/NULL pointer buffer, so the > only other returns we will get is an error. Return right away as there is > nothing to do. Also return if there is an error allocating the buffer, as the > previous code path also allowed for an undefined pointer to be freed. > > Signed-off-by: Roy Franz Thanks, but I restructured the patch (see below). Additionally such bug fixes would better be placed at the start of a series to ease backporting. Jan x86/EFI: fix freeing of uninitialized pointer The only valid response from the LocateHandle() call is EFI_BUFFER_TOO_SMALL, so exit if we get anything else. We pass a 0 size/NULL pointer buffer, so the only other returns we will get is an error. Return right away as there is nothing to do. Also return if there is an error allocating the buffer, as the previous code path also allowed for an undefined pointer to be freed. Signed-off-by: Roy Franz Re-structure the change. Signed-off-by: Jan Beulich --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -595,11 +595,12 @@ static void __init setup_efi_pci(void) struct efi_pci_rom *last = NULL; status = efi_bs->LocateHandle(ByProtocol, &pci_guid, NULL, &size, NULL); - if ( status == EFI_BUFFER_TOO_SMALL ) - status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles); - if ( !EFI_ERROR(status) ) - status = efi_bs->LocateHandle(ByProtocol, &pci_guid, NULL, &size, - handles); + if ( status != EFI_BUFFER_TOO_SMALL ) + return; + status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles); + if ( EFI_ERROR(status) ) + return; + status = efi_bs->LocateHandle(ByProtocol, &pci_guid, NULL, &size, handles); if ( EFI_ERROR(status) ) size = 0;