All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: avoid making unexpected changes to pte
@ 2022-03-03  9:21 Will Wang
  2022-03-23  1:25 ` Palmer Dabbelt
  0 siblings, 1 reply; 2+ messages in thread
From: Will Wang @ 2022-03-03  9:21 UTC (permalink / raw)
  To: paul.walmsley, palmer, aou; +Cc: linux-riscv, Will Wang

_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@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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] riscv: avoid making unexpected changes to pte
  2022-03-03  9:21 [PATCH] riscv: avoid making unexpected changes to pte Will Wang
@ 2022-03-23  1:25 ` Palmer Dabbelt
  0 siblings, 0 replies; 2+ messages in thread
From: Palmer Dabbelt @ 2022-03-23  1:25 UTC (permalink / raw)
  To: guangzhen.wang; +Cc: Paul Walmsley, aou, linux-riscv, guangzhen.wang

On Thu, 03 Mar 2022 01:21:19 PST (-0800), guangzhen.wang@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@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?

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-23  1:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-03  9:21 [PATCH] riscv: avoid making unexpected changes to pte Will Wang
2022-03-23  1:25 ` Palmer Dabbelt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.