All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yehyeong Lee" <yhlee@isslab.korea.ac.kr>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 3/3] scsi: arcmsr: wrap the type B completion index before using it
Date: Mon, 12 Oct 2026 09:18:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-167892@kernel.org> (raw)
In-Reply-To: <d212c8fcde795a43e070d827d1d9d3fe4fcbe65b.1791792888.git.yhlee@isslab.korea.ac.kr>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] scsi: arcmsr: missing lock in arcmsr_hbaB_postqueue_isr() allows double scsi_done
- [High] scsi: arcmsr: missing bounds check on device-supplied flag_ccb pointer arithmetic
--

commit d4c56c066e7826c7ed7b29fee09fa6ea641b3ec5
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>

scsi: arcmsr: wrap the type B completion index before using it

This commit fixes an out-of-bounds read in arcmsr_hbaB_postqueue_isr()
and arcmsr_hbaB_polling_ccbdone() by applying a modulo to doneq_index 
before using it as an array index. The index is read from shared memory 
where it could exceed the maximum queue size before being wrapped.

Cc: stable@vger.kernel.org

> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
> @@ -2568,7 +2568,7 @@ static void arcmsr_hbaB_postqueue_isr(struct AdapterControlBlock *acb)
>  	bool error;
>  	unsigned long cdb_phy_addr;
>  
> -	index = reg->doneq_index;
> +	index = reg->doneq_index % ARCMSR_MAX_HBB_POSTQUEUE;
>  	while ((flag_ccb = reg->done_qbuffer[index]) != 0) {

[Severity: High]
Does this loop need synchronization to protect the shared completion ring?

The SCSI error handler invokes arcmsr_abort() without holding the host_lock,
which in turn calls arcmsr_hbaB_polling_ccbdone(). Neither
arcmsr_hbaB_postqueue_isr() nor arcmsr_hbaB_polling_ccbdone() acquires
acb->doneq_lock (unlike adapters D and F) or any other synchronization
primitive before reading from the hardware completion ring.

If a command times out and arcmsr_abort() executes on CPU 1 just as the
device interrupt fires and executes arcmsr_hbaB_postqueue_isr() on CPU 2,
could both threads fetch the exact same CCB completion entry? This could
result in concurrently invoking arcmsr_ccb_complete(), leading to a double
scsi_dma_unmap(), double scsi_done(), and corruption of the ccb_free_list.

>  		cdb_phy_addr = (flag_ccb << 5) & 0xffffffff;
>  		if (acb->cdb_phyadd_hipart)

[Severity: High]
Can a compromised or malicious hardware device supply a crafted flag_ccb to
trigger arbitrary kernel memory corruption?

The driver derives the pCCB kernel virtual pointer directly from the
device-supplied flag_ccb index without ensuring it falls within the driver's
preallocated CCB pool. When the driver processes this pointer in
arcmsr_drain_donequeue() or arcmsr_report_ccb_state(), it might dereference
an attacker-controlled pointer and write values like DID_OK << 16 to it.

Should there be a software-based bounds check on the calculated offset
before converting it into a CommandControlBlock pointer to protect against
untrusted device inputs?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791792888.git.yhlee@isslab.korea.ac.kr?part=3

      reply	other threads:[~2026-10-12  9:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12  9:01 [PATCH v2 0/3] scsi: arcmsr: bound adapter-supplied completion indices and message lengths Yehyeong Lee
2026-10-12  9:01 ` [PATCH v2 1/3] scsi: arcmsr: bound the firmware-supplied message length Yehyeong Lee
2026-10-12  9:14   ` sashiko-bot
2026-10-12  9:01 ` [PATCH v2 2/3] scsi: arcmsr: check the completion index the adapter reports Yehyeong Lee
2026-10-12  9:14   ` sashiko-bot
2026-10-12  9:01 ` [PATCH v2 3/3] scsi: arcmsr: wrap the type B completion index before using it Yehyeong Lee
2026-10-12  9:18   ` 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=sashiko-outbox-167892@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yhlee@isslab.korea.ac.kr \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.