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: <Ys71P4AsGkzmoRQh@google.com>
Date:   Wed, 13 Jul 2022 09:39:27 -0700
From:   Zach O'Keefe <zokeefe@...gle.com>
To:     Souptick Joarder <jrdr.linux@...il.com>
Cc:     akpm@...ux-foundation.org, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, kernel test robot <lkp@...el.com>,
        Dan Carpenter <dan.carpenter@...cle.com>
Subject: Re: [PATCH] mm/khugepaged: Avoid possible memory leak in failure path

On Jul 13 08:11, Souptick Joarder wrote:
> From: "Souptick Joarder (HPE)" <jrdr.linux@...il.com>
> 
> smatch warnings:
> mm/khugepaged.c:2409 madvise_collapse() warn: possible memory
> leak of 'cc'
> 
> Avoiding possible memory leak.
> 
> Reported-by: kernel test robot <lkp@...el.com>
> Reported-by: Dan Carpenter <dan.carpenter@...cle.com>
> Signed-off-by: Souptick Joarder (HPE) <jrdr.linux@...il.com>
> ---
>  mm/khugepaged.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 0207fc0a5b2a..8da9e7467543 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -2397,12 +2397,6 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev,
>  	BUG_ON(vma->vm_start > start);
>  	BUG_ON(vma->vm_end < end);
>  
> -	cc = kmalloc(sizeof(*cc), GFP_KERNEL);
> -	if (!cc)
> -		return -ENOMEM;
> -	cc->is_khugepaged = false;
> -	cc->last_target_node = NUMA_NO_NODE;
> -
>  	*prev = vma;
>  
>  	/* TODO: Support file/shmem */
> @@ -2415,6 +2409,12 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev,
>  	if (!hugepage_vma_check(vma, vma->vm_flags, false, false, false))
>  		return -EINVAL;
>  
> +	cc = kmalloc(sizeof(*cc), GFP_KERNEL);
> +	if (!cc)
> +		return -ENOMEM;
> +	cc->is_khugepaged = false;
> +	cc->last_target_node = NUMA_NO_NODE;
> +
>  	mmgrab(mm);
>  	lru_add_drain_all();
>  
> -- 
> 2.25.1
> 
> 

Thanks for the fix!

I've also sent out another patch on top which addresses the actual missing
kfree()

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ