Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ivy Lopez" <skunkolee@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: arcmsr: fix DMA memory and IO queue leak on arcmsr_alloc_ccb_pool() failure
Date: Fri, 07 Aug 2026 19:09:05 +0000	[thread overview]
Message-ID: <20260807190905.D352D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807185018.80661-1-skunkolee@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] The patch introduces a kernel panic (NULL pointer dereference) in `arcmsr_free_ccb_pool()` when cleaning up after an XOR buffer allocation failure.

Pre-existing issues:
- [High] A race condition during device removal and probe error teardown leaves work queued on the system workqueue after the adapter struct has been freed, causing a use-after-free.
--

--- Patch [1]: [PATCH] scsi: arcmsr: fix DMA memory and IO queue leak on arcmsr_alloc_ccb_pool() failure ---
commit 54e963f4d0ddf2b670ba41920062308c1b96d75e
Author: Ivy Lopez <skunkolee@gmail.com>

scsi: arcmsr: fix DMA memory and IO queue leak on arcmsr_alloc_ccb_pool() failure

This commit fixes a DMA memory and IO queue leak that occurs when
arcmsr_alloc_ccb_pool() fails. It routes the error path through the
free_ccb_pool label and explicitly frees the IO queue for type F adapters.

> diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
> index 8aa948f06cacf..3ffd160a6a550 100644
> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
> @@ -1144,7 +1144,9 @@ static int arcmsr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  		arcmsr_free_io_queue(acb);
>  	error = arcmsr_alloc_ccb_pool(acb);
>  	if(error){
> -		goto unmap_pci_region;
> +		if (acb->adapter_type == ACB_ADAPTER_TYPE_F)
> +			arcmsr_free_io_queue(acb);
> +		goto free_ccb_pool;

[Severity: High]
Does this routing of the error path to free_ccb_pool introduce a kernel
panic if arcmsr_alloc_ccb_pool() fails during XOR buffer allocation?

If arcmsr_alloc_xor_buffer() fails, acb->xor_mega is already set to a
non-zero value, but acb->xorVirt might be NULL.

When arcmsr_free_ccb_pool() is called from this new error path, it checks
acb->xor_mega and proceeds to calculate a pointer using the NULL
acb->xorVirt:

drivers/scsi/arcmsr/arcmsr_hba.c:arcmsr_free_ccb_pool() {
    ...
    if (acb->xor_mega) {
        struct Xor_sg *pXorPhys;
        ...
        pXorPhys = (struct Xor_sg *)(acb->xorVirt + sizeof(struct HostRamBuf));
        ...
        if (pXorPhys->xorPhys) {
    ...
}

Will this unconditionally dereference the invalid pXorPhys pointer
(address 16) and cause a panic?

[Severity: High]
This is a pre-existing issue, but does the error teardown sequence leave a
window for a use-after-free?

In the arcmsr_probe() error path, flush_work() is called before the hardware
interrupt is freed:

drivers/scsi/arcmsr/arcmsr_hba.c:arcmsr_probe() {
out_free_sysfs:
    ...
    flush_work(&acb->arcmsr_do_message_isr_bh);
    arcmsr_stop_adapter_bgrb(acb);
    arcmsr_flush_adapter_cache(acb);
    arcmsr_free_irq(pdev, acb);
    ...
}

Because the interrupt is still active, could it fire and re-queue
arcmsr_do_message_isr_bh after the flush? When scsi_host_put() subsequently
frees the acb structure, would the system workqueue then dereference the
freed memory?

>  	}
>  	error = scsi_add_host(host, &pdev->dev);
>  	if(error){

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

      reply	other threads:[~2026-08-07 19:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 18:50 [PATCH] scsi: arcmsr: fix DMA memory and IO queue leak on arcmsr_alloc_ccb_pool() failure Ivy Lopez
2026-08-07 19:09 ` 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=20260807190905.D352D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skunkolee@gmail.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