Re: [PATCH v4 4/6] KVM: s390: pci: Fix NULL dereference on AIBV allocation failure

From: Matthew Rosato

Date: Thu Jul 23 2026 - 10:32:22 EST


On 7/22/26 1:06 PM, Farhan Ali wrote:
> The airq_iv_create() can return NULL on failure, but the return value was
> never checked. If it fails, zdev->aibv will be NULL and fail when
> derefenced in kvm_zpci_set_airq(). Add a NULL check and free the previously

Nit: s/derefenced/dereferenced/


> allocated AISB bit and zdev->aisb on failure.
>
> Fixes: 3c5a1b6f0a18 ("KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding")
> Signed-off-by: Farhan Ali <alifm@xxxxxxxxxxxxx>

Reviewed-by: Matthew Rosato <mjrosato@xxxxxxxxxxxxx>

> ---
> arch/s390/kvm/pci.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
> index 33abc15aa685..231a4236fc3c 100644
> --- a/arch/s390/kvm/pci.c
> +++ b/arch/s390/kvm/pci.c
> @@ -314,6 +314,11 @@ static int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
> AIRQ_IV_GUESTVEC,
> phys_to_virt(fib->fmt0.aibv));
>
> + if (!zdev->aibv) {
> + rc = -ENOMEM;
> + goto free_aisb;
> + }
> +
> spin_lock_irq(&aift->gait_lock);
> gaite = aift->gait + zdev->aisb;
>
> @@ -350,6 +355,9 @@ static int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
> rc = kvm_zpci_set_airq(zdev);
> return rc;
>
> +free_aisb:
> + airq_iv_free_bit(aift->sbv, zdev->aisb);
> + zdev->aisb = 0;
> unlock:
> if (pcount > 0)
> unaccount_mem(zdev->kzdev, pcount);