From: Andrew Morton <akpm@linux-foundation.org>
To: Michal Hocko <mhocko@kernel.org>
Cc: gang.chen.5i5j@qq.com, kirill.shutemov@linux.intel.com,
riel@redhat.com, sasha.levin@oracle.com,
gang.chen.5i5j@gmail.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: mmap: Check all failures before set values
Date: Mon, 24 Aug 2015 14:25:55 -0700 [thread overview]
Message-ID: <20150824142555.76d9cf840dcbf8bbd9489b8c@linux-foundation.org> (raw)
In-Reply-To: <20150824113212.GL17078@dhcp22.suse.cz>
On Mon, 24 Aug 2015 13:32:13 +0200 Michal Hocko <mhocko@kernel.org> wrote:
> On Mon 24-08-15 00:59:39, gang.chen.5i5j@qq.com wrote:
> > From: Chen Gang <gang.chen.5i5j@gmail.com>
> >
> > When failure occurs and return, vma->vm_pgoff is already set, which is
> > not a good idea.
>
> Why? The vma is not inserted anywhere and the failure path is supposed
> to simply free the vma.
Yes, it's pretty marginal but I suppose the code is a bit better with
the patch than without. I did this:
From: Chen Gang <gang.chen.5i5j@gmail.com>
Subject: mm/mmap.c:insert_vm_struct(): check for failure before setting values
There's no point in initializing vma->vm_pgoff if the insertion attempt
will be failing anyway. Run the checks before performing the initialization.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/mmap.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff -puN mm/mmap.c~mm-mmap-check-all-failures-before-set-values mm/mmap.c
--- a/mm/mmap.c~mm-mmap-check-all-failures-before-set-values
+++ a/mm/mmap.c
@@ -2859,6 +2859,13 @@ int insert_vm_struct(struct mm_struct *m
struct vm_area_struct *prev;
struct rb_node **rb_link, *rb_parent;
+ if (find_vma_links(mm, vma->vm_start, vma->vm_end,
+ &prev, &rb_link, &rb_parent))
+ return -ENOMEM;
+ if ((vma->vm_flags & VM_ACCOUNT) &&
+ security_vm_enough_memory_mm(mm, vma_pages(vma)))
+ return -ENOMEM;
+
/*
* The vm_pgoff of a purely anonymous vma should be irrelevant
* until its first write fault, when page's anon_vma and index
@@ -2875,12 +2882,6 @@ int insert_vm_struct(struct mm_struct *m
BUG_ON(vma->anon_vma);
vma->vm_pgoff = vma->vm_start >> PAGE_SHIFT;
}
- if (find_vma_links(mm, vma->vm_start, vma->vm_end,
- &prev, &rb_link, &rb_parent))
- return -ENOMEM;
- if ((vma->vm_flags & VM_ACCOUNT) &&
- security_vm_enough_memory_mm(mm, vma_pages(vma)))
- return -ENOMEM;
vma_link(mm, vma, prev, rb_link, rb_parent);
return 0;
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-08-24 21:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-23 16:59 gang.chen.5i5j
2015-08-24 11:32 ` Michal Hocko
[not found] ` <55DB1D94.3050404@hotmail.com>
2015-08-24 13:34 ` Chen Gang
2015-08-24 13:57 ` Michal Hocko
2015-08-24 21:54 ` Chen Gang
2015-08-25 11:35 ` Michal Hocko
[not found] ` <55DCDF7E.6080402@hotmail.com>
2015-08-25 21:33 ` Chen Gang
2015-08-24 21:25 ` Andrew Morton [this message]
[not found] ` <55DB93B2.9010705@hotmail.com>
2015-08-24 21:58 ` Chen Gang
-- strict thread matches above, loose matches on Subject: below --
2015-08-23 16:57 gang.chen.5i5j
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=20150824142555.76d9cf840dcbf8bbd9489b8c@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=gang.chen.5i5j@gmail.com \
--cc=gang.chen.5i5j@qq.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=riel@redhat.com \
--cc=sasha.levin@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