From: sashiko-bot@kernel.org
To: "Yang Xiuwei" <yangxiuwei@kylinos.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 1/2] scsi: bsg: fix TOCTOU in io_uring passthrough command setup
Date: Mon, 20 Jul 2026 03:37:23 +0000 [thread overview]
Message-ID: <20260720033724.24BD81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720032338.461681-2-yangxiuwei@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Kernel memory leak of uninitialized sense buffer bytes to user space.
--
--- Patch [1]: [PATCH 1/2] scsi: bsg: fix TOCTOU in io_uring passthrough command setup ---
commit bb53b6e06613a855cd8556487582a73b36038ec3
Author: Rahul Chandelkar <rc@rexion.ai>
scsi: bsg: fix TOCTOU in io_uring passthrough command setup
This commit fixes a TOCTOU vulnerability in scsi_bsg_uring_cmd() by snapshotting
SQE fields with READ_ONCE() before validation and reuse. The stable map
arguments are then passed into scsi_bsg_map_user_buffer().
Link: https://lore.kernel.org/r/20260527105931.3950913-1-rc@rexion.ai
> diff --git a/drivers/scsi/scsi_bsg.c b/drivers/scsi/scsi_bsg.c
> index e80dec53174ea..c57ce01379de5 100644
> --- a/drivers/scsi/scsi_bsg.c
> +++ b/drivers/scsi/scsi_bsg.c
[ ... ]
> @@ -158,8 +164,14 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc
> scmd->sense_len = cmd->max_response_len ?
> min(cmd->max_response_len, SCSI_SENSE_BUFFERSIZE) : SCSI_SENSE_BUFFERSIZE;
>
[Severity: High]
This isn't a bug introduced by this patch, but does overwriting scmd->sense_len
with the maximum response size leak uninitialized kernel memory to user space?
The SCSI midlayer expects sense_len to hold the actual valid length of the
sense data, but it is overwritten here with the user's max_response_len.
If a command fails, the low-level driver might populate a small amount of sense
data (e.g., 18 bytes) without zeroing the rest of the buffer.
The completion handler in drivers/scsi/scsi_bsg.c retrieves this artificially
inflated sense_len to determine how many bytes to copy:
scsi_bsg_uring_task_cb() {
...
if (pdu->response_addr)
sense_len_wr = min_t(u8, scmd->sense_len,
SCSI_SENSE_BUFFERSIZE);
...
if (copy_to_user(uptr64(pdu->response_addr), scmd->sense_buffer,
sense_len_wr))
...
}
Could this copy uninitialized trailing bytes from the reused sense_buffer to
user space?
> - if (cmd->dout_xfer_len || cmd->din_xfer_len) {
> - ret = scsi_bsg_map_user_buffer(req, ioucmd, issue_flags, gfp_mask);
> + if (dout_xfer_len || din_xfer_len) {
> + bool is_write = dout_xfer_len > 0;
> + u64 buf_addr = is_write ? dout_xferp : din_xferp;
> + unsigned long buf_len = is_write ? dout_xfer_len : din_xfer_len;
> +
> + ret = scsi_bsg_map_user_buffer(req, ioucmd, issue_flags,
> + gfp_mask, is_write, buf_addr,
> + buf_len);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720032338.461681-1-yangxiuwei@kylinos.cn?part=1
next prev parent reply other threads:[~2026-07-20 3:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 3:23 [PATCH 0/2] scsi: bsg: fix io_uring passthrough issues Yang Xiuwei
2026-07-20 3:23 ` [PATCH 1/2] scsi: bsg: fix TOCTOU in io_uring passthrough command setup Yang Xiuwei
2026-07-20 3:37 ` sashiko-bot [this message]
2026-07-20 3:23 ` [PATCH 2/2] scsi: bsg: map io_uring user buffers with GFP_KERNEL Yang Xiuwei
2026-07-20 3:39 ` sashiko-bot
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=20260720033724.24BD81F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yangxiuwei@kylinos.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 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.