diff options
-rw-r--r-- | drivers/md/dm-crypt.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index ccbc7f36bb2e..8bff6f7a4c6c 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
@@ -938,10 +938,15 @@ static int crypt_integrity_ctr(struct crypt_config *cc, struct dm_target *ti) | |||
938 | return -EINVAL; | 938 | return -EINVAL; |
939 | } | 939 | } |
940 | 940 | ||
941 | if (bi->tag_size != cc->on_disk_tag_size) { | 941 | if (bi->tag_size != cc->on_disk_tag_size || |
942 | bi->tuple_size != cc->on_disk_tag_size) { | ||
942 | ti->error = "Integrity profile tag size mismatch."; | 943 | ti->error = "Integrity profile tag size mismatch."; |
943 | return -EINVAL; | 944 | return -EINVAL; |
944 | } | 945 | } |
946 | if (1 << bi->interval_exp != cc->sector_size) { | ||
947 | ti->error = "Integrity profile sector size mismatch."; | ||
948 | return -EINVAL; | ||
949 | } | ||
945 | 950 | ||
946 | if (crypt_integrity_aead(cc)) { | 951 | if (crypt_integrity_aead(cc)) { |
947 | cc->integrity_tag_size = cc->on_disk_tag_size - cc->integrity_iv_size; | 952 | cc->integrity_tag_size = cc->on_disk_tag_size - cc->integrity_iv_size; |
@@ -1322,7 +1327,7 @@ static int crypt_convert(struct crypt_config *cc, | |||
1322 | case -EINPROGRESS: | 1327 | case -EINPROGRESS: |
1323 | ctx->r.req = NULL; | 1328 | ctx->r.req = NULL; |
1324 | ctx->cc_sector += sector_step; | 1329 | ctx->cc_sector += sector_step; |
1325 | tag_offset += sector_step; | 1330 | tag_offset++; |
1326 | continue; | 1331 | continue; |
1327 | /* | 1332 | /* |
1328 | * The request was already processed (synchronously). | 1333 | * The request was already processed (synchronously). |
@@ -1330,7 +1335,7 @@ static int crypt_convert(struct crypt_config *cc, | |||
1330 | case 0: | 1335 | case 0: |
1331 | atomic_dec(&ctx->cc_pending); | 1336 | atomic_dec(&ctx->cc_pending); |
1332 | ctx->cc_sector += sector_step; | 1337 | ctx->cc_sector += sector_step; |
1333 | tag_offset += sector_step; | 1338 | tag_offset++; |
1334 | cond_resched(); | 1339 | cond_resched(); |
1335 | continue; | 1340 | continue; |
1336 | /* | 1341 | /* |
@@ -2735,6 +2740,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
2735 | ti->error = "Cannot allocate integrity tags mempool"; | 2740 | ti->error = "Cannot allocate integrity tags mempool"; |
2736 | goto bad; | 2741 | goto bad; |
2737 | } | 2742 | } |
2743 | |||
2744 | cc->tag_pool_max_sectors <<= cc->sector_shift; | ||
2738 | } | 2745 | } |
2739 | 2746 | ||
2740 | ret = -ENOMEM; | 2747 | ret = -ENOMEM; |
@@ -2816,16 +2823,15 @@ static int crypt_map(struct dm_target *ti, struct bio *bio) | |||
2816 | crypt_io_init(io, cc, bio, dm_target_offset(ti, bio->bi_iter.bi_sector)); | 2823 | crypt_io_init(io, cc, bio, dm_target_offset(ti, bio->bi_iter.bi_sector)); |
2817 | 2824 | ||
2818 | if (cc->on_disk_tag_size) { | 2825 | if (cc->on_disk_tag_size) { |
2819 | unsigned tag_len = cc->on_disk_tag_size * bio_sectors(bio); | 2826 | unsigned tag_len = cc->on_disk_tag_size * (bio_sectors(bio) >> cc->sector_shift); |
2820 | 2827 | ||
2821 | if (unlikely(tag_len > KMALLOC_MAX_SIZE) || | 2828 | if (unlikely(tag_len > KMALLOC_MAX_SIZE) || |
2822 | unlikely(!(io->integrity_metadata = kzalloc(tag_len, | 2829 | unlikely(!(io->integrity_metadata = kmalloc(tag_len, |
2823 | GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN)))) { | 2830 | GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN)))) { |
2824 | if (bio_sectors(bio) > cc->tag_pool_max_sectors) | 2831 | if (bio_sectors(bio) > cc->tag_pool_max_sectors) |
2825 | dm_accept_partial_bio(bio, cc->tag_pool_max_sectors); | 2832 | dm_accept_partial_bio(bio, cc->tag_pool_max_sectors); |
2826 | io->integrity_metadata = mempool_alloc(cc->tag_pool, GFP_NOIO); | 2833 | io->integrity_metadata = mempool_alloc(cc->tag_pool, GFP_NOIO); |
2827 | io->integrity_metadata_from_pool = true; | 2834 | io->integrity_metadata_from_pool = true; |
2828 | memset(io->integrity_metadata, 0, cc->tag_pool_max_sectors * (1 << SECTOR_SHIFT)); | ||
2829 | } | 2835 | } |
2830 | } | 2836 | } |
2831 | 2837 | ||