KVM: nSVM: Gate CET state copy in svm_copy_vmrun_state() on guest SHSTK
PATCH 1/1 KVM: nSVM: Gate CET state copy in svm_copy_vmrun_state() on guest SHSTK
Like nested_vmcb02_prepare_save() and nested_svm_vmexit_update_vmcb12(), svm_copy_vmrun_state() should gate copying s_cet, isst_addr, and ssp on guest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK) (i.e. the feature is advertised to the guest). Instead, copying is gated on kvm_cpu_cap_has(X86_FEATURE_SHSTK) (i.e. the host supports shadow stacks).
Check guest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK) instead of kvm_cpu_cap_has(X86_FEATURE_SHSTK) in svm_copy_vmrun_state().
--- arch/x86/kvm/svm/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/nested.c +1 -1
@@ -1248,7 +1248,7 @@ void svm_copy_vmrun_state(struct kvm_vcpu *vcpu, struct vmcb_save_area *to_save, to_save->rip = from_save->rip; to_save->cpl =0 ; -if (kvm_cpu_cap_has (X86_FEATURE_SHSTK )) { +if (guest_cpu_cap_has (vcpu,X86_FEATURE_SHSTK )) { to_save->s_cet = from_save->s_cet; to_save->isst_addr = from_save->isst_addr; to_save->ssp = from_save->ssp;
Signature · 1 line
2.56.1.703.gf848ed807c-goog
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] KVM: nSVM: undeclared vcpu in svm_copy_vmrun_state() breaks build --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] KVM: nSVM: undeclared vcpu in svm_copy_vmrun_state() breaks build
--
commit 11b89023661c173dccf1cc07088879a6b4ff0bef
Author: Jim Mattson <[email protected]>
KVM: nSVM: Gate CET state copy in svm_copy_vmrun_state() on guest SHSTK
This commit changes svm_copy_vmrun_state() to check guest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK) instead of kvm_cpu_cap_has(X86_FEATURE_SHSTK) before copying CET shadow stack fields.
arch/x86/kvm/svm/nested.c void svm_copy_vmrun_state(struct vmcb_save_area *to_save, · line 1224
Quoted 13 lines
arch/x86/kvm/svm/nested.c +1
-1@@ -1218,7 +1218,7 @@ void svm_copy_vmrun_state(struct vmcb_save_area *to_save, to_save->rip = from_save->rip; to_save->cpl =0 ; -if (kvm_cpu_cap_has (X86_FEATURE_SHSTK )) { +if (guest_cpu_cap_has (vcpu,X86_FEATURE_SHSTK )) { to_save->s_cet = from_save->s_cet; to_save->isst_addr = from_save->isst_addr; to_save->ssp = from_save->ssp;
[Severity: High]
Does this fail to build because vcpu is undeclared in svm_copy_vmrun_state()? The function only takes to_save and from_save, so its signature and callers in svm_set_nested_state(), svm_enter_smm(), and svm_leave_smm() need to pass vcpu as well.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 24 lines · On Thu, Nov 12, 2026 at 1:32 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] KVM: nSVM: undeclared vcpu insvm_copy_vmrun_state()breaks build
--commit
11b89023661c173dccf1cc07088879a6b4ff0bef
Author: Jim Mattson <[email protected]>KVM: nSVM: Gate CET state copy in
svm_copy_vmrun_state()on guest SHSTKThis commit changes
svm_copy_vmrun_state()to checkguest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK)instead ofkvm_cpu_cap_has(X86_FEATURE_SHSTK)before copying CET shadow stack fields.Quoted 8 lines
arch/x86/kvm/svm/nested.c +0
-0@@ -1218,7 +1218,7 @@ void svm_copy_vmrun_state(struct vmcb_save_area *to_save, to_save->rip = from_save->rip; to_save->cpl =0 ;
Quoted 11 lines
arch/x86/kvm/svm/nested.c void svm_copy_vmrun_state(struct kvm_vcpu *vcpu, struct vmcb_save_area *to_save, · line 1254
Quoted 5 lines
arch/x86/kvm/svm/nested.c +1
-1-if (kvm_cpu_cap_has (X86_FEATURE_SHSTK )) { +if (guest_cpu_cap_has (vcpu,X86_FEATURE_SHSTK )) { to_save->s_cet = from_save->s_cet; to_save->isst_addr = from_save->isst_addr; to_save->ssp = from_save->ssp;[Severity: High]
Does this fail to build because vcpu is undeclared insvm_copy_vmrun_state()? The function only takesto_saveandfrom_save, so its signature and callers insvm_set_nested_state(),svm_enter_smm(), andsvm_leave_smm()need to pass vcpu as well.
I should have mentioned that the base-commit isdea4f6380f4ec96e8f3b0aaf2343764bd0d25ef4.
Commit cd0e6f4d7cec ("KVM: SVM: Add a vCPU-aware helper to get supported DEBUGCTL bits") changed the signature of svm_copy_vmrun_state().
Odd that you quote me as writing:
@@ -1218,7 +1218,7 @@ void svm_copy_vmrun_state(struct vmcb_save_area *to_save,
when, in fact, I wrote:
@@ -1248,7 +1248,7 @@ void svm_copy_vmrun_state(struct kvm_vcpu *vcpu, struct vmcb_save_area *to_save,
Quoted 6 lines · Jim Mattson
Like
nested_vmcb02_prepare_save()andnested_svm_vmexit_update_vmcb12(),svm_copy_vmrun_state()should gate copyings_cet,isst_addr, and ssp onguest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK)(i.e. the feature is advertised to the guest). Instead, copying is gated onkvm_cpu_cap_has(X86_FEATURE_SHSTK)(i.e. the host supports shadow stacks).
This is a bit confusing, nested_vmcb02_prepare_save() and nested_svm_vmexit_update_vmcb12() are about vmcb12 <-> vmcb02, so L2's state, while svm_copy_vmrun_state() is for L1's state. I think the patch is correct, but the examples are confusing.
Perhaps a better example would be __kvm_set_msr() and __kvm_get_msr()?
Quoted 26 lines
Check
guest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK)instead ofkvm_cpu_cap_has(X86_FEATURE_SHSTK)insvm_copy_vmrun_state().Fixes c5ba49458513 ("KVM: nSVM: Save/load CET Shadow Stack state to/from vmcb12/vmcb02")Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/svm/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/svm/nested.c +1
-2@@ -1248,7 +1248,7 @@ void svm_copy_vmrun_state(struct kvm_vcpu *vcpu, struct vmcb_save_area *to_save, to_save->rip = from_save->rip; to_save->cpl =0 ; -if (kvm_cpu_cap_has (X86_FEATURE_SHSTK )) { +if (guest_cpu_cap_has (vcpu,X86_FEATURE_SHSTK )) { to_save->s_cet = from_save->s_cet; to_save->isst_addr = from_save->isst_addr; to_save->ssp = from_save->ssp; --2.56.1.703.gf848ed807c-goog
Quoted 9 lines · Yosry Ahmed
Quoted 6 lines · Jim Mattson
Like
nested_vmcb02_prepare_save()andnested_svm_vmexit_update_vmcb12(),svm_copy_vmrun_state()should gate copyings_cet,isst_addr, and ssp onguest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK)(i.e. the feature is advertised to the guest). Instead, copying is gated onkvm_cpu_cap_has(X86_FEATURE_SHSTK)(i.e. the host supports shadow stacks).
Quoted 6 lines
This is a bit confusing,
nested_vmcb02_prepare_save()andnested_svm_vmexit_update_vmcb12()are about vmcb12 <-> vmcb02, so L2's state, whilesvm_copy_vmrun_state()is for L1's state. I think the patch is correct, but the examples are confusing.Perhaps a better example would be
__kvm_set_msr()and__kvm_get_msr()?
Or, perhaps I should just drop the examples?
Yosry Ahmed
Reviewed-byQuoted 11 lines · Jim Mattson
Quoted 9 lines · Yosry Ahmed
Quoted 6 lines · Jim Mattson
Like
nested_vmcb02_prepare_save()andnested_svm_vmexit_update_vmcb12(),svm_copy_vmrun_state()should gate copyings_cet,isst_addr, and ssp onguest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK)(i.e. the feature is advertised to the guest). Instead, copying is gated onkvm_cpu_cap_has(X86_FEATURE_SHSTK)(i.e. the host supports shadow stacks).
Quoted 8 lines
Quoted 6 lines
This is a bit confusing,
nested_vmcb02_prepare_save()andnested_svm_vmexit_update_vmcb12()are about vmcb12 <-> vmcb02, so L2's state, whilesvm_copy_vmrun_state()is for L1's state. I think the patch is correct, but the examples are confusing.Perhaps a better example would be
__kvm_set_msr()and__kvm_get_msr()?Or, perhaps I should just drop the examples?
It's probably useful to mention that without guest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK), the MSRs cannot be set, but I am fine either way. With either changes to the changelog: