Skip to content

Commit c137381

Browse files
surenbaghdasaryantorvalds
authored andcommitted
mm: lock a vma before stack expansion
With recent changes necessitating mmap_lock to be held for write while expanding a stack, per-VMA locks should follow the same rules and be write-locked to prevent page faults into the VMA being expanded. Add the necessary locking. Cc: [email protected] Signed-off-by: Suren Baghdasaryan <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7fcd473 commit c137381

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/mmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,8 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address)
19771977
return -ENOMEM;
19781978
}
19791979

1980+
/* Lock the VMA before expanding to prevent concurrent page faults */
1981+
vma_start_write(vma);
19801982
/*
19811983
* vma->vm_start/vm_end cannot change under us because the caller
19821984
* is required to hold the mmap_lock in read mode. We need the
@@ -2064,6 +2066,8 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address)
20642066
return -ENOMEM;
20652067
}
20662068

2069+
/* Lock the VMA before expanding to prevent concurrent page faults */
2070+
vma_start_write(vma);
20672071
/*
20682072
* vma->vm_start/vm_end cannot change under us because the caller
20692073
* is required to hold the mmap_lock in read mode. We need the

0 commit comments

Comments
 (0)