linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Liam Howlett <liam.howlett@oracle.com>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	Muchun Song <songmuchun@bytedance.com>,
	Carlos Llamas <cmllamas@google.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] mm/mmap: undo ->mmap() when mas_preallocate() fails
Date: Tue, 18 Oct 2022 13:39:35 +0000	[thread overview]
Message-ID: <20221018133917.i2fn5vqfwqntauvk@revolver> (raw)
In-Reply-To: <20221018024945.415036-1-mike.kravetz@oracle.com>

This is for sure necessary.

Thanks Mike & Lukas.

Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>

* Mike Kravetz <mike.kravetz@oracle.com> [221017 22:49]:
> A memory leak in hugetlb_reserve_pages was reported in [1].  The root
> cause was traced to an error path in mmap_region when mas_preallocate()
> fails.  In this case, the vma is freed after a successful call to
> filesystem specific mmap.  The hugetlbfs mmap routine may allocate data
> structures pointed to by m_private_data.  These need to be cleaned up
> by the hugetlb vm_ops->close() routine.
> 
> The same issue was addressed by commit deb0f6562884 ("mm/mmap: undo
> ->mmap() when arch_validate_flags() fails") for the arch_validate_flags()
> test.  Go to the same close_and_free_vma label if mas_preallocate() fails.
> 
> [1] https://lore.kernel.org/linux-mm/CAKXUXMxf7OiCwbxib7MwfR4M1b5+b3cNTU7n5NV9Zm4967=FPQ@mail.gmail.com/
> 
> Fixes: d4af56c5c7c6 ("mm: start tracking VMAs with maple tree")
> Reported-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
>  mm/mmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index bf2122af94e7..3c9890e443a3 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2681,7 +2681,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
>  	if (mas_preallocate(&mas, vma, GFP_KERNEL)) {
>  		error = -ENOMEM;
>  		if (file)
> -			goto unmap_and_free_vma;
> +			goto close_and_free_vma;
>  		else
>  			goto free_vma;
>  	}
> -- 
> 2.37.3
> 

      reply	other threads:[~2022-10-18 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18  2:49 Mike Kravetz
2022-10-18 13:39 ` Liam Howlett [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221018133917.i2fn5vqfwqntauvk@revolver \
    --to=liam.howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=cmllamas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=mike.kravetz@oracle.com \
    --cc=songmuchun@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox