Skip to content

Commit b497e52

Browse files
committed
x86/mm: Teach pte_mkwrite() about stack memory
If a VMA has the VM_SHADOW_STACK flag, it is shadow stack memory. So when it is made writable with pte_mkwrite(), it should create shadow stack memory, not conventionally writable memory. Now that all the places where shadow stack memory might be created pass a VMA into pte_mkwrite(), it can know when it should do this. So make pte_mkwrite() create shadow stack memory when the VMA has the VM_SHADOW_STACK flag. Do the same thing for pmd_mkwrite(). This requires referencing VM_SHADOW_STACK in these functions, which are currently defined in pgtable.h, however mm.h (where VM_SHADOW_STACK is located) can't be pulled in without causing problems for files that reference pgtable.h. So also move pte/pmd_mkwrite() into pgtable.c, where they can safely reference VM_SHADOW_STACK. Signed-off-by: Rick Edgecombe <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Mike Rapoport (IBM) <[email protected]> Acked-by: Deepak Gupta <[email protected]> Tested-by: Pengfei Xu <[email protected]> Tested-by: John Allen <[email protected]> Tested-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/all/20230613001108.3040476-22-rick.p.edgecombe%40intel.com
1 parent 29f890d commit b497e52

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

arch/x86/mm/pgtable.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,13 +875,19 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
875875

876876
pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma)
877877
{
878+
if (vma->vm_flags & VM_SHADOW_STACK)
879+
return pte_mkwrite_shstk(pte);
880+
878881
pte = pte_mkwrite_novma(pte);
879882

880883
return pte_clear_saveddirty(pte);
881884
}
882885

883886
pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma)
884887
{
888+
if (vma->vm_flags & VM_SHADOW_STACK)
889+
return pmd_mkwrite_shstk(pmd);
890+
885891
pmd = pmd_mkwrite_novma(pmd);
886892

887893
return pmd_clear_saveddirty(pmd);

0 commit comments

Comments
 (0)