2019-01-03 00:22:57

by David Rientjes

[permalink] [raw]
Subject: [patch] kvm: sev: Fail KVM_SEV_INIT if already initialized

By code inspection, it was found that multiple calls to KVM_SEV_INIT
could deplete asid bits and overwrite kvm_sev_info's regions_list.

Multiple calls to KVM_SVM_INIT is not likely to occur with QEMU, but this
should likely be fixed anyway.

This code is serialized by kvm->lock.

Fixes: 1654efcbc431 ("KVM: SVM: Add KVM_SEV_INIT command")
Reported-by: Cfir Cohen <[email protected]>
Signed-off-by: David Rientjes <[email protected]>
---
arch/x86/kvm/svm.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -6278,6 +6278,9 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp)
int asid, ret;

ret = -EBUSY;
+ if (unlikely(sev->active))
+ return ret;
+
asid = sev_asid_new();
if (asid < 0)
return ret;


2019-01-03 02:13:28

by Brijesh Singh

[permalink] [raw]
Subject: Re: [patch] kvm: sev: Fail KVM_SEV_INIT if already initialized



On 1/2/19 2:56 PM, David Rientjes wrote:
> By code inspection, it was found that multiple calls to KVM_SEV_INIT
> could deplete asid bits and overwrite kvm_sev_info's regions_list.
>
> Multiple calls to KVM_SVM_INIT is not likely to occur with QEMU, but this
> should likely be fixed anyway.
>
> This code is serialized by kvm->lock.
>
> Fixes: 1654efcbc431 ("KVM: SVM: Add KVM_SEV_INIT command")
> Reported-by: Cfir Cohen <[email protected]>
> Signed-off-by: David Rientjes <[email protected]>

Thanks for the patch. Looks good.

Reviewed-by: Brijesh Singh <[email protected]>

2019-01-11 17:46:44

by Radim Krčmář

[permalink] [raw]
Subject: Re: [patch] kvm: sev: Fail KVM_SEV_INIT if already initialized

2019-01-02 12:56-0800, David Rientjes:
> By code inspection, it was found that multiple calls to KVM_SEV_INIT
> could deplete asid bits and overwrite kvm_sev_info's regions_list.
>
> Multiple calls to KVM_SVM_INIT is not likely to occur with QEMU, but this
> should likely be fixed anyway.
>
> This code is serialized by kvm->lock.
>
> Fixes: 1654efcbc431 ("KVM: SVM: Add KVM_SEV_INIT command")
> Reported-by: Cfir Cohen <[email protected]>
> Signed-off-by: David Rientjes <[email protected]>
> ---

Applied, thanks.