Re: [PATCH v1 2/2] ufs: rpmb: use a fixed-length RPMB dev_id

Jens Wiklander via OP-TEE <[email protected]> Fri, 17 Jul 2026 11:38:31 +0200
Newsgroups org.trustedfirmware.lists.op-tee,org.kernel.vger.linux-kernel,org.kernel.vger.linux-scsi
Message-ID <CAGgiveXtErFjDgxN9reR7s705U3wnnH65c4Su06ZQz_7EYwzuA@mail.gmail.com>
Hi Jorge,

On Thu, Jul 16, 2026 at 10:37=E2=80=AFAM Jorge Ramirez-Ortiz
<[email protected]> wrote:
>
> The RPMB authentication key is derived from the dev_id handed to the
> RPMB subsystem. OP-TEE implements the eMMC RPMB flow, where the dev_id
> is the eMMC CID, a fixed 16-byte value, and it derives the key on that
> assumption.
>
> The UFS RPMB id built here is "<device_id>-R<region>", which is variable
> length and longer than 16 bytes. Passing it verbatim would tie the
> derived key to a length OP-TEE does not expect and diverge from the
> fixed-CID eMMC ABI, requiring OP-TEE to be taught about variable-length
> UFS ids.

Yes, if it's possible, It's nice to avoid that.

>
> Hash the UFS id into a fixed 16-byte dev_id with blake2s instead. This
> keeps the derived key stable and unique per region while matching the
> eMMC CID layout OP-TEE relies on, so the key-derivation ABI stays
> identical and no OP-TEE change is needed.
>
> Signed-off-by: Jorge Ramirez-Ortiz <[email protected]>
> ---
>  drivers/ufs/core/ufs-rpmb.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ufs/core/ufs-rpmb.c b/drivers/ufs/core/ufs-rpmb.c
> index d0c7ea7a36f4..b800871269bb 100644
> --- a/drivers/ufs/core/ufs-rpmb.c
> +++ b/drivers/ufs/core/ufs-rpmb.c
> @@ -10,6 +10,7 @@
>   *     Can Guo <[email protected]>
>   */
>
> +#include <crypto/blake2s.h>
>  #include <linux/module.h>
>  #include <linux/device.h>
>  #include <linux/kernel.h>
> @@ -21,6 +22,7 @@
>  #include <linux/unaligned.h>
>  #include "ufshcd-priv.h"
>
> +#define UFS_RPMB_ID_LEN                        16      /* Match eMMC CID=
 Length */
>  #define UFS_RPMB_SEC_PROTOCOL          0xEC    /* JEDEC UFS application =
*/
>  #define UFS_RPMB_SEC_PROTOCOL_ID       0x01    /* JEDEC UFS RPMB protoco=
l ID, CDB byte3 */
>
> @@ -154,6 +156,7 @@ int ufs_rpmb_probe(struct ufs_hba *hba)
>  {
>         struct ufs_rpmb_dev *ufs_rpmb, *it, *tmp;
>         struct rpmb_dev *rdev;
> +       char *dev_id =3D NULL;
>         char *cid =3D NULL;
>         int region;
>         u32 cap;
> @@ -213,8 +216,17 @@ int ufs_rpmb_probe(struct ufs_hba *hba)
>                         goto err_out;
>                 }
>
> -               descr.dev_id =3D cid;
> -               descr.dev_id_len =3D strlen(cid);
> +               dev_id =3D kzalloc(UFS_RPMB_ID_LEN, GFP_KERNEL);
> +               if (!dev_id) {
> +                       device_unregister(&ufs_rpmb->dev);
> +                       ret =3D -ENOMEM;
> +                       goto err_out;
> +               }
> +
> +               blake2s(NULL, 0, cid, strlen(cid), dev_id, UFS_RPMB_ID_LE=
N);
> +
> +               descr.dev_id =3D dev_id;
> +               descr.dev_id_len =3D UFS_RPMB_ID_LEN;

This change will break current users of this interface, if there are
any. There are currently no upstream users in OP-TEE since you're
adding that with https://github.com/OP-TEE/optee_os/pull/7881, but I
suppose that's not the only use case.

Cheers,
Jens


>                 descr.capacity =3D cap;
>
>                 /* Register RPMB device */
> @@ -228,6 +240,8 @@ int ufs_rpmb_probe(struct ufs_hba *hba)
>
>                 kfree(cid);
>                 cid =3D NULL;
> +               kfree(dev_id);
> +               dev_id =3D NULL;
>
>                 ufs_rpmb->rdev =3D rdev;
>                 ufs_rpmb->region_id =3D region;
> @@ -240,6 +254,7 @@ int ufs_rpmb_probe(struct ufs_hba *hba)
>         return 0;
>  err_out:
>         kfree(cid);
> +       kfree(dev_id);
>         list_for_each_entry_safe(it, tmp, &hba->rpmbs, node) {
>                 list_del(&it->node);
>                 device_unregister(&it->dev);
> --
> 2.54.0
>