block: fix the bio_vec array index out-of-bounds test
PATCH 1/1 block: fix the bio_vec array index out-of-bounds test
From: Kazuhisa Ichikawa <[email protected]>
Current bio_vec array index out-of-bounds test within __end_that_request_first() does not seem correct.
It checks bio->bi_idx against bio->bi_vcnt, but the subsequent code uses idx (which is, bio->bi_idx + next_idx) as the array index into bio_vec array. This means that the test really make sense only at the first iteration of !(nr_bytes >=bio->bi_size) case (when next_idx == zero). Fix this by replacing bio->bi_idx with idx. (This patch applies to 2.6.30-rc4.)
---
block/blk-core.c renamed from block/blk-core.c.ORIG +2 -2
@@ -1768,10 +1768,10 @@ static int __end_that_request_first(stru }else {int idx = bio->bi_idx + next_idx; -if (unlikely (bio->bi_idx >= bio->bi_vcnt)) { +if (unlikely (idx >= bio->bi_vcnt)) {blk_dump_rq_flags (req,"__end_that" );printk (KERN_ERR "%s: bio idx %d >= vcnt %d\n" , - __func__, bio->bi_idx, bio->bi_vcnt); + __func__, idx, bio->bi_vcnt);break ; }
Quoted 18 lines · Kazuhisa Ichikawa
From: Kazuhisa Ichikawa <[email protected]>
Current
bio_vecarray index out-of-bounds test within__end_that_request_first()does not seem correct.
It checksbio->bi_idxagainstbio->bi_vcnt, but the subsequent code uses idx (which is,bio->bi_idx+next_idx) as the array index intobio_vecarray. This means that the test really make sense only at the first iteration of !(nr_bytes >=bio->bi_size) case (whennext_idx== zero). Fix this by replacingbio->bi_idxwith idx. (This patch applies to 2.6.30-rc4.)Signed-off-by Kazuhisa Ichikawa <[email protected]>---
block/blk-core.c renamed from block/blk-core.c.ORIG +0
-0@@ -1768,10 +1768,10 @@ static int __end_that_request_first(stru }else {
block/blk-core.c static int __end_that_request_first(stru · line 1776
Quoted 10 lines
block/blk-core.c renamed from block/blk-core.c.ORIG +2
-2int idx = bio->bi_idx + next_idx; -if (unlikely (bio->bi_idx >= bio->bi_vcnt)) { +if (unlikely (idx >= bio->bi_vcnt)) {blk_dump_rq_flags (req,"__end_that" );printk (KERN_ERR "%s: bio idx %d >= vcnt %d\n" , - __func__, bio->bi_idx, bio->bi_vcnt); + __func__, idx, bio->bi_vcnt);break ; }
Thanks!
Signature · 1 line
Jens Axboe