[PATCH] fork: dup_mm: init vm stat counters under mmap_sem
From: Vladimir Davydov
Date: Wed Jun 18 2014 - 09:33:38 EST
If a forking process has a thread calling (un)mmap (silly but still),
the child process may have some of its mm's vm stats (total_vm and
friends) screwed up, because currently they are copied from oldmm w/o
holding any locks (see dup_mm).
This patch moves the stats initialization to dup_mmap to be called under
oldmm->mmap_sem, which eliminates any possibility of race.
Also, mm->pinned_vm is not reset on fork. Let's fix it.
Signed-off-by: Vladimir Davydov <vdavydov@xxxxxxxxxxxxx>
---
kernel/fork.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/fork.c b/kernel/fork.c
index d2799d1fc952..eaacc75da4f7 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -365,7 +365,12 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
*/
down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING);
+ mm->total_vm = oldmm->total_vm;
mm->locked_vm = 0;
+ mm->pinned_vm = 0;
+ mm->shared_vm = oldmm->shared_vm;
+ mm->exec_vm = oldmm->exec_vm;
+ mm->stack_vm = oldmm->stack_vm;
mm->mmap = NULL;
mm->vmacache_seqnum = 0;
mm->map_count = 0;
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/