Skip to content

Commit 70bca13

Browse files
committed
mm: lock newly mapped VMA which can be modified after it becomes visible
JIRA: https://issues.redhat.com/browse/RHEL-48221 This patch is a backport of the following upstream commit: commit 33313a7 Author: Suren Baghdasaryan <surenb@google.com> Date: Sat Jul 8 12:12:11 2023 -0700 mm: lock newly mapped VMA which can be modified after it becomes visible mmap_region adds a newly created VMA into VMA tree and might modify it afterwards before dropping the mmap_lock. This poses a problem for page faults handled under per-VMA locks because they don't take the mmap_lock and can stumble on this VMA while it's still being modified. Currently this does not pose a problem since post-addition modifications are done only for file-backed VMAs, which are not handled under per-VMA lock. However, once support for handling file-backed page faults with per-VMA locks is added, this will become a race. Fix this by write-locking the VMA before inserting it into the VMA tree. Other places where a new VMA is added into VMA tree do not modify it after the insertion, so do not need the same 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 7874a08 commit 70bca13

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mm/mmap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,6 +2774,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
27742774
if (vma->vm_file)
27752775
i_mmap_lock_write(vma->vm_file->f_mapping);
27762776

2777+
/* Lock the VMA since it is modified after insertion into VMA tree */
2778+
vma_start_write(vma);
27772779
vma_iter_store(&vmi, vma);
27782780
mm->map_count++;
27792781
if (vma->vm_file) {

0 commit comments

Comments
 (0)