Messages in this thread Patch in this message | | | Date | Wed, 23 Sep 2015 17:34:16 +0200 | From | Oleg Nesterov <> | Subject | Re: Multiple potential races on vma->vm_flags |
| |
On 09/11, Kirill A. Shutemov wrote: > > This one is tricky. I *assume* the mm cannot be generally accessible after > mm_users drops to zero, but I'm not entirely sure about it. > procfs? ptrace?
Well, all I can say is that proc/ptrace look fine afaics...
This is off-topic, but how about the patch below? Different threads can expand different vma's at the same time under read_lock(mmap_sem), so vma_lock_anon_vma() can't help to serialize "locked_vm += grow".
Oleg.
--- x/mm/mmap.c +++ x/mm/mmap.c @@ -2146,9 +2146,6 @@ static int acct_stack_growth(struct vm_a if (security_vm_enough_memory_mm(mm, grow)) return -ENOMEM; - /* Ok, everything looks good - let it rip */ - if (vma->vm_flags & VM_LOCKED) - mm->locked_vm += grow; vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow); return 0; } @@ -2210,6 +2207,8 @@ int expand_upwards(struct vm_area_struct * against concurrent vma expansions. */ spin_lock(&vma->vm_mm->page_table_lock); + if (vma->vm_flags & VM_LOCKED) + mm->locked_vm += grow; anon_vma_interval_tree_pre_update_vma(vma); vma->vm_end = address; anon_vma_interval_tree_post_update_vma(vma); @@ -2281,6 +2280,8 @@ int expand_downwards(struct vm_area_stru * against concurrent vma expansions. */ spin_lock(&vma->vm_mm->page_table_lock); + if (vma->vm_flags & VM_LOCKED) + mm->locked_vm += grow; anon_vma_interval_tree_pre_update_vma(vma); vma->vm_start = address; vma->vm_pgoff -= grow;
| |