mts_command_done() receives the data phase of a REQUEST SENSE into srb->sense_buffer (SCSI_SENSE_BUFFERSIZE, 96 bytes), but with the length of the command's own data buffer. A REQUEST SENSE sent through SG_IO, allowed on a read-only /dev/sgN without any capability, can have a much larger buffer (252 bytes with sg_requests), and a device that returns that much writes past the end of the sense buffer. The special case is not needed: for the error handler's own REQUEST SENSE, scsi_eh_prep_cmnd() already points the data buffer at sense_buffer with at most SCSI_SENSE_BUFFERSIZE. Handle REQUEST SENSE like every other data-in command. The bug was found, and the reproducer and this fix were written, by AI agents (Claude Mythos and Claude Opus models). The analysis and the patch were reviewed by a human. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Alexandre Becholey --- An emulated ScanMaker X6 answering a 252-byte SG_IO REQUEST SENSE with 252 bytes triggers it (KASAN in dummy_timer, the HCD's copy into the URB buffer; slub_debug redzone report with xHCI), on v7.3.1 and master 9d66f26fefac. No reports with the fix. User-space REQUEST SENSE now gets the sense data in its own buffer; the error handler's REQUEST SENSE returns the same data as before. Not tested on real hardware. Reproducer available on request. drivers/usb/image/microtek.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c index 1f0b3c44d388..0b8d7f71c3c9 100644 --- a/drivers/usb/image/microtek.c +++ b/drivers/usb/image/microtek.c @@ -445,22 +445,15 @@ static void mts_command_done( struct urb *transfer ) return; } - if (context->srb->cmnd[0] == REQUEST_SENSE) { + if (context->data) { mts_int_submit_urb(transfer, context->data_pipe, - context->srb->sense_buffer, + context->data, context->data_length, - mts_data_done); - } else { if ( context->data ) { - mts_int_submit_urb(transfer, - context->data_pipe, - context->data, - context->data_length, - scsi_sg_count(context->srb) > 1 ? - mts_do_sg : mts_data_done); - } else { - mts_get_status(transfer); - } + scsi_sg_count(context->srb) > 1 ? + mts_do_sg : mts_data_done); + } else { + mts_get_status(transfer); } } -- 2.53.0