linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: "Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Jann Horn <jannh@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: correctly reference merged VMA
Date: Mon, 9 Dec 2024 14:19:17 +0100	[thread overview]
Message-ID: <9e4c39b5-387a-428d-9353-370654337cc9@suse.cz> (raw)
In-Reply-To: <20241206215229.244413-1-lorenzo.stoakes@oracle.com>

On 12/6/24 22:52, Lorenzo Stoakes wrote:
> On second merge attempt on mmap() we incorrectly discard the possibly
> merged VMA, resulting in a possible use-after-free (and most certainly a
> reference to the wrong VMA) in this instance in the subsequent
> __mmap_complete() invocation.
> 
> Correct this mistake by reassigning vma correctly if a merge succeeds in
> this case.
> 
> Suggested-by: Jann Horn <jannh@google.com>
> Reported-by: syzbot+91cf8da9401355f946c3@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/67536a25.050a0220.a30f1.0149.GAE@google.com/
> Fixes: 5ac87a885aec ("mm: defer second attempt at merge on mmap()")

FFS, who reviewed that patch?

> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

Reviewed-by: Vlastimil Babka <vbabka@suse.cz>

(copy/pasted from "git show 5ac87a885aec")

> ---
>  mm/vma.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/vma.c b/mm/vma.c
> index 8a454a7bbc80..1ec349141f5e 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -2460,10 +2460,13 @@ unsigned long __mmap_region(struct file *file, unsigned long addr,
> 
>  	/* If flags changed, we might be able to merge, so try again. */
>  	if (map.retry_merge) {
> +		struct vm_area_struct *merged;
>  		VMG_MMAP_STATE(vmg, &map, vma);
> 
>  		vma_iter_config(map.vmi, map.addr, map.end);
> -		vma_merge_existing_range(&vmg);
> +		merged = vma_merge_existing_range(&vmg);
> +		if (merged)
> +			vma = merged;
>  	}
> 
>  	__mmap_complete(&map, vma);
> --
> 2.47.1



      parent reply	other threads:[~2024-12-09 13:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-06 21:52 Lorenzo Stoakes
2024-12-06 21:55 ` Lorenzo Stoakes
2024-12-06 22:40 ` Liam R. Howlett
2024-12-09 11:02   ` Lorenzo Stoakes
2024-12-09 13:19 ` Vlastimil Babka [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=9e4c39b5-387a-428d-9353-370654337cc9@suse.cz \
    --to=vbabka@suse.cz \
    --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=lorenzo.stoakes@oracle.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