Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Anthony Krowiak <akrowiak@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-s390@vger.kernel.org, kvm@vger.kernel.org,
	Heiko Carstens <hca@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Jason Herne <jjherne@linux.ibm.com>,
	Matthew Rosato <mjrosato@linux.ibm.com>
Subject: Re: [PATCH v2 1/4] s390/vfio-ap: Fix leak of pinned NIB and registered NISC in vfio_ap_irq_enable()
Date: Tue, 25 Aug 2026 12:44:43 -0400	[thread overview]
Message-ID: <dfe22a19-49a0-413f-96e8-35fab4be1a84@linux.ibm.com> (raw)
In-Reply-To: <20260824220737.95C7C1F00A3A@smtp.kernel.org>



On 8/24/26 6:07 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [Critical] Potential host memory corruption if `vfio_ap_irq_disable` times out while the hardware queue is busy.
> --
>
> --- Patch [1]: [PATCH v2 1/4] s390/vfio-ap: Fix leak of pinned NIB and registered NISC in vfio_ap_irq_enable() ---
> commit 85cfee5e61842e2a3b3b8993da6d14f25c2209a2
> Author: Anthony Krowiak <akrowiak@linux.ibm.com>
>
> s390/vfio-ap: Fix leak of pinned NIB and registered NISC in vfio_ap_irq_enable()
>
> This commit fixes a resource leak in vfio_ap_irq_enable() by explicitly
> unregistering the NISC and unpinning the NIB in the default switch case,
> rather than relying on vfio_ap_irq_disable().
>
>> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
>> index 940c0ff668bee..22a6ceaa7b562 100644
>> --- a/drivers/s390/crypto/vfio_ap_ops.c
>> +++ b/drivers/s390/crypto/vfio_ap_ops.c
> [ ... ]
>
>> @@ -503,9 +503,12 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
>>   		vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1);
>>   		break;
>>   	default:
>> -		pr_warn("%s: apqn %04x: response: %02x\n", __func__, q->apqn,
>> -			status.response_code);
>> -		vfio_ap_irq_disable(q);
> [Severity: Critical]
> This isn't a bug introduced by this patch, but pre-exists in the
> vfio_ap_irq_disable() function that was previously called here.
>
> Can this lead to host memory corruption if vfio_ap_irq_disable() times out
> while the hardware queue is busy?
>
> If a guest repeatedly sends requests to keep the AP queue busy, then issues a
> PQAP(AQIC) instruction with the IR bit cleared (or unmaps memory),
> vfio_ap_irq_disable() is invoked. If the queue remains busy, ap_aqic() returns
> AP_RESPONSE_BUSY repeatedly.
>
> After retries, vfio_ap_irq_disable() falls through to end_free:
>
> drivers/s390/crypto/vfio_ap_ops.c:vfio_ap_irq_disable() {
> 	...
> 	} while (retries--);
>
> 	WARN_ONCE(1, "%s: ap_aqic status %d\n", __func__,
> 		  status.response_code);
> end_free:
> 	vfio_ap_free_aqic_resources(q);
> }
>
> By unconditionally unpinning the NIB (Notification Indicator Byte) page via
> vfio_ap_free_aqic_resources() while the hardware still holds its address and
> expects to write to it, the page may be reallocated to another process.
>
> When the hardware eventually triggers an interrupt, wouldn't it perform a DMA
> write to this freed page, causing host memory corruption?

This is a valid concern and is similar to the problem fixed by this patch.
It was also introduced by the same patch identified in the Fixes: tag,
so I will add the fix for the issue pointed out above to this patch and
resubmit it.

>
>> +		/* We could not modify IRQ settings: clear new configuration */
>> +		ret = kvm_s390_gisc_unregister(kvm, isc);
>> +		if (ret)
>> +			VFIO_AP_DBF_WARN("%s: kvm_s390_gisc_unregister: rc=%d isc=%d, apqn=%#04x\n",
>> +					 __func__, ret, isc, q->apqn);
>> +		vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1);
>>   		break;
>>   	}


  reply	other threads:[~2026-08-25 16:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 21:55 [PATCH v2 0/4] s390/vfio-ap: Fix pre-existing bugs in vfio_ap device driver Anthony Krowiak
2026-08-24 21:56 ` [PATCH v2 1/4] s390/vfio-ap: Fix leak of pinned NIB and registered NISC in vfio_ap_irq_enable() Anthony Krowiak
2026-08-24 22:07   ` sashiko-bot
2026-08-25 16:44     ` Anthony Krowiak [this message]
2026-08-24 21:56 ` [PATCH v2 2/4] s390/vfio-ap: Fix failure to release IRQ notification eventfd contexts Anthony Krowiak
2026-08-24 22:07   ` sashiko-bot
2026-08-24 21:56 ` [PATCH v2 3/4] s390/vfio-ap: Fix unbounded loop in apq_reset_check() Anthony Krowiak
2026-08-24 22:11   ` sashiko-bot
2026-08-26 15:26     ` Anthony Krowiak
2026-08-24 21:56 ` [PATCH v2 4/4] s390/vfio-ap: Use AP_DOMAINS for adm_add bitmap size in vfio_ap_mdev_cfg_add() Anthony Krowiak
2026-08-24 22:06   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dfe22a19-49a0-413f-96e8-35fab4be1a84@linux.ibm.com \
    --to=akrowiak@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox