Skip to content

Commit 4f7d461

Browse files
Vladimir Davydovtorvalds
authored andcommitted
fork: copy mm's vm usage counters under mmap_sem
If a forking process has a thread calling (un)mmap (silly but still), the child process may have some of its mm's vm usage counters (total_vm and friends) screwed up, because currently they are copied from oldmm w/o holding any locks (memcpy in dup_mm). This patch moves the counters initialization to dup_mmap() to be called under oldmm->mmap_sem, which eliminates any possibility of race. Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: David Rientjes <rientjes@google.com> Cc: Christoph Lameter <cl@linux.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ce65cef commit 4f7d461

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎kernel/fork.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
374374
*/
375375
down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING);
376376

377+
mm->total_vm = oldmm->total_vm;
378+
mm->shared_vm = oldmm->shared_vm;
379+
mm->exec_vm = oldmm->exec_vm;
380+
mm->stack_vm = oldmm->stack_vm;
381+
377382
rb_link = &mm->mm_rb.rb_node;
378383
rb_parent = NULL;
379384
pprev = &mm->mmap;

0 commit comments

Comments
 (0)