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]
Message-ID: <CAJZ5v0j_7y7craYxv0PiFTKOUgu+sS0mwuSnQi6-qAhRSSkGwg@mail.gmail.com>
Date:   Tue, 25 Oct 2022 17:57:20 +0200
From:   "Rafael J. Wysocki" <rafael@...nel.org>
To:     Jianglei Nie <niejianglei2021@....com>
Cc:     rafael@...nel.org, linux-pm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] PM: hibernate: Fix potential memory leak in
 hibernate_preallocate_memory() and prepare_highmem_image()

On Wed, Sep 7, 2022 at 8:43 AM Jianglei Nie <niejianglei2021@....com> wrote:
>
> hibernate_preallocate_memory() and prepare_highmem_image() allocates
> memory chunk with memory_bm_create(). When the function gets some error
> after memory_bm_create(), relavent memory should be released with
> memory_bm_free().

swsusp_free() called at the end is expected to free all of these
pages.  Doesn't it do that?

> Fix it by calling memory_bm_free() at the right time.
>
> Signed-off-by: Jianglei Nie <niejianglei2021@....com>
> ---
>  kernel/power/snapshot.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
> index 2a406753af90..e5ec204ebe22 100644
> --- a/kernel/power/snapshot.c
> +++ b/kernel/power/snapshot.c
> @@ -1752,6 +1752,7 @@ int hibernate_preallocate_memory(void)
>
>         error = memory_bm_create(&copy_bm, GFP_IMAGE, PG_ANY);
>         if (error) {
> +               memory_bm_free(&orig_bm, PG_UNSAFE_CLEAR);
>                 pr_err("Cannot allocate copy bitmap\n");
>                 goto err_out;
>         }
> @@ -2335,8 +2336,10 @@ static int prepare_highmem_image(struct memory_bitmap *bm,
>         if (memory_bm_create(bm, GFP_ATOMIC, PG_SAFE))
>                 return -ENOMEM;
>
> -       if (get_highmem_buffer(PG_SAFE))
> +       if (get_highmem_buffer(PG_SAFE)) {
> +               memory_bm_free(bm, PG_UNSAFE_CLEAR);
>                 return -ENOMEM;
> +       }
>
>         to_alloc = count_free_highmem_pages();
>         if (to_alloc > *nr_highmem_p)
> --
> 2.25.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ