Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yuho Choi" <dbgh9129@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v1] scsi: be2iscsi: Fix MSI-X IRQ cleanup
Date: Mon, 03 Aug 2026 01:54:17 +0000	[thread overview]
Message-ID: <20260803015417.C18F71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803014224.614347-1-dbgh9129@gmail.com>

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_affinity` in `be2iscsi_enable_msix` is completely inverted, leading to severe resource underutilization on success and guaranteed out-of-bounds array accesses on failure.
--

--- Patch [1]: [PATCH v1] scsi: be2iscsi: Fix MSI-X IRQ cleanup ---
commit 7ef06019dd8a33e5e182606a30c7033f3e41b3de
Author: Yuho Choi <dbgh9129@gmail.com>

scsi: be2iscsi: Fix MSI-X IRQ cleanup
    
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_main.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 = i - 1; j >= 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 = nvec - 1;
			return;
		}
	}

	phba->num_cpus = 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 = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
		eq = &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?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803014224.614347-1-dbgh9129@gmail.com?part=1

      reply	other threads:[~2026-08-03  1:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03  1:42 [PATCH v1] scsi: be2iscsi: Fix MSI-X IRQ cleanup Yuho Choi
2026-08-03  1:54 ` 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=20260803015417.C18F71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dbgh9129@gmail.com \
    --cc=linux-scsi@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