dm-inlinecrypt: move to HW-wrapped key
cover dm-inlinecrypt: move to HW-wrapped key
dm-inlinecrypt currently initializes the blk-crypto key using BLK_CRYPTO_KEY_TYPE_RAW, which implies that the provided key material is a plaintext software key owned by the block layer.
This was requested as the first version in the link
(https://lore.kernel.org/all/20260312070110.GD2359@sol/) to have a a easy way validating the patch.
However, now support for wrapped keys is already upstream and on platforms where dm-inlinecrypt is used together with a hardware-backed key source (e.g. TrustZone/TEE or other secure key wrapping mechanisms), the key material passed down is already wrapped and must be treated as opaque by the block layer.
Switching the blk-crypto key initialization to BLK_CRYPTO_KEY_TYPE_HW_WRAPPED aligns dm-inlinecrypt
with hardware-backed key usage models and avoids incorrect assumptions about key ownership and visibility.
Linlin Zhang (1):
dm-inlinecrypt: initialize blk-crypto key as HW-wrapped key
drivers/md/dm-inlinecrypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
2.34.1
PATCH 1/1 dm-inlinecrypt: initialize blk-crypto key as HW-wrapped key
dm-inlinecrypt currently initializes the blk-crypto key using BLK_CRYPTO_KEY_TYPE_RAW, which implies that the provided key material is a plaintext software key owned by the block layer.
However, on platforms where dm-inlinecrypt is used together with a hardware-backed key source (e.g. TrustZone/TEE or other secure key wrapping mechanisms), the key material passed down is already wrapped and must be treated as opaque by the block layer.
Initialize the blk-crypto key using BLK_CRYPTO_KEY_TYPE_HW_WRAPPED instead, so that dm-inlinecrypt correctly models hardware-wrapped keys and avoids incorrect assumptions about key ownership and visibility.
--- drivers/md/dm-inlinecrypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-inlinecrypt.c +1 -1
@@ -386,7 +386,7 @@ static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) dun_bytes =DIV_ROUND_UP (fls64 (ctx->max_dun),8 ); err =blk_crypto_init_key (&ctx->key, raw_key, ctx->key_size, -BLK_CRYPTO_KEY_TYPE_RAW , +BLK_CRYPTO_KEY_TYPE_HW_WRAPPED , cipher->mode_num, dun_bytes, ctx->sector_size);if (err) {
Signature · 1 line
2.34.1
Re: [PATCH v1 1/1] dm-inlinecrypt: initialize blk-crypto key as HW-wrapped key
Quoted 23 lines · Linlin Zhang
dm-inlinecrypt currently initializes the blk-crypto key using
BLK_CRYPTO_KEY_TYPE_RAW, which implies that the provided key material is a plaintext software key owned by the block layer.However, on platforms where dm-inlinecrypt is used together with a hardware-backed key source (e.g. TrustZone/TEE or other secure key wrapping mechanisms), the key material passed down is already wrapped and must be treated as opaque by the block layer.
Initialize the blk-crypto key using
BLK_CRYPTO_KEY_TYPE_HW_WRAPPEDinstead, so that dm-inlinecrypt correctly models hardware-wrapped keys and avoids incorrect assumptions about key ownership and visibility.Signed-off-by Linlin Zhang <[email protected]>--- drivers/md/dm-inlinecrypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/dm-inlinecrypt.c +0
-0
drivers/md/dm-inlinecrypt.c static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) · line 391
Quoted 7 lines
drivers/md/dm-inlinecrypt.c +1
-1@@ -386,7 +386,7 @@ static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) dun_bytes =DIV_ROUND_UP (fls64 (ctx->max_dun),8 ); err =blk_crypto_init_key (&ctx->key, raw_key, ctx->key_size, -BLK_CRYPTO_KEY_TYPE_RAW , +BLK_CRYPTO_KEY_TYPE_HW_WRAPPED , cipher->mode_num, dun_bytes, ctx->sector_size);
The raw key support is useful too, and it should be the default. I recommend adding a "wrappedkey" optional argument that enables BLK_CRYPTO_KEY_TYPE_HW_WRAPPED.
- Eric
Re: [PATCH v1 1/1] dm-inlinecrypt: initialize blk-crypto key as HW-wrapped key
Quoted 26 lines · Eric Biggers
Quoted 25 lines · Linlin Zhang
dm-inlinecrypt currently initializes the blk-crypto key using
BLK_CRYPTO_KEY_TYPE_RAW, which implies that the provided key material is a plaintext software key owned by the block layer.However, on platforms where dm-inlinecrypt is used together with a hardware-backed key source (e.g. TrustZone/TEE or other secure key wrapping mechanisms), the key material passed down is already wrapped and must be treated as opaque by the block layer.
Initialize the blk-crypto key using
BLK_CRYPTO_KEY_TYPE_HW_WRAPPEDinstead, so that dm-inlinecrypt correctly models hardware-wrapped keys and avoids incorrect assumptions about key ownership and visibility.Signed-off-by Linlin Zhang <[email protected]>--- drivers/md/dm-inlinecrypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/dm-inlinecrypt.c +0
-0@@ -386,7 +386,7 @@ static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) dun_bytes =DIV_ROUND_UP (fls64 (ctx->max_dun),8 );
Quoted 9 lines
drivers/md/dm-inlinecrypt.c static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) · line 391
Quoted 5 lines
drivers/md/dm-inlinecrypt.c +1
-1err =blk_crypto_init_key (&ctx->key, raw_key, ctx->key_size, -BLK_CRYPTO_KEY_TYPE_RAW , +BLK_CRYPTO_KEY_TYPE_HW_WRAPPED , cipher->mode_num, dun_bytes, ctx->sector_size);The raw key support is useful too, and it should be the default. I recommend adding a "wrappedkey" optional argument that enables
BLK_CRYPTO_KEY_TYPE_HW_WRAPPED.
This patch also makes the variable called "raw_key" contain a key that isn't a raw key, which is confusing. "key_bytes" would make more sense for a byte array that can contain either type of key. See e.g. blk_crypto_init_key() which uses that naming convention.
- Eric
Re: [PATCH v1 1/1] dm-inlinecrypt: initialize blk-crypto key as HW-wrapped key
Quoted 37 lines · Eric Biggers
Quoted 26 lines · Eric Biggers
Quoted 25 lines · Linlin Zhang
dm-inlinecrypt currently initializes the blk-crypto key using
BLK_CRYPTO_KEY_TYPE_RAW, which implies that the provided key material is a plaintext software key owned by the block layer.However, on platforms where dm-inlinecrypt is used together with a hardware-backed key source (e.g. TrustZone/TEE or other secure key wrapping mechanisms), the key material passed down is already wrapped and must be treated as opaque by the block layer.
Initialize the blk-crypto key using
BLK_CRYPTO_KEY_TYPE_HW_WRAPPEDinstead, so that dm-inlinecrypt correctly models hardware-wrapped keys and avoids incorrect assumptions about key ownership and visibility.Signed-off-by Linlin Zhang <[email protected]>--- drivers/md/dm-inlinecrypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/dm-inlinecrypt.c +0
-0@@ -386,7 +386,7 @@ static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) dun_bytes =DIV_ROUND_UP (fls64 (ctx->max_dun),8 );Quoted 9 lines
drivers/md/dm-inlinecrypt.c static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) · line 391
Quoted 5 lines
drivers/md/dm-inlinecrypt.c +1
-1err =blk_crypto_init_key (&ctx->key, raw_key, ctx->key_size, -BLK_CRYPTO_KEY_TYPE_RAW , +BLK_CRYPTO_KEY_TYPE_HW_WRAPPED , cipher->mode_num, dun_bytes, ctx->sector_size);The raw key support is useful too, and it should be the default. I recommend adding a "wrappedkey" optional argument that enables
BLK_CRYPTO_KEY_TYPE_HW_WRAPPED.
Quoted 4 lines
This patch also makes the variable called "
raw_key" contain a key that isn't a raw key, which is confusing. "key_bytes" would make more sense for a byte array that can contain either type of key. See e.g.blk_crypto_init_key()which uses that naming convention.
Thanks for your comment!
ACK.
Previously BLK_CRYPTO_KEY_TYPE_HW_WRAPPED was set for blk-crypto-profile entity by default, a raw key won't never passed down to ICE driver, so I replaced raw key type with wrapped key type directly.
Now I see it already changed to query the supported type from ice. There isn't above concern. I'll update a new patch with both wrappedkey and raw key support and adding "wrappedkey" optional argument.
replace "raw_key" with "key_bytes" as well.
Quoted 2 lines
- Eric
Re: [PATCH v1 1/1] dm-inlinecrypt: initialize blk-crypto key as HW-wrapped key
Quoted 9 lines · Linlin Zhang
Previously
BLK_CRYPTO_KEY_TYPE_HW_WRAPPEDwas set for blk-crypto-profile entity by default, a raw key won't never passed down to ICE driver, so I replaced raw key type with wrapped key type directly.Now I see it already changed to query the supported type from ice. There isn't above concern. I'll update a new patch with both wrappedkey and raw key support and adding "wrappedkey" optional argument.
replace "
raw_key" with "key_bytes" as well.
In the upstream kernel, BLK_CRYPTO_KEY_TYPE_HW_WRAPPED was added in v6.15 and has never been the default. Also currently only ufs-qcom and msm-sdhci support it. ufs-exynos, ufs-mediatek, mtk-sd, ufs-sprd, ufshcd-pci currently support raw keys only.
It should be supported, just as an opt-in thing.
- Eric