From: Lorenzo Stoakes <lstoakes@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Jann Horn <jannh@google.com>,
Suren Baghdasaryan <surenb@google.com>,
Matthew Wilcox <willy@infradead.org>,
stable@vger.kernel.org
Subject: Re: [PATCH v3 2/3] mmap: Fix error paths with dup_anon_vma()
Date: Mon, 2 Oct 2023 08:43:41 +0100 [thread overview]
Message-ID: <6f85e46d-78e3-426d-9a24-3aadfd91bdc6@lucifer.local> (raw)
In-Reply-To: <db77d8e7-4b29-2348-c034-3a2cf120b7b2@suse.cz>
On Mon, Oct 02, 2023 at 09:26:03AM +0200, Vlastimil Babka wrote:
> On 9/30/23 00:28, Lorenzo Stoakes wrote:
> > On Fri, Sep 29, 2023 at 02:30:40PM -0400, Liam R. Howlett wrote:
> >> When the calling function fails after the dup_anon_vma(), the
> >> duplication of the anon_vma is not being undone. Add the necessary
> >> unlink_anon_vma() call to the error paths that are missing them.
> >>
> >> This issue showed up during inspection of the error path in vma_merge()
> >> for an unrelated vma iterator issue.
> >>
> >> Users may experience increased memory usage, which may be problematic as
> >> the failure would likely be caused by a low memory situation.
> >>
> >> Fixes: d4af56c5c7c6 ("mm: start tracking VMAs with maple tree")
> >> Cc: stable@vger.kernel.org
> >> Cc: Jann Horn <jannh@google.com>
> >> Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> >> ---
> >> mm/mmap.c | 30 ++++++++++++++++++++++--------
> >> 1 file changed, 22 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/mm/mmap.c b/mm/mmap.c
> >> index acb7dea49e23..f9f0a5fe4db4 100644
> >> --- a/mm/mmap.c
> >> +++ b/mm/mmap.c
> >> @@ -583,11 +583,12 @@ static inline void vma_complete(struct vma_prepare *vp,
> >> * dup_anon_vma() - Helper function to duplicate anon_vma
> >> * @dst: The destination VMA
> >> * @src: The source VMA
> >> + * @dup: Pointer to the destination VMA when successful.
> >> *
> >> * Returns: 0 on success.
> >
> > Being a bit nitpicky/refactory here, but anon_vma_clone() appears to have
> > two possible return values - 0 for success, and -ENOMEM.
> >
> > As a result, it's not really gaining us much passing through this value.
> >
> > It'd be nice if dup_anon_vma() and anon_vma_clone() were therefore updated
> > to instead return NULL on ENOMEM and the dst otherwise.
>
> But we also need to represent that dup_anon_vma() had nothing to do, because
> "(src->anon_vma && !dst->anon_vma)" was false, and in that case we should
> not be returning dst from there?
>
> So maybe we could return NULL for that case and ERR_PTR(ret) for the -ENOMEM
> from anon_vma_clone() ?
Yeah, you're right, actually I think that would probably be the best
approach as you'd both eliminate the awkward out parameter but retain the
fact that there's 3 possible return states (dup'd, no need to dup, error).
>
> > Then we could de-clunk this whole code path, and the quite natural fact of
> > 'thing didn't return a pointer therefore had no memory to allocate it' fals
> > out.
> >
> > But this isn't exactly an earth-shattering concern :)
> >
>
next prev parent reply other threads:[~2023-10-02 7:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 18:30 [PATCH v3 0/3] Fixes for vma_merge() error path Liam R. Howlett
2023-09-29 18:30 ` [PATCH v3 1/3] mmap: Fix vma_iterator in error path of vma_merge() Liam R. Howlett
2023-09-29 22:21 ` Lorenzo Stoakes
2023-10-02 7:09 ` Vlastimil Babka
2023-09-29 18:30 ` [PATCH v3 2/3] mmap: Fix error paths with dup_anon_vma() Liam R. Howlett
2023-09-29 22:28 ` Lorenzo Stoakes
2023-10-02 7:26 ` Vlastimil Babka
2023-10-02 7:43 ` Lorenzo Stoakes [this message]
2023-10-03 14:45 ` Liam R. Howlett
2023-10-02 7:11 ` Vlastimil Babka
2023-10-03 16:21 ` Suren Baghdasaryan
2023-10-03 18:51 ` Liam R. Howlett
2023-10-03 19:40 ` Suren Baghdasaryan
2023-10-06 21:08 ` Andrew Morton
2023-10-06 21:32 ` Suren Baghdasaryan
2023-09-29 18:30 ` [PATCH v3 3/3] mmap: Add clarifying comment to vma_merge() code Liam R. Howlett
2023-09-29 22:30 ` Lorenzo Stoakes
2023-10-02 7:11 ` Vlastimil Babka
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=6f85e46d-78e3-426d-9a24-3aadfd91bdc6@lucifer.local \
--to=lstoakes@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/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
all inboxes | Powered by JetHome®