From: Hugh Dickins <hughd@google.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Colin Cross <ccross@android.com>,
David Rientjes <rientjes@google.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] mm: shift VM_GROWS* check from mmap_region() to do_mmap_pgoff()
Date: Mon, 22 Jul 2013 16:30:51 -0700 (PDT) [thread overview]
Message-ID: <alpine.LNX.2.00.1307221629090.28484@eggly.anvils> (raw)
In-Reply-To: <20130720152307.GB588@redhat.com>
On Sat, 20 Jul 2013, Oleg Nesterov wrote:
> mmap() doesn't allow the non-anonymous mappings with VM_GROWS* bit set.
> In particular this means that mmap_region()->vma_merge(file, vm_flags)
> must always fail if "vm_flags & VM_GROWS" is set incorrectly.
>
> So it does not make sense to check VM_GROWS* after we already allocated
> the new vma, the only caller, do_mmap_pgoff(), which can pass this flag
> can do the check itself.
>
> And this looks a bit more correct, mmap_region() already unmapped the
> old mapping at this stage. But if mmap() is going to fail, it should
> avoid do_munmap() if possible.
>
> Note: we check VM_GROWS at the end to ensure that do_mmap_pgoff() won't
> return EINVAL in the case when it currently returns another error code.
>
> Many thanks to Hugh who nacked the buggy v1.
Aw shucks, no need for that!
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Looks fine to me now, thanks Oleg; as do your other two.
Acked-by: Hugh Dickins <hughd@google.com>
> ---
> mm/mmap.c | 10 ++++------
> 1 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index fbad7b0..92d9f54 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1302,6 +1302,8 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
>
> if (!file->f_op || !file->f_op->mmap)
> return -ENODEV;
> + if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
> + return -EINVAL;
> break;
>
> default:
> @@ -1310,6 +1312,8 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
> } else {
> switch (flags & MAP_TYPE) {
> case MAP_SHARED:
> + if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
> + return -EINVAL;
> /*
> * Ignore pgoff.
> */
> @@ -1544,11 +1548,7 @@ munmap_back:
> vma->vm_pgoff = pgoff;
> INIT_LIST_HEAD(&vma->anon_vma_chain);
>
> - error = -EINVAL; /* when rejecting VM_GROWSDOWN|VM_GROWSUP */
> -
> if (file) {
> - if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
> - goto free_vma;
> if (vm_flags & VM_DENYWRITE) {
> error = deny_write_access(file);
> if (error)
> @@ -1573,8 +1573,6 @@ munmap_back:
> pgoff = vma->vm_pgoff;
> vm_flags = vma->vm_flags;
> } else if (vm_flags & VM_SHARED) {
> - if (unlikely(vm_flags & (VM_GROWSDOWN|VM_GROWSUP)))
> - goto free_vma;
> error = shmem_zero_setup(vma);
> if (error)
> goto free_vma;
> --
> 1.5.5.1
next prev parent reply other threads:[~2013-07-22 23:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-14 16:54 [PATCH 0/3] simple mmap() cleanups Oleg Nesterov
2013-07-14 16:54 ` [PATCH 1/3] mm: shift VM_GROWS* check from mmap_region() to do_mmap_pgoff() Oleg Nesterov
2013-07-16 21:43 ` Andrew Morton
2013-07-20 2:02 ` Hugh Dickins
2013-07-20 15:22 ` [PATCH v2 0/1] " Oleg Nesterov
2013-07-20 15:23 ` [PATCH v2 1/1] " Oleg Nesterov
2013-07-22 23:30 ` Hugh Dickins [this message]
2013-07-14 16:54 ` [PATCH 2/3] mm: do_mmap_pgoff: cleanup the usage of file_inode() Oleg Nesterov
2013-07-14 16:54 ` [PATCH 3/3] mm: mmap_region: kill correct_wcount/inode, use allow_write_access() Oleg Nesterov
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=alpine.LNX.2.00.1307221629090.28484@eggly.anvils \
--to=hughd@google.com \
--cc=akpm@linux-foundation.org \
--cc=ccross@android.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=rientjes@google.com \
--cc=viro@zeniv.linux.org.uk \
/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®