Linux SCSI subsystem development
 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 v3 1/3] scsi: arcmsr: bound the firmware-supplied message length
Date: Mon, 12 Oct 2026 11:54:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-168035@kernel.org> (raw)
In-Reply-To: <adc1e1512a87ff16e99d066c2e96e18a1d28e610.1791803953.git.yhlee@isslab.korea.ac.kr>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scsi: arcmsr: TOCTOU double fetch causes circular buffer corruption
--

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

scsi: arcmsr: bound the firmware-supplied message length

This commit addresses an out-of-bounds write where an unbounded data_len
from the MMIO register could walk past the 128-byte staging buffer. It
clamps the length to the size of the window (124 bytes) in both reader
functions.

> diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
> index 8aa948f06cacf..255f1d898079f 100644
> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
> @@ -2277,6 +2277,8 @@ arcmsr_Read_iop_rqbuffer_in_DWORD(struct AdapterControlBlock *acb,
>  
>  	iop_data = (uint32_t __iomem *)prbuffer->data;
>  	iop_len = readl(&prbuffer->data_len);
> +	if (iop_len > sizeof(prbuffer->data))
> +		iop_len = sizeof(prbuffer->data);

[Severity: Medium]
The commit message notes that the adapter can change data_len between the two
reads. While clamping iop_len to sizeof(prbuffer->data) prevents the staging
buffer overflow, does this still leave a TOCTOU (time-of-check to time-of-use)
vulnerability that can corrupt the circular buffer?

arcmsr_iop2drv_data_wrote_handle() validates the first fetch against
buf_empty_len:

drivers/scsi/arcmsr/arcmsr_hba.c:arcmsr_iop2drv_data_wrote_handle() {
	...
	if (buf_empty_len >= readl(&prbuffer->data_len)) {
		if (arcmsr_Read_iop_rqbuffer_data(acb, prbuffer) == 0)
			...
}

If buf_empty_len is small (e.g., 10 bytes), the first fetch could be 10, passing
the check. If the second fetch here sees an increased data_len from the MMIO
register (e.g., 124 bytes), the while loop below will write more bytes than
buf_empty_len.

Could this cause rqbuf_putIndex to overtake rqbuf_getIndex and corrupt the
driver's internal ring buffer state?

>  	if (iop_len > 0) {
>  		buf1 = kmalloc(128, GFP_ATOMIC);
>  		buf2 = (uint32_t *)buf1;

[ ... ]

> @@ -2319,6 +2321,8 @@ arcmsr_Read_iop_rqbuffer_data(struct AdapterControlBlock *acb,
>  		return arcmsr_Read_iop_rqbuffer_in_DWORD(acb, prbuffer);
>  	iop_data = (uint8_t __iomem *)prbuffer->data;
>  	iop_len = readl(&prbuffer->data_len);
> +	if (iop_len > sizeof(prbuffer->data))
> +		iop_len = sizeof(prbuffer->data);

[Severity: Medium]
This second fetch in the byte-wise reader shares the same vulnerability when
called from arcmsr_iop2drv_data_wrote_handle().

Would passing the validated length down from the caller prevent the hardware
from bypassing the buf_empty_len check entirely?

>  	while (iop_len > 0) {
>  		pQbuffer = &acb->rqbuffer[acb->rqbuf_putIndex];
>  		*pQbuffer = readb(iop_data);

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

  reply	other threads:[~2026-10-12 11:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 11:41 [PATCH v3 0/3] scsi: arcmsr: bound adapter-supplied completion indices and message lengths Yehyeong Lee
2026-10-12 11:41 ` [PATCH v3 1/3] scsi: arcmsr: bound the firmware-supplied message length Yehyeong Lee
2026-10-12 11:54   ` sashiko-bot [this message]
2026-10-12 12:16     ` Yehyeong Lee
2026-10-12 11:41 ` [PATCH v3 2/3] scsi: arcmsr: check the completion index the adapter reports Yehyeong Lee
2026-10-12 11:41 ` [PATCH v3 3/3] scsi: arcmsr: wrap the type B completion index before using it Yehyeong Lee
2026-10-12 11:59   ` sashiko-bot
2026-10-12 12:16     ` Yehyeong Lee

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-168035@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox