All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stanley Jhu" <stanleyjhu@google.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: bsg: Pass reply_len to bsg_setup_queue() to fit UFS ARPMB replies
Date: Tue, 13 Oct 2026 13:39:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-169843@kernel.org> (raw)
In-Reply-To: <20261013132708.1669415-1-stanleyjhu@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] block/bsg: infoleak of recycled reply buffer on synchronous LLD error
--

commit 52ec043e68f598e70d8f2fbea510e68eefe133cc
Author: Stanley Jhu <stanleyjhu@google.com>

scsi: bsg: Pass reply_len to bsg_setup_queue() to fit UFS ARPMB replies

This commit updates bsg_setup_queue() to accept a reply_len parameter,
allowing BSG transports like UFS to specify custom reply buffer sizes.
It modifies bsg-lib to use this dynamic length for memory allocation
and reply copying.

> diff --git a/block/bsg-lib.c b/block/bsg-lib.c
> index 895db30a7033d..536cee4430a76 100644
> --- a/block/bsg-lib.c
> +++ b/block/bsg-lib.c
> @@ -50,7 +53,7 @@ static int bsg_transport_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
>  	reply = job->reply;
>  	memset(job, 0, sizeof(*job));
>  	job->reply = reply;
> -	job->reply_len = SCSI_SENSE_BUFFERSIZE;
> +	job->reply_len = bset->reply_len;

[Severity: Medium]
Does this code leak the contents of the recycled reply buffer to user space
on a synchronous low level driver error?

The job->reply buffer is allocated once per tag during queue setup and is
reused across requests. While the job struct itself is cleared with memset()
here, the job->reply buffer is not zeroed per-request.

If the transport's job handler fails synchronously, the request is completed
with an error, but job->result might not be updated and remains 0.

Later in bsg_transport_sg_io_fn(), the code relies on job->result to restrict
the copy length:

    if (job->result < 0) {
        /* we're only returning the result field in the reply */
        job->reply_len = sizeof(u32);
        ret = job->result;
    }

    if (job->reply_len && hdr->response) {
        int len = min(hdr->max_response_len, job->reply_len);

        if (copy_to_user(uptr64(hdr->response), job->reply, len))

Since job->result is 0, this check is bypassed and the full bset->reply_len
bytes of the uninitialized or recycled job->reply buffer will be copied to
user space. For UFS Advanced RPMB, this could leak up to 104 bytes of the
previous request's data.

Should the reply buffer be cleared when initializing the job, or should
job->result be explicitly set on all error paths?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013132708.1669415-1-stanleyjhu@google.com?part=1

      reply	other threads:[~2026-10-13 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 13:27 [PATCH] scsi: bsg: Pass reply_len to bsg_setup_queue() to fit UFS ARPMB replies Stanley Jhu
2026-10-13 13:39 ` 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-169843@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stanleyjhu@google.com \
    /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.