BACKPORT: 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: 2fb48d88e77f ("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> (cherry picked from commit c984ff1423ae9f70b1f28ce811856db0d9c99021) (resolved conflict due to HW-wrapped key support) Change-Id: I8c889550f97dc3d326930bd5745da6ea64061309 Signed-off-by: Eric Biggers <ebiggers@google.com>
This commit is contained in:
parent
086befddbe
commit
71bedf9d9c
@ -78,7 +78,7 @@ static struct blk_crypto_fallback_keyslot {
|
|||||||
struct crypto_skcipher *tfms[BLK_ENCRYPTION_MODE_MAX];
|
struct crypto_skcipher *tfms[BLK_ENCRYPTION_MODE_MAX];
|
||||||
} *blk_crypto_keyslots;
|
} *blk_crypto_keyslots;
|
||||||
|
|
||||||
static struct blk_crypto_profile blk_crypto_fallback_profile;
|
static struct blk_crypto_profile *blk_crypto_fallback_profile;
|
||||||
static struct workqueue_struct *blk_crypto_wq;
|
static struct workqueue_struct *blk_crypto_wq;
|
||||||
static mempool_t *blk_crypto_bounce_page_pool;
|
static mempool_t *blk_crypto_bounce_page_pool;
|
||||||
static struct bio_set crypto_bio_split;
|
static struct bio_set crypto_bio_split;
|
||||||
@ -294,7 +294,7 @@ static bool blk_crypto_fallback_encrypt_bio(struct bio **bio_ptr)
|
|||||||
* Get a blk-crypto-fallback keyslot that contains a crypto_skcipher for
|
* Get a blk-crypto-fallback keyslot that contains a crypto_skcipher for
|
||||||
* this bio's algorithm and key.
|
* this bio's algorithm and key.
|
||||||
*/
|
*/
|
||||||
blk_st = blk_crypto_get_keyslot(&blk_crypto_fallback_profile,
|
blk_st = blk_crypto_get_keyslot(blk_crypto_fallback_profile,
|
||||||
bc->bc_key, &slot);
|
bc->bc_key, &slot);
|
||||||
if (blk_st != BLK_STS_OK) {
|
if (blk_st != BLK_STS_OK) {
|
||||||
src_bio->bi_status = blk_st;
|
src_bio->bi_status = blk_st;
|
||||||
@ -397,7 +397,7 @@ static void blk_crypto_fallback_decrypt_bio(struct work_struct *work)
|
|||||||
* Get a blk-crypto-fallback keyslot that contains a crypto_skcipher for
|
* Get a blk-crypto-fallback keyslot that contains a crypto_skcipher for
|
||||||
* this bio's algorithm and key.
|
* this bio's algorithm and key.
|
||||||
*/
|
*/
|
||||||
blk_st = blk_crypto_get_keyslot(&blk_crypto_fallback_profile,
|
blk_st = blk_crypto_get_keyslot(blk_crypto_fallback_profile,
|
||||||
bc->bc_key, &slot);
|
bc->bc_key, &slot);
|
||||||
if (blk_st != BLK_STS_OK) {
|
if (blk_st != BLK_STS_OK) {
|
||||||
bio->bi_status = blk_st;
|
bio->bi_status = blk_st;
|
||||||
@ -501,7 +501,7 @@ bool blk_crypto_fallback_bio_prep(struct bio **bio_ptr)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__blk_crypto_cfg_supported(&blk_crypto_fallback_profile,
|
if (!__blk_crypto_cfg_supported(blk_crypto_fallback_profile,
|
||||||
&bc->bc_key->crypto_cfg)) {
|
&bc->bc_key->crypto_cfg)) {
|
||||||
bio->bi_status = BLK_STS_NOTSUPP;
|
bio->bi_status = BLK_STS_NOTSUPP;
|
||||||
return false;
|
return false;
|
||||||
@ -528,7 +528,7 @@ bool blk_crypto_fallback_bio_prep(struct bio **bio_ptr)
|
|||||||
|
|
||||||
int blk_crypto_fallback_evict_key(const struct blk_crypto_key *key)
|
int blk_crypto_fallback_evict_key(const struct blk_crypto_key *key)
|
||||||
{
|
{
|
||||||
return __blk_crypto_evict_key(&blk_crypto_fallback_profile, key);
|
return __blk_crypto_evict_key(blk_crypto_fallback_profile, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool blk_crypto_fallback_inited;
|
static bool blk_crypto_fallback_inited;
|
||||||
@ -536,7 +536,6 @@ static int blk_crypto_fallback_init(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int err;
|
int err;
|
||||||
struct blk_crypto_profile *profile = &blk_crypto_fallback_profile;
|
|
||||||
|
|
||||||
if (blk_crypto_fallback_inited)
|
if (blk_crypto_fallback_inited)
|
||||||
return 0;
|
return 0;
|
||||||
@ -547,19 +546,28 @@ static int blk_crypto_fallback_init(void)
|
|||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
err = blk_crypto_profile_init(profile, blk_crypto_num_keyslots);
|
/* Dynamic allocation is needed because of lockdep_register_key(). */
|
||||||
if (err)
|
blk_crypto_fallback_profile =
|
||||||
|
kzalloc(sizeof(*blk_crypto_fallback_profile), GFP_KERNEL);
|
||||||
|
if (!blk_crypto_fallback_profile) {
|
||||||
|
err = -ENOMEM;
|
||||||
goto fail_free_bioset;
|
goto fail_free_bioset;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = blk_crypto_profile_init(blk_crypto_fallback_profile,
|
||||||
|
blk_crypto_num_keyslots);
|
||||||
|
if (err)
|
||||||
|
goto fail_free_profile;
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
|
|
||||||
profile->ll_ops = blk_crypto_fallback_ll_ops;
|
blk_crypto_fallback_profile->ll_ops = blk_crypto_fallback_ll_ops;
|
||||||
profile->max_dun_bytes_supported = BLK_CRYPTO_MAX_IV_SIZE;
|
blk_crypto_fallback_profile->max_dun_bytes_supported = BLK_CRYPTO_MAX_IV_SIZE;
|
||||||
profile->key_types_supported = BLK_CRYPTO_KEY_TYPE_STANDARD;
|
blk_crypto_fallback_profile->key_types_supported = BLK_CRYPTO_KEY_TYPE_STANDARD;
|
||||||
|
|
||||||
/* All blk-crypto modes have a crypto API fallback. */
|
/* All blk-crypto modes have a crypto API fallback. */
|
||||||
for (i = 0; i < BLK_ENCRYPTION_MODE_MAX; i++)
|
for (i = 0; i < BLK_ENCRYPTION_MODE_MAX; i++)
|
||||||
profile->modes_supported[i] = 0xFFFFFFFF;
|
blk_crypto_fallback_profile->modes_supported[i] = 0xFFFFFFFF;
|
||||||
profile->modes_supported[BLK_ENCRYPTION_MODE_INVALID] = 0;
|
blk_crypto_fallback_profile->modes_supported[BLK_ENCRYPTION_MODE_INVALID] = 0;
|
||||||
|
|
||||||
blk_crypto_wq = alloc_workqueue("blk_crypto_wq",
|
blk_crypto_wq = alloc_workqueue("blk_crypto_wq",
|
||||||
WQ_UNBOUND | WQ_HIGHPRI |
|
WQ_UNBOUND | WQ_HIGHPRI |
|
||||||
@ -600,7 +608,9 @@ static int blk_crypto_fallback_init(void)
|
|||||||
fail_free_wq:
|
fail_free_wq:
|
||||||
destroy_workqueue(blk_crypto_wq);
|
destroy_workqueue(blk_crypto_wq);
|
||||||
fail_destroy_profile:
|
fail_destroy_profile:
|
||||||
blk_crypto_profile_destroy(profile);
|
blk_crypto_profile_destroy(blk_crypto_fallback_profile);
|
||||||
|
fail_free_profile:
|
||||||
|
kfree(blk_crypto_fallback_profile);
|
||||||
fail_free_bioset:
|
fail_free_bioset:
|
||||||
bioset_exit(&crypto_bio_split);
|
bioset_exit(&crypto_bio_split);
|
||||||
out:
|
out:
|
||||||
|
Loading…
Reference in New Issue
Block a user