Skip to content

Commit 5c9d2d5

Browse files
djbwtorvalds
authored andcommitted
mm: replace pte_write with pte_access_permitted in fault + gup paths
The 'access_permitted' helper is used in the gup-fast path and goes beyond the simple _PAGE_RW check to also: - validate that the mapping is writable from a protection keys standpoint - validate that the pte has _PAGE_USER set since all fault paths where pte_write is must be referencing user-memory. Link: http://lkml.kernel.org/r/151043111604.2842.8051684481794973100.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: "Jérôme Glisse" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent c7da82b commit 5c9d2d5

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address,
6666
*/
6767
static inline bool can_follow_write_pte(pte_t pte, unsigned int flags)
6868
{
69-
return pte_write(pte) ||
69+
return pte_access_permitted(pte, WRITE) ||
7070
((flags & FOLL_FORCE) && (flags & FOLL_COW) && pte_dirty(pte));
7171
}
7272

mm/hmm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,11 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp,
456456
continue;
457457
}
458458

459-
if (write_fault && !pte_write(pte))
459+
if (!pte_access_permitted(pte, write_fault))
460460
goto fault;
461461

462462
pfns[i] = hmm_pfn_t_from_pfn(pte_pfn(pte)) | flag;
463-
pfns[i] |= pte_write(pte) ? HMM_PFN_WRITE : 0;
463+
pfns[i] |= pte_access_permitted(pte, WRITE) ? HMM_PFN_WRITE : 0;
464464
continue;
465465

466466
fault:

mm/memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3948,7 +3948,7 @@ static int handle_pte_fault(struct vm_fault *vmf)
39483948
if (unlikely(!pte_same(*vmf->pte, entry)))
39493949
goto unlock;
39503950
if (vmf->flags & FAULT_FLAG_WRITE) {
3951-
if (!pte_write(entry))
3951+
if (!pte_access_permitted(entry, WRITE))
39523952
return do_wp_page(vmf);
39533953
entry = pte_mkdirty(entry);
39543954
}
@@ -4336,7 +4336,7 @@ int follow_phys(struct vm_area_struct *vma,
43364336
goto out;
43374337
pte = *ptep;
43384338

4339-
if ((flags & FOLL_WRITE) && !pte_write(pte))
4339+
if (!pte_access_permitted(pte, flags & FOLL_WRITE))
43404340
goto unlock;
43414341

43424342
*prot = pgprot_val(pte_pgprot(pte));

0 commit comments

Comments
 (0)