Skip to contentSkip to conversation

dm-inlinecrypt: add support for hardware-wrapped keys

PATCH Superseded Linlin Zhang 3 participants 8 messages May 16 – May 22

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover dm-inlinecrypt: add support for hardware-wrapped keys

dm-inlinecrypt currently assumes that all keys are raw software keys. That does not work for platforms where inline encryption expects hardware-wrapped key material managed by secure firmware/hardware.

This series adds support for hardware-wrapped keys in dm-inlinecrypt by introducing an explicit <is_wrappedkey> target argument. The flag lets dm-inlinecrypt select the proper blk-crypto key type at key initialization time:

- 0: BLK_CRYPTO_KEY_TYPE_RAW
- 1: BLK_CRYPTO_KEY_TYPE_HW_WRAPPED

With this change, dm-inlinecrypt can support both raw and wrapped key deployment models without hardcoding one key ownership model.

The series also:

- updates target argument parsing to include the new required flag
- propagates the wrapped/raw state in target status output
- updates dm-inlinecrypt documentation and examples accordingly

Note: this extends target syntax by adding one required parameter, so existing userspace table definitions must be updated. dm-inlinecrypt currently assumes that all keys are raw software keys. That does not work for platforms where inline encryption expects hardware-wrapped key material managed by secure firmware/hardware.

This series adds support for hardware-wrapped keys in dm-inlinecrypt by introducing an explicit <is_wrappedkey> target argument. The flag lets dm-inlinecrypt select the proper blk-crypto key type at key initialization time:

- 0: BLK_CRYPTO_KEY_TYPE_RAW
- 1: BLK_CRYPTO_KEY_TYPE_HW_WRAPPED

With this change, dm-inlinecrypt can support both raw and wrapped key deployment models without hardcoding one key ownership model.

The series also:

- updates target argument parsing to include the new required flag
- propagates the wrapped/raw state in target status output
- updates dm-inlinecrypt documentation and examples accordingly

Note: this extends target syntax by adding one required parameter, so existing userspace table definitions must be updated.

Linlin Zhang (1):
dm-inlinecrypt: add support for hardware-wrapped keys

 .../device-mapper/dm-inlinecrypt.rst          | 10 ++-
 drivers/md/dm-inlinecrypt.c                   | 71 +++++++++++--------
 2 files changed, 50 insertions(+), 31 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/1 dm-inlinecrypt: add support for hardware-wrapped keys

Add support for hardware-wrapped encryption keys to the dm-inlinecrypt target.

Introduce a new parameter <is_wrappedkey> to indicate whether the provided key is a raw key or a hardware-wrapped key. Based on this flag, the appropriate blk-crypto key type is selected when initializing the key.

This allows dm-inlinecrypt to work with hardware that requires keys to be wrapped and managed by the underlying inline encryption engine.

Update the target argument parsing accordingly and pass the key type to blk_crypto_init_key(). Documentation is also updated to reflect the new parameter and usage.

---
 .../device-mapper/dm-inlinecrypt.rst          | 10 ++-
 drivers/md/dm-inlinecrypt.c                   | 71 +++++++++++--------
 2 files changed, 50 insertions(+), 31 deletions(-)
Documentation/admin-guide/device-mapper/dm-inlinecrypt.rst +7 -3
index c71e600efb76..3a4ce2c5f228 100644
@@ -10,7 +10,7 @@ https://docs.kernel.org/block/inline-encryption.html
 
 Parameters::
 
-	      <cipher> <key> <iv_offset> <device path> \
+	      <cipher> <key> <is_wrappedkey> <iv_offset> <device path> \
 	      <offset> [<#opt_params> <opt_params>]
 
 <cipher>
@@ -52,6 +52,10 @@ Parameters::
     The kernel keyring key description inlinecrypt target should look for
     when loading key of <key_type>.
 
+<is_wrappedkey>
+    The flag used to imply if the key is hardware-wrapped or not.
+    '0' means a raw key and '1' means a wrapped key.
+
 <iv_offset>
     The IV offset is a sector count that is added to the sector number
     before creating the IV.
@@ -113,11 +117,11 @@ using dmsetup
 
 	#!/bin/sh
 	# Create a inlinecrypt device using dmsetup
-	dmsetup create inlinecrypt1 --table "0 `blockdev --getsz $1` inlinecrypt aes-xts-plain64 babebabebabebabebabebabebabebabebabebabebabebabebabebabebabebabe 0 $1 0"
+	dmsetup create inlinecrypt1 --table "0 `blockdev --getsz $1` inlinecrypt aes-xts-plain64 babebabebabebabebabebabebabebabebabebabebabebabebabebabebabebabe 0 0 $1 0"
 
 ::
 
 	#!/bin/sh
 	# Create a inlinecrypt device using dmsetup when encryption key is stored in keyring service
-	dmsetup create inlinecrypt2 --table "0 `blockdev --getsz $1` inlinecrypt aes-xts-plain64 :64:logon:fde:dminlinecrypt_test_key 0 $1 0"
+	dmsetup create inlinecrypt2 --table "0 `blockdev --getsz $1` inlinecrypt aes-xts-plain64 :64:logon:fde:dminlinecrypt_test_key 0 0 $1 0"
 
drivers/md/dm-inlinecrypt.c +43 -28

183 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw
Quoted 27 lines · Linlin Zhang

Add support for hardware-wrapped encryption keys to the dm-inlinecrypt target.

Introduce a new parameter <is_wrappedkey> to indicate whether the provided key is a raw key or a hardware-wrapped key. Based on this flag, the appropriate blk-crypto key type is selected when initializing the key.

This allows dm-inlinecrypt to work with hardware that requires keys to be wrapped and managed by the underlying inline encryption engine.

Update the target argument parsing accordingly and pass the key type to blk_crypto_init_key(). Documentation is also updated to reflect the new parameter and usage.

---
  .../device-mapper/dm-inlinecrypt.rst          | 10 ++-
  drivers/md/dm-inlinecrypt.c                   | 71 +++++++++++--------
  2 files changed, 50 insertions(+), 31 deletions(-)
Documentation/admin-guide/device-mapper/dm-inlinecrypt.rst +0 -0
index c71e600efb76..3a4ce2c5f228 100644

Documentation/admin-guide/device-mapper/dm-inlinecrypt.rst https://docs.kernel.org/block/inline-encryption.html · line 14

Quoted 6 lines
Documentation/admin-guide/device-mapper/dm-inlinecrypt.rst +1 -1
@@ -10,7 +10,7 @@ https://docs.kernel.org/block/inline-encryption.html
 
  Parameters::
 
-	      <cipher> <key> <iv_offset> <device path> \
+	      <cipher> <key> <is_wrappedkey> <iv_offset> <device path> \
  	      <offset> [<#opt_params> <opt_params>]

Please use optional parameter.
Adding mandatory field will introduce unnecessary incompatibility with dm-crypt mappings. (The idea was that you can simply switch "crypt" to "inlinecrypt" for raw keys.)

I would probably just add "hw-wrapped" or "keytype=raw|hw-wrapped" optional argument (with raw as default, so no need so specify it).

IOW the mapping will look like this (1 is number of optional parameters):

<cipher> <key> <iv_offset> <device path> <offset> 1 hw-wrapped
or
<cipher> <key> <iv_offset> <device path> <offset> 1 keytype=hw-wrapped

The second option will allow to add new key type much easier.

Please check how other targets implement it, some dm-crypt examples
https://gitlab.com/cryptsetup/cryptsetup/-/wikis/DMCrypt

Thanks,
Milan

#3 lore raw
Quoted 37 lines · Milan Broz
Quoted 27 lines · Linlin Zhang

Add support for hardware-wrapped encryption keys to the dm-inlinecrypt target.

Introduce a new parameter <is_wrappedkey> to indicate whether the provided key is a raw key or a hardware-wrapped key. Based on this flag, the appropriate blk-crypto key type is selected when initializing the key.

This allows dm-inlinecrypt to work with hardware that requires keys to be wrapped and managed by the underlying inline encryption engine.

Update the target argument parsing accordingly and pass the key type to blk_crypto_init_key(). Documentation is also updated to reflect the new parameter and usage.

---
  .../device-mapper/dm-inlinecrypt.rst          | 10 ++- drivers/md/dm-inlinecrypt.c                   | 71 +++++++++++--------

  2 files changed, 50 insertions(+), 31 deletions(-)
Documentation/admin-guide/device-mapper/dm-inlinecrypt.rst +0 -0
index c71e600efb76..3a4ce2c5f228 100644
@@ -10,7 +10,7 @@ https://docs.kernel.org/block/inline-encryption.html
Quoted 4 lines

    Parameters::
  -          <cipher> <key> <iv_offset> <device path> \
+          <cipher> <key> <is_wrappedkey> <iv_offset> <device path> \
            <offset> [<#opt_params> <opt_params>]

Please use optional parameter.
Adding mandatory field will introduce unnecessary incompatibility with dm-crypt mappings. (The idea was that you can simply switch "crypt" to "inlinecrypt" for raw keys.)

Quoted 8 lines

I would probably just add "hw-wrapped" or "keytype=raw|hw-wrapped" optional argument (with raw as default, so no need so specify it).

IOW the mapping will look like this (1 is number of optional parameters):

   <cipher> <key> <iv_offset> <device path> <offset> 1 hw-wrapped or
   <cipher> <key> <iv_offset> <device path> <offset> 1 keytype=hw-wrapped

Thanks for your suggestion!

I agree that keeping "hw-wrapped" or "keytype=raw|hw-wrapped" as an optional argument helps preserve compatibility when switching from "crypt" to "inlinecrypt"

My concern is that, in practice, this optional argument may effectively become mandatory for certain configurations. For instance, "hw-wrapped" or "keytype=raw|hw-wrapped" must be set for a wrapped key. This slightly blurs the original intent of "optional arguments", which are typically expected to be truly optional for correct operation.

Would this be acceptable? which one is more acceptable for upstream? incompatibility semantics mappings b/w dm-crypt and dm-inlinecrypt or blur the original intent of "optional arguments"?

Any additional thoughts or feedback from others would be much appreciated. Thanks!

Quoted 2 lines

The second option will allow to add new key type much easier.

Regarding the second option ("keytype=..."), I agree it is more extensible. Could you please clarify what other key types you envision supporting in the future?

Quoted 7 lines

Please check how other targets implement it, some dm-crypt examples
https://gitlab.com/cryptsetup/cryptsetup/-/wikis/DMCrypt

Thanks,
Milan

maintainer
#4 lore raw
Quoted 62 lines · Linlin Zhang
Quoted 37 lines · Milan Broz
Quoted 27 lines · Linlin Zhang

Add support for hardware-wrapped encryption keys to the dm-inlinecrypt target.

Introduce a new parameter <is_wrappedkey> to indicate whether the provided key is a raw key or a hardware-wrapped key. Based on this flag, the appropriate blk-crypto key type is selected when initializing the key.

This allows dm-inlinecrypt to work with hardware that requires keys to be wrapped and managed by the underlying inline encryption engine.

Update the target argument parsing accordingly and pass the key type to blk_crypto_init_key(). Documentation is also updated to reflect the new parameter and usage.

---
  .../device-mapper/dm-inlinecrypt.rst          | 10 ++- drivers/md/dm-inlinecrypt.c                   | 71 +++++++++++--------

  2 files changed, 50 insertions(+), 31 deletions(-)
Documentation/admin-guide/device-mapper/dm-inlinecrypt.rst +0 -0
index c71e600efb76..3a4ce2c5f228 100644
@@ -10,7 +10,7 @@ https://docs.kernel.org/block/inline-encryption.html
Quoted 4 lines

    Parameters::
  -          <cipher> <key> <iv_offset> <device path> \
+          <cipher> <key> <is_wrappedkey> <iv_offset> <device path> \
            <offset> [<#opt_params> <opt_params>]

Please use optional parameter.
Adding mandatory field will introduce unnecessary incompatibility with dm-crypt mappings. (The idea was that you can simply switch "crypt" to "inlinecrypt" for raw keys.)

Quoted 8 lines

I would probably just add "hw-wrapped" or "keytype=raw|hw-wrapped" optional argument (with raw as default, so no need so specify it).

IOW the mapping will look like this (1 is number of optional parameters):

   <cipher> <key> <iv_offset> <device path> <offset> 1 hw-wrapped or
   <cipher> <key> <iv_offset> <device path> <offset> 1 keytype=hw-wrapped

Thanks for your suggestion!

I agree that keeping "hw-wrapped" or "keytype=raw|hw-wrapped" as an optional argument helps preserve compatibility when switching from "crypt" to "inlinecrypt"

My concern is that, in practice, this optional argument may effectively become mandatory for certain configurations. For instance, "hw-wrapped" or "keytype=raw|hw-wrapped" must be set for a wrapped key. This slightly blurs the original intent of "optional arguments", which are typically expected to be truly optional for correct operation.

Quoted 5 lines

Would this be acceptable? which one is more acceptable for upstream? incompatibility semantics mappings b/w dm-crypt and dm-inlinecrypt or blur the original intent of "optional arguments"?

Any additional thoughts or feedback from others would be much appreciated. Thanks!

Hi

I would prefer an optional argument "keytype:raw" or "keytype:hw-wrapped". Device mapper targets use colon to separate arguments from values, so I would use it here too.

I removed the patch that always sets BLK_CRYPTO_KEY_TYPE_HW_WRAPPED from the linux-dm repository and I will accept a patch that introduces "keytype:hw-wrapped" when you send it.

Mikulas

Quoted 15 lines
Quoted 2 lines

The second option will allow to add new key type much easier.

Regarding the second option ("keytype=..."), I agree it is more extensible. Could you please clarify what other key types you envision supporting in the future?

Quoted 7 lines

Please check how other targets implement it, some dm-crypt examples
https://gitlab.com/cryptsetup/cryptsetup/-/wikis/DMCrypt

Thanks,
Milan

#5 lore raw
Quoted 70 lines · Mikulas Patocka
Quoted 66 lines · Linlin Zhang
Quoted 37 lines · Milan Broz
Quoted 27 lines · Linlin Zhang

Add support for hardware-wrapped encryption keys to the dm-inlinecrypt target.

Introduce a new parameter <is_wrappedkey> to indicate whether the provided key is a raw key or a hardware-wrapped key. Based on this flag, the appropriate blk-crypto key type is selected when initializing the key.

This allows dm-inlinecrypt to work with hardware that requires keys to be wrapped and managed by the underlying inline encryption engine.

Update the target argument parsing accordingly and pass the key type to blk_crypto_init_key(). Documentation is also updated to reflect the new parameter and usage.

---
  .../device-mapper/dm-inlinecrypt.rst          | 10 ++- drivers/md/dm-inlinecrypt.c                   | 71 +++++++++++--------

  2 files changed, 50 insertions(+), 31 deletions(-)
Documentation/admin-guide/device-mapper/dm-inlinecrypt.rst +0 -0
index c71e600efb76..3a4ce2c5f228 100644
@@ -10,7 +10,7 @@ https://docs.kernel.org/block/inline-encryption.html
Quoted 4 lines

    Parameters::
  -          <cipher> <key> <iv_offset> <device path> \
+          <cipher> <key> <is_wrappedkey> <iv_offset> <device path> \
            <offset> [<#opt_params> <opt_params>]

Please use optional parameter.
Adding mandatory field will introduce unnecessary incompatibility with dm-crypt mappings. (The idea was that you can simply switch "crypt" to "inlinecrypt" for raw keys.)

Quoted 8 lines

I would probably just add "hw-wrapped" or "keytype=raw|hw-wrapped" optional argument (with raw as default, so no need so specify it).

IOW the mapping will look like this (1 is number of optional parameters):

   <cipher> <key> <iv_offset> <device path> <offset> 1 hw-wrapped or
   <cipher> <key> <iv_offset> <device path> <offset> 1 keytype=hw-wrapped

Thanks for your suggestion!

I agree that keeping "hw-wrapped" or "keytype=raw|hw-wrapped" as an optional argument helps preserve compatibility when switching from "crypt" to "inlinecrypt"

My concern is that, in practice, this optional argument may effectively become mandatory for certain configurations. For instance, "hw-wrapped" or "keytype=raw|hw-wrapped" must be set for a wrapped key. This slightly blurs the original intent of "optional arguments", which are typically expected to be truly optional for correct operation.

Would this be acceptable? which one is more acceptable for upstream? incompatibility semantics mappings b/w dm-crypt and dm-inlinecrypt or blur the original intent of "optional arguments"?

Quoted 7 lines
Quoted 1 line

Any additional thoughts or feedback from others would be much appreciated. Thanks!

Hi

I would prefer an optional argument "keytype:raw" or "keytype:hw-wrapped". Device mapper targets use colon to separate arguments from values, so I would use it here too.

Thanks for the comment!

ACK. I'll send a new patch with such modification.

Quoted 22 lines

I removed the patch that always sets BLK_CRYPTO_KEY_TYPE_HW_WRAPPED from the linux-dm repository and I will accept a patch that introduces "keytype:hw-wrapped" when you send it.

Mikulas

Quoted 15 lines
Quoted 2 lines

The second option will allow to add new key type much easier.

Regarding the second option ("keytype=..."), I agree it is more extensible. Could you please clarify what other key types you envision supporting in the future?

Quoted 7 lines

Please check how other targets implement it, some dm-crypt examples
https://gitlab.com/cryptsetup/cryptsetup/-/wikis/DMCrypt

Thanks,
Milan

#6 lore raw
In reply to Linlin Zhang

On 5/18/26 10:11 AM, Linlin Zhang wrote:

...

Quoted 7 lines
Quoted 5 lines

IOW the mapping will look like this (1 is number of optional parameters):

   <cipher> <key> <iv_offset> <device path> <offset> 1 hw-wrapped
or
   <cipher> <key> <iv_offset> <device path> <offset> 1 keytype=hw-wrapped

Quoted 5 lines

Thanks for your suggestion!

I agree that keeping "hw-wrapped" or "keytype=raw|hw-wrapped" as an optional argument helps preserve compatibility when switching from "crypt" to "inlinecrypt"

Just use semicolon as separator as Mikulas suggested. (I mixed that up, we always use semicolan as separator.)

Quoted 5 lines

My concern is that, in practice, this optional argument may effectively become mandatory for certain configurations. For instance, "hw-wrapped" or "keytype=raw|hw-wrapped" must be set for a wrapped key. This slightly blurs the original intent of "optional arguments", which are typically expected to be truly optional for correct operation.

It no longer works this way, it is normal that in some scenarios "optional" arguments are required. For example sector_size - once you use non-default, you have to specify it always.

IOW no problem with that.

Milan

#7 lore raw
Quoted 25 lines · Milan Broz

On 5/18/26 10:11 AM, Linlin Zhang wrote:

...

Quoted 7 lines
Quoted 5 lines

IOW the mapping will look like this (1 is number of optional parameters):

    <cipher> <key> <iv_offset> <device path> <offset> 1 hw-wrapped or
    <cipher> <key> <iv_offset> <device path> <offset> 1 keytype=hw-wrapped

Quoted 5 lines

Thanks for your suggestion!

I agree that keeping "hw-wrapped" or "keytype=raw|hw-wrapped" as an optional argument helps preserve compatibility when switching from "crypt" to "inlinecrypt"

Just use semicolon as separator as Mikulas suggested. (I mixed that up, we always use semicolan as separator.)

Quoted 5 lines

My concern is that, in practice, this optional argument may effectively become mandatory for certain configurations. For instance, "hw-wrapped" or "keytype=raw|hw-wrapped" must be set for a wrapped key. This slightly blurs the original intent of "optional arguments", which are typically expected to be truly optional for correct operation.

Quoted 5 lines

It no longer works this way, it is normal that in some scenarios "optional" arguments are required. For example sector_size - once you use non-default, you have to specify it always.

IOW no problem with that.

Thanks for the comments!

ACK. I'll send a new patch with such modification.

Quoted 3 lines

Milan