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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0j3RV-6b8sTv2GoyuSNPX863x1xp4koF7imJDgbOdWXeg@mail.gmail.com>
Date: Tue, 7 May 2024 20:57:02 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Jonathan Cameron <Jonathan.Cameron@...wei.com>
Cc: Thomas Gleixner <tglx@...utronix.de>, Peter Zijlstra <peterz@...radead.org>, linux-pm@...r.kernel.org, 
	loongarch@...ts.linux.dev, linux-acpi@...r.kernel.org, 
	linux-arch@...r.kernel.org, linux-kernel@...r.kernel.org, 
	linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.linux.dev, x86@...nel.org, 
	Russell King <linux@...linux.org.uk>, "Rafael J . Wysocki" <rafael@...nel.org>, 
	Miguel Luis <miguel.luis@...cle.com>, James Morse <james.morse@....com>, 
	Salil Mehta <salil.mehta@...wei.com>, Jean-Philippe Brucker <jean-philippe@...aro.org>, 
	Catalin Marinas <catalin.marinas@....com>, Will Deacon <will@...nel.org>, Marc Zyngier <maz@...nel.org>, 
	Hanjun Guo <guohanjun@...wei.com>, Gavin Shan <gshan@...hat.com>, Ingo Molnar <mingo@...hat.com>, 
	Borislav Petkov <bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>, linuxarm@...wei.com, 
	justin.he@....com, jianyong.wu@....com
Subject: Re: [PATCH v9 05/19] ACPI: processor: Fix memory leaks in error paths
 of processor_add()

On Tue, Apr 30, 2024 at 4:27 PM Jonathan Cameron
<Jonathan.Cameron@...wei.com> wrote:
>
> If acpi_processor_get_info() returned an error, pr and the associated
> pr->throttling.shared_cpu_map were leaked.
>
> The unwind code was in the wrong order wrt to setup, relying on
> some unwind actions having no affect (clearing variables that were
> never set etc).  That makes it harder to reason about so reorder
> and add appropriate labels to only undo what was actually set up
> in the first place.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@...wei.com>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@...el.com>

Thank you!

>
> ---
> v9: New patch in response to Gavin noticing a memory leak later in the
>     series.
> ---
>  drivers/acpi/acpi_processor.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
> index 5f062806ca40..16e36e55a560 100644
> --- a/drivers/acpi/acpi_processor.c
> +++ b/drivers/acpi/acpi_processor.c
> @@ -393,7 +393,7 @@ static int acpi_processor_add(struct acpi_device *device,
>
>         result = acpi_processor_get_info(device);
>         if (result) /* Processor is not physically present or unavailable */
> -               return result;
> +               goto err_clear_driver_data;
>
>         BUG_ON(pr->id >= nr_cpu_ids);
>
> @@ -408,7 +408,7 @@ static int acpi_processor_add(struct acpi_device *device,
>                         "BIOS reported wrong ACPI id %d for the processor\n",
>                         pr->id);
>                 /* Give up, but do not abort the namespace scan. */
> -               goto err;
> +               goto err_clear_driver_data;
>         }
>         /*
>          * processor_device_array is not cleared on errors to allow buggy BIOS
> @@ -420,12 +420,12 @@ static int acpi_processor_add(struct acpi_device *device,
>         dev = get_cpu_device(pr->id);
>         if (!dev) {
>                 result = -ENODEV;
> -               goto err;
> +               goto err_clear_per_cpu;
>         }
>
>         result = acpi_bind_one(dev, device);
>         if (result)
> -               goto err;
> +               goto err_clear_per_cpu;
>
>         pr->dev = dev;
>
> @@ -436,10 +436,11 @@ static int acpi_processor_add(struct acpi_device *device,
>         dev_err(dev, "Processor driver could not be attached\n");
>         acpi_unbind_one(dev);
>
> - err:
> -       free_cpumask_var(pr->throttling.shared_cpu_map);
> -       device->driver_data = NULL;
> + err_clear_per_cpu:
>         per_cpu(processors, pr->id) = NULL;
> + err_clear_driver_data:
> +       device->driver_data = NULL;
> +       free_cpumask_var(pr->throttling.shared_cpu_map);
>   err_free_pr:
>         kfree(pr);
>         return result;
> --
> 2.39.2
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ