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 v4 1/3] scsi: bfa: clamp the received unsolicited frame length to the buffer
Date: Fri, 16 Oct 2026 08:41:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-174028@kernel.org> (raw)
In-Reply-To: <20261016082818.1237059-2-yhlee@isslab.korea.ac.kr>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] scsi: bfa: integer underflow causes massive OOB DMA read in bfa_fcs_lport_echo
- [High] scsi: bfa: missing bounds check on firmware-supplied buf_tag in uf_recv()
--

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

scsi: bfa: clamp the received unsolicited frame length to the buffer

The commit addresses an issue where uf_recv() blindly accepts the
unsolicited frame length from the firmware. By capping uf->data_len to
the size of the posted buffer, it prevents out-of-bounds writes in
downstream consumers.

> diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c
> index df33afaaa6735..1ccf2e994a671 100644
> --- a/drivers/scsi/bfa/bfa_svc.c
> +++ b/drivers/scsi/bfa/bfa_svc.c
> @@ -5453,7 +5453,7 @@ uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m)

[Severity: High]
Since this patch addresses untrusted firmware input by clamping m->xfr_len,
is it safe to use m->buf_tag as a direct array index?

Earlier in this same function:

drivers/scsi/bfa/bfa_svc.c:uf_recv() {
    ...
	u16 uf_tag = m->buf_tag;
	struct bfa_uf_s *uf = &ufm->uf_list[uf_tag];
    ...
	uf_buf = (struct bfa_uf_buf_s *)
			bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len);
    ...
}

If a buggy or malicious firmware provides an out-of-bounds buf_tag, won't this
lead to out-of-bounds array accesses to ufm->uf_list and out-of-bounds DMA
segment calculations?

>  	list_del(&uf->qe);	/* dequeue from posted queue */
>  
>  	uf->data_ptr = buf;
> -	uf->data_len = m->xfr_len;
> +	uf->data_len = min_t(u16, m->xfr_len, sizeof(struct bfa_uf_buf_s));
>  
>  	WARN_ON(uf->data_len < sizeof(struct fchs_s));
>  

[Severity: High]
If the received frame is truncated and m->xfr_len is smaller than
sizeof(struct fchs_s) (24 bytes), this warns but still processes the frame.

Will this lead to an integer underflow later? In bfa_fcs_lport_echo(),
pyld_len is calculated as:

drivers/scsi/bfa/bfa_fcs_lport.c:bfa_fcs_lport_echo() {
    ...
    pyld_len = rx_len - sizeof(struct fchs_s);
    ...
}

If rx_len is less than 24, pyld_len underflows. Since pyld_len is an int,
this evaluates to a negative number, bypassing the subsequent check:

    if (pyld_len > len)

The negative pyld_len is then passed to bfa_fcxp_send(), which takes a u32
reqlen. Does this implicit cast to a massive length (~4.29GB) result in a huge
out-of-bounds DMA read when submitted to the firmware?

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

  reply	other threads:[~2026-10-16  8:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  8:28 [PATCH v4 0/3] scsi: bfa: bound the unsolicited frame receive path Yehyeong Lee
2026-10-16  8:28 ` [PATCH v4 1/3] scsi: bfa: clamp the received unsolicited frame length to the buffer Yehyeong Lee
2026-10-16  8:41   ` sashiko-bot [this message]
2026-10-16  8:28 ` [PATCH v4 2/3] scsi: bfa: drop unsolicited frames shorter than their VFT header Yehyeong Lee
2026-10-16  8:44   ` sashiko-bot
2026-10-16  8:28 ` [PATCH v4 3/3] scsi: bfa: bound the RSCN event list by the received frame length 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-174028@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