Skip to content

Commit dddf71e

Browse files
committed
FROMLIST: mmc: host: sdhci-msm: Add support for wrapped keys
Add the wrapped key support for sdhci-msm by implementing the needed methods in struct blk_crypto_ll_ops and setting the appropriate flag in blk_crypto_profile::key_types_supported. Tested on SC7280 eMMC variant. How to test: Use the "v1.3.0" tag from https://github.com/google/fscryptctl and build fscryptctl that supports generating wrapped keys. Enable the following config options: CONFIG_BLK_INLINE_ENCRYPTION=y CONFIG_QCOM_INLINE_CRYPTO_ENGINE=y CONFIG_FS_ENCRYPTION_INLINE_CRYPT=y CONFIG_MMC_CRYPTO=y Enable "qcom_ice.use_wrapped_keys" via kernel command line. $ mkfs.ext4 -F -O encrypt,stable_inodes /dev/disk/by-partlabel/vm-data $ mount /dev/disk/by-partlabel/vm-data -o inlinecrypt /mnt $ fscryptctl generate_hw_wrapped_key /dev/disk/by-partlabel/vm-data > /mnt/key.longterm $ fscryptctl prepare_hw_wrapped_key /dev/disk/by-partlabel/vm-data < /mnt/key.longterm > /tmp/key.ephemeral $ KEYID=$(fscryptctl add_key --hw-wrapped-key < /tmp/key.ephemeral /mnt) $ rm -rf /mnt/dir $ mkdir /mnt/dir $ fscryptctl set_policy --iv-ino-lblk-32 "$KEYID" /mnt/dir $ dmesg > /mnt/dir/test.txt $ sync Reboot the board $ mount /dev/disk/by-partlabel/vm-data -o inlinecrypt /mnt $ ls /mnt/dir # File should be encrypted $ fscryptctl prepare_hw_wrapped_key /dev/disk/by-partlabel/vm-data < /mnt/key.longterm > /tmp/key.ephemeral $ KEYID=$(fscryptctl add_key --hw-wrapped-key < /tmp/key.ephemeral /mnt) $ fscryptctl set_policy --iv-ino-lblk-32 "$KEYID" /mnt/dir $ cat /mnt/dir/test.txt # File should now be decrypted Link: https://lore.kernel.org/all/20260102124018.3643243-1-neeraj.soni@oss.qualcomm.com/ Tested-by: Wenjia Zhang <wenjia.zhang@oss.qualcomm.com> Signed-off-by: Neeraj Soni <neeraj.soni@oss.qualcomm.com> Acked-by: Adrian Hunter <adrian.hunter@intel.com> Reviewed-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Abhinaba Rakshit <abhinaba.rakshit@oss.qualcomm.com>
1 parent 883da00 commit dddf71e

1 file changed

Lines changed: 41 additions & 6 deletions

File tree

drivers/mmc/host/sdhci-msm.c

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,11 +1914,6 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
19141914
if (IS_ERR_OR_NULL(ice))
19151915
return PTR_ERR_OR_ZERO(ice);
19161916

1917-
if (qcom_ice_get_supported_key_type(ice) != BLK_CRYPTO_KEY_TYPE_RAW) {
1918-
dev_warn(dev, "Wrapped keys not supported. Disabling inline encryption support.\n");
1919-
return 0;
1920-
}
1921-
19221917
msm_host->ice = ice;
19231918

19241919
/* Initialize the blk_crypto_profile */
@@ -1932,7 +1927,7 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
19321927

19331928
profile->ll_ops = sdhci_msm_crypto_ops;
19341929
profile->max_dun_bytes_supported = 4;
1935-
profile->key_types_supported = BLK_CRYPTO_KEY_TYPE_RAW;
1930+
profile->key_types_supported = qcom_ice_get_supported_key_type(ice);
19361931
profile->dev = dev;
19371932

19381933
/*
@@ -2013,9 +2008,49 @@ static int sdhci_msm_ice_keyslot_evict(struct blk_crypto_profile *profile,
20132008
return qcom_ice_evict_key(msm_host->ice, slot);
20142009
}
20152010

2011+
static int sdhci_msm_ice_derive_sw_secret(struct blk_crypto_profile *profile,
2012+
const u8 *eph_key, size_t eph_key_size,
2013+
u8 sw_secret[BLK_CRYPTO_SW_SECRET_SIZE])
2014+
{
2015+
struct sdhci_msm_host *msm_host = sdhci_msm_host_from_crypto_profile(profile);
2016+
2017+
return qcom_ice_derive_sw_secret(msm_host->ice, eph_key, eph_key_size,
2018+
sw_secret);
2019+
}
2020+
2021+
static int sdhci_msm_ice_import_key(struct blk_crypto_profile *profile,
2022+
const u8 *raw_key, size_t raw_key_size,
2023+
u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE])
2024+
{
2025+
struct sdhci_msm_host *msm_host = sdhci_msm_host_from_crypto_profile(profile);
2026+
2027+
return qcom_ice_import_key(msm_host->ice, raw_key, raw_key_size, lt_key);
2028+
}
2029+
2030+
static int sdhci_msm_ice_generate_key(struct blk_crypto_profile *profile,
2031+
u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE])
2032+
{
2033+
struct sdhci_msm_host *msm_host = sdhci_msm_host_from_crypto_profile(profile);
2034+
2035+
return qcom_ice_generate_key(msm_host->ice, lt_key);
2036+
}
2037+
2038+
static int sdhci_msm_ice_prepare_key(struct blk_crypto_profile *profile,
2039+
const u8 *lt_key, size_t lt_key_size,
2040+
u8 eph_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE])
2041+
{
2042+
struct sdhci_msm_host *msm_host = sdhci_msm_host_from_crypto_profile(profile);
2043+
2044+
return qcom_ice_prepare_key(msm_host->ice, lt_key, lt_key_size, eph_key);
2045+
}
2046+
20162047
static const struct blk_crypto_ll_ops sdhci_msm_crypto_ops = {
20172048
.keyslot_program = sdhci_msm_ice_keyslot_program,
20182049
.keyslot_evict = sdhci_msm_ice_keyslot_evict,
2050+
.derive_sw_secret = sdhci_msm_ice_derive_sw_secret,
2051+
.import_key = sdhci_msm_ice_import_key,
2052+
.generate_key = sdhci_msm_ice_generate_key,
2053+
.prepare_key = sdhci_msm_ice_prepare_key,
20192054
};
20202055

20212056
#else /* CONFIG_MMC_CRYPTO */

0 commit comments

Comments
 (0)