Skip to content

Commit 11b8ff5

Browse files
avasummergregkh
authored andcommitted
KVM: s390: pci: fix GAIT table indexing due to double-scaling pointer arithmetic
commit 16d990a upstream. 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: 3c5a1b6 ("KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding") Fixes: 73f91b0 ("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> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Tested-by: Matthew Rosato <mjrosato@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b315b03 commit 11b8ff5

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

arch/s390/kvm/interrupt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,8 +3329,7 @@ static void aen_host_forward(unsigned long si)
33293329
struct zpci_gaite *gaite;
33303330
struct kvm *kvm;
33313331

3332-
gaite = (struct zpci_gaite *)aift->gait +
3333-
(si * sizeof(struct zpci_gaite));
3332+
gaite = aift->gait + si;
33343333
if (gaite->count == 0)
33353334
return;
33363335
if (gaite->aisb != 0)

arch/s390/kvm/pci.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ static int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
292292
phys_to_virt(fib->fmt0.aibv));
293293

294294
spin_lock_irq(&aift->gait_lock);
295-
gaite = (struct zpci_gaite *)aift->gait + (zdev->aisb *
296-
sizeof(struct zpci_gaite));
295+
gaite = aift->gait + zdev->aisb;
297296

298297
/* If assist not requested, host will get all alerts */
299298
if (assist)
@@ -359,8 +358,7 @@ static int kvm_s390_pci_aif_disable(struct zpci_dev *zdev, bool force)
359358
if (zdev->kzdev->fib.fmt0.aibv == 0)
360359
goto out;
361360
spin_lock_irq(&aift->gait_lock);
362-
gaite = (struct zpci_gaite *)aift->gait + (zdev->aisb *
363-
sizeof(struct zpci_gaite));
361+
gaite = aift->gait + zdev->aisb;
364362
isc = gaite->gisc;
365363
gaite->count--;
366364
if (gaite->count == 0) {

0 commit comments

Comments
 (0)