scsi: bsg: copy uring_cmd payload to prevent double-fetch from shared SQE#895
scsi: bsg: copy uring_cmd payload to prevent double-fetch from shared SQE#895blktests-ci[bot] wants to merge 1 commit into
Conversation
|
Upstream branch: e8c2f9f |
|
Upstream branch: e8c2f9f |
927534d to
c75e599
Compare
86d8d37 to
9805659
Compare
|
Upstream branch: eb3f4b7 |
c75e599 to
bc692df
Compare
9805659 to
3f4a345
Compare
|
Upstream branch: 8fde5d1 |
bc692df to
445da35
Compare
3f4a345 to
c6dc343
Compare
|
Upstream branch: e43ffb6 |
445da35 to
e1dac9f
Compare
c6dc343 to
fc36596
Compare
|
Upstream branch: ba3e43a |
e1dac9f to
0b93bb9
Compare
fc36596 to
7bed9c3
Compare
|
Upstream branch: ddd664b |
0b93bb9 to
6a57555
Compare
7bed9c3 to
a7bb5c5
Compare
|
Upstream branch: 979c294 |
6a57555 to
ad06c61
Compare
a7bb5c5 to
5e41a3b
Compare
|
Upstream branch: acb7500 |
ad06c61 to
f380f37
Compare
5e41a3b to
c3a084b
Compare
|
Upstream branch: 9716c08 |
f380f37 to
fce8c9b
Compare
c3a084b to
5f78e5d
Compare
|
Upstream branch: 2a2974b |
fce8c9b to
12df0a3
Compare
5f78e5d to
e48f9db
Compare
|
Upstream branch: 062871f |
12df0a3 to
8f0f501
Compare
199644a to
e6d9eb8
Compare
|
Upstream branch: 66affa3 |
8f0f501 to
9df46ef
Compare
e6d9eb8 to
7d8604f
Compare
… SQE scsi_bsg_uring_cmd() and scsi_bsg_map_user_buffer() read bsg_uring_cmd fields directly from the shared mmap'd io_uring submission ring via io_uring_sqe128_cmd(). On the inline execution path, io_uring has not yet copied the SQE to kernel memory, so a concurrent userspace thread can modify fields between reads. cmd->request_len is read for the bounds check, for the cmd_len assignment, and for the copy_from_user length. A racing thread can change request_len between the bounds check (passes with <= 32) and copy_from_user (uses the enlarged value), overflowing the 32-byte scmd->cmnd[] buffer into subsequent struct scsi_cmnd fields. scsi_bsg_map_user_buffer() independently re-derives its cmd pointer from the same shared SQE, re-reading dout_xfer_len, din_xfer_len, dout_xferp, and din_xferp, enabling direction confusion and buffer length races. Copy struct bsg_uring_cmd to a stack-local variable before use in both functions. The pointer variable 'cmd' is redirected to the local copy so the rest of each function is unchanged. Tested with KASAN on QEMU (virtio-scsi, 2 vCPUs). Without this fix, a two-thread race produces: BUG: KASAN: wild-memory-access in scsi_queue_rq+0x4a3/0x58a0 Write of size 96 at addr dead000000001000 by task poc/67 Call Trace: kasan_report+0xce/0x100 __asan_memset+0x23/0x50 scsi_queue_rq+0x4a3/0x58a0 scsi_bsg_uring_cmd+0x942/0x1570 io_uring_cmd+0x2f6/0x950 io_issue_sqe+0xe5/0x22d0 Fixes: 7b6d325 ("scsi: bsg: add io_uring passthrough handler") Cc: stable@vger.kernel.org Signed-off-by: Rahul Chandelkar <rc@rexion.ai> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
|
Upstream branch: bade58e |
9df46ef to
6104a0d
Compare
Pull request for series with
subject: scsi: bsg: copy uring_cmd payload to prevent double-fetch from shared SQE
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1101589