Re: [PATCH v2 16/39] x86/mm: Update maybe_mkwrite() for shadow stack
From: Kirill A . Shutemov
Date: Mon Oct 03 2022 - 19:53:20 EST
On Thu, Sep 29, 2022 at 03:29:13PM -0700, Rick Edgecombe wrote:
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 8cd413c5a329..fef14ab3abcb 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -981,13 +981,25 @@ void free_compound_page(struct page *page);
> * servicing faults for write access. In the normal case, do always want
> * pte_mkwrite. But get_user_pages can cause write faults for mappings
> * that do not have writing enabled, when used by access_process_vm.
> + *
> + * If a vma is shadow stack (a type of writable memory), mark the pte shadow
> + * stack.
> */
> +#ifndef maybe_mkwrite
> static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
> {
> - if (likely(vma->vm_flags & VM_WRITE))
> + if (!(vma->vm_flags & VM_WRITE))
> + goto out;
> +
> + if (vma->vm_flags & VM_SHADOW_STACK)
> + pte = pte_mkwrite_shstk(pte);
> + else
> pte = pte_mkwrite(pte);
> +
> +out:
> return pte;
> }
> +#endif
Maybe take opportunity to move it to <linux/pgtable.h>? It is really not a
place for the helper.
--
Kiryl Shutsemau / Kirill A. Shutemov