Skip to content

Commit 7874a08

Browse files
committed
mm: lock a vma before stack expansion
JIRA: https://issues.redhat.com/browse/RHEL-48221 This patch is a backport of the following upstream commit: commit c137381 Author: Suren Baghdasaryan <surenb@google.com> Date: Sat Jul 8 12:12:10 2023 -0700 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: stable@vger.kernel.org Signed-off-by: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Rafael Aquini <aquini@redhat.com>
1 parent 6f66ad6 commit 7874a08

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
@@ -2023,6 +2023,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
20232023
return -ENOMEM;
20242024
}
20252025

2026+
/* Lock the VMA before expanding to prevent concurrent page faults */
2027+
vma_start_write(vma);
20262028
/*
20272029
* vma->vm_start/vm_end cannot change under us because the caller
20282030
* is required to hold the mmap_lock in read mode. We need the
@@ -2105,6 +2107,8 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address)
21052107
return -ENOMEM;
21062108
}
21072109

2110+
/* Lock the VMA before expanding to prevent concurrent page faults */
2111+
vma_start_write(vma);
21082112
/*
21092113
* vma->vm_start/vm_end cannot change under us because the caller
21102114
* is required to hold the mmap_lock in read mode. We need the

0 commit comments

Comments
 (0)