target/i386/kvm: Fix CET SSP MSR read feature check
PATCH 1/1 target/i386/kvm: Fix CET SSP MSR read feature check
kvm_get_msrs() adds U_CET and S_CET when CET shadow stacks or IBT are enabled, but it checks FEAT_7_0_EDX with the ECX-defined CPUID_7_0_ECX_CET_SHSTK bit before adding the PL0-PL3 SSP MSRs.
CPUID_7_0_ECX_CET_SHSTK belongs to FEAT_7_0_ECX. The current check therefore skips MSR_IA32_PL0_SSP through MSR_IA32_PL3_SSP even when guest shadow stacks are enabled.
kvm_put_msrs() already uses FEAT_7_0_ECX for the same shadow-stack condition. Use the same feature word in kvm_get_msrs() so QEMU does not restore CET enablement with stale or zero SSP values.
--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/kvm/kvm.c +1 -1
@@ -5021,7 +5021,7 @@ static int kvm_get_msrs(X86CPU *cpu)kvm_msr_entry_add (cpu,MSR_IA32_U_CET ,0 );kvm_msr_entry_add (cpu,MSR_IA32_S_CET ,0 ); -if (env->features[FEAT_7_0_EDX ] &CPUID_7_0_ECX_CET_SHSTK ) { +if (env->features[FEAT_7_0_ECX ] &CPUID_7_0_ECX_CET_SHSTK ) {kvm_msr_entry_add (cpu,MSR_IA32_PL0_SSP ,0 );kvm_msr_entry_add (cpu,MSR_IA32_PL1_SSP ,0 );kvm_msr_entry_add (cpu,MSR_IA32_PL2_SSP ,0 );
Signature · 1 line
2.39.5
Quoted 24 lines · Saul Freedman
kvm_get_msrs()addsU_CETandS_CETwhen CET shadow stacks or IBT are enabled, but it checksFEAT_7_0_EDXwith the ECX-definedCPUID_7_0_ECX_CET_SHSTKbit before adding the PL0-PL3 SSP MSRs.
CPUID_7_0_ECX_CET_SHSTKbelongs toFEAT_7_0_ECX. The current check therefore skipsMSR_IA32_PL0_SSPthroughMSR_IA32_PL3_SSPeven when guest shadow stacks are enabled.
kvm_put_msrs()already usesFEAT_7_0_ECXfor the same shadow-stack condition. Use the same feature word inkvm_get_msrs()so QEMU does not restore CET enablement with stale or zero SSP values.Fixes b6f85c5e4527 ("i386/kvm: Add save/restore support for CET MSRs")Signed-off-by Saul Freedman <[email protected]>--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/kvm/kvm.c +0
-0
target/i386/kvm/kvm.c static int kvm_get_msrs(X86CPU *cpu) · line 5027
Quoted 8 lines
target/i386/kvm/kvm.c +1
-1@@ -5021,7 +5021,7 @@ static int kvm_get_msrs(X86CPU *cpu)kvm_msr_entry_add (cpu,MSR_IA32_U_CET ,0 );kvm_msr_entry_add (cpu,MSR_IA32_S_CET ,0 ); -if (env->features[FEAT_7_0_EDX ] &CPUID_7_0_ECX_CET_SHSTK ) { +if (env->features[FEAT_7_0_ECX ] &CPUID_7_0_ECX_CET_SHSTK ) {kvm_msr_entry_add (cpu,MSR_IA32_PL0_SSP ,0 );kvm_msr_entry_add (cpu,MSR_IA32_PL1_SSP ,0 );kvm_msr_entry_add (cpu,MSR_IA32_PL2_SSP ,0 );
I note this huge function could be made more readable using various has_feature booleans, such:
bool has_cet_shstk = env->features[FEAT_7_0_EDX]
& CPUID_7_0_ECX_CET_SHSTK;
if (has_cet_shstk || ...) {Anyhow this patch looks correct, so:
Queued, thanks.
Paolo