Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bart Van Assche" <bvanassche@acm.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 32/57] scsi: ips: Prepare for enabling lock context analysis
Date: Thu, 30 Jul 2026 23:15:49 +0000	[thread overview]
Message-ID: <20260730231549.E78421F000E9@smtp.kernel.org> (raw)
In-Reply-To: <af0effbc214b28654685796b43f2783236c52c14.1785451174.git.bvanassche@acm.org>

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

Pre-existing issues:
- [High] Calling scsi_done() before unmapping DMA causes a potential use-after-free of the scsi_cmnd structure.
- [High] Incorrect waitlist traversal causes premature loop termination and a potential use-after-free on `struct scsi_cmnd` if command submission fails.
- [High] Memory allocations use GFP_KERNEL in atomic contexts (while holding a spinlock or in a hardirq handler), which can sleep and cause a kernel panic.
- [High] Process-context functions acquire the SCSI host_lock using spin_lock() instead of spin_lock_irqsave(), leaving them vulnerable to deadlocks from the interrupt handler.
- [High] ips_wait() busy-waits with udelay(1000) for up to 60 seconds with hardware interrupts disabled, leading to a hard lockup.
- [High] Using BUG_ON() for scsi_dma_map() failures causes an unnecessary kernel panic.
--

--- Patch [32]: [PATCH v3 32/57] scsi: ips: Prepare for enabling lock context analysis ---
commit 3f51682bbdf047060a964b17e4ca87b13e0de2ad
Author: Bart Van Assche <bvanassche@acm.org>
scsi: ips: Prepare for enabling lock context analysis

This commit annotates ips_next() with __context_unsafe to indicate it
performs conditional locking. This prepares the driver for context lock
analysis.

> diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
> index 41ed73966a48c..5ef70f058ecd6 100644
> --- a/drivers/scsi/ips.c
> +++ b/drivers/scsi/ips.c
> @@ -2506,6 +2506,7 @@ ips_hainit(ips_ha_t * ha)
>  /****************************************************************************/
>  static void
>  ips_next(ips_ha_t * ha, int intr)
> +	__context_unsafe(conditional locking)
>  {
>  	ips_scb_t *scb;

[Severity: High]
This isn't a bug introduced by this patch, but does calling scsi_done()
before unmapping the DMA cause a potential use-after-free?

In ips_next() and ips_done(), the command is completed before the SCB is
freed:

drivers/scsi/ips.c:ips_next() {
    ...
    case IPS_FAILURE:
        if (scb->scsi_cmd) {
            scb->scsi_cmd->result = DID_ERROR << 16;
            scsi_done(scb->scsi_cmd);
        }

        ips_freescb(ha, scb);
        break;
    ...
}

Because scsi_done() hands ownership of the command to the block layer,
the block layer might asynchronously complete and free or recycle the
struct scsi_cmnd. Could ips_freescb() then dereference a freed pointer
when it subsequently calls scsi_dma_unmap(scb->scsi_cmd)?


[Severity: High]
This is a pre-existing issue, but does the waitlist traversal in
ips_next() prematurely terminate the loop and risk a use-after-free?

The list linkage is destroyed by explicitly clearing host_scribble:

drivers/scsi/ips.c:ips_next() {
    ...
    SC = ips_removeq_wait(&ha->scb_waitlist, q);
    ...
    SC->host_scribble = NULL;
    ...
}

If command submission fails or completes synchronously, scsi_done() is
invoked on the command, passing ownership of the command (aliased by p)
to the block layer. Could the loop then execute the following iteration
step using potentially freed memory?

drivers/scsi/ips.c:ips_next() {
    ...
    p = (struct scsi_cmnd *) p->host_scribble;
    ...
}

Furthermore, since host_scribble was set to NULL, would p become NULL
and terminate the dispatch loop early, starving any remaining queued
commands?


[Severity: High]
This isn't a bug introduced by this patch, but do the memory allocations
use GFP_KERNEL in atomic contexts?

When ips_next() processes passthru commands, it holds the host_lock
spinlock. If called from ips_queue_lck via IPS_INTR_IORL, it runs with
interrupts disabled and the lock is not dropped.

During this path, functions like ips_alloc_passthru_buffer() and
ips_flash_copperhead() perform allocations using GFP_KERNEL:

drivers/scsi/ips.c:ips_alloc_passthru_buffer() {
    ...
    bigger_buf = dma_alloc_coherent(&ha->pcidev->dev, length,
                                    &dma_busaddr, GFP_KERNEL);
    ...
}

Since GFP_KERNEL allows blocking, can this sleep in an atomic context
and trigger a kernel panic?


[Severity: High]
This is a pre-existing issue, but is there a deadlock vulnerability
between process-context functions and the interrupt handler?

The hardware interrupt handler do_ipsintr() runs in hardirq context and
acquires the lock using spin_lock(). Meanwhile, process-context
functions like ips_eh_abort() also acquire it without disabling local
interrupts:

drivers/scsi/ips.c:ips_eh_abort() {
    ...
    spin_lock(host->host_lock);
    ...
}

If an interrupt fires on the same CPU while the scsi_eh thread holds the
lock, will the interrupt handler attempt to acquire the lock and cause
an AB-BA self-deadlock?


[Severity: High]
This isn't a bug introduced by this patch, but does ips_wait()
busy-wait for too long with hardware interrupts disabled?

In ips_eh_reset(), hardware interrupts are completely disabled on the
local CPU:

drivers/scsi/ips.c:ips_eh_reset() {
    ...
    spin_lock_irq(SC->device->host->host_lock);
    rc = __ips_eh_reset(SC);
    ...
}

This triggers a flush that eventually falls back to a polling loop in
ips_wait(), which calls udelay(1000) up to 60,000 times:

drivers/scsi/ips.c:ips_wait() {
    ...
    /* This looks like a very evil loop, but it only does this during start-up */
    udelay(1000);
    time--;
    ...
}

Could looping for up to 60 seconds with interrupts disabled violate
latency requirements and trigger the kernel's hard lockup watchdog?


[Severity: High]
This is a pre-existing issue, but does using BUG_ON() for DMA mapping
failures cause an unnecessary kernel panic?

In ips_next(), a mapping failure triggers a system panic:

drivers/scsi/ips.c:ips_next() {
    ...
    scb->sg_count = scsi_dma_map(SC);
    BUG_ON(scb->sg_count < 0);
    ...
}

Since scsi_dma_map() can return negative values like -ENOMEM when IOMMU
mappings or DMA resources are exhausted, would it be better to gracefully
fail the command or propagate the error rather than intentionally crashing
the system?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785451174.git.bvanassche@acm.org?part=32

  reply	other threads:[~2026-07-30 23:15 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 22:44 [PATCH v3 00/57] Enable lock context analysis for the SCSI subsystem Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 01/57] PCI: Convert to_pci_dev() into an inline function Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 02/57] scsi: scsi_debug: Prepare for enabling lock context analysis Bart Van Assche
2026-07-30 23:01   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 03/57] scsi: sg: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 04/57] scsi: st: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 05/57] scsi: BusLogic: Introduce two local variables Bart Van Assche
2026-07-30 23:01   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 06/57] scsi: BusLogic: Prepare for enabling lock context analysis Bart Van Assche
2026-07-30 23:06   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 07/57] scsi: NCR5380: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 08/57] scsi: aacraid: " Bart Van Assche
2026-07-30 23:04   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 09/57] scsi: aic7xxx: Enable " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 10/57] scsi: aha152x: Prepare for enabling " Bart Van Assche
2026-07-30 23:18   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 11/57] scsi: aic7xxx: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 12/57] scsi: aic94xx: Enable " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 13/57] scsi: arcmsr: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 14/57] scsi: arm: " Bart Van Assche
2026-07-30 22:44 ` [PATCH v3 15/57] scsi: be2iscsi: Prepare for enabling " Bart Van Assche
2026-07-30 23:04   ` sashiko-bot
2026-07-30 22:44 ` [PATCH v3 16/57] scsi: be2iscsi: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 17/57] scsi: cxgbi: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 18/57] scsi: bfa: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 19/57] scsi: bnx2fc: " Bart Van Assche
2026-07-30 23:01   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 20/57] scsi: bnx2i: Introduce a local variable Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 21/57] scsi: bnx2i: Enable lock context analysis Bart Van Assche
2026-07-30 23:29   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 22/57] scsi: csiostor: " Bart Van Assche
2026-07-30 23:19   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 23/57] scsi: elx: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 24/57] scsi: esas2r: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 25/57] scsi: fcoe: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 26/57] scsi: fnic: " Bart Van Assche
2026-07-30 23:11   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 27/57] scsi: hisi_sas: " Bart Van Assche
2026-07-30 23:02   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 28/57] scsi: hpsa: Prepare for enabling " Bart Van Assche
2026-07-30 23:27   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 29/57] scsi: ibmvscsi: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 30/57] scsi: ibmvscsi_tgt: " Bart Van Assche
2026-07-30 23:27   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 31/57] scsi: ipr: Prepare for enabling " Bart Van Assche
2026-07-30 23:15   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 32/57] scsi: ips: " Bart Van Assche
2026-07-30 23:15   ` sashiko-bot [this message]
2026-07-30 22:45 ` [PATCH v3 33/57] scsi: isci: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 34/57] scsi: libfc: " Bart Van Assche
2026-07-30 23:19   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 35/57] scsi: libiscsi: Prepare for enabling " Bart Van Assche
2026-07-30 23:17   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 36/57] scsi: libsas: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 37/57] scsi: libsas: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 38/57] scsi: lpfc: Prepare for enabling " Bart Van Assche
2026-07-30 23:09   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 39/57] scsi: megaraid_sas: " Bart Van Assche
2026-07-30 23:15   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 40/57] scsi: megaraid: Enable " Bart Van Assche
2026-07-30 23:15   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 41/57] scsi: mpt3sas: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 42/57] scsi: mvsas: " Bart Van Assche
2026-07-30 23:18   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 43/57] scsi: pcmcia: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 44/57] scsi: pm8001: " Bart Van Assche
2026-07-30 23:31   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 45/57] scsi: qedf: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 46/57] scsi: qedi: " Bart Van Assche
2026-07-30 23:17   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 47/57] scsi: qla1280: Prepare for enabling " Bart Van Assche
2026-07-30 23:19   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 48/57] scsi: qla2xxx: Enable " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 49/57] scsi: qla4xxx: " Bart Van Assche
2026-07-30 23:25   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 50/57] scsi: ufs: " Bart Van Assche
2026-07-30 23:19   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 51/57] scsi: iSCSI transport: Prepare for enabling " Bart Van Assche
2026-07-30 23:23   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 52/57] scsi: smartpqi: Enable " Bart Van Assche
2026-07-30 23:22   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 53/57] scsi: snic: " Bart Van Assche
2026-07-30 22:45 ` [PATCH v3 54/57] scsi: sym53c8xx_2: " Bart Van Assche
2026-07-30 23:27   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 55/57] scsi: core: Pass the SCSI host pointer directly Bart Van Assche
2026-07-30 23:22   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 56/57] scsi: core: Enable lock context analysis Bart Van Assche
2026-07-30 23:36   ` sashiko-bot
2026-07-30 22:45 ` [PATCH v3 57/57] scsi: core: Protect host state changes with the host lock Bart Van Assche
2026-07-30 23:32   ` sashiko-bot

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=20260730231549.E78421F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bvanassche@acm.org \
    --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