All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jorge Ramirez-Ortiz <jorge@foundries.io>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] drivers: optee: rpmb: fix returning CID to TEE
Date: Mon, 18 Nov 2019 12:18:27 +0100	[thread overview]
Message-ID: <f6f123c2-bf26-c381-e86b-4613e3eea6b9@foundries.io> (raw)
In-Reply-To: <CAHUa44FLh2TdScLEF05URW4fz9799YVhkTJYpnLWSuaJbokCTQ@mail.gmail.com>

On 11/18/19 10:36 AM, Jens Wiklander wrote:
> Hi Jorge,


hey!

>
> On Fri, Nov 15, 2019 at 10:37 PM Jorge Ramirez-Ortiz <jorge@foundries.io> wrote:
>> 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]);
>> +
> So it seems to be a byte order issue. I can't find the place in the
> Linux kernel (or in tee-supplicant) where the corresponding byte
> swapping is done. Have you been able to find it or you just tried to
> swap the bytes and it seemed to work?


I compared against the full CID output from Linux and noticed that in
order to match that exact same output this swap seemed to be required. I
didnt dig any deeper since a similar swap operation is done on other
-different - values returned from U-boot to OP-TEE.


>
> I'm not yet convinced that be32_to_cpu() is the correct function here.
> OP-TEE masks out a few fields from the CID when deriving the key:


sure but isnt that a different matter?

AFAICS U-boot should be providing the same CID than Linux does, and
whatever OP-TEE might be masking out on the receiving end is orthogonal
to such value, isnt it? maybe I am not understanding your point?


>
> CID is a uint8_t[16] here
>         /*
>          * PRV/CRC would be changed when doing eMMC FFU
>          * The following fields should be masked off when deriving RPMB key
>          *
>          * CID [55: 48]: PRV (Product revision)
>          * CID [07: 01]: CRC (CRC7 checksum)
>          * CID [00]: not used
>          */
>
> Will this work as expected on a big endian machine?
>
> Cheers,
> Jens
>
>>         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
>>

  reply	other threads:[~2019-11-18 11:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f6f123c2-bf26-c381-e86b-4613e3eea6b9@foundries.io \
    --to=jorge@foundries.io \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.