Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiacheng Xu" <stitch@zju.edu.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: sg: update local scatter size when clamping
Date: Mon, 12 Oct 2026 14:12:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-168246@kernel.org> (raw)
In-Reply-To: <20261012135955.78357-1-stitch@zju.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scsi: sg: compiler reload of lockless global scatter_elem_sz bypasses clamp
--

commit c196717f4b3e3f71b450481a3b45198601caf07e
Author: Jiacheng Xu <stitch@zju.edu.cn>

scsi: sg: update local scatter size when clamping

When scatter_elem_sz is set to a value smaller than PAGE_SIZE through
its writable sysfs module parameter, sg_build_indirect() updates the
global scatter element size variables but leaves the local num
variable unchanged.

> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 3f9e08725602c..64ce489128672 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -1863,6 +1863,7 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
>  	num = scatter_elem_sz;
>  	if (unlikely(num != scatter_elem_sz_prev)) {
>  		if (num < PAGE_SIZE) {
> +			num = PAGE_SIZE;
>  			scatter_elem_sz = PAGE_SIZE;
>  			scatter_elem_sz_prev = PAGE_SIZE;
>  		} else

[Severity: Medium]
Since scatter_elem_sz is a global variable accessed locklessly in
sg_build_indirect(), is there a risk the compiler could reload its value
from memory after the initial read without READ_ONCE()?

If scatter_elem_sz is changed to 0 by a concurrent sysfs write right after
the `num < PAGE_SIZE` check, could a compiler reload in the `else` branch
assign 0 to scatter_elem_sz_prev?

drivers/scsi/sg.c:sg_build_indirect() {
...
		} else
			scatter_elem_sz_prev = num;
...
}

If this happens, on the next execution both variables would be 0, causing
`num != scatter_elem_sz_prev` to evaluate to false.

Would this permanently bypass the clamp and pass 0 to get_order(),
reproducing the exact shift-out-of-bounds bug this patch is attempting to
fix?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012135955.78357-1-stitch@zju.edu.cn?part=1

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 13:59 [PATCH] scsi: sg: update local scatter size when clamping Jiacheng Xu
2026-10-12 14:12 ` 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-168246@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stitch@zju.edu.cn \
    /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