Support for hardware-wrapped inline encryption keys
Subsystems (16)
Eric Biggers
maintainerv11 cover Support for hardware-wrapped inline encryption keys
This patchset is based on v6.14-rc1 and is also available at:
git fetch https://git.kernel.org/pub/scm/fs/fscrypt/linux.git wrapped-keys-v11
This patchset adds support for hardware-wrapped inline encryption keys, a security feature supported by some SoCs. It adds the block and fscrypt framework for the feature as well as support for it with UFS on Qualcomm SoCs.
This feature is described in full detail in the included Documentation changes. But to summarize, hardware-wrapped keys are inline encryption keys that are wrapped (encrypted) by a key internal to the hardware so that they can only be unwrapped (decrypted) by the hardware. Initially keys are wrapped with a permanent hardware key, but during actual use they are re-wrapped with a per-boot ephemeral key for improved security. The hardware supports importing keys as well as generating keys itself.
This differs from the existing support for hardware-wrapped keys in the kernel crypto API (also called "hardware-bound keys" in some places) in the same way that the crypto API differs from blk-crypto: the crypto API is for general crypto operations, whereas blk-crypto is for inline storage encryption.
This feature is already being used by Android downstream for several years
(https://source.android.com/docs/security/features/encryption/hw-wrapped-keys),
but on other platforms userspace support will be provided via fscryptctl and tests via xfstests. The tests have been merged into xfstests, and they pass on the SM8650 HDK with the upstream kernel plus this patchset.
This is targeting 6.15. As per the suggestion from Jens
(https://lore.kernel.org/linux-block/[email protected]/),
I'd like patches 1-3 to be queued up into a branch that gets pulled into the block tree. I'll then take patches 4-7 through the fscrypt tree, also for 6.15. If I end up with too many merge conflicts by trying to take patches 5-7 (given that this is a cross-subsystem feature), my fallback plan will be to wait until 6.16 to land patches 5-7, when they will finally be unblocked by the block patches having landed.
Changed in v11:
- Rebased onto v6.14-rc1. Dropped the patches that were upstreamed in 6.14, and put the block patches first in the series again.
- Significantly cleaned up the patch "soc: qcom: ice: add HWKM support to the ICE driver". Some of the notable changes were dropping the unnecessary support for HWKM v1, and replacing qcom_ice_using_hwkm() with qcom_ice_get_supported_key_type().
- Consistently used and documented the EBADMSG error code for invalid hardware-wrapped keys.
- Other minor cleanups.
Changed in v10:
- Fixed bugs in qcom_scm_derive_sw_secret() and cqhci_crypto_init().
- Added "ufs: qcom: fix crypto key eviction" and
"mmc: sdhci-msm: fix crypto key eviction".
- Split removing ufs_hba_variant_ops::program_key into its own patch.
- Minor cleanups.
- Added Tested-by.
Changed in v9 (relative to v7 patchset from Bartosz Golaszewski):
- ufs-qcom and sdhci-msm now just initialize the blk_crypto_profile themselves, like what ufs-exynos was doing. This avoids needing to add all the host-specific hooks for wrapped key support to the MMC and UFS core drivers.
- When passing the blk_crypto_key further down the stack, it now replaces parameters like the algorithm ID, to avoid creating two sources of truth.
- The module parameter qcom_ice.use_wrapped_keys should work correctly now.
- The fscrypt support no longer uses a policy flag to indicate when a file is protected by a HW-wrapped key, since it was already implied by the file's key identifier being that of a HW-wrapped key. Originally there was an issue where raw and HW-wrapped keys could share key identifiers, but I had fixed that earlier by introducing a new HKDF context byte.
- The term "standard keys" is no longer used. Now "raw keys" is consistently used instead. I've found that people find the term "raw keys" to be more intuitive. Also HW-wrapped keys could in principle be standardized.
- I've reordered the patchset to place preparatory patches that don't depend on the actual HW-wrapped key support first.
For older changelogs, see
https://lore.kernel.org/r/[email protected] and
https://lore.kernel.org/r/[email protected]
Eric Biggers (6):
blk-crypto: add basic hardware-wrapped key support
blk-crypto: show supported key types in sysfs
blk-crypto: add ioctls to create and prepare hardware-wrapped keys
fscrypt: add support for hardware-wrapped keys
soc: qcom: ice: make qcom_ice_program_key() take struct blk_crypto_key
ufs: qcom: add support for wrapped keys
Gaurav Kashyap (1):
soc: qcom: ice: add HWKM support to the ICE driver
Documentation/ABI/stable/sysfs-block | 20 + Documentation/block/inline-encryption.rst | 255 ++++++++++++- Documentation/filesystems/fscrypt.rst | 200 ++++++++-- .../userspace-api/ioctl/ioctl-number.rst | 2 + block/blk-crypto-fallback.c | 7 +- block/blk-crypto-internal.h | 10 + block/blk-crypto-profile.c | 101 +++++ block/blk-crypto-sysfs.c | 35 ++ block/blk-crypto.c | 204 +++++++++- block/ioctl.c | 5 + drivers/md/dm-table.c | 1 + drivers/mmc/host/cqhci-crypto.c | 8 +- drivers/mmc/host/sdhci-msm.c | 17 +- drivers/soc/qcom/ice.c | 349 ++++++++++++++++-- drivers/ufs/core/ufshcd-crypto.c | 7 +- drivers/ufs/host/ufs-exynos.c | 3 +- drivers/ufs/host/ufs-qcom.c | 56 ++- fs/crypto/fscrypt_private.h | 75 +++- fs/crypto/hkdf.c | 4 +- fs/crypto/inline_crypt.c | 42 ++- fs/crypto/keyring.c | 157 ++++++-- fs/crypto/keysetup.c | 63 +++- fs/crypto/keysetup_v1.c | 4 +- include/linux/blk-crypto-profile.h | 73 ++++ include/linux/blk-crypto.h | 73 +++- include/soc/qcom/ice.h | 34 +- include/uapi/linux/blk-crypto.h | 44 +++ include/uapi/linux/fs.h | 6 +- include/uapi/linux/fscrypt.h | 7 +- 29 files changed, 1654 insertions(+), 208 deletions(-) create mode 100644 include/uapi/linux/blk-crypto.h
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
Signature · 1 line
2.48.1
Eric Biggers
maintainerPATCH v11 1/7 blk-crypto: add basic hardware-wrapped key support
From: Eric Biggers <[email protected]>
To prevent keys from being compromised if an attacker acquires read access to kernel memory, some inline encryption hardware can accept keys which are wrapped by a per-boot hardware-internal key. This avoids needing to keep the raw keys in kernel memory, without limiting the number of keys that can be used. Such hardware also supports deriving a "software secret" for cryptographic tasks that can't be handled by inline encryption; this is needed for fscrypt to work properly.
To support this hardware, allow struct blk_crypto_key to represent a hardware-wrapped key as an alternative to a raw key, and make drivers set flags in struct blk_crypto_profile to indicate which types of keys they support. Also add the ->derive_sw_secret() low-level operation, which drivers supporting wrapped keys must implement.
For more information, see the detailed documentation which this patch adds to Documentation/block/inline-encryption.rst.
--- Documentation/block/inline-encryption.rst | 219 +++++++++++++++++++++- block/blk-crypto-fallback.c | 7 +- block/blk-crypto-internal.h | 1 + block/blk-crypto-profile.c | 46 +++++ block/blk-crypto.c | 61 ++++-- drivers/md/dm-table.c | 1 + drivers/mmc/host/cqhci-crypto.c | 8 +- drivers/mmc/host/sdhci-msm.c | 3 +- drivers/ufs/core/ufshcd-crypto.c | 7 +- drivers/ufs/host/ufs-exynos.c | 3 +- drivers/ufs/host/ufs-qcom.c | 3 +- fs/crypto/inline_crypt.c | 4 +- include/linux/blk-crypto-profile.h | 20 ++ include/linux/blk-crypto.h | 72 ++++++- 14 files changed, 417 insertions(+), 38 deletions(-)
Documentation/block/inline-encryption.rst +215 -4
@@ -75,14 +75,14 @@ Constraints and notes Basic design ============ We introduce ``struct blk_crypto_key`` to represent an inline encryption key and -how it will be used. This includes the actual bytes of the key; the size of the -key; the algorithm and data unit size the key will be used with; and the number -of bytes needed to represent the maximum data unit number the key will be used -with. +how it will be used. This includes the type of the key (raw or +hardware-wrapped); the actual bytes of the key; the size of the key; the +algorithm and data unit size the key will be used with; and the number of bytes +needed to represent the maximum data unit number the key will be used with. We introduce ``struct bio_crypt_ctx`` to represent an encryption context. It contains a data unit number and a pointer to a blk_crypto_key. We add pointers to a bio_crypt_ctx to ``struct bio`` and ``struct request``; this allows users of the block layer (e.g. filesystems) to provide an encryption context when
@@ -299,5 +299,216 @@ and disallow the combination for now. Whenever a device supports integrity, the kernel will pretend that the device does not support hardware inline encryption (by setting the blk_crypto_profile in the request_queue of the device to NULL). When the crypto API fallback is enabled, this means that all bios with and encryption context will use the fallback, and IO will complete as usual. When the fallback is disabled, a bio with an encryption context will be failed. + +.. _hardware_wrapped_keys: + +Hardware-wrapped keys +===================== + +Motivation and threat model +--------------------------- + +Linux storage encryption (dm-crypt, fscrypt, eCryptfs, etc.) traditionally +relies on the raw encryption key(s) being present in kernel memory so that the +encryption can be performed. This traditionally isn't seen as a problem because +the key(s) won't be present during an offline attack, which is the main type of +attack that storage encryption is intended to protect from. + +However, there is an increasing desire to also protect users' data from other +types of attacks (to the extent possible), including: + +- Cold boot attacks, where an attacker with physical access to a system suddenly + powers it off, then immediately dumps the system memory to extract recently + in-use encryption keys, then uses these keys to decrypt user data on-disk. + +- Online attacks where the attacker is able to read kernel memory without fully + compromising the system, followed by an offline attack where any extracted + keys can be used to decrypt user data on-disk. An example of such an online + attack would be if the attacker is able to run some code on the system that + exploits a Meltdown-like vulnerability but is unable to escalate privileges. + +- Online attacks where the attacker fully compromises the system, but their data + exfiltration is significantly time-limited and/or bandwidth-limited, so in + order to completely exfiltrate the data they need to extract the encryption + keys to use in a later offline attack. + +Hardware-wrapped keys are a feature of inline encryption hardware that is +designed to protect users' data from the above attacks (to the extent possible), +without introducing limitations such as a maximum number of keys. + +Note that it is impossible to **fully** protect users' data from these attacks. +Even in the attacks where the attacker "just" gets read access to kernel memory, +they can still extract any user data that is present in memory, including +plaintext pagecache pages of encrypted files. The focus here is just on +protecting the encryption keys, as those instantly give access to **all** user +data in any following offline attack, rather than just some of it (where which +data is included in that "some" might not be controlled by the attacker). + +Solution overview +----------------- + +Inline encryption hardware typically has "keyslots" into which software can +program keys for the hardware to use; the contents of keyslots typically can't +be read back by software. As such, the above security goals could be achieved +if the kernel simply erased its copy of the key(s) after programming them into +keyslot(s) and thereafter only referred to them via keyslot number. + +However, that naive approach runs into a couple problems: + +- It limits the number of unlocked keys to the number of keyslots, which + typically is a small number. In cases where there is only one encryption key + system-wide (e.g., a full-disk encryption key), that can be tolerable. + However, in general there can be many logged-in users with many different + keys, and/or many running applications with application-specific encrypted + storage areas. This is especially true if file-based encryption (e.g. + fscrypt) is being used. + +- Inline crypto engines typically lose the contents of their keyslots if the + storage controller (usually UFS or eMMC) is reset. Resetting the storage + controller is a standard error recovery procedure that is executed if certain + types of storage errors occur, and such errors can occur at any time. + Therefore, when inline crypto is being used, the operating system must always + be ready to reprogram the keyslots without user intervention. + +Thus, it is important for the kernel to still have a way to "remind" the +hardware about a key, without actually having the raw key itself. + +Somewhat less importantly, it is also desirable that the raw keys are never +visible to software at all, even while being initially unlocked. This would +ensure that a read-only compromise of system memory will never allow a key to be +extracted to be used off-system, even if it occurs when a key is being unlocked. + +To solve all these problems, some vendors of inline encryption hardware have +made their hardware support *hardware-wrapped keys*. Hardware-wrapped keys +are encrypted keys that can only be unwrapped (decrypted) and used by hardware +-- either by the inline encryption hardware itself, or by a dedicated hardware +block that can directly provision keys to the inline encryption hardware. + +(We refer to them as "hardware-wrapped keys" rather than simply "wrapped keys" +to add some clarity in cases where there could be other types of wrapped keys, +such as in file-based encryption. Key wrapping is a commonly used technique.) + +The key which wraps (encrypts) hardware-wrapped keys is a hardware-internal key +that is never exposed to software; it is either a persistent key (a "long-term +wrapping key") or a per-boot key (an "ephemeral wrapping key"). The long-term +wrapped form of the key is what is initially unlocked, but it is erased from +memory as soon as it is converted into an ephemerally-wrapped key. In-use +hardware-wrapped keys are always ephemerally-wrapped, not long-term wrapped. + +As inline encryption hardware can only be used to encrypt/decrypt data on-disk, +the hardware also includes a level of indirection; it doesn't use the unwrapped +key directly for inline encryption, but rather derives both an inline encryption +key and a "software secret" from it. Software can use the "software secret" for +tasks that can't use the inline encryption hardware, such as filenames +encryption. The software secret is not protected from memory compromise. + +Key hierarchy +------------- + +Here is the key hierarchy for a hardware-wrapped key:: + + Hardware-wrapped key + | + | + <Hardware KDF> + | + ----------------------------- + | | + Inline encryption key Software secret + +The components are: + +- *Hardware-wrapped key*: a key for the hardware's KDF (Key Derivation + Function), in ephemerally-wrapped form. The key wrapping algorithm is a + hardware implementation detail that doesn't impact kernel operation, but a + strong authenticated encryption algorithm such as AES-256-GCM is recommended. + +- *Hardware KDF*: a KDF (Key Derivation Function) which the hardware uses to + derive subkeys after unwrapping the wrapped key. The hardware's choice of KDF + doesn't impact kernel operation, but it does need to be known for testing + purposes, and it's also assumed to have at least a 256-bit security strength. + All known hardware uses the SP800-108 KDF in Counter Mode with AES-256-CMAC, + with a particular choice of labels and contexts; new hardware should use this + already-vetted KDF. + +- *Inline encryption key*: a derived key which the hardware directly provisions + to a keyslot of the inline encryption hardware, without exposing it to + software. In all known hardware, this will always be an AES-256-XTS key. + However, in principle other encryption algorithms could be supported too. + Hardware must derive distinct subkeys for each supported encryption algorithm. + +- *Software secret*: a derived key which the hardware returns to software so + that software can use it for cryptographic tasks that can't use inline + encryption. This value is cryptographically isolated from the inline + encryption key, i.e. knowing one doesn't reveal the other. (The KDF ensures + this.) Currently, the software secret is always 32 bytes and thus is suitable + for cryptographic applications that require up to a 256-bit security strength. + Some use cases (e.g. full-disk encryption) won't require the software secret. + +Example: in the case of fscrypt, the fscrypt master key (the key that protects a +particular set of encrypted directories) is made hardware-wrapped. The inline +encryption key is used as the file contents encryption key, while the software +secret (rather than the master key directly) is used to key fscrypt's KDF +(HKDF-SHA512) to derive other subkeys such as filenames encryption keys. + +Note that currently this design assumes a single inline encryption key per +hardware-wrapped key, without any further key derivation. Thus, in the case of +fscrypt, currently hardware-wrapped keys are only compatible with the "inline +encryption optimized" settings, which use one file contents encryption key per +encryption policy rather than one per file. This design could be extended to +make the hardware derive per-file keys using per-file nonces passed down the +storage stack, and in fact some hardware already supports this; future work is +planned to remove this limitation by adding the corresponding kernel support. + +Kernel support +-------------- + +The inline encryption support of the kernel's block layer ("blk-crypto") has +been extended to support hardware-wrapped keys as an alternative to raw keys, +when hardware support is available. This works in the following way: + +- A ``key_types_supported`` field is added to the crypto capabilities in + ``struct blk_crypto_profile``. This allows device drivers to declare that + they support raw keys, hardware-wrapped keys, or both. + +- ``struct blk_crypto_key`` can now contain a hardware-wrapped key as an + alternative to a raw key; a ``key_type`` field is added to + ``struct blk_crypto_config`` to distinguish between the different key types. + This allows users of blk-crypto to en/decrypt data using a hardware-wrapped + key in a way very similar to using a raw key. + +- A new method ``blk_crypto_ll_ops::derive_sw_secret`` is added. Device drivers + that support hardware-wrapped keys must implement this method. Users of + blk-crypto can call ``blk_crypto_derive_sw_secret()`` to access this method. + +- The programming and eviction of hardware-wrapped keys happens via + ``blk_crypto_ll_ops::keyslot_program`` and + ``blk_crypto_ll_ops::keyslot_evict``, just like it does for raw keys. If a + driver supports hardware-wrapped keys, then it must handle hardware-wrapped + keys being passed to these methods. + +blk-crypto-fallback doesn't support hardware-wrapped keys. Therefore, +hardware-wrapped keys can only be used with actual inline encryption hardware. + +Testability +----------- + +Both the hardware KDF and the inline encryption itself are well-defined +algorithms that don't depend on any secrets other than the unwrapped key. +Therefore, if the unwrapped key is known to software, these algorithms can be +reproduced in software in order to verify the ciphertext that is written to disk +by the inline encryption hardware. + +However, the unwrapped key will only be known to software for testing if the +"import" functionality is used. Proper testing is not possible in the +"generate" case where the hardware generates the key itself. The correct +operation of the "generate" mode thus relies on the security and correctness of +the hardware RNG and its use to generate the key, as well as the testing of the +"import" mode as that should cover all parts other than the key generation. + +For an example of a test that verifies the ciphertext written to disk in the +"import" mode, see the fscrypt hardware-wrapped key tests in xfstests, or +`Android's vts_kernel_encryption_test +<https://android.googlesource.com/platform/test/vts-testcase/kernel/+/refs/heads/main/encryption/>`_.
block/blk-crypto-fallback.c +4 -3
@@ -85,11 +85,11 @@ static struct bio_set crypto_bio_split;/* * This is the key we set when evicting a keyslot. This *should* be the all 0's * key, but AES-XTS rejects that key, so we use some random bytes instead. */ -static u8 blank_key[BLK_CRYPTO_MAX_KEY_SIZE ]; +static u8 blank_key[BLK_CRYPTO_MAX_RAW_KEY_SIZE ];static void blk_crypto_fallback_evict_keyslot (unsigned int slot) {struct blk_crypto_fallback_keyslot *slotp = &blk_crypto_keyslots[slot];enum blk_crypto_mode_num crypto_mode = slotp->crypto_mode;
@@ -117,11 +117,11 @@ blk_crypto_fallback_keyslot_program(struct blk_crypto_profile *profile,if (crypto_mode != slotp->crypto_mode && slotp->crypto_mode !=BLK_ENCRYPTION_MODE_INVALID )blk_crypto_fallback_evict_keyslot (slot); slotp->crypto_mode = crypto_mode; - err =crypto_skcipher_setkey (slotp->tfms[crypto_mode], key->raw, + err =crypto_skcipher_setkey (slotp->tfms[crypto_mode], key->bytes, key->size);if (err) {blk_crypto_fallback_evict_keyslot (slot);return err; }
@@ -537,11 +537,11 @@ static int blk_crypto_fallback_init(void)int err;if (blk_crypto_fallback_inited)return 0 ; -get_random_bytes (blank_key,BLK_CRYPTO_MAX_KEY_SIZE ); +get_random_bytes (blank_key,sizeof (blank_key)); err =bioset_init (&crypto_bio_split,64 ,0 ,0 );if (err) goto out;
@@ -559,10 +559,11 @@ static int blk_crypto_fallback_init(void) goto fail_free_profile; err = -ENOMEM ; blk_crypto_fallback_profile->ll_ops = blk_crypto_fallback_ll_ops; blk_crypto_fallback_profile->max_dun_bytes_supported =BLK_CRYPTO_MAX_IV_SIZE ; + blk_crypto_fallback_profile->key_types_supported =BLK_CRYPTO_KEY_TYPE_RAW ;/* All blk-crypto modes have a crypto API fallback. */ for (i =0 ; i <BLK_ENCRYPTION_MODE_MAX ; i++) blk_crypto_fallback_profile->modes_supported[i] =0xFFFFFFFF ; blk_crypto_fallback_profile->modes_supported[BLK_ENCRYPTION_MODE_INVALID ] =0 ;
block/blk-crypto-internal.h +1 -0
@@ -12,10 +12,11 @@/* Represents a crypto mode supported by blk-crypto */ struct blk_crypto_mode {const char *name;/* name of this mode, shown in sysfs */ const char *cipher_str;/* crypto API name (for fallback case) */ unsigned int keysize;/* key size in bytes */ +unsigned int security_strength;/* security strength in bytes */ unsigned int ivsize;/* iv size in bytes */ };extern const struct blk_crypto_mode blk_crypto_modes[];
block/blk-crypto-profile.c +46 -0
97 lines not on this page · raw message
block/blk-crypto.c +47 -14
165 lines not on this page · raw message
drivers/md/dm-table.c +1 -0
@@ -1248,10 +1248,11 @@ static int dm_table_construct_crypto_profile(struct dm_table *t)blk_crypto_profile_init (profile,0 ); profile->ll_ops.keyslot_evict = dm_keyslot_evict; profile->max_dun_bytes_supported =UINT_MAX ;memset (profile->modes_supported,0xFF ,sizeof (profile->modes_supported)); + profile->key_types_supported = ~0 ;for (i =0 ; i < t->num_targets; i++) {struct dm_target *ti =dm_table_get_target (t, i);if (!dm_target_passes_crypto (ti->type)) {
drivers/mmc/host/cqhci-crypto.c +5 -3
@@ -82,15 +82,15 @@ static int cqhci_crypto_keyslot_program(struct blk_crypto_profile *profile, cfg.crypto_cap_idx = cap_idx; cfg.config_enable =CQHCI_CRYPTO_CONFIGURATION_ENABLE ;if (ccap_array[cap_idx].algorithm_id ==CQHCI_CRYPTO_ALG_AES_XTS ) {/* In XTS mode, the blk_crypto_key's size is already doubled */ -memcpy (cfg.crypto_key, key->raw, key->size/2 ); +memcpy (cfg.crypto_key, key->bytes, key->size/2 );memcpy (cfg.crypto_key +CQHCI_CRYPTO_KEY_MAX_SIZE /2 , - key->raw + key->size/2 , key->size/2 ); + key->bytes + key->size/2 , key->size/2 ); }else { -memcpy (cfg.crypto_key, key->raw, key->size); +memcpy (cfg.crypto_key, key->bytes, key->size); }cqhci_crypto_program_key (cq_host, &cfg, slot);memzero_explicit (&cfg,sizeof (cfg));
@@ -202,10 +202,12 @@ int cqhci_crypto_init(struct cqhci_host *cq_host) profile->dev = dev;/* Unfortunately, CQHCI crypto only supports 32 DUN bits. */ profile->max_dun_bytes_supported =4 ; + profile->key_types_supported =BLK_CRYPTO_KEY_TYPE_RAW ; +/* * Cache all the crypto capabilities and advertise the supported crypto * modes and data unit sizes to the block layer. */ for (cap_idx = 0; cap_idx < cq_host->crypto_capabilities.num_crypto_cap;
drivers/mmc/host/sdhci-msm.c +2 -1
@@ -1893,10 +1893,11 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,if (err)return err; profile->ll_ops = sdhci_msm_crypto_ops; profile->max_dun_bytes_supported =4 ; + profile->key_types_supported =BLK_CRYPTO_KEY_TYPE_RAW ; profile->dev = dev;/* * Currently this driver only supports AES-256-XTS. All known versions * of ICE support it, but to be safe make sure it is really declared in
@@ -1966,11 +1967,11 @@ static int sdhci_msm_ice_keyslot_program(struct blk_crypto_profile *profile,return -EOPNOTSUPP ;return qcom_ice_program_key (msm_host->ice,QCOM_ICE_CRYPTO_ALG_AES_XTS ,QCOM_ICE_CRYPTO_KEY_SIZE_256 , - key->raw, + key->bytes, key->crypto_cfg.data_unit_size /512 , slot); } static int sdhci_msm_ice_keyslot_evict(struct blk_crypto_profile *profile,
drivers/ufs/core/ufshcd-crypto.c +4 -3
@@ -70,15 +70,15 @@ static int ufshcd_crypto_keyslot_program(struct blk_crypto_profile *profile, cfg.crypto_cap_idx = cap_idx; cfg.config_enable =UFS_CRYPTO_CONFIGURATION_ENABLE ;if (ccap_array[cap_idx].algorithm_id ==UFS_CRYPTO_ALG_AES_XTS ) {/* In XTS mode, the blk_crypto_key's size is already doubled */ -memcpy (cfg.crypto_key, key->raw, key->size/2 ); +memcpy (cfg.crypto_key, key->bytes, key->size/2 );memcpy (cfg.crypto_key +UFS_CRYPTO_KEY_MAX_SIZE /2 , - key->raw + key->size/2 , key->size/2 ); + key->bytes + key->size/2 , key->size/2 ); }else { -memcpy (cfg.crypto_key, key->raw, key->size); +memcpy (cfg.crypto_key, key->bytes, key->size); }ufshcd_program_key (hba, &cfg, slot);memzero_explicit (&cfg,sizeof (cfg));
@@ -183,10 +183,11 @@ int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba) goto out; hba->crypto_profile.ll_ops = ufshcd_crypto_ops;/* UFS only supports 8 bytes for any DUN */ hba->crypto_profile.max_dun_bytes_supported =8 ; + hba->crypto_profile.key_types_supported =BLK_CRYPTO_KEY_TYPE_RAW ; hba->crypto_profile.dev = hba->dev;/* * Cache all the UFS crypto capabilities and advertise the supported * crypto modes and data unit sizes to the block layer.
drivers/ufs/host/ufs-exynos.c +2 -1
@@ -1318,10 +1318,11 @@ static void exynos_ufs_fmp_init(struct ufs_hba *hba, struct exynos_ufs *ufs)dev_err (hba->dev,"Failed to initialize crypto profile: %d\n" , err);return ; } profile->max_dun_bytes_supported =AES_BLOCK_SIZE ; + profile->key_types_supported =BLK_CRYPTO_KEY_TYPE_RAW ; profile->dev = hba->dev; profile->modes_supported[BLK_ENCRYPTION_MODE_AES_256_XTS ] =DATA_UNIT_SIZE ;/* Advertise crypto support to ufshcd-core. */
@@ -1364,11 +1365,11 @@ static inline __be64 fmp_key_word(const u8 *key, int j)static int exynos_ufs_fmp_fill_prdt (struct ufs_hba *hba,const struct bio_crypt_ctx *crypt_ctx,void *prdt,unsigned int num_segments) {struct fmp_sg_entry *fmp_prdt = prdt; -const u8 *enckey = crypt_ctx->bc_key->raw; +const u8 *enckey = crypt_ctx->bc_key->bytes;const u8 *twkey = enckey +AES_KEYSIZE_256 ;u64 dun_lo = crypt_ctx->bc_dun[0 ];u64 dun_hi = crypt_ctx->bc_dun[1 ];unsigned int i;
drivers/ufs/host/ufs-qcom.c +2 -1
@@ -145,10 +145,11 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host)if (err)return err; profile->ll_ops = ufs_qcom_crypto_ops; profile->max_dun_bytes_supported =8 ; + profile->key_types_supported =BLK_CRYPTO_KEY_TYPE_RAW ; profile->dev = dev;/* * Currently this driver only supports AES-256-XTS. All known versions * of ICE support it, but to be safe make sure it is really declared in
@@ -200,11 +201,11 @@ static int ufs_qcom_ice_keyslot_program(struct blk_crypto_profile *profile,ufshcd_hold (hba); err =qcom_ice_program_key (host->ice,QCOM_ICE_CRYPTO_ALG_AES_XTS ,QCOM_ICE_CRYPTO_KEY_SIZE_256 , - key->raw, + key->bytes, key->crypto_cfg.data_unit_size /512 , slot);ufshcd_release (hba);return err; }
fs/crypto/inline_crypt.c +3 -1
@@ -128,10 +128,11 @@ int fscrypt_select_encryption_impl(struct fscrypt_inode_info *ci)* crypto configuration that the file would use. */ crypto_cfg.crypto_mode = ci->ci_mode->blk_crypto_mode; crypto_cfg.data_unit_size =1U << ci->ci_data_unit_bits; crypto_cfg.dun_bytes =fscrypt_get_dun_bytes (ci); + crypto_cfg.key_type =BLK_CRYPTO_KEY_TYPE_RAW ; devs =fscrypt_get_devices (sb, &num_devs);if (IS_ERR (devs))return PTR_ERR (devs);
@@ -164,11 +165,12 @@ int fscrypt_prepare_inline_crypt_key(struct fscrypt_prepared_key *prep_key, blk_key =kmalloc (sizeof (*blk_key),GFP_KERNEL );if (!blk_key)return -ENOMEM ; - err =blk_crypto_init_key (blk_key, raw_key, crypto_mode, + err =blk_crypto_init_key (blk_key, raw_key, ci->ci_mode->keysize, +BLK_CRYPTO_KEY_TYPE_RAW , crypto_mode,fscrypt_get_dun_bytes (ci),1U << ci->ci_data_unit_bits);if (err) {fscrypt_err (inode,"error %d initializing blk-crypto key" , err); goto fail;
include/linux/blk-crypto-profile.h +20 -0
@@ -55,10 +55,24 @@ struct blk_crypto_ll_ops {* Must return 0 on success, or -errno on failure. */ int (*keyslot_evict)(struct blk_crypto_profile *profile,const struct blk_crypto_key *key,unsigned int slot); + +/** +* @derive_sw_secret: Derive the software secret from a hardware-wrapped +* key in ephemerally-wrapped form. +* +* This only needs to be implemented if BLK_CRYPTO_KEY_TYPE_HW_WRAPPED +* is supported. +* +* Must return 0 on success, -EBADMSG if the key is invalid, or another +* -errno code on other errors. +*/ +int (*derive_sw_secret)(struct blk_crypto_profile *profile, +const u8 *eph_key,size_t eph_key_size, +u8 sw_secret[BLK_CRYPTO_SW_SECRET_SIZE ]); };/** * struct blk_crypto_profile - inline encryption profile for a device *
@@ -82,10 +96,16 @@ struct blk_crypto_profile {* specifying the data unit number (DUN). Specifically, the range of * supported DUNs is 0 through (1 << (8 * max_dun_bytes_supported)) - 1. */ unsigned int max_dun_bytes_supported; +/** +* @key_types_supported: A bitmask of the supported key types: +* BLK_CRYPTO_KEY_TYPE_RAW and/or BLK_CRYPTO_KEY_TYPE_HW_WRAPPED. +*/ +unsigned int key_types_supported; +/** * @modes_supported: Array of bitmasks that specifies whether each * combination of crypto mode and data unit size is supported. * Specifically, the i'th bit of modes_supported[crypto_mode] is set if * crypto_mode can be used with a data unit size of (1 << i). Note that
include/linux/blk-crypto.h +65 -7
139 lines not on this page · raw message
Signature · 1 line
2.48.1
Eric Biggers
maintainerPATCH v11 2/7 blk-crypto: show supported key types in sysfs
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Add sysfs files that indicate which type(s) of keys are supported by the inline encryption hardware associated with a particular request queue:
/sys/block/$disk/queue/crypto/hw_wrapped_keys /sys/block/$disk/queue/crypto/raw_keys
Userspace can use the presence or absence of these files to decide what encyption settings to use.
Don't use a single key_type file, as devices might support both key types at the same time.
--- Documentation/ABI/stable/sysfs-block | 20 ++++++++++++++++ block/blk-crypto-sysfs.c | 35 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
Documentation/ABI/stable/sysfs-block +20 -0
@@ -227,10 +227,21 @@ Description: subdirectory contains files which describe the inline encryption capabilities of the device. For more information about inline encryption, refer to Documentation/block/inline-encryption.rst. +What: /sys/block/<disk>/queue/crypto/hw_wrapped_keys +Date: February 2025 +Contact: [email protected] +Description: + [RO] The presence of this file indicates that the device + supports hardware-wrapped inline encryption keys, i.e. key blobs + that can only be unwrapped and used by dedicated hardware. For + more information about hardware-wrapped inline encryption keys, + see Documentation/block/inline-encryption.rst. + + What: /sys/block/<disk>/queue/crypto/max_dun_bits Date: February 2022 Contact: [email protected] Description: [RO] This file shows the maximum length, in bits, of data unit
@@ -265,10 +276,19 @@ Contact: [email protected] Description: [RO] This file shows the number of keyslots the device has for use with inline encryption. +What: /sys/block/<disk>/queue/crypto/raw_keys +Date: February 2025 +Contact: [email protected] +Description: + [RO] The presence of this file indicates that the device + supports raw inline encryption keys, i.e. keys that are managed + in raw, plaintext form in software. + + What: /sys/block/<disk>/queue/dax Date: June 2016 Contact: [email protected] Description: [RO] This file indicates whether the device supports Direct
block/blk-crypto-sysfs.c +35 -0
@@ -29,10 +29,17 @@ static struct blk_crypto_profile *kobj_to_crypto_profile(struct kobject *kobj)static struct blk_crypto_attr *attr_to_crypto_attr (struct attribute *attr) { return container_of(attr, struct blk_crypto_attr, attr); } +static ssize_t hw_wrapped_keys_show (struct blk_crypto_profile *profile, +struct blk_crypto_attr *attr,char *page) +{ +/* Always show supported, since the file doesn't exist otherwise. */ +return sysfs_emit (page,"supported\n" ); +} +static ssize_t max_dun_bits_show (struct blk_crypto_profile *profile,struct blk_crypto_attr *attr,char *page) {return sysfs_emit (page,"%u\n" ,8 * profile->max_dun_bytes_supported); }
@@ -41,24 +48,52 @@ static ssize_t num_keyslots_show(struct blk_crypto_profile *profile, struct blk_crypto_attr *attr, char *page) { return sysfs_emit(page, "%u\n", profile->num_slots); } +static ssize_t raw_keys_show (struct blk_crypto_profile *profile, +struct blk_crypto_attr *attr,char *page) +{ +/* Always show supported, since the file doesn't exist otherwise. */ +return sysfs_emit (page,"supported\n" ); +} +#define BLK_CRYPTO_RO_ATTR (_name) \ static struct blk_crypto_attr _name##_attr = __ATTR_RO(_name) +BLK_CRYPTO_RO_ATTR (hw_wrapped_keys);BLK_CRYPTO_RO_ATTR (max_dun_bits);BLK_CRYPTO_RO_ATTR (num_keyslots); +BLK_CRYPTO_RO_ATTR (raw_keys); + +static umode_t blk_crypto_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ +struct blk_crypto_profile *profile =kobj_to_crypto_profile (kobj); +struct blk_crypto_attr *a =attr_to_crypto_attr (attr); + +if (a == &hw_wrapped_keys_attr && + !(profile->key_types_supported &BLK_CRYPTO_KEY_TYPE_HW_WRAPPED )) +return 0 ; +if (a == &raw_keys_attr && + !(profile->key_types_supported &BLK_CRYPTO_KEY_TYPE_RAW )) +return 0 ; + +return 0444 ; +}static struct attribute *blk_crypto_attrs[] = { + &hw_wrapped_keys_attr.attr, &max_dun_bits_attr.attr, &num_keyslots_attr.attr, + &raw_keys_attr.attr,NULL , };static const struct attribute_group blk_crypto_attr_group = { .attrs = blk_crypto_attrs, + .is_visible = blk_crypto_is_visible, };/* * The encryption mode attributes. To avoid hard-coding the list of encryption * modes, these are initialized at boot time by blk_crypto_sysfs_init().
Signature · 1 line
2.48.1
Eric Biggers
maintainerPATCH v11 3/7 blk-crypto: add ioctls to create and prepare hardware-wrapped keys
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Until this point, the kernel can use hardware-wrapped keys to do encryption if userspace provides one -- specifically a key in ephemerally-wrapped form. However, no generic way has been provided for userspace to get such a key in the first place.
Getting such a key is a two-step process. First, the key needs to be imported from a raw key or generated by the hardware, producing a key in long-term wrapped form. This happens once in the whole lifetime of the key. Second, the long-term wrapped key needs to be converted into ephemerally-wrapped form. This happens each time the key is "unlocked".
In Android, these operations are supported in a generic way through KeyMint, a userspace abstraction layer. However, that method is Android-specific and can't be used on other Linux systems, may rely on proprietary libraries, and also misleads people into supporting KeyMint features like rollback resistance that make sense for other KeyMint keys but don't make sense for hardware-wrapped inline encryption keys.
Therefore, this patch provides a generic kernel interface for these operations by introducing new block device ioctls:
- BLKCRYPTOIMPORTKEY: convert a raw key to long-term wrapped form.
- BLKCRYPTOGENERATEKEY: have the hardware generate a new key, then return it in long-term wrapped form.
- BLKCRYPTOPREPAREKEY: convert a key from long-term wrapped form to ephemerally-wrapped form.
These ioctls are implemented using new operations in blk_crypto_ll_ops.
--- Documentation/block/inline-encryption.rst | 36 +++++ .../userspace-api/ioctl/ioctl-number.rst | 2 + block/blk-crypto-internal.h | 9 ++ block/blk-crypto-profile.c | 55 +++++++ block/blk-crypto.c | 143 ++++++++++++++++++ block/ioctl.c | 5 + include/linux/blk-crypto-profile.h | 53 +++++++ include/linux/blk-crypto.h | 1 + include/uapi/linux/blk-crypto.h | 44 ++++++ include/uapi/linux/fs.h | 6 +- 10 files changed, 350 insertions(+), 4 deletions(-) create mode 100644 include/uapi/linux/blk-crypto.h
Documentation/block/inline-encryption.rst +36 -0
@@ -490,10 +490,46 @@ when hardware support is available. This works in the following way: keys being passed to these methods. blk-crypto-fallback doesn't support hardware-wrapped keys. Therefore, hardware-wrapped keys can only be used with actual inline encryption hardware. +All the above deals with hardware-wrapped keys in ephemerally-wrapped form only. +To get such keys in the first place, new block device ioctls have been added to +provide a generic interface to creating and preparing such keys: + +- ``BLKCRYPTOIMPORTKEY`` converts a raw key to long-term wrapped form. It takes + in a pointer to a ``struct blk_crypto_import_key_arg``. The caller must set + ``raw_key_ptr`` and ``raw_key_size`` to the pointer and size (in bytes) of the + raw key to import. On success, ``BLKCRYPTOIMPORTKEY`` returns 0 and writes + the resulting long-term wrapped key blob to the buffer pointed to by + ``lt_key_ptr``, which is of maximum size ``lt_key_size``. It also updates + ``lt_key_size`` to be the actual size of the key. On failure, it returns -1 + and sets errno. An errno of ``EOPNOTSUPP`` indicates that the block device + does not support hardware-wrapped keys. An errno of ``EOVERFLOW`` indicates + that the output buffer did not have enough space for the key blob. + +- ``BLKCRYPTOGENERATEKEY`` is like ``BLKCRYPTOIMPORTKEY``, but it has the + hardware generate the key instead of importing one. It takes in a pointer to + a ``struct blk_crypto_generate_key_arg``. + +- ``BLKCRYPTOPREPAREKEY`` converts a key from long-term wrapped form to + ephemerally-wrapped form. It takes in a pointer to a ``struct + blk_crypto_prepare_key_arg``. The caller must set ``lt_key_ptr`` and + ``lt_key_size`` to the pointer and size (in bytes) of the long-term wrapped + key blob to convert. On success, ``BLKCRYPTOPREPAREKEY`` returns 0 and writes + the resulting ephemerally-wrapped key blob to the buffer pointed to by + ``eph_key_ptr``, which is of maximum size ``eph_key_size``. It also updates + ``eph_key_size`` to be the actual size of the key. On failure, it returns -1 + and sets errno. Errno values of ``EOPNOTSUPP`` and ``EOVERFLOW`` mean the + same as they do for ``BLKCRYPTOIMPORTKEY``. An errno of ``EBADMSG`` indicates + that the long-term wrapped key is invalid. + +Userspace needs to use either ``BLKCRYPTOIMPORTKEY`` or ``BLKCRYPTOGENERATEKEY`` +once to create a key, and then ``BLKCRYPTOPREPAREKEY`` each time the key is +unlocked and added to the kernel. Note that these ioctls have no relevance for +raw keys; they are only for hardware-wrapped keys. + Testability ----------- Both the hardware KDF and the inline encryption itself are well-defined algorithms that don't depend on any secrets other than the unwrapped key.
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -83,10 +83,12 @@ Code Seq# Include File Comments 0x10 00-0F drivers/char/s390/vmcp.h 0x10 10-1F arch/s390/include/uapi/sclp_ctl.h 0x10 20-2F arch/s390/include/uapi/asm/hypfs.h 0x12 all linux/fs.h BLK* ioctls linux/blkpg.h + linux/blkzoned.h + linux/blk-crypto.h 0x15 all linux/fs.h FS_IOC_* ioctls 0x1b all InfiniBand Subsystem <http://infiniband.sourceforge.net/> 0x20 all drivers/cdrom/cm206.h 0x22 all scsi/sg.h
block/blk-crypto-internal.h +9 -0
@@ -81,10 +81,13 @@ int __blk_crypto_evict_key(struct blk_crypto_profile *profile, const struct blk_crypto_key *key);bool __blk_crypto_cfg_supported (struct blk_crypto_profile *profile,const struct blk_crypto_config *cfg); +int blk_crypto_ioctl (struct block_device *bdev,unsigned int cmd, +void __user *argp); +#else /* CONFIG_BLK_INLINE_ENCRYPTION */ static inline int blk_crypto_sysfs_register (struct gendisk *disk) {return 0 ;
@@ -128,10 +131,16 @@ static inline bool blk_crypto_rq_is_encrypted(struct request *rq)static inline bool blk_crypto_rq_has_keyslot (struct request *rq) {return false; } +static inline int blk_crypto_ioctl (struct block_device *bdev,unsigned int cmd, +void __user *argp) +{ +return -ENOTTY ; +} +#endif /* CONFIG_BLK_INLINE_ENCRYPTION */ void __bio_crypt_advance (struct bio *bio,unsigned int bytes);static inline void bio_crypt_advance (struct bio *bio,unsigned int bytes) {
block/blk-crypto-profile.c +55 -0
65 lines not on this page · raw message
block/blk-crypto.c +143 -0
148 lines not on this page · raw message
block/ioctl.c +5 -0
@@ -13,10 +13,11 @@#include <linux/uaccess.h> #include <linux/pagemap.h> #include <linux/io_uring/cmd.h> #include <uapi/linux/blkdev.h> #include "blk.h" +#include "blk-crypto-internal.h" static int blkpg_do_ioctl (struct block_device *bdev,struct blkpg_partition __user *upart,int op) {struct gendisk *disk = bdev->bd_disk;
@@ -618,10 +619,14 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode, mode | BLK_OPEN_STRICT_SCAN);case BLKTRACESTART :case BLKTRACESTOP :case BLKTRACETEARDOWN :return blk_trace_ioctl (bdev, cmd, argp); +case BLKCRYPTOIMPORTKEY : +case BLKCRYPTOGENERATEKEY : +case BLKCRYPTOPREPAREKEY : +return blk_crypto_ioctl (bdev, cmd, argp);case IOC_PR_REGISTER :return blkdev_pr_register (bdev, mode, argp);case IOC_PR_RESERVE :return blkdev_pr_reserve (bdev, mode, argp);case IOC_PR_RELEASE :
include/linux/blk-crypto-profile.h +53 -0
73 lines not on this page · raw message
include/linux/blk-crypto.h +1 -0
@@ -6,10 +6,11 @@#ifndef __LINUX_BLK_CRYPTO_H#define __LINUX_BLK_CRYPTO_H#include <linux/minmax.h> #include <linux/types.h> +#include <uapi/linux/blk-crypto.h> enum blk_crypto_mode_num {BLK_ENCRYPTION_MODE_INVALID ,BLK_ENCRYPTION_MODE_AES_256_XTS , BLK_ENCRYPTION_MODE_AES_128_CBC_ESSIV,
include/uapi/linux/blk-crypto.h new file +44 -0
44 lines not on this page · raw message
include/uapi/linux/fs.h +2 -4
@@ -210,14 +210,12 @@ struct fsxattr {#define BLKDISCARDZEROES _IO(0x12,124)#define BLKSECDISCARD _IO(0x12,125)#define BLKROTATIONAL _IO(0x12,126)#define BLKZEROOUT _IO(0x12,127)#define BLKGETDISKSEQ _IOR(0x12,128,__u64) -/* -* A jump here: 130-136 are reserved for zoned block devices -* (see uapi/linux/blkzoned.h) -*/ +/* 130-136 are used by zoned block device ioctls (uapi/linux/blkzoned.h) */ +/* 137-141 are used by blk-crypto ioctls (uapi/linux/blk-crypto.h) */ #define BMAP_IOCTL 1/* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1)/* bmap access */ #define FIGETBSZ _IO(0x00,2)/* get the block size used for bmap */ #define FIFREEZE _IOWR('X', 119, int)/* Freeze */
Signature · 1 line
2.48.1
Eric Biggers
maintainerPATCH v11 4/7 fscrypt: add support for hardware-wrapped keys
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Add support for hardware-wrapped keys to fscrypt. Such keys are protected from certain attacks, such as cold boot attacks. For more information, see the "Hardware-wrapped keys" section of Documentation/block/inline-encryption.rst.
To support hardware-wrapped keys in fscrypt, we allow the fscrypt master keys to be hardware-wrapped. File contents encryption is done by passing the wrapped key to the inline encryption hardware via blk-crypto. Other fscrypt operations such as filenames encryption continue to be done by the kernel, using the "software secret" which the hardware derives. For more information, see the documentation which this patch adds to Documentation/filesystems/fscrypt.rst.
Note that this feature doesn't require any filesystem-specific changes. However it does depend on inline encryption support, and thus currently it is only applicable to ext4 and f2fs.
The version of this feature introduced by this patch is mostly equivalent to the version that has existed downstream in the Android kernels since 2020. However, a couple fixes are included. First, the flags field in struct fscrypt_add_key_arg is now placed in the proper location. Second, an option is now provided to derive key identifiers for HW-wrapped keys using a distinct HKDF context byte; this fixes a bug where a raw key could have the same identifier as a HW-wrapped key.
This patch has been heavily rewritten from the original version by Gaurav Kashyap <[email protected]> and
Barani Muthukumaran <[email protected]>.
--- Documentation/filesystems/fscrypt.rst | 200 ++++++++++++++++++++------ fs/crypto/fscrypt_private.h | 75 ++++++++-- fs/crypto/hkdf.c | 4 +- fs/crypto/inline_crypt.c | 44 +++++- fs/crypto/keyring.c | 157 ++++++++++++++------ fs/crypto/keysetup.c | 63 ++++++-- fs/crypto/keysetup_v1.c | 4 +- include/uapi/linux/fscrypt.h | 7 +- 8 files changed, 443 insertions(+), 111 deletions(-)
Documentation/filesystems/fscrypt.rst +159 -41
@@ -68,11 +68,11 @@ an authorized user later accessing the filesystem. Online attacks -------------- fscrypt (and storage encryption in general) can only provide limited -protection, if any at all, against online attacks. In detail: +protection against online attacks. In detail: Side-channel attacks ~~~~~~~~~~~~~~~~~~~~ fscrypt is only resistant to side-channel attacks, such as timing or
@@ -97,20 +97,27 @@ system itself, is *not* protected by the mathematical properties of encryption but rather only by the correctness of the kernel. Therefore, any encryption-specific access control checks would merely be enforced by kernel *code* and therefore would be largely redundant with the wide variety of access control mechanisms already available.) -Kernel memory compromise -~~~~~~~~~~~~~~~~~~~~~~~~ +Read-only kernel memory compromise +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Unless `hardware-wrapped keys`_ are used, an attacker who gains the +ability to read from arbitrary kernel memory, e.g. by mounting a +physical attack or by exploiting a kernel security vulnerability, can +compromise all fscrypt keys that are currently in-use. This also +extends to cold boot attacks; if the system is suddenly powered off, +keys the system was using may remain in memory for a short time. -An attacker who compromises the system enough to read from arbitrary -memory, e.g. by mounting a physical attack or by exploiting a kernel -security vulnerability, can compromise all encryption keys that are -currently in use. +However, if hardware-wrapped keys are used, then the fscrypt master +keys and file contents encryption keys (but not other types of fscrypt +subkeys such as filenames encryption keys) are protected from +compromises of arbitrary kernel memory. -However, fscrypt allows encryption keys to be removed from the kernel, -which may protect them from later compromise. +In addition, fscrypt allows encryption keys to be removed from the +kernel, which may protect them from later compromise. In more detail, the FS_IOC_REMOVE_ENCRYPTION_KEY ioctl (or the FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS ioctl) can wipe a master encryption key from kernel memory. If it does so, it will also try to evict all cached inodes which had been "unlocked" using the key,
@@ -143,10 +150,28 @@ However, these ioctls have some limitations: - Secret keys might still exist in CPU registers, in crypto accelerator hardware (if used by the crypto API to implement any of the algorithms), or in other places not explicitly considered here. +Full system compromise +~~~~~~~~~~~~~~~~~~~~~~ + +An attacker who gains "root" access and/or the ability to execute +arbitrary kernel code can freely exfiltrate data that is protected by +any in-use fscrypt keys. Thus, usually fscrypt provides no meaningful +protection in this scenario. (Data that is protected by a key that is +absent throughout the entire attack remains protected, modulo the +limitations of key removal mentioned above in the case where the key +was removed prior to the attack.) + +However, if `hardware-wrapped keys`_ are used, such attackers will be +unable to exfiltrate the master keys or file contents keys in a form +that will be usable after the system is powered off. This may be +useful if the attacker is significantly time-limited and/or +bandwidth-limited, so they can only exfiltrate some data and need to +rely on a later offline attack to exfiltrate the rest of it. + Limitations of v1 policies ~~~~~~~~~~~~~~~~~~~~~~~~~~ v1 encryption policies have some weaknesses with respect to online attacks:
@@ -169,10 +194,14 @@ this reason among others, it is recommended to use v2 encryption policies on all new encrypted directories. Key hierarchy ============= +Note: this section assumes the use of raw keys rather than +hardware-wrapped keys. The use of hardware-wrapped keys modifies the +key hierarchy slightly. For details, see `Hardware-wrapped keys`_. + Master Keys ----------- Each encrypted directory tree is protected by a *master key*. Master keys can be up to 64 bytes long, and must be at least as long as the
@@ -834,11 +863,14 @@ a pointer to struct fscrypt_add_key_arg, defined as follows:: struct fscrypt_add_key_arg { struct fscrypt_key_specifier key_spec; __u32 raw_size; __u32 key_id; - __u32 __reserved[8]; + #define FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_V0 0x00000001 + #define FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_V1 0x00000002 + __u32 flags; + __u32 __reserved[7]; __u8 raw[]; }; #define FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR 1 #define FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER 2
@@ -853,11 +885,11 @@ a pointer to struct fscrypt_add_key_arg, defined as follows:: } u; }; struct fscrypt_provisioning_key_payload { __u32 type; - __u32 __reserved; + __u32 flags; __u8 raw[]; }; struct fscrypt_add_key_arg must be zeroed, then initialized as follows:
@@ -881,28 +913,41 @@ as follows: - ``raw_size`` must be the size of the ``raw`` key provided, in bytes. Alternatively, if ``key_id`` is nonzero, this field must be 0, since in that case the size is implied by the specified Linux keyring key. -- ``key_id`` is 0 if the raw key is given directly in the ``raw`` - field. Otherwise ``key_id`` is the ID of a Linux keyring key of - type "fscrypt-provisioning" whose payload is - struct fscrypt_provisioning_key_payload whose ``raw`` field contains - the raw key and whose ``type`` field matches ``key_spec.type``. - Since ``raw`` is variable-length, the total size of this key's - payload must be ``sizeof(struct fscrypt_provisioning_key_payload)`` - plus the raw key size. The process must have Search permission on - this key. - - Most users should leave this 0 and specify the raw key directly. - The support for specifying a Linux keyring key is intended mainly to +- ``key_id`` is 0 if the key is given directly in the ``raw`` field. + Otherwise ``key_id`` is the ID of a Linux keyring key of type + "fscrypt-provisioning" whose payload is struct + fscrypt_provisioning_key_payload whose ``raw`` field contains the + key, whose ``type`` field matches ``key_spec.type``, and whose + ``flags`` field matches ``flags``. Since ``raw`` is + variable-length, the total size of this key's payload must be + ``sizeof(struct fscrypt_provisioning_key_payload)`` plus the number + of key bytes. The process must have Search permission on this key. + + Most users should leave this 0 and specify the key directly. The + support for specifying a Linux keyring key is intended mainly to allow re-adding keys after a filesystem is unmounted and re-mounted, - without having to store the raw keys in userspace memory. + without having to store the keys in userspace memory. + +- ``flags`` contains optional flags from ``<linux/fscrypt.h>``: + + - FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_V0: Similar to + FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_V1 but selects an old on-disk + format. Prefer to use V1 on new directories. This flag can only be + used by privileged users. (V1 does not have that restriction.) + + - FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_V1: This denotes that the key is a + hardware-wrapped key. See `Hardware-wrapped keys`_. This flag + can't be used if FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR is used. - ``raw`` is a variable-length field which must contain the actual key, ``raw_size`` bytes long. Alternatively, if ``key_id`` is - nonzero, then this field is unused. + nonzero, then this field is unused. Note that despite being named + ``raw``, if one of the FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_* flags is + specified then it will contain a wrapped key, not a raw key. For v2 policy keys, the kernel keeps track of which user (identified by effective user ID) added the key, and only allows the key to be removed by that user --- or by "root", if they use `FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS`_.
@@ -910,34 +955,38 @@ removed by that user --- or by "root", if they use However, if another user has added the key, it may be desirable to prevent that other user from unexpectedly removing it. Therefore, FS_IOC_ADD_ENCRYPTION_KEY may also be used to add a v2 policy key *again*, even if it's already added by other user(s). In this case, FS_IOC_ADD_ENCRYPTION_KEY will just install a claim to the key for the -current user, rather than actually add the key again (but the raw key -must still be provided, as a proof of knowledge). +current user, rather than actually add the key again (but the key must +still be provided, as a proof of knowledge). FS_IOC_ADD_ENCRYPTION_KEY returns 0 if either the key or a claim to the key was either added or already exists. FS_IOC_ADD_ENCRYPTION_KEY can fail with the following errors: -- ``EACCES``: FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR was specified, but the - caller does not have the CAP_SYS_ADMIN capability in the initial - user namespace; or the raw key was specified by Linux key ID but the - process lacks Search permission on the key. +- ``EACCES``: FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR or + FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_V0 was specified, but the caller + does not have the CAP_SYS_ADMIN capability in the initial user + namespace; or the key was specified by Linux key ID but the process + lacks Search permission on the key. +- ``EBADMSG``: invalid hardware-wrapped key - ``EDQUOT``: the key quota for this user would be exceeded by adding the key - ``EINVAL``: invalid key size or key specifier type, or reserved bits were set -- ``EKEYREJECTED``: the raw key was specified by Linux key ID, but the - key has the wrong type -- ``ENOKEY``: the raw key was specified by Linux key ID, but no key - exists with that ID +- ``EKEYREJECTED``: the key was specified by Linux key ID, but the key + has the wrong type +- ``ENOKEY``: the key was specified by Linux key ID, but no key exists + with that ID - ``ENOTTY``: this type of filesystem does not implement encryption - ``EOPNOTSUPP``: the kernel was not configured with encryption support for this filesystem, or the filesystem superblock has not - had encryption enabled on it + had encryption enabled on it; or a hardware wrapped key was specified + but the filesystem does not support inline encryption or the hardware + does not support hardware-wrapped keys Legacy method ~~~~~~~~~~~~~ For v1 encryption policies, a master encryption key can also be
@@ -996,13 +1045,12 @@ These two ioctls differ only in cases where v2 policy keys are added or removed by non-root users. These ioctls don't work on keys that were added via the legacy process-subscribed keyrings mechanism. -Before using these ioctls, read the `Kernel memory compromise`_ -section for a discussion of the security goals and limitations of -these ioctls. +Before using these ioctls, read the `Online attacks`_ section for a +discussion of the security goals and limitations of these ioctls. FS_IOC_REMOVE_ENCRYPTION_KEY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The FS_IOC_REMOVE_ENCRYPTION_KEY ioctl removes a claim to a master
@@ -1318,19 +1366,89 @@ encryption when possible; it doesn't force its use. fscrypt will still fall back to using the kernel crypto API on files where the inline encryption hardware doesn't have the needed crypto capabilities (e.g. support for the needed encryption algorithm and data unit size) and where blk-crypto-fallback is unusable. (For blk-crypto-fallback to be usable, it must be enabled in the kernel configuration with -CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK=y.) +CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK=y, and the file must be +protected by a raw key rather than a hardware-wrapped key.) Currently fscrypt always uses the filesystem block size (which is usually 4096 bytes) as the data unit size. Therefore, it can only use inline encryption hardware that supports that data unit size. Inline encryption doesn't affect the ciphertext or other aspects of the on-disk format, so users may freely switch back and forth between -using "inlinecrypt" and not using "inlinecrypt". +using "inlinecrypt" and not using "inlinecrypt". An exception is that +files that are protected by a hardware-wrapped key can only be +encrypted/decrypted by the inline encryption hardware and therefore +can only be accessed when the "inlinecrypt" mount option is used. For +more information about hardware-wrapped keys, see below. + +Hardware-wrapped keys +--------------------- + +fscrypt supports using *hardware-wrapped keys* when the inline +encryption hardware supports it. Such keys are only present in kernel +memory in wrapped (encrypted) form; they can only be unwrapped +(decrypted) by the inline encryption hardware and are temporally bound +to the current boot. This prevents the keys from being compromised if +kernel memory is leaked. This is done without limiting the number of +keys that can be used and while still allowing the execution of +cryptographic tasks that are tied to the same key but can't use inline +encryption hardware, e.g. filenames encryption. + +Note that hardware-wrapped keys aren't specific to fscrypt; they are a +block layer feature (part of *blk-crypto*). For more details about +hardware-wrapped keys, see the block layer documentation at +:ref:`Documentation/block/inline-encryption.rst +<hardware_wrapped_keys>`. The rest of this section just focuses on +the details of how fscrypt can use hardware-wrapped keys. + +fscrypt supports hardware-wrapped keys by allowing the fscrypt master +keys to be hardware-wrapped keys as an alternative to raw keys. To +add a hardware-wrapped key with `FS_IOC_ADD_ENCRYPTION_KEY`_, +userspace must specify one of the FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_* +flags in the ``flags`` field of struct fscrypt_add_key_arg and also in +the ``flags`` field of struct fscrypt_provisioning_key_payload when +applicable. The key must be in ephemerally-wrapped form, not +long-term wrapped form. + +Some limitations apply. First, files protected by a hardware-wrapped +key are tied to the system's inline encryption hardware. Therefore +they can only be accessed when the "inlinecrypt" mount option is used, +and they can't be included in portable filesystem images. Second, +currently the hardware-wrapped key support is only compatible with +`IV_INO_LBLK_64 policies`_ and `IV_INO_LBLK_32 policies`_, as it +assumes that there is just one file contents encryption key per +fscrypt master key rather than one per file. Future work may address +this limitation by passing per-file nonces down the storage stack to +allow the hardware to derive per-file keys. + +Implementation-wise, to encrypt/decrypt the contents of files that are +protected by a hardware-wrapped key, fscrypt uses blk-crypto, +attaching the hardware-wrapped key to the bio crypt contexts. As is +the case with raw keys, the block layer will program the key into a +keyslot when it isn't already in one. However, when programming a +hardware-wrapped key, the hardware doesn't program the given key +directly into a keyslot but rather unwraps it (using the hardware's +ephemeral wrapping key) and derives the inline encryption key from it. +The inline encryption key is the key that actually gets programmed +into a keyslot, and it is never exposed to software. + +However, fscrypt doesn't just do file contents encryption; it also +uses its master keys to derive filenames encryption keys, key +identifiers, and sometimes some more obscure types of subkeys such as +dirhash keys. So even with file contents encryption out of the +picture, fscrypt still needs a raw key to work with. To get such a +key from a hardware-wrapped key, fscrypt asks the inline encryption +hardware to derive a cryptographically isolated "software secret" from +the hardware-wrapped key. fscrypt uses this "software secret" to key +its KDF to derive all subkeys other than file contents keys. + +Note that this implies that the hardware-wrapped key feature only +protects the file contents encryption keys. It doesn't protect other +fscrypt subkeys such as filenames encryption keys. Direct I/O support ================== For direct I/O on an encrypted file to work, the following conditions
fs/crypto/fscrypt_private.h +65 -10
182 lines not on this page · raw message
fs/crypto/hkdf.c +3 -1
@@ -2,11 +2,13 @@/* * Implementation of HKDF ("HMAC-based Extract-and-Expand Key Derivation * Function"), aka RFC 5869. See also the original paper (Krawczyk 2010): * "Cryptographic Extraction and Key Derivation: The HKDF Scheme". * -* This is used to derive keys from the fscrypt master keys. +* This is used to derive keys from the fscrypt master keys (or from the +* "software secrets" which hardware derives from the fscrypt master keys, in +* the case that the fscrypt master keys are hardware-wrapped keys). * * Copyright 2019 Google LLC */ #include <crypto/hash.h>
fs/crypto/inline_crypt.c +38 -6
99 lines not on this page · raw message
fs/crypto/keyring.c +116 -41
291 lines not on this page · raw message
fs/crypto/keysetup.c +55 -8
152 lines not on this page · raw message
fs/crypto/keysetup_v1.c +2 -2
@@ -116,11 +116,11 @@ find_and_lock_process_key(const char *prefix, goto invalid; payload = (const struct fscrypt_key *)ukp->data;if (ukp->datalen !=sizeof (struct fscrypt_key ) || - payload->size <1 || payload->size >FSCRYPT_MAX_KEY_SIZE ) { + payload->size <1 || payload->size >sizeof (payload->raw)) {fscrypt_warn (NULL ,"key with description '%s' has invalid payload" , key->description); goto invalid; }
@@ -147,11 +147,11 @@ struct fscrypt_direct_key {struct hlist_node dk_node;refcount_t dk_refcount;const struct fscrypt_mode *dk_mode;struct fscrypt_prepared_key dk_key;u8 dk_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE ]; -u8 dk_raw[FSCRYPT_MAX_KEY_SIZE ]; +u8 dk_raw[FSCRYPT_MAX_RAW_KEY_SIZE ]; };static void free_direct_key (struct fscrypt_direct_key *dk) {if (dk) {
include/uapi/linux/fscrypt.h +5 -2
@@ -117,20 +117,23 @@ struct fscrypt_key_specifier {* Payload of Linux keyring key of type "fscrypt-provisioning", referenced by * fscrypt_add_key_arg::key_id as an alternative to fscrypt_add_key_arg::raw. */ struct fscrypt_provisioning_key_payload {__u32 type; -__u32 __reserved; +__u32 flags;__u8 raw[]; };/* Struct passed to FS_IOC_ADD_ENCRYPTION_KEY */ struct fscrypt_add_key_arg {struct fscrypt_key_specifier key_spec;__u32 raw_size;__u32 key_id; -__u32 __reserved[8 ]; +#define FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_V0 0x00000001 +#define FSCRYPT_ADD_KEY_FLAG_HW_WRAPPED_V1 0x00000002 +__u32 flags; +__u32 __reserved[7 ];__u8 raw[]; };/* Struct passed to FS_IOC_REMOVE_ENCRYPTION_KEY */ struct fscrypt_remove_key_arg {
Signature · 1 line
2.48.1
Eric Biggers
maintainerPATCH v11 5/7 soc: qcom: ice: make qcom_ice_program_key() take struct blk_crypto_key
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
qcom_ice_program_key() currently accepts the key as an array of bytes, algorithm ID, key size enum, and data unit size. However both callers have a struct blk_crypto_key which contains all that information. Thus they both have similar code that converts the blk_crypto_key into the form that qcom_ice_program_key() wants. Once wrapped key support is added, the key type would need to be added to the arguments too.
Therefore, this patch changes qcom_ice_program_key() to take in all this information as a struct blk_crypto_key directly. The calling code is updated accordingly. This ends up being much simpler, and it makes the key type be passed down automatically once wrapped key support is added.
Based on a patch by Gaurav Kashyap <[email protected]> that replaced the byte array argument only. This patch makes the blk_crypto_key replace other arguments like the algorithm ID too, ensuring that there remains only one source of truth.
--- drivers/mmc/host/sdhci-msm.c | 11 +---------- drivers/soc/qcom/ice.c | 23 ++++++++++++----------- drivers/ufs/host/ufs-qcom.c | 11 +---------- include/soc/qcom/ice.h | 22 +++------------------- 4 files changed, 17 insertions(+), 50 deletions(-)
drivers/mmc/host/sdhci-msm.c +1 -10
@@ -1960,20 +1960,11 @@ static int sdhci_msm_ice_keyslot_program(struct blk_crypto_profile *profile, unsigned int slot) {struct sdhci_msm_host *msm_host =sdhci_msm_host_from_crypto_profile (profile); -/* Only AES-256-XTS has been tested so far. */ -if (key->crypto_cfg.crypto_mode !=BLK_ENCRYPTION_MODE_AES_256_XTS ) -return -EOPNOTSUPP ; - -return qcom_ice_program_key (msm_host->ice, -QCOM_ICE_CRYPTO_ALG_AES_XTS , -QCOM_ICE_CRYPTO_KEY_SIZE_256 , - key->bytes, - key->crypto_cfg.data_unit_size /512 , - slot); +return qcom_ice_program_key (msm_host->ice, slot, key); }static int sdhci_msm_ice_keyslot_evict (struct blk_crypto_profile *profile,const struct blk_crypto_key *key,unsigned int slot)
drivers/soc/qcom/ice.c +12 -11
@@ -159,41 +159,42 @@ int qcom_ice_suspend(struct qcom_ice *ice)return 0 ; }EXPORT_SYMBOL_GPL (qcom_ice_suspend); -int qcom_ice_program_key (struct qcom_ice *ice, -u8 algorithm_id,u8 key_size, -const u8 crypto_key[],u8 data_unit_size, -int slot) +int qcom_ice_program_key (struct qcom_ice *ice,unsigned int slot, +const struct blk_crypto_key *blk_key) {struct device *dev = ice->dev;union {u8 bytes[AES_256_XTS_KEY_SIZE ];u32 words[AES_256_XTS_KEY_SIZE /sizeof (u32)]; } key;int i;int err;/* Only AES-256-XTS has been tested so far. */ -if (algorithm_id !=QCOM_ICE_CRYPTO_ALG_AES_XTS || - key_size !=QCOM_ICE_CRYPTO_KEY_SIZE_256 ) { -dev_err_ratelimited (dev, -"Unhandled crypto capability; algorithm_id=%d, key_size=%d\n" , - algorithm_id, key_size); +if (blk_key->crypto_cfg.crypto_mode != +BLK_ENCRYPTION_MODE_AES_256_XTS ) { +dev_err_ratelimited (dev,"Unsupported crypto mode: %d\n" , + blk_key->crypto_cfg.crypto_mode);return -EINVAL ; } -memcpy (key.bytes, crypto_key,AES_256_XTS_KEY_SIZE ); +if (blk_key->size !=AES_256_XTS_KEY_SIZE ) { +dev_err_ratelimited (dev,"Incorrect key size\n" ); +return -EINVAL ; + } +memcpy (key.bytes, blk_key->bytes,AES_256_XTS_KEY_SIZE );/* The SCM call requires that the key words are encoded in big endian */ for (i =0 ; i <ARRAY_SIZE (key.words); i++)__cpu_to_be32s (&key.words[i]); err =qcom_scm_ice_set_key (slot, key.bytes,AES_256_XTS_KEY_SIZE ,QCOM_SCM_ICE_CIPHER_AES_256_XTS , - data_unit_size); + blk_key->crypto_cfg.data_unit_size /512 );memzero_explicit (&key,sizeof (key));return err; }
drivers/ufs/host/ufs-qcom.c +1 -10
@@ -193,21 +193,12 @@ static int ufs_qcom_ice_keyslot_program(struct blk_crypto_profile *profile, {struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile);struct ufs_qcom_host *host =ufshcd_get_variant (hba);int err; -/* Only AES-256-XTS has been tested so far. */ -if (key->crypto_cfg.crypto_mode !=BLK_ENCRYPTION_MODE_AES_256_XTS ) -return -EOPNOTSUPP ; -ufshcd_hold (hba); - err =qcom_ice_program_key (host->ice, -QCOM_ICE_CRYPTO_ALG_AES_XTS , -QCOM_ICE_CRYPTO_KEY_SIZE_256 , - key->bytes, - key->crypto_cfg.data_unit_size /512 , - slot); + err =qcom_ice_program_key (host->ice, slot, key);ufshcd_release (hba);return err; } static int ufs_qcom_ice_keyslot_evict(struct blk_crypto_profile *profile,
include/soc/qcom/ice.h +3 -19
@@ -4,34 +4,18 @@*/ #ifndef __QCOM_ICE_H__#define __QCOM_ICE_H__ +#include <linux/blk-crypto.h> #include <linux/types.h> struct qcom_ice ; -enum qcom_ice_crypto_key_size { -QCOM_ICE_CRYPTO_KEY_SIZE_INVALID =0x0 , -QCOM_ICE_CRYPTO_KEY_SIZE_128 =0x1 , -QCOM_ICE_CRYPTO_KEY_SIZE_192 =0x2 , -QCOM_ICE_CRYPTO_KEY_SIZE_256 =0x3 , -QCOM_ICE_CRYPTO_KEY_SIZE_512 =0x4 , -}; - -enum qcom_ice_crypto_alg { -QCOM_ICE_CRYPTO_ALG_AES_XTS =0x0 , -QCOM_ICE_CRYPTO_ALG_BITLOCKER_AES_CBC =0x1 , -QCOM_ICE_CRYPTO_ALG_AES_ECB =0x2 , -QCOM_ICE_CRYPTO_ALG_ESSIV_AES_CBC =0x3 , -}; -int qcom_ice_enable (struct qcom_ice *ice);int qcom_ice_resume (struct qcom_ice *ice);int qcom_ice_suspend (struct qcom_ice *ice); -int qcom_ice_program_key (struct qcom_ice *ice, -u8 algorithm_id,u8 key_size, -const u8 crypto_key[],u8 data_unit_size, -int slot); +int qcom_ice_program_key (struct qcom_ice *ice,unsigned int slot, +const struct blk_crypto_key *blk_key);int qcom_ice_evict_key (struct qcom_ice *ice,int slot);struct qcom_ice *of_qcom_ice_get (struct device *dev);#endif /* __QCOM_ICE_H__ */
Signature · 1 line
2.48.1
Eric Biggers
maintainerPATCH v11 6/7 soc: qcom: ice: add HWKM support to the ICE driver
In reply to Eric BiggersFrom: Gaurav Kashyap <[email protected]>
Qualcomm's Inline Crypto Engine (ICE) version 3.2 and later includes a key management hardware block called the Hardware Key Manager (HWKM). Add support for HWKM to the ICE driver. HWKM provides hardware-wrapped key support where the ICE (storage) keys are not exposed to software and instead are protected in hardware. Later patches will wire up this feature to ufs-qcom and sdhci-msm using the support added in this patch.
HWKM and legacy mode are currently mutually exclusive. The selection of which mode to use has to be made before the storage driver(s) registers any inline encryption capable disk(s) with the block layer (i.e., generally at boot time) so that the appropriate crypto capabilities can be advertised to upper layers. Therefore, make the ICE driver select HWKM mode when the all of the following are true:
- The new module parameter qcom_ice.use_wrapped_keys=1 is specified.
- HWKM is present and is at least v2, i.e. ICE is v3.2.1 or later.
- The SCM calls needed to fully use HWKM are supported by TrustZone.
[EB: merged related patches; fixed the module parameter to work
correctly; dropped unnecessary support for HWKM v1; fixed error handling; improved log messages, comments, and commit message; fixed naming; merged enable and init functions; and other cleanups]
--- drivers/mmc/host/sdhci-msm.c | 5 + drivers/soc/qcom/ice.c | 326 +++++++++++++++++++++++++++++++++-- drivers/ufs/host/ufs-qcom.c | 5 + include/soc/qcom/ice.h | 12 ++ 4 files changed, 338 insertions(+), 10 deletions(-)
drivers/mmc/host/sdhci-msm.c +5 -0
@@ -1880,10 +1880,15 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host, }if (IS_ERR_OR_NULL (ice))return PTR_ERR_OR_ZERO (ice); +if (qcom_ice_get_supported_key_type (ice) !=BLK_CRYPTO_KEY_TYPE_RAW ) { +dev_warn (dev,"Wrapped keys not supported. Disabling inline encryption support.\n" ); +return 0 ; + } + msm_host->ice = ice;/* Initialize the blk_crypto_profile */ caps.reg_val =cpu_to_le32 (cqhci_readl (cq_host,CQHCI_CCAP ));
drivers/soc/qcom/ice.c +316 -10
430 lines not on this page · raw message
drivers/ufs/host/ufs-qcom.c +5 -0
@@ -132,10 +132,15 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host) }if (IS_ERR_OR_NULL (ice))return PTR_ERR_OR_ZERO (ice); +if (qcom_ice_get_supported_key_type (ice) !=BLK_CRYPTO_KEY_TYPE_RAW ) { +dev_warn (dev,"Wrapped keys not supported. Disabling inline encryption support.\n" ); +return 0 ; + } + host->ice = ice;/* Initialize the blk_crypto_profile */ caps.reg_val =cpu_to_le32 (ufshcd_readl (hba,REG_UFS_CCAP ));
include/soc/qcom/ice.h +12 -0
@@ -15,7 +15,19 @@ int qcom_ice_enable(struct qcom_ice *ice);int qcom_ice_resume (struct qcom_ice *ice);int qcom_ice_suspend (struct qcom_ice *ice);int qcom_ice_program_key (struct qcom_ice *ice,unsigned int slot,const struct blk_crypto_key *blk_key);int qcom_ice_evict_key (struct qcom_ice *ice,int slot); +enum blk_crypto_key_type qcom_ice_get_supported_key_type (struct qcom_ice *ice); +int qcom_ice_derive_sw_secret (struct qcom_ice *ice, +const u8 *eph_key,size_t eph_key_size, +u8 sw_secret[BLK_CRYPTO_SW_SECRET_SIZE ]); +int qcom_ice_generate_key (struct qcom_ice *ice, +u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]); +int qcom_ice_prepare_key (struct qcom_ice *ice, +const u8 *lt_key,size_t lt_key_size, +u8 eph_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]); +int qcom_ice_import_key (struct qcom_ice *ice, +const u8 *raw_key,size_t raw_key_size, +u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]);struct qcom_ice *of_qcom_ice_get (struct device *dev);#endif /* __QCOM_ICE_H__ */
Signature · 1 line
2.48.1
Eric Biggers
maintainerPATCH v11 7/7 ufs: qcom: add support for wrapped keys
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Wire up the wrapped key support for ufs-qcom by implementing the needed methods in struct blk_crypto_ll_ops and setting the appropriate flag in blk_crypto_profile::key_types_supported.
For more information about this feature and how to use it, refer to the sections about hardware-wrapped keys in Documentation/block/inline-encryption.rst and Documentation/filesystems/fscrypt.rst.
Based on patches by Gaurav Kashyap <[email protected]>. Reworked to use the custom crypto profile support.
--- drivers/ufs/host/ufs-qcom.c | 51 ++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-)
drivers/ufs/host/ufs-qcom.c +45 -6
@@ -132,15 +132,10 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host) }if (IS_ERR_OR_NULL (ice))return PTR_ERR_OR_ZERO (ice); -if (qcom_ice_get_supported_key_type (ice) !=BLK_CRYPTO_KEY_TYPE_RAW ) { -dev_warn (dev,"Wrapped keys not supported. Disabling inline encryption support.\n" ); -return 0 ; - } - host->ice = ice;/* Initialize the blk_crypto_profile */ caps.reg_val =cpu_to_le32 (ufshcd_readl (hba,REG_UFS_CCAP ));
@@ -150,11 +145,11 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host)if (err)return err; profile->ll_ops = ufs_qcom_crypto_ops; profile->max_dun_bytes_supported =8 ; - profile->key_types_supported =BLK_CRYPTO_KEY_TYPE_RAW ; + profile->key_types_supported =qcom_ice_get_supported_key_type (ice); profile->dev = dev;/* * Currently this driver only supports AES-256-XTS. All known versions * of ICE support it, but to be safe make sure it is really declared in
@@ -218,13 +213,57 @@ static int ufs_qcom_ice_keyslot_evict(struct blk_crypto_profile *profile, err =qcom_ice_evict_key (host->ice, slot);ufshcd_release (hba);return err; } +static int ufs_qcom_ice_derive_sw_secret (struct blk_crypto_profile *profile, +const u8 *eph_key,size_t eph_key_size, +u8 sw_secret[BLK_CRYPTO_SW_SECRET_SIZE ]) +{ +struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile); +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +return qcom_ice_derive_sw_secret (host->ice, eph_key, eph_key_size, + sw_secret); +} + +static int ufs_qcom_ice_import_key (struct blk_crypto_profile *profile, +const u8 *raw_key,size_t raw_key_size, +u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]) +{ +struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile); +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +return qcom_ice_import_key (host->ice, raw_key, raw_key_size, lt_key); +} + +static int ufs_qcom_ice_generate_key (struct blk_crypto_profile *profile, +u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]) +{ +struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile); +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +return qcom_ice_generate_key (host->ice, lt_key); +} + +static int ufs_qcom_ice_prepare_key (struct blk_crypto_profile *profile, +const u8 *lt_key,size_t lt_key_size, +u8 eph_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]) +{ +struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile); +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +return qcom_ice_prepare_key (host->ice, lt_key, lt_key_size, eph_key); +} +static const struct blk_crypto_ll_ops ufs_qcom_crypto_ops = { .keyslot_program = ufs_qcom_ice_keyslot_program, .keyslot_evict = ufs_qcom_ice_keyslot_evict, + .derive_sw_secret = ufs_qcom_ice_derive_sw_secret, + .import_key = ufs_qcom_ice_import_key, + .generate_key = ufs_qcom_ice_generate_key, + .prepare_key = ufs_qcom_ice_prepare_key, };#else static inline void ufs_qcom_ice_enable (struct ufs_qcom_host *host)
Signature · 1 line
2.48.1
Quoted 40 lines · Eric Biggers
This patchset is based on v6.14-rc1 and is also available at:
git fetch https://git.kernel.org/pub/scm/fs/fscrypt/linux.git wrapped-keys-v11
This patchset adds support for hardware-wrapped inline encryption keys, a security feature supported by some SoCs. It adds the block and fscrypt framework for the feature as well as support for it with UFS on Qualcomm SoCs.
This feature is described in full detail in the included Documentation changes. But to summarize, hardware-wrapped keys are inline encryption keys that are wrapped (encrypted) by a key internal to the hardware so that they can only be unwrapped (decrypted) by the hardware. Initially keys are wrapped with a permanent hardware key, but during actual use they are re-wrapped with a per-boot ephemeral key for improved security. The hardware supports importing keys as well as generating keys itself.
This differs from the existing support for hardware-wrapped keys in the kernel crypto API (also called "hardware-bound keys" in some places) in the same way that the crypto API differs from blk-crypto: the crypto API is for general crypto operations, whereas blk-crypto is for inline storage encryption.
This feature is already being used by Android downstream for several years
(https://source.android.com/docs/security/features/encryption/hw-wrapped-keys),
but on other platforms userspace support will be provided via fscryptctl and tests via xfstests. The tests have been merged into xfstests, and they pass on the SM8650 HDK with the upstream kernel plus this patchset.This is targeting 6.15. As per the suggestion from Jens
(https://lore.kernel.org/linux-block/[email protected]/),
I'd like patches 1-3 to be queued up into a branch that gets pulled into the block tree. I'll then take patches 4-7 through the fscrypt tree, also for 6.15. If I end up with too many merge conflicts by trying to take patches 5-7 (given that this is a cross-subsystem feature), my fallback plan will be to wait until 6.16 to land patches 5-7, when they will finally be unblocked by the block patches having landed.
Quoted 11 lines
Changed in v11:
- Rebased onto v6.14-rc1. Dropped the patches that were upstreamed in 6.14, and put the block patches first in the series again.
- Significantly cleaned up the patch "soc: qcom: ice: add HWKM support to the ICE driver". Some of the notable changes were dropping the unnecessary support for HWKM v1, and replacingqcom_ice_using_hwkm()withqcom_ice_get_supported_key_type().
- Consistently used and documented the EBADMSG error code for invalid hardware-wrapped keys.
- Other minor cleanups.
kernel test robot
build botRe: [PATCH v11 6/7] soc: qcom: ice: add HWKM support to the ICE driver
In reply to Eric Biggerskernel test robot noticed the following build warnings:
Hi Eric,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 2014c95afecee3e76ca4a56956a936e23283f05b]
url: https://github.com/intel-lab-lkp/linux/commits/Eric-Biggers/blk-crypto-add-basic-hardware-wrapped-key-support/20250204-140702 base: 2014c95afecee3e76ca4a56956a936e23283f05b patch link: https://lore.kernel.org/r/20250204060041.409950-7-ebiggers%40kernel.org patch subject: [PATCH v11 6/7] soc: qcom: ice: add HWKM support to the ICE driver config: openrisc-randconfig-r111-20250208 (https://download.01.org/0day-ci/archive/20250209/[email protected]/config) compiler: or1k-linux-gcc (GCC) 14.2.0 reproduce: (https://download.01.org/0day-ci/archive/20250209/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/soc/qcom/ice.c:337:9: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] value @@ got restricted __le32 [usertype] regval @@
drivers/soc/qcom/ice.c:337:9: sparse: expected unsigned int [usertype] value
drivers/soc/qcom/ice.c:337:9: sparse: got restricted __le32 [usertype] regval
vim +337 drivers/soc/qcom/ice.c
302
303 static int qcom_ice_program_wrapped_key(struct qcom_ice *ice, unsigned int slot,
304 const struct blk_crypto_key *bkey)
305 {
306 struct device *dev = ice->dev;
307 union crypto_cfg cfg = {
308 .dusize = bkey->crypto_cfg.data_unit_size / 512,
309 .capidx = QCOM_SCM_ICE_CIPHER_AES_256_XTS,
310 .cfge = QCOM_ICE_HWKM_CFG_ENABLE_VAL,
311 };
312 int err;
313
314 if (!ice->use_hwkm) {
315 dev_err_ratelimited(dev, "Got wrapped key when not using HWKM\n");
316 return -EINVAL;
317 }
318 if (!ice->hwkm_init_complete) {
319 dev_err_ratelimited(dev, "HWKM not yet initialized\n");
320 return -EINVAL;
321 }
322
323 /* Clear CFGE before programming the key. */
324 qcom_ice_writel(ice, 0x0, QCOM_ICE_REG_CRYPTOCFG(slot));
325
326 /* Call into TrustZone to program the wrapped key using HWKM. */
327 err = qcom_scm_ice_set_key(translate_hwkm_slot(ice, slot), bkey->bytes,
328 bkey->size, cfg.capidx, cfg.dusize);
329 if (err) {
330 dev_err_ratelimited(dev,
331 "qcom_scm_ice_set_key failed; err=%d, slot=%u\n",
332 err, slot);
333 return err;
334 }
335
336 /* Set CFGE after programming the key. */
> 337 qcom_ice_writel(ice, cfg.regval, QCOM_ICE_REG_CRYPTOCFG(slot));
338 return 0;
339 }
340
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v11 5/7] soc: qcom: ice: make qcom_ice_program_key() take struct blk_crypto_key
In reply to Eric BiggersQuoted 14 lines · Eric Biggers
From: Eric Biggers <[email protected]>
qcom_ice_program_key()currently accepts the key as an array of bytes, algorithm ID, key size enum, and data unit size. However both callers have a structblk_crypto_keywhich contains all that information. Thus they both have similar code that converts theblk_crypto_keyinto the form thatqcom_ice_program_key()wants. Once wrapped key support is added, the key type would need to be added to the arguments too.Therefore, this patch changes
qcom_ice_program_key()to take in all this information as a structblk_crypto_keydirectly. The calling code is updated accordingly. This ends up being much simpler, and it makes the key type be passed down automatically once wrapped key support is added.
Quoted 6 lines
Based on a patch by Gaurav Kashyap <[email protected]> that replaced the byte array argument only. This patch makes the
blk_crypto_keyreplace other arguments like the algorithm ID too, ensuring that there remains only one source of truth.Signed-off-by Eric Biggers <[email protected]>
For ufs-qcom:
- Mani
Quoted 163 lines
--- drivers/mmc/host/sdhci-msm.c | 11 +---------- drivers/soc/qcom/ice.c | 23 ++++++++++++----------- drivers/ufs/host/ufs-qcom.c | 11 +---------- include/soc/qcom/ice.h | 22 +++------------------- 4 files changed, 17 insertions(+), 50 deletions(-)drivers/mmc/host/sdhci-msm.c +1
-10@@ -1960,20 +1960,11 @@ static int sdhci_msm_ice_keyslot_program(struct blk_crypto_profile *profile, unsigned int slot) {struct sdhci_msm_host *msm_host =sdhci_msm_host_from_crypto_profile (profile); -/* Only AES-256-XTS has been tested so far. */ -if (key->crypto_cfg.crypto_mode !=BLK_ENCRYPTION_MODE_AES_256_XTS ) -return -EOPNOTSUPP ; - -return qcom_ice_program_key (msm_host->ice, -QCOM_ICE_CRYPTO_ALG_AES_XTS , -QCOM_ICE_CRYPTO_KEY_SIZE_256 , - key->bytes, - key->crypto_cfg.data_unit_size /512 , - slot); +return qcom_ice_program_key (msm_host->ice, slot, key); }static int sdhci_msm_ice_keyslot_evict (struct blk_crypto_profile *profile,const struct blk_crypto_key *key,unsigned int slot)drivers/soc/qcom/ice.c +12
-11@@ -159,41 +159,42 @@ int qcom_ice_suspend(struct qcom_ice *ice)return 0 ; }EXPORT_SYMBOL_GPL (qcom_ice_suspend); -int qcom_ice_program_key (struct qcom_ice *ice, -u8 algorithm_id,u8 key_size, -const u8 crypto_key[],u8 data_unit_size, -int slot) +int qcom_ice_program_key (struct qcom_ice *ice,unsigned int slot, +const struct blk_crypto_key *blk_key) {struct device *dev = ice->dev;union {u8 bytes[AES_256_XTS_KEY_SIZE ];u32 words[AES_256_XTS_KEY_SIZE /sizeof (u32)]; } key;int i;int err;/* Only AES-256-XTS has been tested so far. */ -if (algorithm_id !=QCOM_ICE_CRYPTO_ALG_AES_XTS || - key_size !=QCOM_ICE_CRYPTO_KEY_SIZE_256 ) { -dev_err_ratelimited (dev, -"Unhandled crypto capability; algorithm_id=%d, key_size=%d\n" , - algorithm_id, key_size); +if (blk_key->crypto_cfg.crypto_mode != +BLK_ENCRYPTION_MODE_AES_256_XTS ) { +dev_err_ratelimited (dev,"Unsupported crypto mode: %d\n" , + blk_key->crypto_cfg.crypto_mode);return -EINVAL ; } -memcpy (key.bytes, crypto_key,AES_256_XTS_KEY_SIZE ); +if (blk_key->size !=AES_256_XTS_KEY_SIZE ) { +dev_err_ratelimited (dev,"Incorrect key size\n" ); +return -EINVAL ; + } +memcpy (key.bytes, blk_key->bytes,AES_256_XTS_KEY_SIZE );/* The SCM call requires that the key words are encoded in big endian */ for (i =0 ; i <ARRAY_SIZE (key.words); i++)__cpu_to_be32s (&key.words[i]); err =qcom_scm_ice_set_key (slot, key.bytes,AES_256_XTS_KEY_SIZE ,QCOM_SCM_ICE_CIPHER_AES_256_XTS , - data_unit_size); + blk_key->crypto_cfg.data_unit_size /512 );memzero_explicit (&key,sizeof (key));return err; }drivers/ufs/host/ufs-qcom.c +1
-10@@ -193,21 +193,12 @@ static int ufs_qcom_ice_keyslot_program(struct blk_crypto_profile *profile, {struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile);struct ufs_qcom_host *host =ufshcd_get_variant (hba);int err; -/* Only AES-256-XTS has been tested so far. */ -if (key->crypto_cfg.crypto_mode !=BLK_ENCRYPTION_MODE_AES_256_XTS ) -return -EOPNOTSUPP ; -ufshcd_hold (hba); - err =qcom_ice_program_key (host->ice, -QCOM_ICE_CRYPTO_ALG_AES_XTS , -QCOM_ICE_CRYPTO_KEY_SIZE_256 , - key->bytes, - key->crypto_cfg.data_unit_size /512 , - slot); + err =qcom_ice_program_key (host->ice, slot, key);ufshcd_release (hba);return err; } static int ufs_qcom_ice_keyslot_evict(struct blk_crypto_profile *profile,include/soc/qcom/ice.h +3
-19@@ -4,34 +4,18 @@*/ #ifndef __QCOM_ICE_H__#define __QCOM_ICE_H__ +#include <linux/blk-crypto.h> #include <linux/types.h> struct qcom_ice ; -enum qcom_ice_crypto_key_size { -QCOM_ICE_CRYPTO_KEY_SIZE_INVALID =0x0 , -QCOM_ICE_CRYPTO_KEY_SIZE_128 =0x1 , -QCOM_ICE_CRYPTO_KEY_SIZE_192 =0x2 , -QCOM_ICE_CRYPTO_KEY_SIZE_256 =0x3 , -QCOM_ICE_CRYPTO_KEY_SIZE_512 =0x4 , -}; - -enum qcom_ice_crypto_alg { -QCOM_ICE_CRYPTO_ALG_AES_XTS =0x0 , -QCOM_ICE_CRYPTO_ALG_BITLOCKER_AES_CBC =0x1 , -QCOM_ICE_CRYPTO_ALG_AES_ECB =0x2 , -QCOM_ICE_CRYPTO_ALG_ESSIV_AES_CBC =0x3 , -}; -int qcom_ice_enable (struct qcom_ice *ice);int qcom_ice_resume (struct qcom_ice *ice);int qcom_ice_suspend (struct qcom_ice *ice); -int qcom_ice_program_key (struct qcom_ice *ice, -u8 algorithm_id,u8 key_size, -const u8 crypto_key[],u8 data_unit_size, -int slot); +int qcom_ice_program_key (struct qcom_ice *ice,unsigned int slot, +const struct blk_crypto_key *blk_key);int qcom_ice_evict_key (struct qcom_ice *ice,int slot);struct qcom_ice *of_qcom_ice_get (struct device *dev);#endif /* __QCOM_ICE_H__ */ Signature · 1 line
2.48.1
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Re: [PATCH v11 7/7] ufs: qcom: add support for wrapped keys
In reply to Eric BiggersQuoted 6 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Wire up the wrapped key support for ufs-qcom by implementing the needed methods in struct
blk_crypto_ll_opsand setting the appropriate flag inblk_crypto_profile::key_types_supported.
Quoted 8 lines
For more information about this feature and how to use it, refer to the sections about hardware-wrapped keys in
Documentation/block/inline-encryption.rstandDocumentation/filesystems/fscrypt.rst.Based on patches by Gaurav Kashyap <[email protected]>. Reworked to use the custom crypto profile support.
Instead of mentioning the contribution in description, you should use relevant tags IMO.
Quoted 1 line
Signed-off-by Eric Biggers <[email protected]>
- Mani
Quoted 98 lines
--- drivers/ufs/host/ufs-qcom.c | 51 ++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-)drivers/ufs/host/ufs-qcom.c +45
-6@@ -132,15 +132,10 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host) }if (IS_ERR_OR_NULL (ice))return PTR_ERR_OR_ZERO (ice); -if (qcom_ice_get_supported_key_type (ice) !=BLK_CRYPTO_KEY_TYPE_RAW ) { -dev_warn (dev,"Wrapped keys not supported. Disabling inline encryption support.\n" ); -return 0 ; - } - host->ice = ice;/* Initialize the blk_crypto_profile */ caps.reg_val =cpu_to_le32 (ufshcd_readl (hba,REG_UFS_CCAP ));@@ -150,11 +145,11 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host)if (err)return err; profile->ll_ops = ufs_qcom_crypto_ops; profile->max_dun_bytes_supported =8 ; - profile->key_types_supported =BLK_CRYPTO_KEY_TYPE_RAW ; + profile->key_types_supported =qcom_ice_get_supported_key_type (ice); profile->dev = dev;/* * Currently this driver only supports AES-256-XTS. All known versions * of ICE support it, but to be safe make sure it is really declared in @@ -218,13 +213,57 @@ static int ufs_qcom_ice_keyslot_evict(struct blk_crypto_profile *profile, err =qcom_ice_evict_key (host->ice, slot);ufshcd_release (hba);return err; } +static int ufs_qcom_ice_derive_sw_secret (struct blk_crypto_profile *profile, +const u8 *eph_key,size_t eph_key_size, +u8 sw_secret[BLK_CRYPTO_SW_SECRET_SIZE ]) +{ +struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile); +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +return qcom_ice_derive_sw_secret (host->ice, eph_key, eph_key_size, + sw_secret); +} + +static int ufs_qcom_ice_import_key (struct blk_crypto_profile *profile, +const u8 *raw_key,size_t raw_key_size, +u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]) +{ +struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile); +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +return qcom_ice_import_key (host->ice, raw_key, raw_key_size, lt_key); +} + +static int ufs_qcom_ice_generate_key (struct blk_crypto_profile *profile, +u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]) +{ +struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile); +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +return qcom_ice_generate_key (host->ice, lt_key); +} + +static int ufs_qcom_ice_prepare_key (struct blk_crypto_profile *profile, +const u8 *lt_key,size_t lt_key_size, +u8 eph_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE ]) +{ +struct ufs_hba *hba =ufs_hba_from_crypto_profile (profile); +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +return qcom_ice_prepare_key (host->ice, lt_key, lt_key_size, eph_key); +} +static const struct blk_crypto_ll_ops ufs_qcom_crypto_ops = { .keyslot_program = ufs_qcom_ice_keyslot_program, .keyslot_evict = ufs_qcom_ice_keyslot_evict, + .derive_sw_secret = ufs_qcom_ice_derive_sw_secret, + .import_key = ufs_qcom_ice_import_key, + .generate_key = ufs_qcom_ice_generate_key, + .prepare_key = ufs_qcom_ice_prepare_key, };#else static inline void ufs_qcom_ice_enable (struct ufs_qcom_host *host)Signature · 1 line
2.48.1
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Eric Biggers
maintainerRe: [PATCH v11 7/7] ufs: qcom: add support for wrapped keys
Quoted 12 lines · Manivannan Sadhasivam
Quoted 11 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Wire up the wrapped key support for ufs-qcom by implementing the needed methods in struct
blk_crypto_ll_opsand setting the appropriate flag inblk_crypto_profile::key_types_supported.For more information about this feature and how to use it, refer to the sections about hardware-wrapped keys in
Documentation/block/inline-encryption.rstandDocumentation/filesystems/fscrypt.rst.
Quoted 6 lines
Quoted 3 lines
Based on patches by Gaurav Kashyap <[email protected]>. Reworked to use the custom crypto profile support.
Instead of mentioning the contribution in description, you should use relevant tags IMO.
I had to rewrite this patch from scratch, and it is a much simpler implementation of what was originally 6 patches. So in this case I don't think it would make sense to keep authorship or co-developed-by.
- Eric
Eric Biggers
maintainerHi Jens,
Quoted 8 lines · Eric Biggers
This is targeting 6.15. As per the suggestion from Jens
(https://lore.kernel.org/linux-block/[email protected]/),
I'd like patches 1-3 to be queued up into a branch that gets pulled into the block tree. I'll then take patches 4-7 through the fscrypt tree, also for 6.15. If I end up with too many merge conflicts by trying to take patches 5-7 (given that this is a cross-subsystem feature), my fallback plan will be to wait until 6.16 to land patches 5-7, when they will finally be unblocked by the block patches having landed.
Let me know what you think about this plan.
- Eric
Re: (subset) [PATCH v11 0/7] Support for hardware-wrapped inline encryption keys
In reply to Eric BiggersQuoted 10 lines · Eric Biggers
This patchset is based on v6.14-rc1 and is also available at:
git fetch https://git.kernel.org/pub/scm/fs/fscrypt/linux.git wrapped-keys-v11
This patchset adds support for hardware-wrapped inline encryption keys, a security feature supported by some SoCs. It adds the block and fscrypt framework for the feature as well as support for it with UFS on Qualcomm SoCs.
[...]
Applied, thanks!
[1/7] blk-crypto: add basic hardware-wrapped key support
commit: ebc4176551cdd021d02f4d2ed734e7b65e44442a
[2/7] blk-crypto: show supported key types in sysfs
commit: e35fde43e25ad725d27315992fba8088d1210b01
[3/7] blk-crypto: add ioctls to create and prepare hardware-wrapped keys
commit: 1ebd4a3c095cd538d3c1c7c12738ef47d8e71f96Best regards,
Signature · 1 line
Jens Axboe