Skip to content

Commit

Permalink
Revert "mm: avoid data corruption on CoW fault into PFN-mapped VMA"
Browse files Browse the repository at this point in the history
This reverts commit e7466cc.
  • Loading branch information
xyz-sundram committed Jan 23, 2024
1 parent b3879e0 commit 9150207
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2173,11 +2173,11 @@ static inline bool cow_user_page(struct page *dst, struct page *src,
* On architectures with software "accessed" bits, we would
* take a double page fault, so mark it accessed here.
*/
if (arch_faults_on_old_pte() && !pte_young(vmf->orig_pte)) {
force_mkyoung = arch_faults_on_old_pte() && !pte_young(vmf->orig_pte);
if (force_mkyoung) {
pte_t entry;

vmf->pte = pte_offset_map_lock(mm, vmf->pmd, addr, &vmf->ptl);
locked = true;
if (!likely(pte_same(*vmf->pte, vmf->orig_pte))) {
/*
* Other thread has already handled the fault
Expand All @@ -2201,31 +2201,12 @@ static inline bool cow_user_page(struct page *dst, struct page *src,
* zeroes.
*/
if (__copy_from_user_inatomic(kaddr, uaddr, PAGE_SIZE)) {
if (locked)
goto warn;

/* Re-validate under PTL if the page is still mapped */
vmf->pte = pte_offset_map_lock(mm, vmf->pmd, addr, &vmf->ptl);
locked = true;
if (!likely(pte_same(*vmf->pte, vmf->orig_pte))) {
/* The PTE changed under us. Retry page fault. */
ret = false;
goto pte_unlock;
}

/*
* The same page can be mapped back since last copy attampt.
* Try to copy again under PTL.
* Give a warn in case there can be some obscure
* use-case
*/
if (__copy_from_user_inatomic(kaddr, uaddr, PAGE_SIZE)) {
/*
* Give a warn in case there can be some obscure
* use-case
*/
warn:
WARN_ON_ONCE(1);
clear_page(kaddr);
}
WARN_ON_ONCE(1);
clear_page(kaddr);
}

ret = true;
Expand Down

0 comments on commit 9150207

Please sign in to comment.