Re: [PATCH v1] scsi: be2iscsi: Fix MSI-X IRQ cleanup

[email protected] Mon, 03 Aug 2026 01:54:17 +0000
Newsgroups org.kernel.vger.linux-scsi
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(=
s) to consider:

Pre-existing issues:
- [High] The logic handling the return value of `pci_alloc_irq_vectors_affi=
nity` in `be2iscsi_enable_msix` is completely inverted, leading to severe r=
esource underutilization on success and guaranteed out-of-bounds array acce=
sses on failure.
--

--- Patch [1]: [PATCH v1] scsi: be2iscsi: Fix MSI-X IRQ cleanup ---
commit 7ef06019dd8a33e5e182606a30c7033f3e41b3de
Author: Yuho Choi <[email protected]>

scsi: be2iscsi: Fix MSI-X IRQ cleanup
   =20
This patch fixes the MSI-X IRQ cleanup path in beiscsi_init_irqs(). When
unwinding an allocation failure, it uses the correct index to release the
same vectors that were registered.

> diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_m=
ain.c
> index fd18d4d3d219b..9833ab06b299a 100644
> --- a/drivers/scsi/be2iscsi/be_main.c
> +++ b/drivers/scsi/be2iscsi/be_main.c
> @@ -878,7 +878,7 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
>  	return 0;
>  free_msix_irqs:
>  	for (j =3D i - 1; j >=3D 0; j--) {
> -		free_irq(pci_irq_vector(pcidev, i), &phwi_context->be_eq[j]);
> +		free_irq(pci_irq_vector(pcidev, j), &phwi_context->be_eq[j]);
>  		kfree(phba->msi_name[j]);
>  	}
>  	return ret;

[Severity: High]
This is a pre-existing issue, but while reviewing the MSI-X initialization =
in
this driver, I noticed what appears to be inverted error handling logic in
be2iscsi_enable_msix():

drivers/scsi/be2iscsi/be_main.c:be2iscsi_enable_msix() {
    ...
		if (pci_alloc_irq_vectors_affinity(phba->pcidev, 2, nvec,
				PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, &desc) < 0) {
			phba->num_cpus =3D nvec - 1;
			return;
		}
	}

	phba->num_cpus =3D 1;
    ...
}

Does this code set phba->num_cpus to a high value on allocation failure, and
limit it to 1 on success?

If pci_alloc_irq_vectors_affinity() fails, phba->num_cpus is set to nvec - =
1,
where nvec can be up to 2048. Subsequent functions iterate up to this value:

drivers/scsi/be2iscsi/be_main.c:beiscsi_create_eqs() {
    ...
	for (i =3D 0; i < (phba->num_cpus + eq_for_mcc); i++) {
		eq =3D &phwi_context->be_eq[i].q;
    ...
}

Because the be_eq array in struct hwi_context_memory is strictly bounded by
MAX_CPUS (64), can this out-of-bounds access corrupt memory if the MSI-X
allocation fails?

--=20
Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260803014224.6143=
[email protected]?part=3D1