Skip to contentSkip to conversation

block: Allocate a sense buffer before executing an SG_IO ioctl

PATCH In review Bart Van Assche 1 participant 2 messages Jan 23, 2019 – Jan 24, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Allocate a sense buffer before executing an SG_IO ioctl

Some time ago blk_execute_rq() was modified such that it no longer allocates a sense buffer. Make sg_io() allocate and use a sense buffer. This patch avoids that the following bug is triggered when running the libiscsi tests against the scsi_debug driver:

usercopy: Kernel memory exposure attempt detected from null address (offset 0, size 18)!

------------[ cut here ]------------
kernel BUG at mm/usercopy.c:102!
CPU: 5 PID: 693 Comm: iscsi-test-cu Not tainted 5.0.0-rc3-dbg+ #3
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014
RIP: 0010:usercopy_abort+0x7a/0x7c
Call Trace:
 __check_object_size.cold.1+0x37/0x3d
 sg_io+0x5a2/0x700
 scsi_cmd_ioctl+0x4d4/0x540
 scsi_cmd_blk_ioctl+0x7b/0x8b
 sd_ioctl+0xba/0x150
 blkdev_ioctl+0x6e1/0xea0
 block_ioctl+0x79/0x90
 do_vfs_ioctl+0x12b/0x9b0
 ksys_ioctl+0x41/0x80
 __x64_sys_ioctl+0x43/0x50
 do_syscall_64+0x71/0x210
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
Cc Christoph Hellwig <[email protected]>
Cc Martin K. Petersen <[email protected]>
Cc Douglas Gilbert <[email protected]>
Cc <[email protected]> # v4.11+
Fixes 82ed4db499b8 ("block: split scsi_request out of struct request")
---
 block/scsi_ioctl.c | 2 ++
 1 file changed, 2 insertions(+)
block/scsi_ioctl.c +2 -0
index 533f4aee8567..066929ec0d61 100644
@@ -299,6 +299,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
 	struct request *rq;
 	struct scsi_request *req;
 	struct bio *bio;
+	u8 sense[SCSI_SENSE_BUFFERSIZE];
 
 	if (hdr->interface_id != 'S')
 		return -EINVAL;
@@ -361,6 +362,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
 
 	bio = rq->bio;
 	req->retries = 0;
+	req->sense = sense;
 
 	start_time = jiffies;
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#1 lore raw
Quoted 34 lines · Bart Van Assche

Some time ago blk_execute_rq() was modified such that it no longer allocates a sense buffer. Make sg_io() allocate and use a sense buffer. This patch avoids that the following bug is triggered when running the libiscsi tests against the scsi_debug driver:

usercopy: Kernel memory exposure attempt detected from null address (offset 0, size 18)!>------------[cut here ]------------ kernel BUG at mm/usercopy.c:102!>CPU: 5 PID: 693 Comm: iscsi-test-cu Not tainted 5.0.0-rc3-dbg+- #3

Hardware name: QEMU Standard PC (i440FX +- PIIX, 1996), BIOS 1.10.2-1 04/01/2014
RIP: 0010:usercopy_abort+-0x7a/0x7c
Call Trace:

__check_object_size.cold.1+-0x37/0x3d
sg_io+-0x5a2/0x700
scsi_cmd_ioctl+-0x4d4/0x540
scsi_cmd_blk_ioctl+-0x7b/0x8b
sd_ioctl+-0xba/0x150
blkdev_ioctl+-0x6e1/0xea0
block_ioctl+-0x79/0x90
do_vfs_ioctl+-0x12b/0x9b0
ksys_ioctl+-0x41/0x80
__x64_sys_ioctl+-0x43/0x50
do_syscall_64+-0x71/0x210
entry_SYSCALL_64_after_hwframe+-0x49/0xbe

Cc Christoph Hellwig <[email protected]>>Cc: Martin K. Petersen <[email protected]>>Cc: Douglas Gilbert <[email protected]>>Cc: <[email protected]>#v4.11+-
Fixes 82ed4db499b8 ("block: split scsi_request out of struct request"

block/scsi_ioctl.c |2 +-+-

1 file changed, 2 insertions(+-)
block/scsi_ioctl.c +1 -1
index 533f4aee8567..066929ec0d61 100644
--- a/block/scsi_ioctl.c
+-+-+- b/block/scsi_ioctl.c

@@-299,6 +-299,7 @@static int sg_io(struct request_queue *q, struct gendisk *bd_disk,

Quoted 6 lines
	struct request *rq;> 	struct scsi_request *req;> 	struct bio *bio;>+-	u8 sense[SCSI_SENSE_BUFFERSIZE];> 
	if (hdr->interface_id !='S')
		return -EINVAL;>@@-361,6 +-362,7 @@static int sg_io(struct request_queue *q, struct gendisk *bd_disk,

	bio =rq->bio;> 	req->retries =0;>+-	req->sense =sense;> 
	start_time =jiffies;

Please ignore this patch - I just realized that this is not the right way to fix the reported issue.

Bart.