Skip to contentSkip to conversation

x86/fpu/xstate: Fix PKRU covert channel

PATCH Applied Jim Mattson 3 participants 4 messages Aug 31, 2023 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/fpu/xstate: Fix PKRU covert channel

When XCR0[9] is set, PKRU can be read and written from userspace with XSAVE and XRSTOR, even when CR4.PKE is clear.

Clear XCR0[9] when protection keys are disabled.

---
 arch/x86/kernel/fpu/xstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/fpu/xstate.c +1 -1
index 1afbc4866b10..a27b4f7b9365 100644
@@ -71,7 +71,7 @@ static unsigned short xsave_cpuid_features[] __initdata = {
 	[XFEATURE_ZMM_Hi256]			= X86_FEATURE_AVX512F,
 	[XFEATURE_Hi16_ZMM]			= X86_FEATURE_AVX512F,
 	[XFEATURE_PT_UNIMPLEMENTED_SO_FAR]	= X86_FEATURE_INTEL_PT,
-	[XFEATURE_PKRU]				= X86_FEATURE_PKU,
+	[XFEATURE_PKRU]				= X86_FEATURE_OSPKE,
 	[XFEATURE_PASID]			= X86_FEATURE_ENQCMD,
 	[XFEATURE_XTILE_CFG]			= X86_FEATURE_AMX_TILE,
 	[XFEATURE_XTILE_DATA]			= X86_FEATURE_AMX_TILE,
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jim Mattson

When XCR0[9] is set, PKRU can be read and written from userspace with XSAVE and XRSTOR, even when CR4.PKE is clear.

Clear XCR0[9] when protection keys are disabled.

Is there any way to trigger this other than "nopku" on the command-line?

I'm not sure how scary this particular covert channel is, but it does make sense to do this even if it's only to avoid wasting XSAVE space on a feature that nobody can use (for things other than covert channels).

#2 lore raw
Quoted 11 lines · Dave Hansen
Quoted 7 lines · Jim Mattson

When XCR0[9] is set, PKRU can be read and written from userspace with XSAVE and XRSTOR, even when CR4.PKE is clear.

Clear XCR0[9] when protection keys are disabled.

Is there any way to trigger this other than "nopku" on the command-line?

Or by configuration option:

CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS=n

Quoted 5 lines

I'm not sure how scary this particular covert channel is, but it does make sense to do this even if it's only to avoid wasting XSAVE space on a feature that nobody can use (for things other than covert channels).

merge bot Applied
#3 lore raw
In reply to Jim Mattson
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:     18032b47adf1db7b7f5fb2d1344e65aafe6417df
Gitweb:        https://git.kernel.org/tip/18032b47adf1db7b7f5fb2d1344e65aafe6417df
Author:        Jim Mattson <[email protected]>
AuthorDate:    Wed, 30 Aug 2023 21:32:21 -07:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 31 Aug 2023 23:29:49 +02:00

x86/fpu/xstate: Fix PKRU covert channel

When XCR0[9] is set, PKRU can be read and written from userspace with XSAVE and XRSTOR, even when CR4.PKE is clear.

Clear XCR0[9] when protection keys are disabled.

---
 arch/x86/kernel/fpu/xstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/fpu/xstate.c +1 -1
index 1afbc48..a27b4f7 100644
@@ -71,7 +71,7 @@ static unsigned short xsave_cpuid_features[] __initdata = {
 	[XFEATURE_ZMM_Hi256]			= X86_FEATURE_AVX512F,
 	[XFEATURE_Hi16_ZMM]			= X86_FEATURE_AVX512F,
 	[XFEATURE_PT_UNIMPLEMENTED_SO_FAR]	= X86_FEATURE_INTEL_PT,
-	[XFEATURE_PKRU]				= X86_FEATURE_PKU,
+	[XFEATURE_PKRU]				= X86_FEATURE_OSPKE,
 	[XFEATURE_PASID]			= X86_FEATURE_ENQCMD,
 	[XFEATURE_XTILE_CFG]			= X86_FEATURE_AMX_TILE,
 	[XFEATURE_XTILE_DATA]			= X86_FEATURE_AMX_TILE,