Skip to content

Commit 4ee86ba

Browse files
hreineckeaxboe
authored andcommitted
blk-mq: add bounds check on tag-to-rq conversion
We need to check for a valid index before accessing the array element to avoid accessing invalid memory regions. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jeff Moyer <jmoyer@redhat.com> Modified by Jens to drop the unlikely(), and make the fall through path be having a valid tag. Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 2b88551 commit 4ee86ba

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

block/blk-mq.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,10 @@ EXPORT_SYMBOL(blk_mq_abort_requeue_list);
544544

545545
struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag)
546546
{
547-
return tags->rqs[tag];
547+
if (tag < tags->nr_tags)
548+
return tags->rqs[tag];
549+
550+
return NULL;
548551
}
549552
EXPORT_SYMBOL(blk_mq_tag_to_rq);
550553

0 commit comments

Comments
 (0)