diff options
author | Joe Lawrence <joe.lawrence@stratus.com> | 2014-07-02 15:35:16 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-08-26 17:20:23 -0400 |
commit | eb571eeade2598635f813b3284d02c13a380301e (patch) | |
tree | 539842ad23a4eaae8c272278fd9fea389afa6b93 | |
parent | 52addcf9d6669fa439387610bc65c92fa0980cef (diff) |
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>
-rw-r--r-- | block/scsi_ioctl.c | 9 | ||||
-rw-r--r-- | drivers/block/paride/pd.c | 2 | ||||
-rw-r--r-- | drivers/block/pktcdvd.c | 2 | ||||
-rw-r--r-- | drivers/scsi/scsi_error.c | 2 |
4 files changed, 14 insertions, 1 deletions
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 51bf5155ee75..29d056782833 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c | |||
@@ -448,6 +448,10 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, | |||
448 | } | 448 | } |
449 | 449 | ||
450 | rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT); | 450 | rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT); |
451 | if (!rq) { | ||
452 | err = -ENODEV; | ||
453 | goto error_free_buffer; | ||
454 | } | ||
451 | 455 | ||
452 | cmdlen = COMMAND_SIZE(opcode); | 456 | cmdlen = COMMAND_SIZE(opcode); |
453 | 457 | ||
@@ -520,8 +524,9 @@ out: | |||
520 | } | 524 | } |
521 | 525 | ||
522 | error: | 526 | error: |
523 | kfree(buffer); | ||
524 | blk_put_request(rq); | 527 | blk_put_request(rq); |
528 | error_free_buffer: | ||
529 | kfree(buffer); | ||
525 | return err; | 530 | return err; |
526 | } | 531 | } |
527 | EXPORT_SYMBOL_GPL(sg_scsi_ioctl); | 532 | EXPORT_SYMBOL_GPL(sg_scsi_ioctl); |
@@ -534,6 +539,8 @@ static int __blk_send_generic(struct request_queue *q, struct gendisk *bd_disk, | |||
534 | int err; | 539 | int err; |
535 | 540 | ||
536 | rq = blk_get_request(q, WRITE, __GFP_WAIT); | 541 | rq = blk_get_request(q, WRITE, __GFP_WAIT); |
542 | if (!rq) | ||
543 | return -ENODEV; | ||
537 | blk_rq_set_block_pc(rq); | 544 | blk_rq_set_block_pc(rq); |
538 | rq->timeout = BLK_DEFAULT_SG_TIMEOUT; | 545 | rq->timeout = BLK_DEFAULT_SG_TIMEOUT; |
539 | rq->cmd[0] = cmd; | 546 | rq->cmd[0] = cmd; |
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c index fea7e76a00de..ca831f741d89 100644 --- a/drivers/block/paride/pd.c +++ b/drivers/block/paride/pd.c | |||
@@ -722,6 +722,8 @@ static int pd_special_command(struct pd_unit *disk, | |||
722 | int err = 0; | 722 | int err = 0; |
723 | 723 | ||
724 | rq = blk_get_request(disk->gd->queue, READ, __GFP_WAIT); | 724 | rq = blk_get_request(disk->gd->queue, READ, __GFP_WAIT); |
725 | if (!rq) | ||
726 | return -ENODEV; | ||
725 | 727 | ||
726 | rq->cmd_type = REQ_TYPE_SPECIAL; | 728 | rq->cmd_type = REQ_TYPE_SPECIAL; |
727 | rq->special = func; | 729 | rq->special = func; |
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 758ac442c5b5..7fa8c80e8982 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c | |||
@@ -704,6 +704,8 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command * | |||
704 | 704 | ||
705 | rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ? | 705 | rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ? |
706 | WRITE : READ, __GFP_WAIT); | 706 | WRITE : READ, __GFP_WAIT); |
707 | if (!rq) | ||
708 | return -ENODEV; | ||
707 | blk_rq_set_block_pc(rq); | 709 | blk_rq_set_block_pc(rq); |
708 | 710 | ||
709 | if (cgc->buflen) { | 711 | if (cgc->buflen) { |
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 5db8454474ee..4c433bf47a06 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c | |||
@@ -1960,6 +1960,8 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) | |||
1960 | * request becomes available | 1960 | * request becomes available |
1961 | */ | 1961 | */ |
1962 | req = blk_get_request(sdev->request_queue, READ, GFP_KERNEL); | 1962 | req = blk_get_request(sdev->request_queue, READ, GFP_KERNEL); |
1963 | if (!req) | ||
1964 | return; | ||
1963 | 1965 | ||
1964 | blk_rq_set_block_pc(req); | 1966 | blk_rq_set_block_pc(req); |
1965 | 1967 | ||