Message ID | 20210316151054.5405-17-yu-cheng.yu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Control-flow Enforcement: Shadow Stack | expand |
On Tue, Mar 16, 2021 at 08:10:42AM -0700, Yu-cheng Yu wrote: > When serving a page fault, maybe_mkwrite() makes a PTE writable if it is in > a writable vma. A shadow stack vma is writable, but its PTEs need > _PAGE_DIRTY to be set to become writable. For this reason, maybe_mkwrite() > has been updated. > > There are a few places that call pte_mkwrite() directly, but effect the > same result as from maybe_mkwrite(). These sites need to be updated for s/effect the same result/have the same result/ > shadow stack as well. Thus, change them to maybe_mkwrite(): > > - do_anonymous_page() and migrate_vma_insert_page() check VM_WRITE directly > and call pte_mkwrite(), which is the same as maybe_mkwrite(). Change > them to maybe_mkwrite(). > > - In do_numa_page(), if the numa entry 'was-writable', then pte_mkwrite() You can simply say "was writable" instead of trying to hint at the variable there. > is called directly. Fix it by doing maybe_mkwrite(). > > - In change_pte_range(), pte_mkwrite() is called directly. Replace it with > maybe_mkwrite(). > > A shadow stack vma is writable but has different vma > flags, and handled accordingly in maybe_mkwrite(). > > Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com> > Reviewed-by: Kees Cook <keescook@chromium.org> > --- > mm/memory.c | 5 ++--- > mm/migrate.c | 3 +-- > mm/mprotect.c | 2 +- > 3 files changed, 4 insertions(+), 6 deletions(-) As with the previous one, I guess this one needs a mm person ACK. I mean, it is pretty obvious but still... Thx.
On Thu, Mar 18, 2021 at 10:47:40AM +0100, Borislav Petkov wrote: > As with the previous one, I guess this one needs a mm person ACK. I > mean, it is pretty obvious but still... And that needs to happen for all mm patches in here.
diff --git a/mm/memory.c b/mm/memory.c index 5efa07fb6cdc..c70c3847f79d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3561,8 +3561,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) __SetPageUptodate(page); entry = mk_pte(page, vma->vm_page_prot); - if (vma->vm_flags & VM_WRITE) - entry = pte_mkwrite(pte_mkdirty(entry)); + entry = maybe_mkwrite(pte_mkdirty(entry), vma); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); @@ -4125,7 +4124,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) pte = pte_modify(old_pte, vma->vm_page_prot); pte = pte_mkyoung(pte); if (was_writable) - pte = pte_mkwrite(pte); + pte = maybe_mkwrite(pte, vma); ptep_modify_prot_commit(vma, vmf->address, vmf->pte, old_pte, pte); update_mmu_cache(vma, vmf->address, vmf->pte); diff --git a/mm/migrate.c b/mm/migrate.c index 62b81d5257aa..7251c88a3d64 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2976,8 +2976,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, } } else { entry = mk_pte(page, vma->vm_page_prot); - if (vma->vm_flags & VM_WRITE) - entry = pte_mkwrite(pte_mkdirty(entry)); + entry = maybe_mkwrite(pte_mkdirty(entry), vma); } ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl); diff --git a/mm/mprotect.c b/mm/mprotect.c index 94188df1ee55..c1ce78d688b6 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -135,7 +135,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, if (dirty_accountable && pte_dirty(ptent) && (pte_soft_dirty(ptent) || !(vma->vm_flags & VM_SOFTDIRTY))) { - ptent = pte_mkwrite(ptent); + ptent = maybe_mkwrite(ptent, vma); } ptep_modify_prot_commit(vma, addr, pte, oldpte, ptent); pages++;