[PATCH] riscv: avoid making unexpected changes to pte

Palmer Dabbelt palmer at dabbelt.com
Tue Mar 22 18:25:55 PDT 2022


On Thu, 03 Mar 2022 01:21:19 PST (-0800), guangzhen.wang at tihchip.com wrote:
> _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) \

This seems like it's a bug it whatever's calling this.  IMO it'd be 
better to fix the caller rather than just silently throwing away some 
bits.  Do you have any more information on how this is manifesting a 
bug?



More information about the linux-riscv mailing list