diff mbox series

arm64: pgtable: Clear the GP bit for non-executable kernel pages

Message ID 20200615154642.3579-1-will@kernel.org (mailing list archive)
State Mainlined
Commit 034aa9cd698e315c767af1bac3fd1ff8898d2cd7
Headers show
Series arm64: pgtable: Clear the GP bit for non-executable kernel pages | expand

Commit Message

Will Deacon June 15, 2020, 3:46 p.m. UTC
Commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable")
introduced 'pgprot_nx(prot)' for arm64 but colliding silently with the
BTI support during the merge window, which endeavours to clear the GP
bit for non-executable kernel mappings in set_memory_nx().

For consistency between the two APIs, clear the GP bit in pgprot_nx().

Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Will Deacon <will@kernel.org>
---
 arch/arm64/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mark Brown June 15, 2020, 4:19 p.m. UTC | #1
On Mon, Jun 15, 2020 at 04:46:42PM +0100, Will Deacon wrote:
> Commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable")
> introduced 'pgprot_nx(prot)' for arm64 but colliding silently with the
> BTI support during the merge window, which endeavours to clear the GP
> bit for non-executable kernel mappings in set_memory_nx().

Reviewed-by: Mark Brown <broonie@kernel.org>
Mark Rutland June 16, 2020, 8:45 a.m. UTC | #2
On Mon, Jun 15, 2020 at 04:46:42PM +0100, Will Deacon wrote:
> Commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable")
> introduced 'pgprot_nx(prot)' for arm64 but colliding silently with the
> BTI support during the merge window, which endeavours to clear the GP
> bit for non-executable kernel mappings in set_memory_nx().
> 
> For consistency between the two APIs, clear the GP bit in pgprot_nx().
> 
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Mark Brown <broonie@kernel.org>
> Signed-off-by: Will Deacon <will@kernel.org>
> ---
>  arch/arm64/include/asm/pgtable.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 6dbd267ab931..758e2d1577d0 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -416,7 +416,7 @@ static inline pmd_t pmd_mkdevmap(pmd_t pmd)
>  	__pgprot((pgprot_val(prot) & ~(mask)) | (bits))
>  
>  #define pgprot_nx(prot) \
> -	__pgprot_modify(prot, 0, PTE_PXN)
> +	__pgprot_modify(prot, PTE_MAYBE_GP, PTE_PXN)

Since this is just used to clear the bit, we could use PTE_GP directly
and allow the compiler to constant fold this.

Either way:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

>  
>  /*
>   * Mark the prot value as uncacheable and unbufferable.
> -- 
> 2.27.0.290.gba653c62da-goog
>
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 6dbd267ab931..758e2d1577d0 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -416,7 +416,7 @@  static inline pmd_t pmd_mkdevmap(pmd_t pmd)
 	__pgprot((pgprot_val(prot) & ~(mask)) | (bits))
 
 #define pgprot_nx(prot) \
-	__pgprot_modify(prot, 0, PTE_PXN)
+	__pgprot_modify(prot, PTE_MAYBE_GP, PTE_PXN)
 
 /*
  * Mark the prot value as uncacheable and unbufferable.