From: Jens Axboe <axboe@kernel.dk>
To: Caleb Sander Mateos <csander@purestorage.com>,
Rahul Chandelkar <rc@rexion.ai>
Cc: James.Bottomley@hansenpartnership.com,
martin.petersen@oracle.com, fujita.tomonori@lab.ntt.co.jp,
linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
io-uring@vger.kernel.org
Subject: Re: [PATCH] scsi: bsg: copy uring_cmd payload to prevent double-fetch from shared SQE
Date: Wed, 27 May 2026 10:45:16 -0600 [thread overview]
Message-ID: <07c25a67-54b3-4ecd-bdf1-7ca0cefc8e38@kernel.dk> (raw)
In-Reply-To: <CADUfDZr6LJckoVt2NRfRt3Njs-WAqsg5-QnTDi6xbUDiO950Fw@mail.gmail.com>
On 5/27/26 10:27 AM, Caleb Sander Mateos wrote:
> On Wed, May 27, 2026 at 9:19 AM Rahul Chandelkar <rc@rexion.ai> wrote:
>>
>> On Wed, May 27, 2026 at 10:06:44AM -0600, Jens Axboe wrote:
>>> I don't think this is the right way to fix it, ->sqe should've been
>>> stable upfront if this ends up happening. Can you share your poc with
>>> me? Your trace has been trimmed down way too much to be useful.
>>
>> Agreed that a core-level copy before the inline callback would be the
>> right fix and would eliminate the entire class for every uring_cmd
>> driver. The per-driver copy was meant as a minimal backportable fix
>> for the immediate scsi_bsg path.
>>
>> PoC and full trace below.
>>
>> --- PoC (poc_bsg_toctou.c) ---
>>
>> Build: gcc -O2 -pthread -static -o poc poc_bsg_toctou.c
>> Usage: ./poc /dev/bsg/X
>> Needs: 2+ CPUs, io_uring, /dev/bsg/* access
>>
>> The racer thread flips request_len between 16 (passes the <=32 bounds
>> check) and 128 (used by copy_from_user, overflows scmd->cmnd[32]).
>> The overflow payload plants 0xdead000000001000 at the sense_buffer
>> pointer offset (+84 from cmnd[0]). When scsi_queue_rq() does
>> memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE) it faults on the
>> corrupted pointer.
>
> Then the fix is to use READ_ONCE() to access the SQE fields, right?
> Copying the entire SQE seems like unnecessary overhead. See
> nvme_uring_cmd_io() for prior art.
That is indeed the correct fix.
--
Jens Axboe
next prev parent reply other threads:[~2026-05-27 16:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 10:59 [PATCH] scsi: bsg: copy uring_cmd payload to prevent double-fetch from shared SQE Rahul Chandelkar
2026-05-27 16:03 ` Bart Van Assche
2026-05-27 16:06 ` Jens Axboe
2026-05-27 16:19 ` Rahul Chandelkar
2026-05-27 16:27 ` Caleb Sander Mateos
2026-05-27 16:45 ` Jens Axboe [this message]
2026-05-27 16:48 ` Jens Axboe
2026-05-27 19:17 ` [PATCH v2] scsi: bsg: read io_uring command fields once Rahul Chandelkar
2026-05-30 18:02 ` Yang Xiuwei
2026-06-25 3:25 ` Yang Xiuwei
2026-06-25 12:06 ` Jens Axboe
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=07c25a67-54b3-4ecd-bdf1-7ca0cefc8e38@kernel.dk \
--to=axboe@kernel.dk \
--cc=James.Bottomley@hansenpartnership.com \
--cc=csander@purestorage.com \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=io-uring@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=rc@rexion.ai \
/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