Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit d0653d6

Browse files
heatdTreehugger Robot
authored andcommitted
UPSTREAM: mm/mprotect: replace can_modify_mm with can_modify_vma
Avoid taking an extra trip down the mmap tree by checking the vmas directly. mprotect (per POSIX) tolerates partial failure. Link: https://lkml.kernel.org/r/[email protected] Change-Id: I519796354b9c88444854e53a8eea105e3e824010 Signed-off-by: Pedro Falcato <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Cc: Jeff Xu <[email protected]> Cc: Kees Cook <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]> (cherry picked from commit 4a2dd02)
1 parent 4b1c79a commit d0653d6

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

mm/mprotect.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb,
587587
pgoff_t pgoff;
588588
int error;
589589

590+
if (!can_modify_vma(vma))
591+
return -EPERM;
592+
590593
if (newflags == oldflags) {
591594
*pprev = vma;
592595
return 0;
@@ -756,15 +759,6 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
756759
}
757760
}
758761

759-
/*
760-
* checking if memory is sealed.
761-
* can_modify_mm assumes we have acquired the lock on MM.
762-
*/
763-
if (unlikely(!can_modify_mm(current->mm, start, end))) {
764-
error = -EPERM;
765-
goto out;
766-
}
767-
768762
prev = vma_prev(&vmi);
769763
if (start > vma->vm_start)
770764
prev = vma;

0 commit comments

Comments
 (0)