Skip to content

Commit c984ff1

Browse files
sweetteaaxboe
authored andcommitted
blk-crypto: dynamically allocate fallback profile
blk_crypto_profile_init() calls lockdep_register_key(), which warns and does not register if the provided memory is a static object. blk-crypto-fallback currently has a static blk_crypto_profile and calls blk_crypto_profile_init() thereupon, resulting in the warning and failure to register. Fortunately it is simple enough to use a dynamically allocated profile and make lockdep function correctly. Fixes: 2fb48d8 ("blk-crypto: use dynamic lock class for blk_crypto_profile::lock") Cc: stable@vger.kernel.org Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me> Reviewed-by: Eric Biggers <ebiggers@google.com> Link: https://lore.kernel.org/r/20230817141615.15387-1-sweettea-kernel@dorminy.me Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c164c7b commit c984ff1

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

block/blk-crypto-fallback.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static struct blk_crypto_fallback_keyslot {
7878
struct crypto_skcipher *tfms[BLK_ENCRYPTION_MODE_MAX];
7979
} *blk_crypto_keyslots;
8080

81-
static struct blk_crypto_profile blk_crypto_fallback_profile;
81+
static struct blk_crypto_profile *blk_crypto_fallback_profile;
8282
static struct workqueue_struct *blk_crypto_wq;
8383
static mempool_t *blk_crypto_bounce_page_pool;
8484
static struct bio_set crypto_bio_split;
@@ -292,7 +292,7 @@ static bool blk_crypto_fallback_encrypt_bio(struct bio **bio_ptr)
292292
* Get a blk-crypto-fallback keyslot that contains a crypto_skcipher for
293293
* this bio's algorithm and key.
294294
*/
295-
blk_st = blk_crypto_get_keyslot(&blk_crypto_fallback_profile,
295+
blk_st = blk_crypto_get_keyslot(blk_crypto_fallback_profile,
296296
bc->bc_key, &slot);
297297
if (blk_st != BLK_STS_OK) {
298298
src_bio->bi_status = blk_st;
@@ -395,7 +395,7 @@ static void blk_crypto_fallback_decrypt_bio(struct work_struct *work)
395395
* Get a blk-crypto-fallback keyslot that contains a crypto_skcipher for
396396
* this bio's algorithm and key.
397397
*/
398-
blk_st = blk_crypto_get_keyslot(&blk_crypto_fallback_profile,
398+
blk_st = blk_crypto_get_keyslot(blk_crypto_fallback_profile,
399399
bc->bc_key, &slot);
400400
if (blk_st != BLK_STS_OK) {
401401
bio->bi_status = blk_st;
@@ -499,7 +499,7 @@ bool blk_crypto_fallback_bio_prep(struct bio **bio_ptr)
499499
return false;
500500
}
501501

502-
if (!__blk_crypto_cfg_supported(&blk_crypto_fallback_profile,
502+
if (!__blk_crypto_cfg_supported(blk_crypto_fallback_profile,
503503
&bc->bc_key->crypto_cfg)) {
504504
bio->bi_status = BLK_STS_NOTSUPP;
505505
return false;
@@ -526,15 +526,14 @@ bool blk_crypto_fallback_bio_prep(struct bio **bio_ptr)
526526

527527
int blk_crypto_fallback_evict_key(const struct blk_crypto_key *key)
528528
{
529-
return __blk_crypto_evict_key(&blk_crypto_fallback_profile, key);
529+
return __blk_crypto_evict_key(blk_crypto_fallback_profile, key);
530530
}
531531

532532
static bool blk_crypto_fallback_inited;
533533
static int blk_crypto_fallback_init(void)
534534
{
535535
int i;
536536
int err;
537-
struct blk_crypto_profile *profile = &blk_crypto_fallback_profile;
538537

539538
if (blk_crypto_fallback_inited)
540539
return 0;
@@ -545,18 +544,27 @@ static int blk_crypto_fallback_init(void)
545544
if (err)
546545
goto out;
547546

548-
err = blk_crypto_profile_init(profile, blk_crypto_num_keyslots);
549-
if (err)
547+
/* Dynamic allocation is needed because of lockdep_register_key(). */
548+
blk_crypto_fallback_profile =
549+
kzalloc(sizeof(*blk_crypto_fallback_profile), GFP_KERNEL);
550+
if (!blk_crypto_fallback_profile) {
551+
err = -ENOMEM;
550552
goto fail_free_bioset;
553+
}
554+
555+
err = blk_crypto_profile_init(blk_crypto_fallback_profile,
556+
blk_crypto_num_keyslots);
557+
if (err)
558+
goto fail_free_profile;
551559
err = -ENOMEM;
552560

553-
profile->ll_ops = blk_crypto_fallback_ll_ops;
554-
profile->max_dun_bytes_supported = BLK_CRYPTO_MAX_IV_SIZE;
561+
blk_crypto_fallback_profile->ll_ops = blk_crypto_fallback_ll_ops;
562+
blk_crypto_fallback_profile->max_dun_bytes_supported = BLK_CRYPTO_MAX_IV_SIZE;
555563

556564
/* All blk-crypto modes have a crypto API fallback. */
557565
for (i = 0; i < BLK_ENCRYPTION_MODE_MAX; i++)
558-
profile->modes_supported[i] = 0xFFFFFFFF;
559-
profile->modes_supported[BLK_ENCRYPTION_MODE_INVALID] = 0;
566+
blk_crypto_fallback_profile->modes_supported[i] = 0xFFFFFFFF;
567+
blk_crypto_fallback_profile->modes_supported[BLK_ENCRYPTION_MODE_INVALID] = 0;
560568

561569
blk_crypto_wq = alloc_workqueue("blk_crypto_wq",
562570
WQ_UNBOUND | WQ_HIGHPRI |
@@ -597,7 +605,9 @@ static int blk_crypto_fallback_init(void)
597605
fail_free_wq:
598606
destroy_workqueue(blk_crypto_wq);
599607
fail_destroy_profile:
600-
blk_crypto_profile_destroy(profile);
608+
blk_crypto_profile_destroy(blk_crypto_fallback_profile);
609+
fail_free_profile:
610+
kfree(blk_crypto_fallback_profile);
601611
fail_free_bioset:
602612
bioset_exit(&crypto_bio_split);
603613
out:

0 commit comments

Comments
 (0)