Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efb3311d authored by Neeraj Soni's avatar Neeraj Soni Committed by Gerrit - the friendly Code Review server
Browse files

security: pfe: Set DUN size accroding to file system and storage type



EXT4 FS and F2FS has different way of setting Data Unit Number (DUN)
size value for UFS and eMMC storage devices. EXT4 FS uses sector number
while F2FS uses inode|pgidx. Check Storage and file system type
before setting the DUN value in Inline Crypto Engine (ICE).

Change-Id: If822863893fc0725a5ff0410e7418c352ad70fc1
Signed-off-by: default avatarNeeraj Soni <neersoni@codeaurora.org>
parent d1255832
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -49,6 +49,18 @@ struct ice_data_setting {
	bool				encr_bypass;
};

/* MSM ICE Crypto Data Unit of target DUN of Transfer Request */
enum ice_crypto_data_unit {
	ICE_CRYPTO_DATA_UNIT_512_B          = 0,
	ICE_CRYPTO_DATA_UNIT_1_KB           = 1,
	ICE_CRYPTO_DATA_UNIT_2_KB           = 2,
	ICE_CRYPTO_DATA_UNIT_4_KB           = 3,
	ICE_CRYPTO_DATA_UNIT_8_KB           = 4,
	ICE_CRYPTO_DATA_UNIT_16_KB          = 5,
	ICE_CRYPTO_DATA_UNIT_32_KB          = 6,
	ICE_CRYPTO_DATA_UNIT_64_KB          = 7,
};

typedef void (*ice_error_cb)(void *, u32 error);

struct qcom_ice_variant_ops *qcom_ice_get_variant_ops(struct device_node *node);
+14 −6
Original line number Diff line number Diff line
@@ -75,7 +75,9 @@ typedef int (*pfk_parse_inode_type)(const struct bio *bio,
	const struct inode *inode,
	struct pfk_key_info *key_info,
	enum ice_cryto_algo_mode *algo,
	bool *is_pfe);
	bool *is_pfe,
	unsigned int *data_unit,
	const char *storage_type);

typedef bool (*pfk_allow_merge_bio_type)(const struct bio *bio1,
	const struct bio *bio2, const struct inode *inode1,
@@ -281,21 +283,24 @@ bool pfe_is_inode_filesystem_type(const struct inode *inode,
static int pfk_get_key_for_bio(const struct bio *bio,
		struct pfk_key_info *key_info,
		enum ice_cryto_algo_mode *algo_mode,
		bool *is_pfe)
		bool *is_pfe, unsigned int *data_unit)
{
	const struct inode *inode;
	enum pfe_type which_pfe;
	const struct blk_encryption_key *key;
	char *s_type = NULL;

	inode = pfk_bio_get_inode(bio);
	which_pfe = pfk_get_pfe_type(inode);
	s_type = (char *)pfk_kc_get_storage_type();

	if (which_pfe != INVALID_PFE) {
		/* Encrypted file; override ->bi_crypt_key */
		pr_debug("parsing inode %lu with PFE type %d\n",
			 inode->i_ino, which_pfe);
		return (*(pfk_parse_inode_ftable[which_pfe]))
				(bio, inode, key_info, algo_mode, is_pfe);
				(bio, inode, key_info, algo_mode, is_pfe,
					data_unit, (const char *)s_type);
	}

	/*
@@ -348,6 +353,7 @@ int pfk_load_key_start(const struct bio *bio,
	struct pfk_key_info key_info = {NULL, NULL, 0, 0};
	enum ice_cryto_algo_mode algo_mode = ICE_CRYPTO_ALGO_MODE_AES_XTS;
	enum ice_crpto_key_size key_size_type = 0;
	unsigned int data_unit = 1 << ICE_CRYPTO_DATA_UNIT_512_B;
	u32 key_index = 0;

	if (!is_pfe) {
@@ -370,7 +376,8 @@ int pfk_load_key_start(const struct bio *bio,
		return -EINVAL;
	}

	ret = pfk_get_key_for_bio(bio, &key_info, &algo_mode, is_pfe);
	ret = pfk_get_key_for_bio(bio, &key_info, &algo_mode, is_pfe,
					&data_unit);

	if (ret != 0)
		return ret;
@@ -380,7 +387,8 @@ int pfk_load_key_start(const struct bio *bio,
		return ret;

	ret = pfk_kc_load_key_start(key_info.key, key_info.key_size,
			key_info.salt, key_info.salt_size, &key_index, async);
			key_info.salt, key_info.salt_size, &key_index, async,
			data_unit);
	if (ret) {
		if (ret != -EBUSY && ret != -EAGAIN)
			pr_err("start: could not load key into pfk key cache, error %d\n",
@@ -431,7 +439,7 @@ int pfk_load_key_end(const struct bio *bio, bool *is_pfe)
	if (!pfk_is_ready())
		return -ENODEV;

	ret = pfk_get_key_for_bio(bio, &key_info, NULL, is_pfe);
	ret = pfk_get_key_for_bio(bio, &key_info, NULL, is_pfe, NULL);
	if (ret != 0)
		return ret;

+16 −1
Original line number Diff line number Diff line
@@ -141,7 +141,9 @@ int pfk_ext4_parse_inode(const struct bio *bio,
	const struct inode *inode,
	struct pfk_key_info *key_info,
	enum ice_cryto_algo_mode *algo,
	bool *is_pfe)
	bool *is_pfe,
	unsigned int *data_unit,
	const char *storage_type)
{
	int ret = 0;

@@ -155,6 +157,19 @@ int pfk_ext4_parse_inode(const struct bio *bio,
	 */
	*is_pfe = true;

	/* Update dun based upon storage type.
	 * For ext4 FS UFS has 4k dun whereas eMMC
	 * uses 512Byte dun.
	 */
	if (storage_type && data_unit) {
		if (!memcmp(storage_type, "ufs", strlen("ufs")))
			*data_unit = 1 << ICE_CRYPTO_DATA_UNIT_4_KB;
		else if (!memcmp(storage_type, "sdcc", strlen("sdcc")))
			*data_unit = 1 << ICE_CRYPTO_DATA_UNIT_512_B;
		else
			return -EINVAL;
	}

	if (!pfk_ext4_is_ready())
		return -ENODEV;

+3 −1
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ int pfk_ext4_parse_inode(const struct bio *bio,
	const struct inode *inode,
	struct pfk_key_info *key_info,
	enum ice_cryto_algo_mode *algo,
	bool *is_pfe);
	bool *is_pfe,
	unsigned int *data_unit,
	const char *storage_type);

bool pfk_ext4_allow_merge_bio(const struct bio *bio1,
	const struct bio *bio2, const struct inode *inode1,
+15 −1
Original line number Diff line number Diff line
@@ -116,7 +116,9 @@ int pfk_f2fs_parse_inode(const struct bio *bio,
		const struct inode *inode,
		struct pfk_key_info *key_info,
		enum ice_cryto_algo_mode *algo,
		bool *is_pfe)
		bool *is_pfe,
		unsigned int *data_unit,
		const char *storage_type)
{
	int ret = 0;

@@ -130,6 +132,18 @@ int pfk_f2fs_parse_inode(const struct bio *bio,
	 */
	*is_pfe = true;

	/* Update the dun based upon storage type.
	 * Right now both UFS and eMMC storage uses 4KB dun
	 * for F2FS
	 */
	if (storage_type && data_unit) {
		if (!memcmp(storage_type, "ufs", strlen("ufs")) ||
			!memcmp(storage_type, "sdcc", strlen("sdcc")))
			*data_unit = 1 << ICE_CRYPTO_DATA_UNIT_4_KB;
		else
			return -EINVAL;
	}

	if (!pfk_f2fs_is_ready())
		return -ENODEV;

Loading