All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Peter Collingbourne <pcc@google.com>
Cc: Marc Zyngier <maz@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	Catalin Marinas <catalin.marinas@arm.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] arm64: set UXN on swapper page tables
Date: Wed, 20 Jul 2022 10:56:15 +0100	[thread overview]
Message-ID: <20220720095614.GD15752@willie-the-truck> (raw)
In-Reply-To: <20220719234909.1398992-1-pcc@google.com>

On Tue, Jul 19, 2022 at 04:49:09PM -0700, Peter Collingbourne wrote:
> On a system that implements FEAT_EPAN, read/write access to the idmap
> is denied because UXN is not set on the swapper PTEs. As a result,
> idmap_kpti_install_ng_mappings panics the kernel when accessing
> __idmap_kpti_flag. Fix it by setting UXN on these PTEs.
> 
> Fixes: 18107f8a2df6 ("arm64: Support execute-only permissions with Enhanced PAN")
> Cc: <stable@vger.kernel.org> # 5.15
> Link: https://linux-review.googlesource.com/id/Ic452fa4b4f74753e54f71e61027e7222a0fae1b1
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> ---
> This fix is no longer needed since commit c3cee924bd85 ("arm64: head:
> cover entire kernel image in initial ID map"), which moved __idmap_kpti_flag
> to .data, but that commit is currently only present in next.
> 
>  arch/arm64/include/asm/kernel-pgtable.h | 4 ++--
>  arch/arm64/kernel/head.S                | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
> index 96dc0f7da258..a971d462f531 100644
> --- a/arch/arm64/include/asm/kernel-pgtable.h
> +++ b/arch/arm64/include/asm/kernel-pgtable.h
> @@ -103,8 +103,8 @@
>  /*
>   * Initial memory map attributes.
>   */
> -#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
> -#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
> +#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED | PTE_UXN)
> +#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S | PMD_SECT_UXN)
>  
>  #if ARM64_KERNEL_USES_PMD_MAPS
>  #define SWAPPER_MM_MMUFLAGS	(PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS)
> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index 6a98f1a38c29..8a93a0a7489b 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -285,7 +285,7 @@ SYM_FUNC_START_LOCAL(__create_page_tables)
>  	subs	x1, x1, #64
>  	b.ne	1b
>  
> -	mov	x7, SWAPPER_MM_MMUFLAGS
> +	mov_q	x7, SWAPPER_MM_MMUFLAGS

Heh, nice find:

Acked-by: Will Deacon <will@kernel.org>

Catalin, I guess this needs to land for 5.19 given that it's no longer
relevant after the idmap rework pending for 5.20? If it all explodes in
-next, I can merge in for-next/fixes.

Will

WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will@kernel.org>
To: Peter Collingbourne <pcc@google.com>
Cc: Marc Zyngier <maz@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	Catalin Marinas <catalin.marinas@arm.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] arm64: set UXN on swapper page tables
Date: Wed, 20 Jul 2022 10:56:15 +0100	[thread overview]
Message-ID: <20220720095614.GD15752@willie-the-truck> (raw)
In-Reply-To: <20220719234909.1398992-1-pcc@google.com>

On Tue, Jul 19, 2022 at 04:49:09PM -0700, Peter Collingbourne wrote:
> On a system that implements FEAT_EPAN, read/write access to the idmap
> is denied because UXN is not set on the swapper PTEs. As a result,
> idmap_kpti_install_ng_mappings panics the kernel when accessing
> __idmap_kpti_flag. Fix it by setting UXN on these PTEs.
> 
> Fixes: 18107f8a2df6 ("arm64: Support execute-only permissions with Enhanced PAN")
> Cc: <stable@vger.kernel.org> # 5.15
> Link: https://linux-review.googlesource.com/id/Ic452fa4b4f74753e54f71e61027e7222a0fae1b1
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> ---
> This fix is no longer needed since commit c3cee924bd85 ("arm64: head:
> cover entire kernel image in initial ID map"), which moved __idmap_kpti_flag
> to .data, but that commit is currently only present in next.
> 
>  arch/arm64/include/asm/kernel-pgtable.h | 4 ++--
>  arch/arm64/kernel/head.S                | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
> index 96dc0f7da258..a971d462f531 100644
> --- a/arch/arm64/include/asm/kernel-pgtable.h
> +++ b/arch/arm64/include/asm/kernel-pgtable.h
> @@ -103,8 +103,8 @@
>  /*
>   * Initial memory map attributes.
>   */
> -#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
> -#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
> +#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED | PTE_UXN)
> +#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S | PMD_SECT_UXN)
>  
>  #if ARM64_KERNEL_USES_PMD_MAPS
>  #define SWAPPER_MM_MMUFLAGS	(PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS)
> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index 6a98f1a38c29..8a93a0a7489b 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -285,7 +285,7 @@ SYM_FUNC_START_LOCAL(__create_page_tables)
>  	subs	x1, x1, #64
>  	b.ne	1b
>  
> -	mov	x7, SWAPPER_MM_MMUFLAGS
> +	mov_q	x7, SWAPPER_MM_MMUFLAGS

Heh, nice find:

Acked-by: Will Deacon <will@kernel.org>

Catalin, I guess this needs to land for 5.19 given that it's no longer
relevant after the idmap rework pending for 5.20? If it all explodes in
-next, I can merge in for-next/fixes.

Will

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

  reply	other threads:[~2022-07-20  9:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 23:49 [PATCH] arm64: set UXN on swapper page tables Peter Collingbourne
2022-07-19 23:49 ` Peter Collingbourne
2022-07-20  9:56 ` Will Deacon [this message]
2022-07-20  9:56   ` Will Deacon
2022-07-20 19:04 ` Catalin Marinas
2022-07-20 19:04   ` Catalin Marinas
2022-07-21 16:19   ` Catalin Marinas
2022-07-21 16:19     ` Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220720095614.GD15752@willie-the-truck \
    --to=will@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=pcc@google.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.