Skip to content

Commit d407432

Browse files
Claudio Imbrendaborntraeger
authored andcommitted
KVM: s390: pv: avoid double free of sida page
If kvm_s390_pv_destroy_cpu is called more than once, we risk calling free_page on a random page, since the sidad field is aliased with the gbea, which is not guaranteed to be zero. This can happen, for example, if userspace calls the KVM_PV_DISABLE IOCTL, and it fails, and then userspace calls the same IOCTL again. This scenario is only possible if KVM has some serious bug or if the hardware is broken. The solution is to simply return successfully immediately if the vCPU was already non secure. Signed-off-by: Claudio Imbrenda <[email protected]> Fixes: 19e1227 ("KVM: S390: protvirt: Introduce instruction data area bounce buffer") Reviewed-by: Janosch Frank <[email protected]> Reviewed-by: Christian Borntraeger <[email protected]> Message-Id: <[email protected]> Signed-off-by: Janosch Frank <[email protected]> Signed-off-by: Christian Borntraeger <[email protected]>
1 parent 57c5df1 commit d407432

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

arch/s390/kvm/pv.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616

1717
int kvm_s390_pv_destroy_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc)
1818
{
19-
int cc = 0;
19+
int cc;
2020

21-
if (kvm_s390_pv_cpu_get_handle(vcpu)) {
22-
cc = uv_cmd_nodata(kvm_s390_pv_cpu_get_handle(vcpu),
23-
UVC_CMD_DESTROY_SEC_CPU, rc, rrc);
21+
if (!kvm_s390_pv_cpu_get_handle(vcpu))
22+
return 0;
23+
24+
cc = uv_cmd_nodata(kvm_s390_pv_cpu_get_handle(vcpu), UVC_CMD_DESTROY_SEC_CPU, rc, rrc);
25+
26+
KVM_UV_EVENT(vcpu->kvm, 3, "PROTVIRT DESTROY VCPU %d: rc %x rrc %x",
27+
vcpu->vcpu_id, *rc, *rrc);
28+
WARN_ONCE(cc, "protvirt destroy cpu failed rc %x rrc %x", *rc, *rrc);
2429

25-
KVM_UV_EVENT(vcpu->kvm, 3,
26-
"PROTVIRT DESTROY VCPU %d: rc %x rrc %x",
27-
vcpu->vcpu_id, *rc, *rrc);
28-
WARN_ONCE(cc, "protvirt destroy cpu failed rc %x rrc %x",
29-
*rc, *rrc);
30-
}
3130
/* Intended memory leak for something that should never happen. */
3231
if (!cc)
3332
free_pages(vcpu->arch.pv.stor_base,

0 commit comments

Comments
 (0)