Skip to content

Commit 7c88f7c

Browse files
Hou TaoMikulas Patocka
authored andcommitted
dm-crypt: fully initialize clone->bi_iter in crypt_alloc_buffer()
Both kcryptd_io_read() and kcryptd_crypt_write_convert() will invoke crypt_alloc_buffer() to allocate a new bio. Both of these two callers initialize bi_iter.bi_sector for the new bio separatedly after crypt_alloc_buffer() returns. However, kcryptd_crypt_write_convert() will copy the bi_iter of the new bio into ctx.iter_out or ctx.iter_in. Although it doesn't incur any harm now, it is better to fully initialize bi_iter before it is used. Therefore, initialize bi_iter.bi_sector in crypt_alloc_buffer() instead. Signed-off-by: Hou Tao <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]>
1 parent 6fd2cb3 commit 7c88f7c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/md/dm-crypt.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned int size)
17191719
clone->bi_private = io;
17201720
clone->bi_end_io = crypt_endio;
17211721
clone->bi_ioprio = io->base_bio->bi_ioprio;
1722+
clone->bi_iter.bi_sector = cc->start + io->sector;
17221723

17231724
remaining_size = size;
17241725

@@ -1909,7 +1910,6 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
19091910
crypt_dec_pending(io);
19101911
return 1;
19111912
}
1912-
clone->bi_iter.bi_sector = cc->start + io->sector;
19131913
crypt_convert_init(cc, &io->ctx, clone, clone, io->sector);
19141914
io->saved_bi_iter = clone->bi_iter;
19151915
dm_submit_bio_remap(io->base_bio, clone);
@@ -1925,13 +1925,13 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
19251925
clone = bio_alloc_clone(cc->dev->bdev, io->base_bio, gfp, &cc->bs);
19261926
if (!clone)
19271927
return 1;
1928+
1929+
clone->bi_iter.bi_sector = cc->start + io->sector;
19281930
clone->bi_private = io;
19291931
clone->bi_end_io = crypt_endio;
19301932

19311933
crypt_inc_pending(io);
19321934

1933-
clone->bi_iter.bi_sector = cc->start + io->sector;
1934-
19351935
if (dm_crypt_integrity_io_alloc(io, clone)) {
19361936
crypt_dec_pending(io);
19371937
bio_put(clone);
@@ -2039,8 +2039,6 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int async)
20392039
/* crypt_convert should have filled the clone bio */
20402040
BUG_ON(io->ctx.iter_out.bi_size);
20412041

2042-
clone->bi_iter.bi_sector = cc->start + io->sector;
2043-
20442042
if ((likely(!async) && test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags)) ||
20452043
test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags)) {
20462044
dm_submit_bio_remap(io->base_bio, clone);

0 commit comments

Comments
 (0)