@@ -214,7 +214,8 @@ struct crypt_config {
214
214
215
215
unsigned int integrity_tag_size ;
216
216
unsigned int integrity_iv_size ;
217
- unsigned int on_disk_tag_size ;
217
+ unsigned int used_tag_size ;
218
+ unsigned int tuple_size ;
218
219
219
220
/*
220
221
* pool for per bio private data, crypto requests,
@@ -256,7 +257,7 @@ static unsigned get_max_request_size(struct crypt_config *cc, bool wrt)
256
257
val = !wrt ? READ_ONCE (max_read_size ) : READ_ONCE (max_write_size );
257
258
if (likely (!val ))
258
259
val = !wrt ? DM_CRYPT_DEFAULT_MAX_READ_SIZE : DM_CRYPT_DEFAULT_MAX_WRITE_SIZE ;
259
- if (wrt || cc -> on_disk_tag_size ) {
260
+ if (wrt || cc -> used_tag_size ) {
260
261
if (unlikely (val > BIO_MAX_VECS << PAGE_SHIFT ))
261
262
val = BIO_MAX_VECS << PAGE_SHIFT ;
262
263
}
@@ -1176,14 +1177,14 @@ static int dm_crypt_integrity_io_alloc(struct dm_crypt_io *io, struct bio *bio)
1176
1177
unsigned int tag_len ;
1177
1178
int ret ;
1178
1179
1179
- if (!bio_sectors (bio ) || !io -> cc -> on_disk_tag_size )
1180
+ if (!bio_sectors (bio ) || !io -> cc -> tuple_size )
1180
1181
return 0 ;
1181
1182
1182
1183
bip = bio_integrity_alloc (bio , GFP_NOIO , 1 );
1183
1184
if (IS_ERR (bip ))
1184
1185
return PTR_ERR (bip );
1185
1186
1186
- tag_len = io -> cc -> on_disk_tag_size * (bio_sectors (bio ) >> io -> cc -> sector_shift );
1187
+ tag_len = io -> cc -> tuple_size * (bio_sectors (bio ) >> io -> cc -> sector_shift );
1187
1188
1188
1189
bip -> bip_iter .bi_sector = io -> cc -> start + io -> sector ;
1189
1190
@@ -1207,18 +1208,18 @@ static int crypt_integrity_ctr(struct crypt_config *cc, struct dm_target *ti)
1207
1208
return - EINVAL ;
1208
1209
}
1209
1210
1210
- if (bi -> tag_size != cc -> on_disk_tag_size ||
1211
- bi -> tuple_size != cc -> on_disk_tag_size ) {
1211
+ if (bi -> tuple_size < cc -> used_tag_size ) {
1212
1212
ti -> error = "Integrity profile tag size mismatch." ;
1213
1213
return - EINVAL ;
1214
1214
}
1215
+ cc -> tuple_size = bi -> tuple_size ;
1215
1216
if (1 << bi -> interval_exp != cc -> sector_size ) {
1216
1217
ti -> error = "Integrity profile sector size mismatch." ;
1217
1218
return - EINVAL ;
1218
1219
}
1219
1220
1220
1221
if (crypt_integrity_aead (cc )) {
1221
- cc -> integrity_tag_size = cc -> on_disk_tag_size - cc -> integrity_iv_size ;
1222
+ cc -> integrity_tag_size = cc -> used_tag_size - cc -> integrity_iv_size ;
1222
1223
DMDEBUG ("%s: Integrity AEAD, tag size %u, IV size %u." , dm_device_name (md ),
1223
1224
cc -> integrity_tag_size , cc -> integrity_iv_size );
1224
1225
@@ -1230,7 +1231,7 @@ static int crypt_integrity_ctr(struct crypt_config *cc, struct dm_target *ti)
1230
1231
DMDEBUG ("%s: Additional per-sector space %u bytes for IV." , dm_device_name (md ),
1231
1232
cc -> integrity_iv_size );
1232
1233
1233
- if ((cc -> integrity_tag_size + cc -> integrity_iv_size ) != bi -> tag_size ) {
1234
+ if ((cc -> integrity_tag_size + cc -> integrity_iv_size ) > cc -> tuple_size ) {
1234
1235
ti -> error = "Not enough space for integrity tag in the profile." ;
1235
1236
return - EINVAL ;
1236
1237
}
@@ -1309,7 +1310,7 @@ static void *tag_from_dmreq(struct crypt_config *cc,
1309
1310
struct dm_crypt_io * io = container_of (ctx , struct dm_crypt_io , ctx );
1310
1311
1311
1312
return & io -> integrity_metadata [* org_tag_of_dmreq (cc , dmreq ) *
1312
- cc -> on_disk_tag_size ];
1313
+ cc -> tuple_size ];
1313
1314
}
1314
1315
1315
1316
static void * iv_tag_from_dmreq (struct crypt_config * cc ,
@@ -1390,9 +1391,9 @@ static int crypt_convert_block_aead(struct crypt_config *cc,
1390
1391
aead_request_set_crypt (req , dmreq -> sg_in , dmreq -> sg_out ,
1391
1392
cc -> sector_size , iv );
1392
1393
r = crypto_aead_encrypt (req );
1393
- if (cc -> integrity_tag_size + cc -> integrity_iv_size != cc -> on_disk_tag_size )
1394
+ if (cc -> integrity_tag_size + cc -> integrity_iv_size != cc -> tuple_size )
1394
1395
memset (tag + cc -> integrity_tag_size + cc -> integrity_iv_size , 0 ,
1395
- cc -> on_disk_tag_size - (cc -> integrity_tag_size + cc -> integrity_iv_size ));
1396
+ cc -> tuple_size - (cc -> integrity_tag_size + cc -> integrity_iv_size ));
1396
1397
} else {
1397
1398
aead_request_set_crypt (req , dmreq -> sg_in , dmreq -> sg_out ,
1398
1399
cc -> sector_size + cc -> integrity_tag_size , iv );
@@ -1822,7 +1823,7 @@ static void crypt_dec_pending(struct dm_crypt_io *io)
1822
1823
return ;
1823
1824
1824
1825
if (likely (!io -> ctx .aead_recheck ) && unlikely (io -> ctx .aead_failed ) &&
1825
- cc -> on_disk_tag_size && bio_data_dir (base_bio ) == READ ) {
1826
+ cc -> used_tag_size && bio_data_dir (base_bio ) == READ ) {
1826
1827
io -> ctx .aead_recheck = true;
1827
1828
io -> ctx .aead_failed = false;
1828
1829
io -> error = 0 ;
@@ -3206,7 +3207,7 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar
3206
3207
ti -> error = "Invalid integrity arguments" ;
3207
3208
return - EINVAL ;
3208
3209
}
3209
- cc -> on_disk_tag_size = val ;
3210
+ cc -> used_tag_size = val ;
3210
3211
sval = strchr (opt_string + strlen ("integrity:" ), ':' ) + 1 ;
3211
3212
if (!strcasecmp (sval , "aead" )) {
3212
3213
set_bit (CRYPT_MODE_INTEGRITY_AEAD , & cc -> cipher_flags );
@@ -3418,12 +3419,12 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3418
3419
if (ret )
3419
3420
goto bad ;
3420
3421
3421
- cc -> tag_pool_max_sectors = POOL_ENTRY_SIZE / cc -> on_disk_tag_size ;
3422
+ cc -> tag_pool_max_sectors = POOL_ENTRY_SIZE / cc -> tuple_size ;
3422
3423
if (!cc -> tag_pool_max_sectors )
3423
3424
cc -> tag_pool_max_sectors = 1 ;
3424
3425
3425
3426
ret = mempool_init_kmalloc_pool (& cc -> tag_pool , MIN_IOS ,
3426
- cc -> tag_pool_max_sectors * cc -> on_disk_tag_size );
3427
+ cc -> tag_pool_max_sectors * cc -> tuple_size );
3427
3428
if (ret ) {
3428
3429
ti -> error = "Cannot allocate integrity tags mempool" ;
3429
3430
goto bad ;
@@ -3535,8 +3536,8 @@ static int crypt_map(struct dm_target *ti, struct bio *bio)
3535
3536
io = dm_per_bio_data (bio , cc -> per_bio_data_size );
3536
3537
crypt_io_init (io , cc , bio , dm_target_offset (ti , bio -> bi_iter .bi_sector ));
3537
3538
3538
- if (cc -> on_disk_tag_size ) {
3539
- unsigned int tag_len = cc -> on_disk_tag_size * (bio_sectors (bio ) >> cc -> sector_shift );
3539
+ if (cc -> tuple_size ) {
3540
+ unsigned int tag_len = cc -> tuple_size * (bio_sectors (bio ) >> cc -> sector_shift );
3540
3541
3541
3542
if (unlikely (tag_len > KMALLOC_MAX_SIZE ))
3542
3543
io -> integrity_metadata = NULL ;
@@ -3608,7 +3609,7 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
3608
3609
num_feature_args += test_bit (DM_CRYPT_NO_WRITE_WORKQUEUE , & cc -> flags );
3609
3610
num_feature_args += cc -> sector_size != (1 << SECTOR_SHIFT );
3610
3611
num_feature_args += test_bit (CRYPT_IV_LARGE_SECTORS , & cc -> cipher_flags );
3611
- if (cc -> on_disk_tag_size )
3612
+ if (cc -> used_tag_size )
3612
3613
num_feature_args ++ ;
3613
3614
if (num_feature_args ) {
3614
3615
DMEMIT (" %d" , num_feature_args );
@@ -3624,8 +3625,8 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
3624
3625
DMEMIT (" no_read_workqueue" );
3625
3626
if (test_bit (DM_CRYPT_NO_WRITE_WORKQUEUE , & cc -> flags ))
3626
3627
DMEMIT (" no_write_workqueue" );
3627
- if (cc -> on_disk_tag_size )
3628
- DMEMIT (" integrity:%u:%s" , cc -> on_disk_tag_size , cc -> cipher_auth );
3628
+ if (cc -> used_tag_size )
3629
+ DMEMIT (" integrity:%u:%s" , cc -> used_tag_size , cc -> cipher_auth );
3629
3630
if (cc -> sector_size != (1 << SECTOR_SHIFT ))
3630
3631
DMEMIT (" sector_size:%d" , cc -> sector_size );
3631
3632
if (test_bit (CRYPT_IV_LARGE_SECTORS , & cc -> cipher_flags ))
@@ -3647,9 +3648,9 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
3647
3648
DMEMIT (",iv_large_sectors=%c" , test_bit (CRYPT_IV_LARGE_SECTORS , & cc -> cipher_flags ) ?
3648
3649
'y' : 'n' );
3649
3650
3650
- if (cc -> on_disk_tag_size )
3651
+ if (cc -> used_tag_size )
3651
3652
DMEMIT (",integrity_tag_size=%u,cipher_auth=%s" ,
3652
- cc -> on_disk_tag_size , cc -> cipher_auth );
3653
+ cc -> used_tag_size , cc -> cipher_auth );
3653
3654
if (cc -> sector_size != (1 << SECTOR_SHIFT ))
3654
3655
DMEMIT (",sector_size=%d" , cc -> sector_size );
3655
3656
if (cc -> cipher_string )
@@ -3757,7 +3758,7 @@ static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits)
3757
3758
3758
3759
static struct target_type crypt_target = {
3759
3760
.name = "crypt" ,
3760
- .version = {1 , 26 , 0 },
3761
+ .version = {1 , 27 , 0 },
3761
3762
.module = THIS_MODULE ,
3762
3763
.ctr = crypt_ctr ,
3763
3764
.dtr = crypt_dtr ,
0 commit comments