Skip to content

Commit eb571ee

Browse files
Joe Lawrenceaxboe
authored andcommitted
block,scsi: verify return pointer from blk_get_request
The blk-core dead queue checks introduce an error scenario to blk_get_request that returns NULL if the request queue has been shutdown. This affects the behavior for __GFP_WAIT callers, who should verify the return value before dereferencing. Signed-off-by: Joe Lawrence <joe.lawrence@stratus.com> Acked-by: Jiri Kosina <jkosina@suse.cz> [for pktdvd] Reviewed-by: Jeff Moyer <jmoyer@redhat.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 52addcf commit eb571ee

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎block/scsi_ioctl.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
448448
}
449449

450450
rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT);
451+
if (!rq) {
452+
err = -ENODEV;
453+
goto error_free_buffer;
454+
}
451455

452456
cmdlen = COMMAND_SIZE(opcode);
453457

@@ -520,8 +524,9 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
520524
}
521525

522526
error:
523-
kfree(buffer);
524527
blk_put_request(rq);
528+
error_free_buffer:
529+
kfree(buffer);
525530
return err;
526531
}
527532
EXPORT_SYMBOL_GPL(sg_scsi_ioctl);
@@ -534,6 +539,8 @@ static int __blk_send_generic(struct request_queue *q, struct gendisk *bd_disk,
534539
int err;
535540

536541
rq = blk_get_request(q, WRITE, __GFP_WAIT);
542+
if (!rq)
543+
return -ENODEV;
537544
blk_rq_set_block_pc(rq);
538545
rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
539546
rq->cmd[0] = cmd;

‎drivers/block/paride/pd.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,8 @@ static int pd_special_command(struct pd_unit *disk,
722722
int err = 0;
723723

724724
rq = blk_get_request(disk->gd->queue, READ, __GFP_WAIT);
725+
if (!rq)
726+
return -ENODEV;
725727

726728
rq->cmd_type = REQ_TYPE_SPECIAL;
727729
rq->special = func;

‎drivers/block/pktcdvd.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
704704

705705
rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ?
706706
WRITE : READ, __GFP_WAIT);
707+
if (!rq)
708+
return -ENODEV;
707709
blk_rq_set_block_pc(rq);
708710

709711
if (cgc->buflen) {

‎drivers/scsi/scsi_error.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,8 @@ static void scsi_eh_lock_door(struct scsi_device *sdev)
19601960
* request becomes available
19611961
*/
19621962
req = blk_get_request(sdev->request_queue, READ, GFP_KERNEL);
1963+
if (!req)
1964+
return;
19631965

19641966
blk_rq_set_block_pc(req);
19651967

0 commit comments

Comments
 (0)