From: Anthony Krowiak <akrowiak@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Heiko Carstens <hca@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
kvm@vger.kernel.org, Vasily Gorbik <gor@linux.ibm.com>,
linux-s390@vger.kernel.org,
Matthew Rosato <mjrosato@linux.ibm.com>,
Jason Herne <jjherne@linux.ibm.com>
Subject: Re: [PATCH v7 1/6] s390/vfio-ap: Fix leaks of pinned NIB and registered GISC
Date: Tue, 22 Sep 2026 10:29:01 -0400 [thread overview]
Message-ID: <a0a5fbf4-829f-42bc-98f1-a8ee022b6c4b@linux.ibm.com> (raw)
In-Reply-To: <20260904225127.A201D1F00A3E@smtp.kernel.org>
On 9/4/26 6:51 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Critical] Eagerly freeing AQIC resources when ap_zapq() or ap_tapq() returns an unrecognized response allows wild DMA writes to freed host memory.
> --
>
> commit 6c73d9ea4d311d5d68e8f5501374842cccbe2c90
> Author: Anthony Krowiak <akrowiak@linux.ibm.com>
>
> s390/vfio-ap: Fix leaks of pinned NIB and registered GISC
>
> Several code paths in the vfio_ap driver failed to free the AQIC
> resources — the pinned guest NIB page and the registered guest ISC
> used to enable interrupts for a queue — when a queue became unavailable
> or when unexpected response codes were returned. This could cause memory
> exhaustion and depletion of KVM interrupt subclass registrations over time
> with repeated dynamic AP reconfiguration.
>
>> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
>> index 940c0ff668bee..9d4f5b9e3301f 100644
>> --- a/drivers/s390/crypto/vfio_ap_ops.c
>> +++ b/drivers/s390/crypto/vfio_ap_ops.c
> [ ... ]
>> @@ -1959,8 +2087,16 @@ static void apq_reset_check(struct work_struct *reset_work)
>> elapsed += AP_RESET_INTERVAL;
>> status = ap_tapq(q->apqn, NULL);
>> ret = apq_status_check(q->apqn, &status);
>> - if (ret == -EIO)
>> + if (ret == -EIO) {
>> + /*
>> + * TAPQ returned an invalid response code. This
>> + * indicates a hardware or firmware bug; the queue
>> + * cannot generate AP interrupts or DMA-write to the
>> + * NIB, so free the AQIC resources rather than leak them.
>> + */
>> + vfio_ap_free_aqic_resources(q);
>> return;
>> + }
> [Severity: Critical]
> If apq_status_check() returns -EIO due to an unrecognized TAPQ response,
> is it safe to eagerly free the AQIC resources?
>
> If the hardware is in an unknown state (due to a bug or unrecognized code),
> could it still be actively DMA-writing to the pinned Notification Indicator
> Byte (NIB) page?
>
> If vfio_ap_free_aqic_resources() unpins the page and returns it to the
> system allocator, could a subsequent wild DMA write from the malfunctioning
> AP queue corrupt memory belonging to a new owner, potentially causing a host
> panic?
Since we don't know the state of the queue, the AQIC resources should be
intentionally leaked here lest the NIB page be re-allocated to another
process potentially resulting in a wild DMA-write.
>
> [ ... ]
>> @@ -1995,22 +2135,30 @@ static void vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q)
>> switch (status.response_code) {
>> case AP_RESPONSE_NORMAL:
>> case AP_RESPONSE_RESET_IN_PROGRESS:
>> - case AP_RESPONSE_BUSY:
>> case AP_RESPONSE_STATE_CHANGE_IN_PROGRESS:
>> /*
>> * Let's verify whether the ZAPQ completed successfully on a work queue.
>> */
>> queue_work(system_long_wq, &q->reset_work);
>> break;
>> + case AP_RESPONSE_Q_NOT_AVAIL:
>> case AP_RESPONSE_DECONFIGURED:
>> case AP_RESPONSE_CHECKSTOPPED:
>> vfio_ap_free_aqic_resources(q);
>> break;
>> default:
>> + /*
>> + * The architecture defines only the response codes above as
>> + * valid for ZAPQ. Any other response code indicates a hardware
>> + * or firmware bug. Since a malfunctioning queue cannot generate
>> + * AP interrupts or DMA-write to the NIB, free the AQIC resources
>> + * rather than leak them.
>> + */
>> WARN(true,
>> "PQAP/ZAPQ for %02x.%04x failed with invalid rc=%u\n",
>> AP_QID_CARD(q->apqn), AP_QID_QUEUE(q->apqn),
>> status.response_code);
>> + vfio_ap_free_aqic_resources(q);
>> }
>> }
> [Severity: Critical]
> Similarly, if ZAPQ fails with an unrecognized response code in
> vfio_ap_mdev_reset_queue(), does freeing the AQIC resources here present the
> same wild DMA risk?
>
> Even if a later patch in this series adds a retry loop that explicitly
> handles AP_RESPONSE_BUSY, does this default case still expose the host to
> memory corruption if any other unexpected response code is returned?
Same as the above response
>
next prev parent reply other threads:[~2026-09-22 14:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 22:35 [PATCH v7 0/6] s390/vfio-ap: Fix pre-existing bugs in vfio_ap device driver Anthony Krowiak
2026-09-04 22:35 ` [PATCH v7 1/6] s390/vfio-ap: Fix leaks of pinned NIB and registered GISC Anthony Krowiak
2026-09-04 22:51 ` sashiko-bot
2026-09-22 14:29 ` Anthony Krowiak [this message]
2026-09-22 16:54 ` Christian Borntraeger
2026-09-04 22:35 ` [PATCH v7 2/6] s390/vfio-ap: Fix failure to release IRQ notification eventfd contexts Anthony Krowiak
2026-09-04 22:49 ` sashiko-bot
2026-09-04 22:35 ` [PATCH v7 3/6] s390/vfio-ap: Fix unbounded loop in apq_reset_check() Anthony Krowiak
2026-09-04 22:49 ` sashiko-bot
2026-09-04 22:35 ` [PATCH v7 4/6] s390/vfio-ap: Use AP_DOMAINS for adm_add bitmap size in vfio_ap_mdev_cfg_add() Anthony Krowiak
2026-09-04 22:46 ` sashiko-bot
2026-09-04 22:35 ` [PATCH v7 5/6] s390/vfio-ap: fix queue state leakage to guest and host Anthony Krowiak
2026-09-04 22:46 ` sashiko-bot
2026-09-24 21:47 ` Anthony Krowiak
2026-09-04 22:35 ` [PATCH v7 6/6] s390/vfio-ap: replace guest-reachable WARNs with ratelimited warnings and add dmesg visibility to DBF_WARNs Anthony Krowiak
2026-09-04 22:50 ` 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=a0a5fbf4-829f-42bc-98f1-a8ee022b6c4b@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