Skip to content

Commit 6db73f1

Browse files
thomashvmwsuryasaimadhu
authored andcommitted
x86: Don't let pgprot_modify() change the page encryption bit
When SEV or SME is enabled and active, vm_get_page_prot() typically returns with the encryption bit set. This means that users of pgprot_modify(, vm_get_page_prot()) (mprotect_fixup(), do_mmap()) end up with a value of vma->vm_pg_prot that is not consistent with the intended protection of the PTEs. This is also important for fault handlers that rely on the VMA vm_page_prot to set the page protection. Fix this by not allowing pgprot_modify() to change the encryption bit, similar to how it's done for PAT bits. Signed-off-by: Thomas Hellstrom <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Acked-by: Tom Lendacky <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6a9feaa commit 6db73f1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,15 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
627627
return __pmd(val);
628628
}
629629

630-
/* mprotect needs to preserve PAT bits when updating vm_page_prot */
630+
/*
631+
* mprotect needs to preserve PAT and encryption bits when updating
632+
* vm_page_prot
633+
*/
631634
#define pgprot_modify pgprot_modify
632635
static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
633636
{
634637
pgprotval_t preservebits = pgprot_val(oldprot) & _PAGE_CHG_MASK;
635-
pgprotval_t addbits = pgprot_val(newprot);
638+
pgprotval_t addbits = pgprot_val(newprot) & ~_PAGE_CHG_MASK;
636639
return __pgprot(preservebits | addbits);
637640
}
638641

arch/x86/include/asm/pgtable_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
*/
119119
#define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \
120120
_PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY | \
121-
_PAGE_SOFT_DIRTY | _PAGE_DEVMAP)
121+
_PAGE_SOFT_DIRTY | _PAGE_DEVMAP | _PAGE_ENC)
122122
#define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE)
123123

124124
/*

0 commit comments

Comments
 (0)