Skip to contentSkip to conversation

virtio_blk: Fix an SG_IO regression

PATCH Superseded Bart Van Assche 2 participants 2 messages Oct 24, 2017

Subsystems (6)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio_blk: Fix an SG_IO regression

Avoid that submitting an SG_IO ioctl triggers a kernel oops that is preceded by:

usercopy: kernel memory overwrite attempt detected to (null) (<null>) (6 bytes) kernel BUG at mm/usercopy.c:72!

Additionally, make it easier to diagnose crashes like the one fixed by this patch.

Fixes commit ca18d6f769d2 ("block: Make most scsi_req_init() calls implicit")
Cc Dann Frazier <[email protected]>
Cc Martin K. Petersen <[email protected]>
Cc <[email protected]> # v4.13
---
 drivers/block/virtio_blk.c | 1 +
 drivers/scsi/sg.c          | 2 ++
 2 files changed, 3 insertions(+)
drivers/block/virtio_blk.c +1 -0
index 34e17ee799be..15e11a519801 100644
@@ -597,6 +597,7 @@ static const struct blk_mq_ops virtio_mq_ops = {
 	.queue_rq	= virtio_queue_rq,
 	.complete	= virtblk_request_done,
 	.init_request	= virtblk_init_request,
+	.initialize_rq_fn = scsi_initialize_rq,
 	.map_queues	= virtblk_map_queues,
 };
 
drivers/scsi/sg.c +2 -0
index 0419c2298eab..14096f67eebb 100644
@@ -1722,6 +1722,8 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
 	}
 	req = scsi_req(rq);
 
+	WARN_ON_ONCE(!req->cmd);
+
 	if (hp->cmd_len > BLK_MAX_CDB)
 		req->cmd = long_cmdp;
 	memcpy(req->cmd, cmd, hp->cmd_len);
Signature · 1 line
2.14.2
maintainer
#1 lore raw
Quoted 8 lines · Bart Van Assche

Avoid that submitting an SG_IO ioctl triggers a kernel oops that is preceded by:

usercopy: kernel memory overwrite attempt detected to (null) (<null>) (6 bytes) kernel BUG at mm/usercopy.c:72!

Additionally, make it easier to diagnose crashes like the one fixed by this patch.

This really should have been two patches... Anyway, applied for 4.14.

Signature · 1 line
Jens Axboe