All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
@ 2021-06-15  9:32 ` Anshuman Khandual
  0 siblings, 0 replies; 8+ messages in thread
From: Anshuman Khandual @ 2021-06-15  9:32 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Rutland,
	James Morse, linux-kernel

When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be
the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be
packed into the TTBR using phys_to_ttbr(), but we forget to do this in some
of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may
happen in the uaccess routines), this could result in UNPREDICTABLE
behaviour.

Since hardware with 52-bit PA support almost certainly has HW PAN, which
will be used in preference, this shouldn't be a practical issue, but let's
fix this for consistency.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Fixes: 529c4b05a3cb ("arm64: handle 52-bit addresses in TTBR")
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
Just found via code inspection. Applies on v5.13-rc6.

 arch/arm64/include/asm/mmu_context.h | 4 ++--
 arch/arm64/kernel/setup.c            | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h
index d3cef9133539..eeb210997149 100644
--- a/arch/arm64/include/asm/mmu_context.h
+++ b/arch/arm64/include/asm/mmu_context.h
@@ -177,9 +177,9 @@ static inline void update_saved_ttbr0(struct task_struct *tsk,
 		return;
 
 	if (mm == &init_mm)
-		ttbr = __pa_symbol(reserved_pg_dir);
+		ttbr = phys_to_ttbr(__pa_symbol(reserved_pg_dir));
 	else
-		ttbr = virt_to_phys(mm->pgd) | ASID(mm) << 48;
+		ttbr = phys_to_ttbr(virt_to_phys(mm->pgd)) | ASID(mm) << 48;
 
 	WRITE_ONCE(task_thread_info(tsk)->ttbr0, ttbr);
 }
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 61845c0821d9..68b30e8c22db 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -381,7 +381,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
 	 * faults in case uaccess_enable() is inadvertently called by the init
 	 * thread.
 	 */
-	init_task.thread_info.ttbr0 = __pa_symbol(reserved_pg_dir);
+	init_task.thread_info.ttbr0 = phys_to_ttbr(__pa_symbol(reserved_pg_dir));
 #endif
 
 	if (boot_args[1] || boot_args[2] || boot_args[3]) {
-- 
2.20.1


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

* [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
@ 2021-06-15  9:32 ` Anshuman Khandual
  0 siblings, 0 replies; 8+ messages in thread
From: Anshuman Khandual @ 2021-06-15  9:32 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Anshuman Khandual, Catalin Marinas, Will Deacon, Mark Rutland,
	James Morse, linux-kernel

When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be
the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be
packed into the TTBR using phys_to_ttbr(), but we forget to do this in some
of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may
happen in the uaccess routines), this could result in UNPREDICTABLE
behaviour.

Since hardware with 52-bit PA support almost certainly has HW PAN, which
will be used in preference, this shouldn't be a practical issue, but let's
fix this for consistency.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Fixes: 529c4b05a3cb ("arm64: handle 52-bit addresses in TTBR")
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
Just found via code inspection. Applies on v5.13-rc6.

 arch/arm64/include/asm/mmu_context.h | 4 ++--
 arch/arm64/kernel/setup.c            | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h
index d3cef9133539..eeb210997149 100644
--- a/arch/arm64/include/asm/mmu_context.h
+++ b/arch/arm64/include/asm/mmu_context.h
@@ -177,9 +177,9 @@ static inline void update_saved_ttbr0(struct task_struct *tsk,
 		return;
 
 	if (mm == &init_mm)
-		ttbr = __pa_symbol(reserved_pg_dir);
+		ttbr = phys_to_ttbr(__pa_symbol(reserved_pg_dir));
 	else
-		ttbr = virt_to_phys(mm->pgd) | ASID(mm) << 48;
+		ttbr = phys_to_ttbr(virt_to_phys(mm->pgd)) | ASID(mm) << 48;
 
 	WRITE_ONCE(task_thread_info(tsk)->ttbr0, ttbr);
 }
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 61845c0821d9..68b30e8c22db 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -381,7 +381,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
 	 * faults in case uaccess_enable() is inadvertently called by the init
 	 * thread.
 	 */
-	init_task.thread_info.ttbr0 = __pa_symbol(reserved_pg_dir);
+	init_task.thread_info.ttbr0 = phys_to_ttbr(__pa_symbol(reserved_pg_dir));
 #endif
 
 	if (boot_args[1] || boot_args[2] || boot_args[3]) {
-- 
2.20.1


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

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

* Re: [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
  2021-06-15  9:32 ` Anshuman Khandual
@ 2021-06-15 14:25   ` Catalin Marinas
  -1 siblings, 0 replies; 8+ messages in thread
From: Catalin Marinas @ 2021-06-15 14:25 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, Will Deacon, Mark Rutland, James Morse, linux-kernel

On Tue, Jun 15, 2021 at 03:02:58PM +0530, Anshuman Khandual wrote:
> When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be
> the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be
> packed into the TTBR using phys_to_ttbr(), but we forget to do this in some
> of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may
> happen in the uaccess routines), this could result in UNPREDICTABLE
> behaviour.
> 
> Since hardware with 52-bit PA support almost certainly has HW PAN, which
> will be used in preference, this shouldn't be a practical issue, but let's
> fix this for consistency.

I'm ok with fixing this for consistency. We should never hit those paths
unless someone built hardware with 52-bit PA (8.2) but without PAN (8.1)
and it would not be architecture compliant.

I'll leave it with Will for 5.14, it's no a fix that needs urgent
queuing.

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

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

* Re: [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
@ 2021-06-15 14:25   ` Catalin Marinas
  0 siblings, 0 replies; 8+ messages in thread
From: Catalin Marinas @ 2021-06-15 14:25 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-arm-kernel, Will Deacon, Mark Rutland, James Morse, linux-kernel

On Tue, Jun 15, 2021 at 03:02:58PM +0530, Anshuman Khandual wrote:
> When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be
> the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be
> packed into the TTBR using phys_to_ttbr(), but we forget to do this in some
> of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may
> happen in the uaccess routines), this could result in UNPREDICTABLE
> behaviour.
> 
> Since hardware with 52-bit PA support almost certainly has HW PAN, which
> will be used in preference, this shouldn't be a practical issue, but let's
> fix this for consistency.

I'm ok with fixing this for consistency. We should never hit those paths
unless someone built hardware with 52-bit PA (8.2) but without PAN (8.1)
and it would not be architecture compliant.

I'll leave it with Will for 5.14, it's no a fix that needs urgent
queuing.

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

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

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

* Re: [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
  2021-06-15 14:25   ` Catalin Marinas
@ 2021-06-15 14:26     ` Will Deacon
  -1 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2021-06-15 14:26 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Anshuman Khandual, linux-arm-kernel, Mark Rutland, James Morse,
	linux-kernel

On Tue, Jun 15, 2021 at 03:25:39PM +0100, Catalin Marinas wrote:
> On Tue, Jun 15, 2021 at 03:02:58PM +0530, Anshuman Khandual wrote:
> > When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be
> > the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be
> > packed into the TTBR using phys_to_ttbr(), but we forget to do this in some
> > of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may
> > happen in the uaccess routines), this could result in UNPREDICTABLE
> > behaviour.
> > 
> > Since hardware with 52-bit PA support almost certainly has HW PAN, which
> > will be used in preference, this shouldn't be a practical issue, but let's
> > fix this for consistency.
> 
> I'm ok with fixing this for consistency. We should never hit those paths
> unless someone built hardware with 52-bit PA (8.2) but without PAN (8.1)
> and it would not be architecture compliant.
> 
> I'll leave it with Will for 5.14, it's no a fix that needs urgent
> queuing.
> 
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

Cheers, I'll pick it up.

Will

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

* Re: [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
@ 2021-06-15 14:26     ` Will Deacon
  0 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2021-06-15 14:26 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Anshuman Khandual, linux-arm-kernel, Mark Rutland, James Morse,
	linux-kernel

On Tue, Jun 15, 2021 at 03:25:39PM +0100, Catalin Marinas wrote:
> On Tue, Jun 15, 2021 at 03:02:58PM +0530, Anshuman Khandual wrote:
> > When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be
> > the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be
> > packed into the TTBR using phys_to_ttbr(), but we forget to do this in some
> > of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may
> > happen in the uaccess routines), this could result in UNPREDICTABLE
> > behaviour.
> > 
> > Since hardware with 52-bit PA support almost certainly has HW PAN, which
> > will be used in preference, this shouldn't be a practical issue, but let's
> > fix this for consistency.
> 
> I'm ok with fixing this for consistency. We should never hit those paths
> unless someone built hardware with 52-bit PA (8.2) but without PAN (8.1)
> and it would not be architecture compliant.
> 
> I'll leave it with Will for 5.14, it's no a fix that needs urgent
> queuing.
> 
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

Cheers, I'll pick it up.

Will

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

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

* Re: [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
  2021-06-15  9:32 ` Anshuman Khandual
@ 2021-06-15 19:18   ` Will Deacon
  -1 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2021-06-15 19:18 UTC (permalink / raw)
  To: linux-arm-kernel, Anshuman Khandual
  Cc: catalin.marinas, kernel-team, Will Deacon, Mark Rutland,
	linux-kernel, James Morse

On Tue, 15 Jun 2021 15:02:58 +0530, Anshuman Khandual wrote:
> When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be
> the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be
> packed into the TTBR using phys_to_ttbr(), but we forget to do this in some
> of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may
> happen in the uaccess routines), this could result in UNPREDICTABLE
> behaviour.
> 
> [...]

Applied to arm64 (for-next/mm), thanks!

[1/1] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
      https://git.kernel.org/arm64/c/9163f0113030

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

* Re: [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
@ 2021-06-15 19:18   ` Will Deacon
  0 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2021-06-15 19:18 UTC (permalink / raw)
  To: linux-arm-kernel, Anshuman Khandual
  Cc: catalin.marinas, kernel-team, Will Deacon, Mark Rutland,
	linux-kernel, James Morse

On Tue, 15 Jun 2021 15:02:58 +0530, Anshuman Khandual wrote:
> When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be
> the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be
> packed into the TTBR using phys_to_ttbr(), but we forget to do this in some
> of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may
> happen in the uaccess routines), this could result in UNPREDICTABLE
> behaviour.
> 
> [...]

Applied to arm64 (for-next/mm), thanks!

[1/1] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan
      https://git.kernel.org/arm64/c/9163f0113030

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

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

end of thread, other threads:[~2021-06-15 22:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15  9:32 [PATCH] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan Anshuman Khandual
2021-06-15  9:32 ` Anshuman Khandual
2021-06-15 14:25 ` Catalin Marinas
2021-06-15 14:25   ` Catalin Marinas
2021-06-15 14:26   ` Will Deacon
2021-06-15 14:26     ` Will Deacon
2021-06-15 19:18 ` Will Deacon
2021-06-15 19:18   ` Will Deacon

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.