Skip to content

Commit 29417d2

Browse files
lorenzo-stoakesakpm00
authored andcommitted
mm/mmap/vma_merge: always check invariants
We may still have inconsistent input parameters even if we choose not to merge and the vma_merge() invariant checks are useful for checking this with no production runtime cost (these are only relevant when CONFIG_DEBUG_VM is specified). Therefore, perform these checks regardless of whether we merge. This is relevant, as a recent issue (addressed in commit "mm/mempolicy: Correctly update prev when policy is equal on mbind") in the mbind logic was only picked up in the 6.2.y stable branch where these assertions are performed prior to determining mergeability. Had this remained the same in mainline this issue may have been picked up faster, so moving forward let's always check them. Link: https://lkml.kernel.org/r/df548a6ae3fa135eec3b446eb3dae8eb4227da97.1682885809.git.lstoakes@gmail.com Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 418d5c9 commit 29417d2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mm/mmap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,17 +960,17 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm,
960960
merge_next = true;
961961
}
962962

963+
/* Verify some invariant that must be enforced by the caller. */
964+
VM_WARN_ON(prev && addr <= prev->vm_start);
965+
VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end));
966+
VM_WARN_ON(addr >= end);
967+
963968
if (!merge_prev && !merge_next)
964969
return NULL; /* Not mergeable. */
965970

966971
res = vma = prev;
967972
remove = remove2 = adjust = NULL;
968973

969-
/* Verify some invariant that must be enforced by the caller. */
970-
VM_WARN_ON(prev && addr <= prev->vm_start);
971-
VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end));
972-
VM_WARN_ON(addr >= end);
973-
974974
/* Can we merge both the predecessor and the successor? */
975975
if (merge_prev && merge_next &&
976976
is_mergeable_anon_vma(prev->anon_vma, next->anon_vma, NULL)) {

0 commit comments

Comments
 (0)