[PATCH 4.14 01/18] bio: ensure __bio_clone_fast copies bi_partno

From: Greg Kroah-Hartman
Date: Wed Nov 22 2017 - 05:18:16 EST


4.14-stable review patch. If anyone has any objections, please let me know.

------------------

From: Michael Lyle <mlyle@xxxxxxxx>

commit 62530ed8b1d07a45dec94d46e521c0c6c2d476e6 upstream.

A new field was introduced in 74d46992e0d9, bi_partno, instead of using
bdev->bd_contains and encoding the partition information in the bi_bdev
field. __bio_clone_fast was changed to copy the disk information, but
not the partition information. At minimum, this regressed bcache and
caused data corruption.

Signed-off-by: Michael Lyle <mlyle@xxxxxxxx>
Fixes: 74d46992e0d9 ("block: replace bi_bdev with a gendisk pointer and partitions index")
Reported-by: Pavel Goran <via-bcache@xxxxxxxxxxxx>
Reported-by: Campbell Steven <casteven@xxxxxxxxx>
Reviewed-by: Coly Li <colyli@xxxxxxx>
Reviewed-by: Ming Lei <ming.lei@xxxxxxxxxx>
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
block/bio.c | 1 +
1 file changed, 1 insertion(+)

--- a/block/bio.c
+++ b/block/bio.c
@@ -597,6 +597,7 @@ void __bio_clone_fast(struct bio *bio, s
* so we don't set nor calculate new physical/hw segment counts here
*/
bio->bi_disk = bio_src->bi_disk;
+ bio->bi_partno = bio_src->bi_partno;
bio_set_flag(bio, BIO_CLONED);
bio->bi_opf = bio_src->bi_opf;
bio->bi_write_hint = bio_src->bi_write_hint;