All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] drivers: optee: rpmb: fix returning CID to TEE
@ 2019-11-15 21:37 Jorge Ramirez-Ortiz
  2019-11-18  9:36 ` Jens Wiklander
  0 siblings, 1 reply; 17+ messages in thread
From: Jorge Ramirez-Ortiz @ 2019-11-15 21:37 UTC (permalink / raw)
  To: u-boot

The MMC CID value is one of the input parameters to unequivocally
provision the the RPMB key.

Before this patch, the value returned by the mmc driver in the Linux
kernel differs from the one returned by uboot to optee.

This means that if Linux provisions the RPMB key, uboot wont be able
to access it (and the other way around).

Fix it so both uboot and linux can access the RPMB partition
independently of who provisions the key.

Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io>
---
 drivers/tee/optee/rpmb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
index 955155b3f8..5dbb1eae4a 100644
--- a/drivers/tee/optee/rpmb.c
+++ b/drivers/tee/optee/rpmb.c
@@ -98,6 +98,7 @@ static struct mmc *get_mmc(struct optee_private *priv, int dev_id)
 static u32 rpmb_get_dev_info(u16 dev_id, struct rpmb_dev_info *info)
 {
 	struct mmc *mmc = find_mmc_device(dev_id);
+	int i;
 
 	if (!mmc)
 		return TEE_ERROR_ITEM_NOT_FOUND;
@@ -105,7 +106,9 @@ static u32 rpmb_get_dev_info(u16 dev_id, struct rpmb_dev_info *info)
 	if (!mmc->ext_csd)
 		return TEE_ERROR_GENERIC;
 
-	memcpy(info->cid, mmc->cid, sizeof(info->cid));
+	for (i = 0; i < ARRAY_SIZE(mmc->cid); i++)
+		((u32 *) info->cid)[i] = be32_to_cpu(mmc->cid[i]);
+
 	info->rel_wr_sec_c = mmc->ext_csd[222];
 	info->rpmb_size_mult = mmc->ext_csd[168];
 	info->ret_code = RPMB_CMD_GET_DEV_INFO_RET_OK;
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread
* [U-Boot] [PATCH] drivers: optee: rpmb: fix returning CID to TEE
@ 2019-11-26 16:19 Jorge Ramirez-Ortiz
  2019-11-27  7:53 ` Jens Wiklander
  2019-12-05 22:09 ` Tom Rini
  0 siblings, 2 replies; 17+ messages in thread
From: Jorge Ramirez-Ortiz @ 2019-11-26 16:19 UTC (permalink / raw)
  To: u-boot

The mmc CID value is one of the input parameters used to provision the
RPMB key. The trusted execution environment expects this value to be
specified in big endian format.

Before this fix, on little endian systems, the value returned by the
linux kernel mmc driver differed from the one returned by u-boot.
This meant that if linux provisioned the RPMB key, u-boot would not
have access to the partition (and the other way around).

Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io>
---
 drivers/tee/optee/rpmb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
index 955155b3f8..cf1ce77e6e 100644
--- a/drivers/tee/optee/rpmb.c
+++ b/drivers/tee/optee/rpmb.c
@@ -98,6 +98,7 @@ static struct mmc *get_mmc(struct optee_private *priv, int dev_id)
 static u32 rpmb_get_dev_info(u16 dev_id, struct rpmb_dev_info *info)
 {
 	struct mmc *mmc = find_mmc_device(dev_id);
+	int i;
 
 	if (!mmc)
 		return TEE_ERROR_ITEM_NOT_FOUND;
@@ -105,7 +106,9 @@ static u32 rpmb_get_dev_info(u16 dev_id, struct rpmb_dev_info *info)
 	if (!mmc->ext_csd)
 		return TEE_ERROR_GENERIC;
 
-	memcpy(info->cid, mmc->cid, sizeof(info->cid));
+	for (i = 0; i < ARRAY_SIZE(mmc->cid); i++)
+		((u32 *) info->cid)[i] = cpu_to_be32(mmc->cid[i]);
+
 	info->rel_wr_sec_c = mmc->ext_csd[222];
 	info->rpmb_size_mult = mmc->ext_csd[168];
 	info->ret_code = RPMB_CMD_GET_DEV_INFO_RET_OK;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-12-05 22:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-15 21:37 [U-Boot] [PATCH] drivers: optee: rpmb: fix returning CID to TEE Jorge Ramirez-Ortiz
2019-11-18  9:36 ` Jens Wiklander
2019-11-18 11:18   ` Jorge Ramirez-Ortiz
2019-11-18 12:42     ` Jens Wiklander
2019-11-18 13:18       ` Jorge Ramirez-Ortiz
2019-11-19  9:02         ` Jens Wiklander
2019-11-19 11:53           ` Jorge Ramirez-Ortiz
2019-11-19 17:21             ` Jorge Ramirez-Ortiz
2019-11-20  7:20               ` Jens Wiklander
2019-11-20  8:21                 ` Jorge Ramirez-Ortiz
2019-11-20 10:33                   ` Jens Wiklander
2019-11-26  8:22                     ` Jorge
2019-11-26 11:46                       ` Jens Wiklander
2019-11-26 15:41                         ` Jorge
2019-11-26 16:19 Jorge Ramirez-Ortiz
2019-11-27  7:53 ` Jens Wiklander
2019-12-05 22:09 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.