[PATCH] riscv: avoid making unexpected changes to pte

Will Wang guangzhen.wang at tihchip.com
Thu Mar 3 01:21:19 PST 2022


_PAGE_CHG_MASK does not protect the pte value in pte_modify as
described. Use _PAGE_CHG_MASK to limit the value of newprot.

Signed-off-by: Guangzhen Wang <guangzhen.wang at tihchip.com>
---
 arch/riscv/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index bf204e7c1f74..dfc9cc4146d0 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -370,7 +370,7 @@ static inline int pmd_protnone(pmd_t pmd)
 /* Modify page protection bits */
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
-	return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
+	return __pte((pte_val(pte) & _PAGE_CHG_MASK) | (pgprot_val(newprot) & ~_PAGE_CHG_MASK));
 }
 
 #define pgd_ERROR(e) \
-- 
2.17.1




More information about the linux-riscv mailing list