Skip to contentSkip to conversation

x86/cpu: Fix check for RDPKRU in __show_regs()

PATCH Applied [email protected] 2 participants 2 messages Apr 21, 2024 – Apr 24, 2024 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/cpu: Fix check for RDPKRU in __show_regs()

From: David Kaplan <[email protected]>

cpu_feature_enabled(X86_FEATURE_OSPKE) does not necessarily reflect whether CR4.PKE is set on the CPU. In particular, they may differ on non-BSP CPUs before setup_pku() is executed. In this scenario, RDPKRU will #UD causing the system to hang.

Fix by checking CR4 for PKE enablement which is always correct for the current CPU.

The scenario happens by inserting a WARN* before setup_pku() in identiy_cpu() or some other diagnostic which would lead to calling __show_regs().

[ bp: Massage commit message. ]

---
 arch/x86/kernel/process_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/process_64.c +1 -1
index 7062b84dd467..6d3d20e3e43a 100644
@@ -139,7 +139,7 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
 		       log_lvl, d3, d6, d7);
 	}
 
-	if (cpu_feature_enabled(X86_FEATURE_OSPKE))
+	if (cr4 & X86_CR4_PKE)
 		printk("%sPKRU: %08x\n", log_lvl, read_pkru());
 }
 
Signature · 1 line
2.43.0
merge bot Applied
#1 lore raw
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     b53c6bd5d271d023857174b8fd3e32f98ae51372
Gitweb:        https://git.kernel.org/tip/b53c6bd5d271d023857174b8fd3e32f98ae51372
Author:        David Kaplan <[email protected]>
AuthorDate:    Sun, 21 Apr 2024 21:17:28 +02:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Wed, 24 Apr 2024 14:30:21 +02:00

x86/cpu: Fix check for RDPKRU in __show_regs()

cpu_feature_enabled(X86_FEATURE_OSPKE) does not necessarily reflect whether CR4.PKE is set on the CPU. In particular, they may differ on non-BSP CPUs before setup_pku() is executed. In this scenario, RDPKRU will #UD causing the system to hang.

Fix by checking CR4 for PKE enablement which is always correct for the current CPU.

The scenario happens by inserting a WARN* before setup_pku() in identiy_cpu() or some other diagnostic which would lead to calling __show_regs().

[ bp: Massage commit message. ]

---
 arch/x86/kernel/process_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/process_64.c +1 -1
index 7062b84..6d3d20e 100644
@@ -139,7 +139,7 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
 		       log_lvl, d3, d6, d7);
 	}
 
-	if (cpu_feature_enabled(X86_FEATURE_OSPKE))
+	if (cr4 & X86_CR4_PKE)
 		printk("%sPKRU: %08x\n", log_lvl, read_pkru());
 }