Skip to contentSkip to conversation

arm64: cpufeature: make sure cpu_mitigations_off then kpti off

PATCH In review Liu Song 2 participants 3 messages Jun 16, 2022 – Jun 24, 2022 arm64

lore
Share & tools
lore

Liu Song

author
#0 lore raw

PATCH 1/1 arm64: cpufeature: make sure cpu_mitigations_off then kpti off

From: Liu Song <[email protected]>

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".

---
 arch/arm64/kernel/cpufeature.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm64/kernel/cpufeature.c +5 -5
index 42ea2bd..27d4850 100644
@@ -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;
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 27 lines · Liu Song

From: Liu Song <[email protected]>

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".

---
 arch/arm64/kernel/cpufeature.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm64/kernel/cpufeature.c +5 -0
index 42ea2bd..27d4850 100644
@@ -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) {

arch/arm64/kernel/cpufeature.c static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, · line 1630

Quoted 7 lines
arch/arm64/kernel/cpufeature.c +0 -4
@@ -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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#2 lore raw
Quoted 39 lines · Liu Song
Quoted 27 lines

From: Liu Song <[email protected]>

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".

---
 arch/arm64/kernel/cpufeature.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm64/kernel/cpufeature.c +5 -0
index 42ea2bd..27d4850 100644
@@ -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) {

arch/arm64/kernel/cpufeature.c static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, · line 1630

Quoted 7 lines
arch/arm64/kernel/cpufeature.c +0 -4
@@ -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.

Quoted 1 line

Will

Hi

According to the description of mitigaions=off in kernel-parameters.txt, it is equivalent to kpti=0 under ARM64, so the description here will mislead users. I have proposed a patch to fix this.

Thanks