linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Liu Zixian <liuzixian4@huawei.com>,
	akpm@linux-foundation.org, linmiaohe@huawei.com,
	louhongxiang@huawei.com, linux-mm@kvack.org
Cc: hushiyuan@huawei.com
Subject: Re: [PATCH] fix mmap return value when vma is merged after call_mmap()
Date: Tue, 1 Dec 2020 15:19:29 +0100	[thread overview]
Message-ID: <40c802c5-ef94-ed3b-7932-45b02cec8527@redhat.com> (raw)
In-Reply-To: <20201201132755.5076-1-liuzixian4@huawei.com>

On 01.12.20 14:27, Liu Zixian wrote:
> On success, mmap should return the begin address of newly mapped area,
> but patch "mm: mmap: merge vma after call_mmap() if possible" 
> set vm_start of newly merged vma to return value addr.
> Users of mmap will get wrong address if vma is merged after call_mmap().
> We fix this by moving the assignment to addr before merging vma.
> 
> Fixes: d70cec898324 ("mm: mmap: merge vma after call_mmap() if possible")
> 
> Signed-off-by: Liu Zixian <liuzixian4@huawei.com>
> ---
>  mm/mmap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d91ecb00d38c..9199b5e8cc1e 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1820,12 +1820,12 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
>  				 * and cause general protection fault ultimately.
>  				 */
>  				fput(vma->vm_file);
> -				vm_area_free(vma);
> -				vma = merge;
>  				/* Update vm_flags and possible addr to pick up the change. We don't
>  				 * warn here if addr changed as the vma is not linked by vma_link().
>  				 */
>  				addr = vma->vm_start;
> +				vm_area_free(vma);
> +				vma = merge;
>  				vm_flags = vma->vm_flags;
>  				goto unmap_writable;
>  			}
> 

I assume this is quite hard to trigger, right (having vm_flags change)?

"The vm_flags may be changed after call_mmap() because drivers may set
some flags for their own purpose."

Because how you describe it (returning wrong mmap address) this will
completely mess up userspace.

-- 
Thanks,

David / dhildenb



  reply	other threads:[~2020-12-01 14:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01 13:27 [PATCH] fix mmap return value when vma is merged after call_mmap() Liu Zixian
2020-12-01 14:19 ` David Hildenbrand [this message]
2020-12-01 16:06 ` Jason Gunthorpe
2020-12-03  9:01   ` Liu Zixian

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=40c802c5-ef94-ed3b-7932-45b02cec8527@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hushiyuan@huawei.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-mm@kvack.org \
    --cc=liuzixian4@huawei.com \
    --cc=louhongxiang@huawei.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;
as well as URLs for NNTP newsgroup(s).