Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64: cpufeature: make sure cpu_mitigations_off then kpti off
@ 2022-06-16 12:35 Liu Song
  2022-06-23 17:27 ` Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Song @ 2022-06-16 12:35 UTC (permalink / raw)
  To: catalin.marinas, will; +Cc: linux-arm-kernel, linux-kernel

From: Liu Song <liusong@linux.alibaba.com>

If kaslr is enabled, kpti cannot be turned off even if "mitigations=off",
adjust the code order to ensure that kpti is off when "mitigations=off".

Signed-off-by: Liu Song <liusong@linux.alibaba.com>
---
 arch/arm64/kernel/cpufeature.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 42ea2bd..27d4850 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -1616,6 +1616,11 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,
 		__kpti_forced = -1;
 	}
 
+	if (cpu_mitigations_off() && !__kpti_forced) {
+		str = "mitigations=off";
+		__kpti_forced = -1;
+	}
+
 	/* Useful for KASLR robustness */
 	if (kaslr_requires_kpti()) {
 		if (!__kpti_forced) {
@@ -1624,11 +1629,6 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,
 		}
 	}
 
-	if (cpu_mitigations_off() && !__kpti_forced) {
-		str = "mitigations=off";
-		__kpti_forced = -1;
-	}
-
 	if (!IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0)) {
 		pr_info_once("kernel page table isolation disabled by kernel configuration\n");
 		return false;
-- 
1.8.3.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] 2+ messages in thread

* Re: [PATCH] arm64: cpufeature: make sure cpu_mitigations_off then kpti off
  2022-06-16 12:35 [PATCH] arm64: cpufeature: make sure cpu_mitigations_off then kpti off Liu Song
@ 2022-06-23 17:27 ` Will Deacon
  0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2022-06-23 17:27 UTC (permalink / raw)
  To: Liu Song; +Cc: catalin.marinas, linux-arm-kernel, linux-kernel

On Thu, Jun 16, 2022 at 08:35:38PM +0800, Liu Song wrote:
> From: Liu Song <liusong@linux.alibaba.com>
> 
> If kaslr is enabled, kpti cannot be turned off even if "mitigations=off",
> adjust the code order to ensure that kpti is off when "mitigations=off".
> 
> Signed-off-by: Liu Song <liusong@linux.alibaba.com>
> ---
>  arch/arm64/kernel/cpufeature.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
> index 42ea2bd..27d4850 100644
> --- a/arch/arm64/kernel/cpufeature.c
> +++ b/arch/arm64/kernel/cpufeature.c
> @@ -1616,6 +1616,11 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,
>  		__kpti_forced = -1;
>  	}
>  
> +	if (cpu_mitigations_off() && !__kpti_forced) {
> +		str = "mitigations=off";
> +		__kpti_forced = -1;
> +	}
> +
>  	/* Useful for KASLR robustness */
>  	if (kaslr_requires_kpti()) {
>  		if (!__kpti_forced) {
> @@ -1624,11 +1629,6 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry,
>  		}
>  	}
>  
> -	if (cpu_mitigations_off() && !__kpti_forced) {
> -		str = "mitigations=off";
> -		__kpti_forced = -1;
> -	}

The current behaviour is intentional: KASLR is trivial to bypass when kpti
is disabled.

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] 2+ messages in thread

end of thread, other threads:[~2022-06-23 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-16 12:35 [PATCH] arm64: cpufeature: make sure cpu_mitigations_off then kpti off Liu Song
2022-06-23 17:27 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox