Skip to contentSkip to conversation

Replay Protected Memory Block (RPMB) driver

RFC PATCH In review Shyam Saini 9 participants 21 messages Jul 22, 2023 – Aug 24, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Replay Protected Memory Block (RPMB) driver

Hi everyone,

This is yet another attempt to come up with an RPMB API for the kernel. This patch is based on patch 1 of last submission except few minor changes. The last discussion of this was in the thread:

Subject: [PATCH v2 1/4] rpmb: add Replay Protected Memory Block (RPMB) subsystem
Date: Tue, 5 Apr 2022 10:37:56 +0100 [thread overview]
Message-ID: <[email protected]>

The patch provides a simple RPMB driver. This is a RFC version and this single driver can't be used by its own. It would require further work to make use of API's provided by this driver.

Changes since the last posting:
drop RPMB char driver
drop virtio rpmb frontend driver
drop rpmb: add RPBM access tool
Rename get_write_count to get_write_counter Make return type for rpmb_set_key() function explicit

Alex Bennée (1):
rpmb: add Replay Protected Memory Block (RPMB) driver

 MAINTAINERS           |   7 +
 drivers/Kconfig       |   1 +
 drivers/Makefile      |   2 +
 drivers/rpmb/Kconfig  |  11 ++
 drivers/rpmb/Makefile |   7 +
 drivers/rpmb/core.c   | 439 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/rpmb.h  | 182 +++++++++++++++++
 7 files changed, 649 insertions(+)
 create mode 100644 drivers/rpmb/Kconfig
 create mode 100644 drivers/rpmb/Makefile
 create mode 100644 drivers/rpmb/core.c
 create mode 100644 include/linux/rpmb.h
Signature · 1 line
2.34.1
#1 lore raw

RFC PATCH 1/1 rpmb: add Replay Protected Memory Block (RPMB) driver

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

* program_key - a one time operation for setting up a new device
* get_capacity - introspect the device capacity
* get_write_counter - check the write counter
* write_blocks - write a series of blocks to the RPMB device
* read_blocks - read a series of blocks from the RPMB device

The detailed operation of implementing the access is left to the TEE device driver itself.

The framing details and HW specific bits (JDEC vs NVME frames) are left to the lower level TEE driver to worry about.

Without kernel fast path to RPMB access doesn't work when IMA try to extend ftpm's PCR registers.

This fast-path would require additional work in linux optee driver and as well as in MMC driver.

[1] https://lore.kernel.org/lkml/20220405093759.1126835-2-alex.bennee(a)linaro.org/
[2] https://lore.kernel.org/linux-mmc/1478548394-8184-2-git-send-email-tomas.winkler(a)intel.com/
[3] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Cc Tomas Winkler <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Sumit Garg <[email protected]>
Cc Tyler Hicks <[email protected]>
Cc Srivatsa S. Bhat (Microsoft) <[email protected]>
Cc Paul Moore <[email protected]>
Cc Allen Pais <[email protected]>
---
 MAINTAINERS           |   7 +
 drivers/Kconfig       |   1 +
 drivers/Makefile      |   2 +
 drivers/rpmb/Kconfig  |  11 ++
 drivers/rpmb/Makefile |   7 +
 drivers/rpmb/core.c   | 439 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/rpmb.h  | 182 +++++++++++++++++
 7 files changed, 649 insertions(+)
 create mode 100644 drivers/rpmb/Kconfig
 create mode 100644 drivers/rpmb/Makefile
 create mode 100644 drivers/rpmb/core.c
 create mode 100644 include/linux/rpmb.h
MAINTAINERS +7 -0
index 139106909db6..52d2020ba1d8 100644
@@ -18480,6 +18480,13 @@ T:	git git://linuxtv.org/media_tree.git
 F:	Documentation/devicetree/bindings/media/allwinner,sun8i-a83t-de2-rotate.yaml
 F:	drivers/media/platform/sunxi/sun8i-rotate/
 
+RPMB SUBSYSTEM
+M:	?
+L:	linux-kernel(a)vger.kernel.org
+S:	Supported
+F:	drivers/rpmb/*
+F:	include/linux/rpmb.h
+
 RPMSG TTY DRIVER
 M:	Arnaud Pouliquen <[email protected]>
 L:	linux-remoteproc(a)vger.kernel.org
drivers/Kconfig +1 -0
index 514ae6b24cb2..9db924f85e07 100644
@@ -242,5 +242,6 @@ source "drivers/peci/Kconfig"
 source "drivers/hte/Kconfig"
 
 source "drivers/cdx/Kconfig"
+source "drivers/rpmb/Kconfig"
 
 endmenu
drivers/Makefile +2 -0
index 7241d80a7b29..f8f8d9212567 100644
@@ -195,3 +195,5 @@ obj-$(CONFIG_PECI)		+= peci/
 obj-$(CONFIG_HTE)		+= hte/
 obj-$(CONFIG_DRM_ACCEL)		+= accel/
 obj-$(CONFIG_CDX_BUS)		+= cdx/
+obj-$(CONFIG_RPMB)             += rpmb/
+
drivers/rpmb/Kconfig new file +11 -0
new file mode 100644
index 000000000000..f2a9ebdc4435
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2015-2019, Intel Corporation.
+
+config RPMB
+	tristate "RPMB partition interface"
+	help
+	  Unified RPMB partition interface for RPMB capable devices such as
+          eMMC and UFS. Provides interface for in kernel security controllers to
+	  access RPMB partition.
+
+	  If unsure, select N.
drivers/rpmb/Makefile new file +7 -0
new file mode 100644
index 000000000000..24d4752a9a53
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2015-2019, Intel Corporation.
+
+obj-$(CONFIG_RPMB) += rpmb.o
+rpmb-objs += core.o
+
+ccflags-y += -D__CHECK_ENDIAN__
drivers/rpmb/core.c new file +439 -0

439 lines not on this page · raw message

include/linux/rpmb.h new file +182 -0

182 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Hi--

Quoted 6 lines · Shyam Saini
drivers/rpmb/Kconfig new file +0 -0
new file mode 100644
index 000000000000..f2a9ebdc4435

drivers/rpmb/Kconfig line 8

Quoted 8 lines
drivers/rpmb/Kconfig new file +8 -0
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2015-2019, Intel Corporation.
+
+config RPMB
+	tristate "RPMB partition interface"
+	help
+	  Unified RPMB partition interface for RPMB capable devices such as
+          eMMC and UFS. Provides interface for in kernel security controllers to

Indent the line above with one tab + 2 spaces instead of many spaces.

drivers/rpmb/Kconfig line 11

Quoted 3 lines
drivers/rpmb/Kconfig new file +3 -0
+	  access RPMB partition.
+
+	  If unsure, select N.

Do we want a separate subdir in drivers/ for various "misc" drivers? with only one driver in it?

Will there be other drivers in rpmb?

Thanks.

Signature · 1 line
~Randy
#3 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Hi Randy,

Thank you for the reviews.

Quoted 19 lines

Hi--

Quoted 6 lines · Shyam Saini
drivers/rpmb/Kconfig new file +0 -0
new file mode 100644
index 000000000000..f2a9ebdc4435

drivers/rpmb/Kconfig line 8

Quoted 8 lines
drivers/rpmb/Kconfig new file +8 -0
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2015-2019, Intel Corporation.
+
+config RPMB
+	tristate "RPMB partition interface"
+	help
+	  Unified RPMB partition interface for RPMB capable devices such as
+          eMMC and UFS. Provides interface for in kernel security controllers to

Indent the line above with one tab + 2 spaces instead of many spaces.

Quoted 9 lines

drivers/rpmb/Kconfig line 11

Quoted 3 lines
drivers/rpmb/Kconfig new file +3 -0
+	  access RPMB partition.
+
+	  If unsure, select N.

Do we want a separate subdir in drivers/ for various "misc" drivers? with only one driver in it?

Will there be other drivers in rpmb?

There may be others as the usage of rpmb driver grow over time but for now, this is the only driver.
Should i keep it like this ?[A

Thanks,
Shyam

#4 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

In reply to Shyam Saini
Quoted 14 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

Quoted 8 lines

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

Quoted 27 lines

* program_key - a one time operation for setting up a new device
* get_capacity - introspect the device capacity
* get_write_counter - check the write counter
* write_blocks - write a series of blocks to the RPMB device
* read_blocks - read a series of blocks from the RPMB device

The detailed operation of implementing the access is left to the TEE device driver itself.

The framing details and HW specific bits (JDEC vs NVME frames) are left to the lower level TEE driver to worry about.

Without kernel fast path to RPMB access doesn't work when IMA try to extend ftpm's PCR registers.

This fast-path would require additional work in linux optee driver and as well as in MMC driver.

[1] https://lore.kernel.org/lkml/20220405093759.1126835-2-alex.bennee(a)linaro.org/
[2] https://lore.kernel.org/linux-mmc/1478548394-8184-2-git-send-email-tomas.winkler(a)intel.com/
[3] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

[...]

Quoted 42 lines
drivers/rpmb/core.c new file +42 -0
+/**
+ * rpmb_dev_find_device() - return first matching rpmb device
+ * @data: data for the match function
+ * @match: the matching function
+ *
+ * Return: matching rpmb device or NULL on failure
+ */
+static
+struct rpmb_dev *rpmb_dev_find_device(const void *data,
+                                     int (*match)(struct device *dev,
+                                                  const void *data))
+{
+       struct device *dev;
+
+       dev = class_find_device(&rpmb_class, NULL, data, match);
+
+       return dev ? to_rpmb_dev(dev) : NULL;
+}
+
+struct device_with_target {
+       const struct device *dev;
+       u8 target;
+};
+
+static int match_by_parent(struct device *dev, const void *data)
+{
+       const struct device_with_target *d = data;
+       struct rpmb_dev *rdev = to_rpmb_dev(dev);
+
+       return (d->dev && dev->parent == d->dev && rdev->target == d->target);
+}
+
+/**
+ * rpmb_dev_find_by_device() - retrieve rpmb device from the parent device
+ * @parent: parent device of the rpmb device
+ * @target: RPMB target/region within the physical device
+ *
+ * Return: NULL if there is no rpmb device associated with the parent device
+ */
+struct rpmb_dev *rpmb_dev_find_by_device(struct device *parent, u8 target)
+{
+       struct device_with_target t;

drivers/rpmb/core.c line 271

Quoted 10 lines
drivers/rpmb/core.c new file +10 -0
+
+       if (!parent)
+               return NULL;
+
+       t.dev = parent;
+       t.target = target;
+
+       return rpmb_dev_find_device(&t, match_by_parent);
+}
+EXPORT_SYMBOL_GPL(rpmb_dev_find_by_device);

Is this what the TEE driver would be calling to find the rpmb device/partition?

Quoted 5 lines
drivers/rpmb/core.c new file +5 -0
+
+/**
+ * rpmb_dev_unregister() - unregister RPMB partition from the RPMB subsystem
+ * @rdev: the rpmb device to unregister
+ * Return:

drivers/rpmb/core.c line 286

Quoted 10 lines
drivers/rpmb/core.c new file +10 -0
+ * *        0 on success
+ * *        -EINVAL on wrong parameters
+ */
+int rpmb_dev_unregister(struct rpmb_dev *rdev)
+{
+       if (!rdev)
+               return -EINVAL;
+
+       mutex_lock(&rdev->lock);
+       rpmb_cdev_del(rdev);

I can't find the function above. I guess it should be included as a part of the patch too?

Quoted 8 lines
drivers/rpmb/core.c new file +8 -0
+       device_del(&rdev->dev);
+       mutex_unlock(&rdev->lock);
+
+       rpmb_dev_put(rdev);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(rpmb_dev_unregister);

[...]

Quoted 43 lines
drivers/rpmb/core.c new file +43 -0
+/**
+ * rpmb_dev_register - register RPMB partition with the RPMB subsystem
+ * @dev: storage device of the rpmb device
+ * @target: RPMB target/region within the physical device
+ * @ops: device specific operations
+ *
+ * Return: a pointer to rpmb device
+ */
+struct rpmb_dev *rpmb_dev_register(struct device *dev, u8 target,
+                                  const struct rpmb_ops *ops)
+{
+       struct rpmb_dev *rdev;
+       int id;
+       int ret;
+
+       if (!dev || !ops)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->program_key)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->get_capacity)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->get_write_counter)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->write_blocks)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->read_blocks)
+               return ERR_PTR(-EINVAL);
+
+       rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
+       if (!rdev)
+               return ERR_PTR(-ENOMEM);
+
+       id = ida_simple_get(&rpmb_ida, 0, 0, GFP_KERNEL);
+       if (id < 0) {
+               ret = id;
+               goto exit;
+       }
+

drivers/rpmb/core.c line 400

Quoted 10 lines
drivers/rpmb/core.c new file +10 -0
+       mutex_init(&rdev->lock);
+       rdev->ops = ops;
+       rdev->id = id;
+       rdev->target = target;
+
+       dev_set_name(&rdev->dev, "rpmb%d", id);
+       rdev->dev.class = &rpmb_class;
+       rdev->dev.parent = dev;
+
+       rpmb_cdev_prepare(rdev);

Ditto.

drivers/rpmb/core.c line 406

Quoted 6 lines
drivers/rpmb/core.c new file +6 -0
+
+       ret = device_register(&rdev->dev);
+       if (ret)
+               goto exit;
+
+       rpmb_cdev_add(rdev);

Ditto.

drivers/rpmb/core.c line 419

Quoted 13 lines
drivers/rpmb/core.c new file +13 -0
+
+       dev_dbg(&rdev->dev, "registered device\n");
+
+       return rdev;
+
+exit:
+       if (id >= 0)
+               ida_simple_remove(&rpmb_ida, id);
+       kfree(rdev);
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(rpmb_dev_register);
+

[...]

Kind regards
Uffe

#5 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb, but in case if a system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Sumit, do you have suggestions for this ?

Quoted 76 lines
Quoted 27 lines

* program_key - a one time operation for setting up a new device
* get_capacity - introspect the device capacity
* get_write_counter - check the write counter
* write_blocks - write a series of blocks to the RPMB device
* read_blocks - read a series of blocks from the RPMB device

The detailed operation of implementing the access is left to the TEE device driver itself.

The framing details and HW specific bits (JDEC vs NVME frames) are left to the lower level TEE driver to worry about.

Without kernel fast path to RPMB access doesn't work when IMA try to extend ftpm's PCR registers.

This fast-path would require additional work in linux optee driver and as well as in MMC driver.

[1] https://lore.kernel.org/lkml/20220405093759.1126835-2-alex.bennee(a)linaro.org/
[2] https://lore.kernel.org/linux-mmc/1478548394-8184-2-git-send-email-tomas.winkler(a)intel.com/
[3] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

[...]

Quoted 46 lines
drivers/rpmb/core.c new file +46 -0
+/**
+ * rpmb_dev_find_device() - return first matching rpmb device
+ * @data: data for the match function
+ * @match: the matching function
+ *
+ * Return: matching rpmb device or NULL on failure
+ */
+static
+struct rpmb_dev *rpmb_dev_find_device(const void *data,
+                                     int (*match)(struct device *dev,
+                                                  const void *data))
+{
+       struct device *dev;
+
+       dev = class_find_device(&rpmb_class, NULL, data, match);
+
+       return dev ? to_rpmb_dev(dev) : NULL;
+}
+
+struct device_with_target {
+       const struct device *dev;
+       u8 target;
+};
+
+static int match_by_parent(struct device *dev, const void *data)
+{
+       const struct device_with_target *d = data;
+       struct rpmb_dev *rdev = to_rpmb_dev(dev);
+
+       return (d->dev && dev->parent == d->dev && rdev->target == d->target);
+}
+
+/**
+ * rpmb_dev_find_by_device() - retrieve rpmb device from the parent device
+ * @parent: parent device of the rpmb device
+ * @target: RPMB target/region within the physical device
+ *
+ * Return: NULL if there is no rpmb device associated with the parent device
+ */
+struct rpmb_dev *rpmb_dev_find_by_device(struct device *parent, u8 target)
+{
+       struct device_with_target t;
+
+       if (!parent)
+               return NULL;
+
Quoted 8 lines

drivers/rpmb/core.c line 271

Quoted 6 lines
drivers/rpmb/core.c new file +6 -0
+       t.dev = parent;
+       t.target = target;
+
+       return rpmb_dev_find_device(&t, match_by_parent);
+}
+EXPORT_SYMBOL_GPL(rpmb_dev_find_by_device);

Is this what the TEE driver would be calling to find the rpmb device/partition?

yes, that's the idea.

Quoted 10 lines
Quoted 10 lines
drivers/rpmb/core.c new file +10 -0
+
+/**
+ * rpmb_dev_unregister() - unregister RPMB partition from the RPMB subsystem
+ * @rdev: the rpmb device to unregister
+ * Return:
+ * *        0 on success
+ * *        -EINVAL on wrong parameters
+ */
+int rpmb_dev_unregister(struct rpmb_dev *rdev)
+{
Quoted 8 lines

drivers/rpmb/core.c line 286

Quoted 5 lines
drivers/rpmb/core.c new file +5 -0
+       if (!rdev)
+               return -EINVAL;
+
+       mutex_lock(&rdev->lock);
+       rpmb_cdev_del(rdev);

I can't find the function above. I guess it should be included as a part of the patch too?

Sorry for the confusion, this is leftover from original version Will be removed in next iteration.

Quoted 58 lines
Quoted 8 lines
drivers/rpmb/core.c new file +8 -0
+       device_del(&rdev->dev);
+       mutex_unlock(&rdev->lock);
+
+       rpmb_dev_put(rdev);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(rpmb_dev_unregister);

[...]

Quoted 47 lines
drivers/rpmb/core.c new file +47 -0
+/**
+ * rpmb_dev_register - register RPMB partition with the RPMB subsystem
+ * @dev: storage device of the rpmb device
+ * @target: RPMB target/region within the physical device
+ * @ops: device specific operations
+ *
+ * Return: a pointer to rpmb device
+ */
+struct rpmb_dev *rpmb_dev_register(struct device *dev, u8 target,
+                                  const struct rpmb_ops *ops)
+{
+       struct rpmb_dev *rdev;
+       int id;
+       int ret;
+
+       if (!dev || !ops)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->program_key)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->get_capacity)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->get_write_counter)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->write_blocks)
+               return ERR_PTR(-EINVAL);
+
+       if (!ops->read_blocks)
+               return ERR_PTR(-EINVAL);
+
+       rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
+       if (!rdev)
+               return ERR_PTR(-ENOMEM);
+
+       id = ida_simple_get(&rpmb_ida, 0, 0, GFP_KERNEL);
+       if (id < 0) {
+               ret = id;
+               goto exit;
+       }
+
+       mutex_init(&rdev->lock);
+       rdev->ops = ops;
+       rdev->id = id;
+       rdev->target = target;
Quoted 8 lines

drivers/rpmb/core.c line 400

Quoted 6 lines
drivers/rpmb/core.c new file +6 -0
+
+       dev_set_name(&rdev->dev, "rpmb%d", id);
+       rdev->dev.class = &rpmb_class;
+       rdev->dev.parent = dev;
+
+       rpmb_cdev_prepare(rdev);

Ditto.

same as my last comment

Quoted 8 lines

drivers/rpmb/core.c line 406

Quoted 6 lines
drivers/rpmb/core.c new file +6 -0
+
+       ret = device_register(&rdev->dev);
+       if (ret)
+               goto exit;
+
+       rpmb_cdev_add(rdev);

Ditto.

same as above.

Quoted 7 lines
Quoted 7 lines
drivers/rpmb/core.c new file +7 -0
+
+       dev_dbg(&rdev->dev, "registered device\n");
+
+       return rdev;
+
+exit:
+       if (id >= 0)
Quoted 9 lines
Quoted 6 lines
drivers/rpmb/core.c new file +6 -0
+               ida_simple_remove(&rpmb_ida, id);
+       kfree(rdev);
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(rpmb_dev_register);
+

[...]

[1] https://source.denx.de/u-boot/u-boot/-/commit/4853ad3e13e21462a86e09caee4ea27ae68e764b

Best Regards,
Shyam

#6 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 6 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

Signature · 1 line
Jerome
#7 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 35 lines · Jerome Forissier
Quoted 31 lines · Shyam Saini

Hi Ulf,

Quoted 27 lines
Quoted 14 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

Quoted 8 lines

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

Quoted 6 lines
Quoted 6 lines

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

Quoted 9 lines
Quoted 4 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 8 lines
Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

-Sumit

Quoted 3 lines

--
Jerome

#8 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 42 lines · Sumit Garg
Quoted 39 lines · Jerome Forissier
Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

+1

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Quoted 7 lines
Quoted 4 lines

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

Another option is for OP-TEE to iterate over all RPMBs with a programmed key and test if the key OP-TEE would use works. That should avoid the problem of provisioning a device-unique secure DTB. I'd expect that the RPMB key is programmed by a trusted provisioning tool since allowing OP-TEE to program the RPMB key has never been secure, not unless the OP-TEE binary is rollback protected.

Cheers,
Jens

Quoted 6 lines

-Sumit

Quoted 3 lines

--
Jerome

#9 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 70 lines · Jens Wiklander
Quoted 42 lines · Sumit Garg
Quoted 39 lines · Jerome Forissier
Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

+1

Quoted 16 lines
Quoted 16 lines
Quoted 5 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

Another option is for OP-TEE to iterate over all RPMBs with a programmed key and test if the key OP-TEE would use works.

That would require intercepting OP-TEE RPMB frames such that any "write key" frame is blocked. As we don't want OP-TEE to occupy unprovisioned RPMB partitions.

Quoted 2 lines

That should
avoid the problem of provisioning a device-unique secure DTB.

Okay I see the scalability concerns. So how about instead we have a UFS/eMMC/NVMe controller specific boolean secure RPMB DT property?

Quoted 4 lines

I'd
expect that the RPMB key is programmed by a trusted provisioning tool since allowing OP-TEE to program the RPMB key has never been secure, not unless the OP-TEE binary is rollback protected.

Agree but any such RPMB key provisioning tool should either belong to OP-TEE, u-boot or Linux.

-Sumit

Quoted 10 lines

Cheers,
Jens

Quoted 6 lines

-Sumit

Quoted 3 lines

--
Jerome

#10 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

In reply to Jens Wiklander
Quoted 76 lines · Jens Wiklander
Quoted 42 lines · Sumit Garg
Quoted 39 lines · Jerome Forissier
Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

+1

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Quoted 7 lines
Quoted 4 lines

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

Quoted 6 lines

Another option is for OP-TEE to iterate over all RPMBs with a programmed key and test if the key OP-TEE would use works. That should avoid the problem of provisioning a device-unique secure DTB. I'd expect that the RPMB key is programmed by a trusted provisioning tool since allowing OP-TEE to program the RPMB key has never been secure, not unless the OP-TEE binary is rollback protected.

+1 to that. Overall we shound't 'trust' to do the programming. For example, in OP-TEE if you compile it with device programming capabilities, you can easily convince OP-TEE to send you the symmetric key by swapping the supplicant with a malicious application.

Thanks
/Ilias

Quoted 10 lines

Cheers,
Jens

Quoted 6 lines

-Sumit

Quoted 3 lines

--
Jerome

#11 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 85 lines · Ilias Apalodimas
Quoted 76 lines · Jens Wiklander
Quoted 42 lines · Sumit Garg
Quoted 39 lines · Jerome Forissier
Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

+1

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Quoted 7 lines
Quoted 4 lines

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

Quoted 6 lines

Another option is for OP-TEE to iterate over all RPMBs with a programmed key and test if the key OP-TEE would use works. That should avoid the problem of provisioning a device-unique secure DTB. I'd expect that the RPMB key is programmed by a trusted provisioning tool since allowing OP-TEE to program the RPMB key has never been secure, not unless the OP-TEE binary is rollback protected.

Quoted 5 lines

+1 to that. Overall we shound't 'trust' to do the programming. For example, in OP-TEE if you compile it with device programming capabilities, you can easily convince OP-TEE to send you the symmetric key by swapping the supplicant with a malicious application.

Agree, with your overall intent, that OP-TEE shouldn't expose RPMB key in plain form. But with suggested OP-TEE RPMB frames routing via kernel, tee-supplicant won't be used for RPMB accesses.

-Sumit

Quoted 12 lines

Thanks
/Ilias

Quoted 10 lines

Cheers,
Jens

Quoted 6 lines

-Sumit

Quoted 3 lines

--
Jerome

#12 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 94 lines
Quoted 85 lines · Ilias Apalodimas
Quoted 76 lines · Jens Wiklander
Quoted 42 lines · Sumit Garg
Quoted 39 lines · Jerome Forissier
Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

+1

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Quoted 7 lines
Quoted 4 lines

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

Quoted 6 lines

Another option is for OP-TEE to iterate over all RPMBs with a programmed key and test if the key OP-TEE would use works. That should avoid the problem of provisioning a device-unique secure DTB. I'd expect that the RPMB key is programmed by a trusted provisioning tool since allowing OP-TEE to program the RPMB key has never been secure, not unless the OP-TEE binary is rollback protected.

Quoted 5 lines

+1 to that. Overall we shound't 'trust' to do the programming. For example, in OP-TEE if you compile it with device programming capabilities, you can easily convince OP-TEE to send you the symmetric key by swapping the supplicant with a malicious application.

Quoted 3 lines

Agree, with your overall intent, that OP-TEE shouldn't expose RPMB key in plain form. But with suggested OP-TEE RPMB frames routing via kernel, tee-supplicant won't be used for RPMB accesses.

do we plan to disable access to RPMB devices, once we have this RPMB driver in place. User space tools like mmc-utils/nvme/ufs utils can still access RPMB and programme the key and should RPMB driver deny access to RPMB ?

#13 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 4 lines · Shyam Saini

do we plan to disable access to RPMB devices, once we have this RPMB driver in place. User space tools like mmc-utils/nvme/ufs utils can still access RPMB and programme the key and should RPMB driver deny access to RPMB ?

We don't break userspace. Just not. This is not an option.

The RPMB subsystem simply has to provide the rpmb character device the same way the MMC subsystem did, or provide an in-kernel backend to the MMC subsystem so that it can provide the same device. Whatever solution is best.

No deprecation and deletion and breaking userspace. Ever.

Yours,
Linus Walleij

#14 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 9 lines · Linus Walleij
Quoted 4 lines · Shyam Saini

do we plan to disable access to RPMB devices, once we have this RPMB driver in place. User space tools like mmc-utils/nvme/ufs utils can still access RPMB and programme the key and should RPMB driver deny access to RPMB ?

Quoted 9 lines

We don't break userspace. Just not. This is not an option.

The RPMB subsystem simply has to provide the rpmb character device the same way the MMC subsystem did, or provide an in-kernel backend to the MMC subsystem so that it can provide the same device. Whatever solution is best.

No deprecation and deletion and breaking userspace. Ever.

Agree, that's the golden rule of thumb we follow in kernel development. Also, we still need to allow cases where trusted provisioning user-space tools can program OP-TEE RPMB key during factory provisioning. And once that is provisioned, I don't think there is much harm in still exposing the RPMB device to user-space since it can't do anything malicious without access to OP-TEE RPMB key.

-Sumit

Quoted 2 lines

Yours,
Linus Walleij

#15 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

In reply to Jens Wiklander
Quoted 75 lines · Jens Wiklander
Quoted 42 lines · Sumit Garg
Quoted 39 lines · Jerome Forissier
Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

+1

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Quoted 7 lines
Quoted 4 lines

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

Quoted 6 lines

Another option is for OP-TEE to iterate over all RPMBs with a programmed key and test if the key OP-TEE would use works. That should avoid the problem of provisioning a device-unique secure DTB. I'd expect that the RPMB key is programmed by a trusted provisioning tool since allowing OP-TEE to program the RPMB key has never been secure, not unless the OP-TEE binary is rollback protected.

+1 if we can assume the same key won't be used for several devices, which is probably reasonable.

Quoted 10 lines

Cheers,
Jens

Quoted 6 lines

-Sumit

Quoted 3 lines

--
Jerome

#16 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

In reply to Sumit Garg

Hi Sumit,

Quoted 41 lines
Quoted 39 lines · Jerome Forissier
Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

I was looking into UFS/NVMe user-space utils, it seems we may have to adapt rpmb frame data structure in optee-os to to handle NVMe/UFS specific bits.

For nvme rpmb data frame, I think we would need an extra "target" member in rpmb data frame structure,
as NVMe can support upto 7 RPMB units, see [1] "struct rpmb_data_frame_t" UFS may support upto 3 or 4 RPMB regions.

So even if we use CID to uniquely identify RPMB device either from eMMC/NVMe/UFS, we still need identify which RPMB target/unit in case if the device is NVMe, and which RPMB region if the device UFS.

Also both NVMe/UFS utils have two extra RPMB operations implemented, Although new request/response operation than eMMC spec:
1) Authenticated Device Configuration Block Write
2) Authenticated Device Configuration Block Read

see [2] enum rpmb_request/response_type and [3]enum rpmb_op_type

do we need those implemented as well ?

Please let me know what you think about these.

[1] https://github.com/linux-nvme/nvme-cli/blob/master/nvme-rpmb.c#L252
[2] https://github.com/linux-nvme/nvme-cli/blob/master/nvme-rpmb.c#L230
[3] https://github.com/westerndigitalcorporation/ufs-utils/blob/dev/ufs_rpmb.c#L27

Quoted 27 lines
Quoted 9 lines
Quoted 4 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 8 lines
Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

-Sumit

Quoted 3 lines

--
Jerome

#17 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Quoted 66 lines · Shyam Saini

Hi Sumit,

Quoted 41 lines
Quoted 39 lines · Jerome Forissier
Quoted 35 lines · Shyam Saini

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

It would be better to have this OP-TEE use case fully implemented. So that we can justify it as a valid user for this proposed RPMB subsystem. If you are looking for any further suggestions then please let us know.

I was looking into UFS/NVMe user-space utils, it seems we may have to adapt rpmb frame data structure in optee-os to to handle NVMe/UFS specific bits.

For nvme rpmb data frame, I think we would need an extra "target" member in rpmb data frame structure,
as NVMe can support upto 7 RPMB units, see [1] "struct rpmb_data_frame_t" UFS may support upto 3 or 4 RPMB regions.

So even if we use CID to uniquely identify RPMB device either from eMMC/NVMe/UFS, we still need identify which RPMB target/unit in case if the device is NVMe, and which RPMB region if the device UFS.

Quoted 8 lines

Also both NVMe/UFS utils have two extra RPMB operations implemented, Although new request/response operation than eMMC spec:
1) Authenticated Device Configuration Block Write
2) Authenticated Device Configuration Block Read

see [2] enum rpmb_request/response_type and [3]enum rpmb_op_type

do we need those implemented as well ?

IMO, we should start with eMMC RPMB support first with OP-TEE. This is what OP-TEE currently supports. And later on we can extend that framework for UFS and NVMe RPMB.

We need to put extra care here regarding the eMMC RPMB ABI among OP-TEE and Linux kernel. It should be designed in a way that it is future compatible for UFS/NMVe. IOW, the bits that you have already discovered above.

Also, we have to be backwards compatible with eMMC RPMB ABI towards u-boot too since OP-TEE would use the same ABI whether it is towards Linux or u-boot.

-Sumit

Quoted 34 lines

Please let me know what you think about these.

[1] https://github.com/linux-nvme/nvme-cli/blob/master/nvme-rpmb.c#L252
[2] https://github.com/linux-nvme/nvme-cli/blob/master/nvme-rpmb.c#L230
[3] https://github.com/westerndigitalcorporation/ufs-utils/blob/dev/ufs_rpmb.c#L27

Quoted 27 lines
Quoted 9 lines
Quoted 4 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Quoted 8 lines
Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

I would suggest having an OP-TEE secure DT property that would provide the RPMB CID which is allocated to the secure world.

-Sumit

Quoted 3 lines

--
Jerome

#18 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

In reply to Jerome Forissier

Hi Jerome,

Quoted 40 lines · Shyam Saini
Quoted 37 lines

Hi Ulf,

Quoted 21 lines
Quoted 19 lines · Shyam Saini

From: Alex Bennée <[email protected]>

[This is patch 1 from [1] Alex's submission and this RPMB layer was originally proposed by [2]Thomas Winkler ]

A number of storage technologies support a specialised hardware partition designed to be resistant to replay attacks. The underlying HW protocols differ but the operations are common. The RPMB partition cannot be accessed via standard block layer, but by a set of specific
commands: WRITE, READ, GET_WRITE_COUNTER, and PROGRAM_KEY. Such a partition provides authenticated and replay protected access, hence suitable as a secure storage.

The initial aim of this patch is to provide a simple RPMB Driver which can be accessed by Linux's optee driver to facilitate fast-path for RPMB access to optee OS(secure OS) during the boot time. [1] Currently, Optee OS relies on user-tee supplicant to access eMMC RPMB partition.

Quoted 6 lines
Quoted 3 lines

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB driver provides a series of operations for interacting with the device.

I don't quite follow this. More exactly, how will the TEE driver know what RPMB device it should use?

I don't have complete code to for this yet, but i think OP-TEE driver should register with RPMB subsystem and then we can have eMMC/UFS/NVMe specific implementation for RPMB operations.

Linux optee driver can handle RPMB frames and pass it to RPMB subsystem

Quoted 8 lines
Quoted 4 lines

[1] U-Boot has mmc specific implementation

I think OPTEE-OS has CFG_RPMB_FS_DEV_ID option
CFG_RPMB_FS_DEV_ID=1 for /dev/mmcblk1rpmb,

Correct. Note that tee-supplicant will ignore this device ID if --rmb-cid is given and use the specified RPMB instead (the CID is a non-ambiguous way to identify a RPMB device).

Thanks, but we may still need to address with multiple RPMB targets/regions in case of UFS/NVMe.

Quoted 7 lines
Quoted 3 lines

but in case if a
system has multiple RPMB devices such as UFS/eMMC/NVMe, one them should be declared as secure storage and optee should access that one only.

Indeed, that would be an equivalent of tee-supplicant's --rpmb-cid.

Quoted 1 line

Sumit, do you have suggestions for this ?

#19 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

In reply to Shyam Saini

drivers/rpmb/Kconfig line 11

Quoted 8 lines · Shyam Saini
drivers/rpmb/Kconfig new file +8 -0
+config RPMB
+	tristate "RPMB partition interface"
+	help
+	  Unified RPMB partition interface for RPMB capable devices such as
+          eMMC and UFS. Provides interface for in kernel security controllers to
+	  access RPMB partition.
+
+	  If unsure, select N.

Please also mention NVMe.

Please change the word "partition" into "unit" to avoid confusion with the concept "LBA range partition".

Quoted 1 line

+static DEFINE_IDA(rpmb_ida);

How are accesses to this IDA serialized?

Quoted 10 lines

+/**
+ * rpmb_get_capacity() - returns the capacity of the rpmb device
+ * @rdev: rpmb device
+ *
+ * Return:

+ * *        capacity of the device in units of 128K, on success
+ * *        -EINVAL on wrong parameters
+ * *        -EOPNOTSUPP if device doesn't support the requested operation
+ * *        < 0 if the operation fails

+ */

Why in units of 128 KiB?

Quoted 7 lines

+/**
+ * rpmb_dev_find_by_device() - retrieve rpmb device from the parent device
+ * @parent: parent device of the rpmb device
+ * @target: RPMB target/region within the physical device
+ *
+ * Return: NULL if there is no rpmb device associated with the parent device
+ */

Can an NVMe controller have multiple RPMB units? From the NVMe
specification: "The controller may support multiple RPMB targets."

Can rpmb_dev_find_by_device() be used if multiple RPMB units are associated with a single controller?

Quoted 60 lines
drivers/rpmb/core.c new file +60 -0
+/**
+ * rpmb_dev_register - register RPMB partition with the RPMB subsystem
+ * @dev: storage device of the rpmb device
+ * @target: RPMB target/region within the physical device
+ * @ops: device specific operations
+ *
+ * Return: a pointer to rpmb device
+ */
+struct rpmb_dev *rpmb_dev_register(struct device *dev, u8 target,
+				   const struct rpmb_ops *ops)
+{
+	struct rpmb_dev *rdev;
+	int id;
+	int ret;
+
+	if (!dev || !ops)
+		return ERR_PTR(-EINVAL);
+
+	if (!ops->program_key)
+		return ERR_PTR(-EINVAL);
+
+	if (!ops->get_capacity)
+		return ERR_PTR(-EINVAL);
+
+	if (!ops->get_write_counter)
+		return ERR_PTR(-EINVAL);
+
+	if (!ops->write_blocks)
+		return ERR_PTR(-EINVAL);
+
+	if (!ops->read_blocks)
+		return ERR_PTR(-EINVAL);
+
+	rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
+	if (!rdev)
+		return ERR_PTR(-ENOMEM);
+
+	id = ida_simple_get(&rpmb_ida, 0, 0, GFP_KERNEL);
+	if (id < 0) {
+		ret = id;
+		goto exit;
+	}
+
+	mutex_init(&rdev->lock);
+	rdev->ops = ops;
+	rdev->id = id;
+	rdev->target = target;
+
+	dev_set_name(&rdev->dev, "rpmb%d", id);
+	rdev->dev.class = &rpmb_class;
+	rdev->dev.parent = dev;
+
+	rpmb_cdev_prepare(rdev);
+
+	ret = device_register(&rdev->dev);
+	if (ret)
+		goto exit;
+
+	rpmb_cdev_add(rdev);
+

drivers/rpmb/core.c line 417

Quoted 10 lines
drivers/rpmb/core.c new file +10 -0
+	dev_dbg(&rdev->dev, "registered device\n");
+
+	return rdev;
+
+exit:
+	if (id >= 0)
+		ida_simple_remove(&rpmb_ida, id);
+	kfree(rdev);
+	return ERR_PTR(ret);
+}

How is user space software supposed to map an NVMe RPMB target ID to an RPMB device name?

Quoted 1 line

+MODULE_AUTHOR("Intel Corporation");

Shouldn't this be the name of a person instead of the name of a company?

Thanks,

Bart.

#20 lore raw

Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver

Hi Bart,

sorry for not replying earlier, as I am very new to NVMe/UFS spec and was figuring out few details about them.

Quoted 11 lines · Shyam Saini
Quoted 9 lines

+config RPMB
+ tristate "RPMB partition interface"
+ help
+ Unified RPMB partition interface for RPMB capable devices such as
+ eMMC and UFS. Provides interface for in kernel security
controllers to
+ access RPMB partition.
+
+ If unsure, select N.

Quoted 1 line

Please also mention NVMe.

Sure,

Quoted 2 lines

Please change the word "partition" into "unit" to avoid confusion with the concept "LBA range partition".

sure, in next iteration

Quoted 3 lines
Quoted 1 line

+static DEFINE_IDA(rpmb_ida);

How are accesses to this IDA serialized?

I will look into that.

Quoted 11 lines
Quoted 10 lines

+/**
+ * rpmb_get_capacity() - returns the capacity of the rpmb device
+ * @rdev: rpmb device
+ *
+ * Return:

 + * *        capacity of the device in units of 128K, on success
 + * *        -EINVAL on wrong parameters
 + * *        -EOPNOTSUPP if device doesn't support the requested operation
 + * *        < 0 if the operation fails

+ */

Quoted 1 line

Why in units of 128 KiB?

I think UFS/eMMC RPMB spec suggests size of RPMB multiple of 128K and NVMe spec suggests RPMB Data Area to be multiple of 128K as well.

Quoted 10 lines
Quoted 9 lines

+/**
+ * rpmb_dev_find_by_device() - retrieve rpmb device from the parent device
+ * @parent: parent device of the rpmb device
+ * @target: RPMB target/region within the physical device
+ *
+ * Return: NULL if there is no rpmb device associated with the parent device
+ */

Quoted 2 lines

Can an NVMe controller have multiple RPMB units? From the NVMe specification:
"The controller may support multiple RPMB targets."

That we have to figure, I see NVMe device can have upto 7 RPMB targets/units

Quoted 2 lines

Can rpmb_dev_find_by_device() be used if multiple RPMB units are associated with a single controller?

That's not finalised yet, but we some ideas from Optee folks on the other replies.

Quoted 71 lines
Quoted 62 lines

+/**
+ * rpmb_dev_register - register RPMB partition with the RPMB subsystem
+ * @dev: storage device of the rpmb device
+ * @target: RPMB target/region within the physical device
+ * @ops: device specific operations
+ *
+ * Return: a pointer to rpmb device
+ */
+struct rpmb_dev *rpmb_dev_register(struct device *dev, u8 target,
+ const struct rpmb_ops *ops)
+{
+ struct rpmb_dev *rdev;
+ int id;
+ int ret;
+
+ if (!dev || !ops)
+ return ERR_PTR(-EINVAL);
+
+ if (!ops->program_key)
+ return ERR_PTR(-EINVAL);
+
+ if (!ops->get_capacity)
+ return ERR_PTR(-EINVAL);
+
+ if (!ops->get_write_counter)
+ return ERR_PTR(-EINVAL);
+
+ if (!ops->write_blocks)
+ return ERR_PTR(-EINVAL);
+
+ if (!ops->read_blocks)
+ return ERR_PTR(-EINVAL);
+
+ rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
+ if (!rdev)
+ return ERR_PTR(-ENOMEM);
+
+ id = ida_simple_get(&rpmb_ida, 0, 0, GFP_KERNEL);
+ if (id < 0) {
+ ret = id;
+ goto exit;
+ }
+
+ mutex_init(&rdev->lock);
+ rdev->ops = ops;
+ rdev->id = id;
+ rdev->target = target;
+
+ dev_set_name(&rdev->dev, "rpmb%d", id);
+ rdev->dev.class = &rpmb_class;
+ rdev->dev.parent = dev;
+
+ rpmb_cdev_prepare(rdev);
+
+ ret = device_register(&rdev->dev);
+ if (ret)
+ goto exit;
+
+ rpmb_cdev_add(rdev);
+
+ dev_dbg(&rdev->dev, "registered device\n");
+

Quoted 8 lines

+ return rdev;
+
+exit:
+ if (id >= 0)
+ ida_simple_remove(&rpmb_ida, id);
+ kfree(rdev);
+ return ERR_PTR(ret);
+}

Quoted 2 lines

How is user space software supposed to map an NVMe RPMB target ID to an RPMB device name?

I am not sure, this driver aims to provide in kernel RPMB access APIs, user space support may be added later on, but i will look if the current RFC version has any implication on future user-space support.

Quoted 4 lines
Quoted 1 line

+MODULE_AUTHOR("Intel Corporation");

Shouldn't this be the name of a person instead of the name of a company?

Thanks, I will address that in next iteration.

Please keep posted your reviews and feedback.

Best Regards,
Shyam