提交 b3a834b1 编写于 作者: B Bartlomiej Zolnierkiewicz 提交者: Jens Axboe

blk-mq: fix undefined behaviour in order_to_size()

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-g33656a1f #22

Fix the code by checking this_order variable for not having the zero
value first.
Reported-by: NMeelis Roos <mroos@linux.ee>
Fixes: 320ae51f ("blk-mq: new multi-queue block IO queueing mechanism")
Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: NJens Axboe <axboe@fb.com>
上级 59fa0224
...@@ -1495,7 +1495,7 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set, ...@@ -1495,7 +1495,7 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
int to_do; int to_do;
void *p; void *p;
while (left < order_to_size(this_order - 1) && this_order) while (this_order && left < order_to_size(this_order - 1))
this_order--; this_order--;
do { do {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册