Skip to content

Commit d3cb8bf

Browse files
Mel Gormantorvalds
authored andcommitted
mm: migrate: Close race between migration completion and mprotect
A migration entry is marked as write if pte_write was true at the time the entry was created. The VMA protections are not double checked when migration entries are being removed as mprotect marks write-migration-entries as read. It means that potentially we take a spurious fault to mark PTEs write again but it's straight-forward. However, there is a race between write migrations being marked read and migrations finishing. This potentially allows a PTE to be write that should have been read. Close this race by double checking the VMA permissions using maybe_mkwrite when migration completes. [torvalds@linux-foundation.org: use maybe_mkwrite] Cc: stable@vger.kernel.org Signed-off-by: Mel Gorman <mgorman@suse.de> Acked-by: Rik van Riel <riel@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 50dddff commit d3cb8bf

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎mm/migrate.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,11 @@ static int remove_migration_pte(struct page *new, struct vm_area_struct *vma,
146146
pte = pte_mkold(mk_pte(new, vma->vm_page_prot));
147147
if (pte_swp_soft_dirty(*ptep))
148148
pte = pte_mksoft_dirty(pte);
149+
150+
/* Recheck VMA as permissions can change since migration started */
149151
if (is_write_migration_entry(entry))
150-
pte = pte_mkwrite(pte);
152+
pte = maybe_mkwrite(pte, vma);
153+
151154
#ifdef CONFIG_HUGETLB_PAGE
152155
if (PageHuge(new)) {
153156
pte = pte_mkhuge(pte);

0 commit comments

Comments
 (0)