Skip to content

Commit

Permalink
blk-mq: fix undefined behaviour in order_to_size()
Browse files Browse the repository at this point in the history
When this_order variable in blk_mq_init_rq_map() becomes zero
the code incorrectly decrements the variable and passes the result
to order_to_size() helper causing undefined behaviour:

 UBSAN: Undefined behaviour in block/blk-mq.c:1459:27
 shift exponent 4294967295 is too large for 32-bit type 'unsigned int'
 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.6.0-rc6-00072-g33656a1 TheScarastic#22

Fix the code by checking this_order variable for not having the zero
value first.

Reported-by: Meelis Roos <[email protected]>
Fixes: 320ae51 ("blk-mq: new multi-queue block IO queueing mechanism")
Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: utsavbalar1231 <[email protected]>
  • Loading branch information
bzolnier authored and kondors1995 committed Apr 27, 2019
1 parent 8491e1d commit c83e13b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
int to_do;
void *p;

while (left < order_to_size(this_order - 1) && this_order)
while (this_order && left < order_to_size(this_order - 1))
this_order--;

do {
Expand Down

0 comments on commit c83e13b

Please sign in to comment.