diff mbox series

[U-Boot] drivers: optee: rpmb: fix returning CID to TEE

Message ID 20191126161934.7826-1-jorge@foundries.io
State Accepted
Commit 2464b229b5ab281d8698aa0f4d4de6d4d3fabf7d
Delegated to: Tom Rini
Headers show
Series [U-Boot] drivers: optee: rpmb: fix returning CID to TEE | expand

Commit Message

Jorge Ramirez-Ortiz, Foundries Nov. 26, 2019, 4:19 p.m. UTC
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(-)

Comments

Jens Wiklander Nov. 27, 2019, 7:53 a.m. UTC | #1
On Tue, Nov 26, 2019 at 05:19:34PM +0100, Jorge Ramirez-Ortiz wrote:
> 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>

Looks good to me:
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>

Thanks,
Jens

> ---
>  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
>
Tom Rini Dec. 5, 2019, 10:09 p.m. UTC | #2
On Tue, Nov 26, 2019 at 05:19:34PM +0100, Jorge Ramirez-Ortiz wrote:

> 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>
> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

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;