From: Christian Borntraeger <borntraeger@linux.ibm.com>
To: Junrui Luo <moonafterrain@outlook.com>,
Janosch Frank <frankja@linux.ibm.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>,
David Hildenbrand <david@kernel.org>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Farhan Ali <alifm@linux.ibm.com>,
Eric Farman <farman@linux.ibm.com>,
Niklas Schnelle <schnelle@linux.ibm.com>,
Pierre Morel <pmorel@linux.ibm.com>
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
linux-kernel@vger.kernel.org, Yuhao Jiang <danisjiang@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] KVM: s390: pci: fix GAIT table indexing due to double-scaling pointer arithmetic
Date: Thu, 16 Apr 2026 15:06:56 +0200 [thread overview]
Message-ID: <b1f22f3a-398e-4ce6-8092-aff9c9aaaf9f@linux.ibm.com> (raw)
In-Reply-To: <SYBPR01MB7881AB7449FEB6B58E4BA6F2AF222@SYBPR01MB7881.ausprd01.prod.outlook.com>
Am 15.04.26 um 11:26 schrieb Junrui Luo:
> kvm_s390_pci_aif_enable(), kvm_s390_pci_aif_disable(), and
> aen_host_forward() index the GAIT by manually multiplying the index
> with sizeof(struct zpci_gaite).
>
> Since aift->gait is already a struct zpci_gaite pointer, this
> double-scales the offset, accessing element aisb*16 instead of aisb.
>
> This causes out-of-bounds accesses when aisb >= 32 (with
> ZPCI_NR_DEVICES=512)
>
> Fix by removing the erroneous sizeof multiplication.
>
> Fixes: 3c5a1b6f0a18 ("KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding")
> Fixes: 73f91b004321 ("KVM: s390: pci: enable host forwarding of Adapter Event Notifications")
> Reported-by: Yuhao Jiang <danisjiang@gmail.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
looks good to me.
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Out of interest, was this found by static code checking or AI by any chance?
@Matt, can you test/review this as well?
> ---
> arch/s390/kvm/interrupt.c | 3 +--
> arch/s390/kvm/pci.c | 6 ++----
> 2 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
> index 7cb8ce833b62..f48f25c7dc8f 100644
> --- a/arch/s390/kvm/interrupt.c
> +++ b/arch/s390/kvm/interrupt.c
> @@ -3307,8 +3307,7 @@ static void aen_host_forward(unsigned long si)
> struct zpci_gaite *gaite;
> struct kvm *kvm;
>
> - gaite = (struct zpci_gaite *)aift->gait +
> - (si * sizeof(struct zpci_gaite));
> + gaite = aift->gait + si;
> if (gaite->count == 0)
> return;
> if (gaite->aisb != 0)
> diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
> index 86d93e8dddae..eed45af1a92d 100644
> --- a/arch/s390/kvm/pci.c
> +++ b/arch/s390/kvm/pci.c
> @@ -290,8 +290,7 @@ static int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
> phys_to_virt(fib->fmt0.aibv));
>
> spin_lock_irq(&aift->gait_lock);
> - gaite = (struct zpci_gaite *)aift->gait + (zdev->aisb *
> - sizeof(struct zpci_gaite));
> + gaite = aift->gait + zdev->aisb;
>
> /* If assist not requested, host will get all alerts */
> if (assist)
> @@ -357,8 +356,7 @@ static int kvm_s390_pci_aif_disable(struct zpci_dev *zdev, bool force)
> if (zdev->kzdev->fib.fmt0.aibv == 0)
> goto out;
> spin_lock_irq(&aift->gait_lock);
> - gaite = (struct zpci_gaite *)aift->gait + (zdev->aisb *
> - sizeof(struct zpci_gaite));
> + gaite = aift->gait + zdev->aisb;
> isc = gaite->gisc;
> gaite->count--;
> if (gaite->count == 0) {
>
next prev parent reply other threads:[~2026-04-16 13:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 9:26 [PATCH] KVM: s390: pci: fix GAIT table indexing due to double-scaling pointer arithmetic Junrui Luo
2026-04-16 13:06 ` Christian Borntraeger [this message]
2026-04-16 19:46 ` Matthew Rosato
2026-04-17 5:44 ` Junrui Luo
2026-04-17 7:48 ` Christian Borntraeger
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=b1f22f3a-398e-4ce6-8092-aff9c9aaaf9f@linux.ibm.com \
--to=borntraeger@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=danisjiang@gmail.com \
--cc=david@kernel.org \
--cc=farman@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=moonafterrain@outlook.com \
--cc=pmorel@linux.ibm.com \
--cc=schnelle@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=svens@linux.ibm.com \
/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