]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: s390: Do not free SCA if it was not allocated
authorClaudio Imbrenda <imbrenda@linux.ibm.com>
Mon, 3 Aug 2026 12:40:29 +0000 (14:40 +0200)
committerClaudio Imbrenda <imbrenda@linux.ibm.com>
Mon, 3 Aug 2026 14:51:28 +0000 (16:51 +0200)
If VM creation fails early in kvm_arch_init_vm(), the cleanup code
tries to free up the SCA, even though the address is 0. Due to using
free_pages_exact(), only the first page is skipped, accidentally
freeing pages 1, 2, and 3.

Fix by checking whether the pointer is NULL before attempting to free
the SCA in sca_dispose().

Fixes: e72753ed1267 ("KVM: s390: Use ESCA instead of BSCA at VM init")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Message-ID: <20260803124040.126471-3-imbrenda@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
arch/s390/kvm/kvm-s390.c

index f86b4b0b356f42a294b5d73f7ae90f193a92c281..1b3290a5ad1aee1c616feec456ce49a5b6b3ab75 100644 (file)
@@ -3247,7 +3247,8 @@ static void kvm_s390_crypto_init(struct kvm *kvm)
 
 static void sca_dispose(struct kvm *kvm)
 {
-       free_pages_exact(kvm->arch.sca, sizeof(*kvm->arch.sca));
+       if (kvm->arch.sca)
+               free_pages_exact(kvm->arch.sca, sizeof(*kvm->arch.sca));
        kvm->arch.sca = NULL;
 }