lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Tue, 21 Jun 2011 13:46:01 +0100
From:	Catalin Marinas <catalin.marinas@....com>
To:	Bernd Schubert <bernd.schubert@...m.fraunhofer.de>
Cc:	"x86@...nel.org" <x86@...nel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	Bjorn Helgaas <bjorn.helgaas@...com>
Subject: Re: [PATCH] Fix a memory leak reported by kmemleak.

On Tue, Jun 21, 2011 at 12:08:53PM +0100, Bernd Schubert wrote:
> Memory allocated by get_current_resources() will be never free'ed
> if 'pci_use_crs' is not set.
> 
> Signed-off-by: Bernd Schubert <bernd.schubert@...m.fraunhofer.de>
> ---
>  arch/x86/pci/acpi.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
> index 0972315..3ad040a 100644
> --- a/arch/x86/pci/acpi.c
> +++ b/arch/x86/pci/acpi.c
> @@ -228,8 +228,11 @@ static void add_resources(struct pci_root_info *info)
>  	int i;
>  	struct resource *res, *root, *conflict;
>  
> -	if (!pci_use_crs)
> +	if (!pci_use_crs) {
> +		kfree(info->res);
> +		kfree(info->name);
>  		return;
> +	}
>  
>  	coalesce_windows(info, IORESOURCE_MEM);
>  	coalesce_windows(info, IORESOURCE_IO);

Thanks for looking into this. I cc'ed Bjorn as he seems to be the last
one changing this file. I'm not familiar with part of the kernel, so not
sure whether info->res or info->name could be used somewhere else under
certain conditions.

An alternative patch (just to keep allocation/freeing in the same
function):

diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index 0972315..684cf82 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -228,9 +228,6 @@ static void add_resources(struct pci_root_info *info)
 	int i;
 	struct resource *res, *root, *conflict;
 
-	if (!pci_use_crs)
-		return;
-
 	coalesce_windows(info, IORESOURCE_MEM);
 	coalesce_windows(info, IORESOURCE_IO);
 
@@ -286,8 +283,11 @@ get_current_resources(struct acpi_device *device, int busnum,
 	acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
 				&info);
 
-	add_resources(&info);
-	return;
+	if (pci_use_crs) {
+		add_resources(&info);
+		return;
+	}
+	kfree(info.name);
 
 name_alloc_fail:
 	kfree(info.res);

-- 
Catalin

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ