From: sashiko-bot@kernel.org
To: "Farhan Ali" <alifm@linux.ibm.com>
Cc: linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v3 4/4] KVM: s390: pci: Fix resource leak on IRQ registration failure
Date: Mon, 20 Jul 2026 18:42:38 +0000 [thread overview]
Message-ID: <20260720184238.DA83B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720175819.1723-5-alifm@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The `aisbo` (Adapter Interrupt Summary Bit Offset) provided by userspace is not bounds-checked, leading to a host kernel memory out-of-bounds write.
- [Critical] The `aibv` address and `noi` (number of interrupts) provided by userspace are not bounds-checked, allowing hardware DMA to write out-of-bounds into unpinned host physical memory.
- [High] Missing check for already-enabled AIF allows massive resource leak, accounting exhaustion, and subsequent Use-After-Free on double registration.
--
--- Patch [4]: [PATCH v3 4/4] KVM: s390: pci: Fix resource leak on IRQ registration failure ---
commit 54ecbcfac4858add9c2dd09fc30b8b84a8fbfca3
Author: Farhan Ali <alifm@linux.ibm.com>
KVM: s390: pci: Fix resource leak on IRQ registration failure
Currently if kvm_zpci_set_airq() fails, kvm_s390_pci_aif_enable() returns
the error code but doesn't do any resource cleanup thus leaking resources.
Fix this by cleaning up all the resources such as the GAITE, AIBV, AISB and
unpinning any pinned pages.
> diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
> index 85f4fb5d36b38..d328bbd0dd997 100644
> --- a/arch/s390/kvm/pci.c
> +++ b/arch/s390/kvm/pci.c
> @@ -337,19 +337,32 @@ static int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
[Severity: High]
This is a pre-existing issue, but does kvm_s390_pci_zpci_reg_aen() prevent
double registration?
If a malicious or buggy userspace repeatedly calls the KVM_S390_ZPCIOP_REG_AEN
ioctl on the same PCI device, kvm_s390_pci_aif_enable() unconditionally
allocates new resources:
arch/s390/kvm/pci.c:kvm_s390_pci_aif_enable() {
...
bit = airq_iv_alloc_bit(aift->sbv);
...
zdev->aibv = airq_iv_create(...);
...
}
Because it doesn't check if AIF is already enabled, it blindly pins new host
pages and overwrites the old zdev->aibv and zdev->aisb pointers.
Could this permanently leak the previous allocations and repeatedly increment
the memory accounting on user->locked_vm until it exhausts the limit?
[Severity: Critical]
This is a pre-existing issue, but does this code bounds-check the DMA length
against the pinned page?
kvm_s390_pci_aif_enable() calculates the physical base address for the
interrupt bit vector using a user-supplied page offset:
arch/s390/kvm/pci.c:kvm_s390_pci_aif_enable() {
...
gaddr = page_to_phys(aibv_page) + (fib->fmt0.aibv & ~PAGE_MASK);
fib->fmt0.aibv = gaddr;
...
}
This physical address is passed directly to the hardware via
kvm_zpci_set_airq().
If the guest places the base address near the end of the page (e.g., offset
4095) and zdev->max_msi requires 2+ bytes, will the hardware DMA cross the
single pinned page's boundary?
Could this silently corrupt adjacent unpinned host physical pages?
[Severity: Critical]
This isn't a bug introduced by this patch, but is the aisbo value from
userspace properly bounds-checked?
In kvm_s390_pci_aif_enable(), gaite->aisbo is set directly from the
user-controlled fib->fmt0.aisbo:
arch/s390/kvm/pci.c:kvm_s390_pci_aif_enable() {
...
if (fib->fmt0.sum == 1) {
gaite->aisbo = fib->fmt0.aisbo;
gaite->aisb = virt_to_phys(page_address(aisb_page) +
(fib->fmt0.aisb & ~PAGE_MASK));
}
...
}
Upon an adapter interrupt, aen_host_forward() executes an out-of-bounds
bitwise write operation:
arch/s390/kvm/interrupt.c:aen_host_forward() {
...
set_bit_inv(gaite->aisbo, phys_to_virt(gaite->aisb));
...
}
Since gaite->aisbo can be up to 255 (a 31-byte offset) and the guest offset
within the page can be up to 4095, the calculation (offset) + (aisbo / 8)
can reach 4126.
Could this cross the 4096-byte page boundary and perform a bitwise write up to
31 bytes out-of-bounds into the adjacent physical page?
> aift->kzdev[zdev->aisb] = zdev->kzdev;
> spin_unlock_irq(&aift->gait_lock);
>
> - /* Update guest FIB for re-issue */
> - fib->fmt0.aisbo = zdev->aisb & 63;
> - fib->fmt0.aisb = virt_to_phys(aift->sbv->vector) + (zdev->aisb / 64) * 8;
> - fib->fmt0.isc = gisc;
> -
> /* Save some guest fib values in the host for later use */
> - zdev->kzdev->fib.fmt0.isc = fib->fmt0.isc;
> + zdev->kzdev->fib.fmt0.isc = gisc;
> zdev->kzdev->fib.fmt0.aibv = fib->fmt0.aibv;
> - mutex_unlock(&aift->aift_lock);
>
> /* Issue the clp to setup the irq now */
> rc = kvm_zpci_set_airq(zdev);
> - return rc;
> + if (!rc) {
> + mutex_unlock(&aift->aift_lock);
> + return rc;
> + }
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720175819.1723-1-alifm@linux.ibm.com?part=4
prev parent reply other threads:[~2026-07-20 18:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 17:58 [PATCH v3 0/4] KVM s390x PCI fixes Farhan Ali
2026-07-20 17:58 ` [PATCH v3 1/4] KVM: s390: pci: Fix memory accounting for pinned/unpinned pages Farhan Ali
2026-07-20 18:18 ` sashiko-bot
2026-07-20 17:58 ` [PATCH v3 2/4] KVM: s390: pci: Fix missing error codes and memory unaccounting Farhan Ali
2026-07-20 18:13 ` sashiko-bot
2026-07-20 17:58 ` [PATCH v3 3/4] KVM: s390: pci: Fix NULL dereference on AIBV allocation failure Farhan Ali
2026-07-20 18:25 ` sashiko-bot
2026-07-20 17:58 ` [PATCH v3 4/4] KVM: s390: pci: Fix resource leak on IRQ registration failure Farhan Ali
2026-07-20 18:42 ` sashiko-bot [this message]
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=20260720184238.DA83B1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--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