Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Weibin Liu" <liuwb@xiaopeng.com>, linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: mpt3sas: fix OOB SGE write at the request frame boundary
Date: Thu, 15 Oct 2026 02:15:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-172135@kernel.org> (raw)
In-Reply-To: <20261015-mpt3sas-sge-offset-v1-1-9b91c265f2c1@xiaopeng.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: mpt3sas: incomplete bounds check leaves OOB write unpatched
--

commit c6cf70bbba6355fabaab51bc07707d150970dad8
Author: Weibin Liu <liuwb@xiaopeng.com>

scsi: mpt3sas: fix OOB SGE write at the request frame boundary

_ctl_do_mpt_command() bounds the user-supplied data_sge_offset with
strict inequalities. When data_sge_offset * 4 is exactly ioc->request_sz,
both comparisons pass, allowing an OOB write. This commit changes the
comparison to >= to reject offsets that point exactly at or past the
end of the request frame.

> diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> index 8bb947004885b..d8d3ee11ed520 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> @@ -739,7 +739,7 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
>  	}
>  
>  	/* Check for overflow and wraparound */
> -	if (karg.data_sge_offset * 4 > ioc->request_sz ||
> +	if (karg.data_sge_offset * 4 >= ioc->request_sz ||
>  	    karg.data_sge_offset > (UINT_MAX / 4)) {

[Severity: High]
Does this bounds check leave an out-of-bounds write unpatched?

If a user issues an MPT3COMMAND ioctl with karg.data_sge_offset set such
that karg.data_sge_offset * 4 is slightly less than ioc->request_sz
(e.g., ioc->request_sz - 4), the updated validation still passes because
ioc->request_sz - 4 is not >= ioc->request_sz.

The SGE array pointer psge would then be set to point 4 bytes before the
end of the request frame. The SGE builder functions (ioc->build_sg, such
as _base_build_sg() or _base_build_zero_len_sge()) write a minimum of 8
to 32 bytes of scatter-gather elements to psge without further bounds
checking:

drivers/scsi/mpt3sas/mpt3sas_base.c:_base_build_sg() {
...
	if (!data_out_sz && !data_in_sz) {
		_base_build_zero_len_sge(ioc, psge);
		return;
	}
...
}

Since only 4 bytes remain in the frame, the SGE write overflows the request
buffer by at least 4 bytes. Because the request buffers are allocated
contiguously in a DMA pool array, does this overflow corrupt the adjacent
request frame?

>  		ret = -EINVAL;
>  		goto out;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015-mpt3sas-sge-offset-v1-1-9b91c265f2c1@xiaopeng.com?part=1

      reply	other threads:[~2026-10-15  2:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  2:05 [PATCH] scsi: mpt3sas: fix OOB SGE write at the request frame boundary Weibin Liu
2026-10-15  2:15 ` 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-172135@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=liuwb@xiaopeng.com \
    --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