Skip to content

Commit faa242b

Browse files
RichardWeiYangakpm00
authored andcommitted
mm/mlock: set the correct prev on failure
After commit 94d7d92 ("mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al."), if vma_modify_flags() return error, the vma is set to an error code. This will lead to an invalid prev be returned. Generally this shouldn't matter as the caller should treat an error as indicating state is now invalidated, however unfortunately apply_mlockall_flags() does not check for errors and assumes that mlock_fixup() correctly maintains prev even if an error were to occur. This patch fixes that assumption. [[email protected]: provide a better fix and rephrase the log] Link: https://lkml.kernel.org/r/[email protected] Fixes: 94d7d92 ("mm: abstract the vma_merge()/split_vma() pattern for mprotect() et al.") Signed-off-by: Wei Yang <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Jann Horn <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent cb6fcef commit faa242b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mm/mlock.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,17 @@ static int apply_mlockall_flags(int flags)
725725
}
726726

727727
for_each_vma(vmi, vma) {
728+
int error;
728729
vm_flags_t newflags;
729730

730731
newflags = vma->vm_flags & ~VM_LOCKED_MASK;
731732
newflags |= to_add;
732733

733-
/* Ignore errors */
734-
mlock_fixup(&vmi, vma, &prev, vma->vm_start, vma->vm_end,
735-
newflags);
734+
error = mlock_fixup(&vmi, vma, &prev, vma->vm_start, vma->vm_end,
735+
newflags);
736+
/* Ignore errors, but prev needs fixing up. */
737+
if (error)
738+
prev = vma;
736739
cond_resched();
737740
}
738741
out:

0 commit comments

Comments
 (0)