Skip to contentSkip to conversation

rpmb subsystem, uapi and virtio-rpmb driver

PATCH In review Alex Bennée 10 participants 30 messages Apr 5, 2022 – Jun 13, 2023

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

v2 cover rpmb subsystem, uapi and virtio-rpmb driver

Hi,

This is another attempt to come up with an RPMB API for the kernel. The last discussion of this was in the thread:

Subject: [RFC PATCH 0/5] RPMB internal and user-space API + WIP virtio-rpmb frontend
Date: Wed, 3 Mar 2021 13:54:55 +0000
Message-Id: <[email protected]>

The series provides for the RPMB sub-system, a new chardev API driven by ioctls and a full multi-block capable virtio-rpmb driver. You can find a working vhost-user backend in my QEMU branch here:

https://github.com/stsquad/qemu/commits/virtio/vhost-user-rpmb-v2

The branch is a little messy but I'll be posting a cleaned up version in the following weeks. The only real changes to the backend is the multi-block awareness and some tweaks to deal with QEMU internals handling VirtIO config space messages which weren't previously exercised. The test.sh script in tools/rpmb works through the various transactions but isn't comprehensive.

Changes since the last posting:

- frame construction is mostly back in userspace

The previous discussion showed there wasn't any appetite for using the kernels keyctl() interface so userspace yet again takes responsibility for constructing most* frames. Currently these are all pure virtio-rpmb frames but the code is written so we can plug in additional frame types. The virtio-rpmb driver does some validation and in some cases (* read-blocks) constructs the request frame in the driver. It would take someone implementing a driver for another RPMB device type to see if this makes sense.

- user-space interface is still split across several ioctls

Although 3 of the ioctls share the common rpmb_ioc_reqresp_cmd structure it does mean things like capacity, write_count and read_blocks can have their own structure associated with the command.

As before I shall follow up with the QEMU based vhost-user backend and hopefully a rust-vmm re-implementation. However I've no direct interest in implementing the interfaces to real hardware. I leave that to people who have access to such things and are willing to take up the maintainer burden if this is merged.

Regards,

Alex

Alex Bennée (4):
rpmb: add Replay Protected Memory Block (RPMB) subsystem
char: rpmb: provide a user space interface
rpmb: create virtio rpmb frontend driver
tools rpmb: add RPBM access tool

 .../userspace-api/ioctl/ioctl-number.rst      |    1 +
 MAINTAINERS                                   |    9 +
 drivers/Kconfig                               |    2 +
 drivers/Makefile                              |    1 +
 drivers/rpmb/Kconfig                          |   28 +
 drivers/rpmb/Makefile                         |    9 +
 drivers/rpmb/cdev.c                           |  309 +++++
 drivers/rpmb/core.c                           |  439 +++++++
 drivers/rpmb/rpmb-cdev.h                      |   17 +
 drivers/rpmb/virtio_rpmb.c                    |  518 ++++++++
 include/linux/rpmb.h                          |  182 +++
 include/uapi/linux/rpmb.h                     |   99 ++
 include/uapi/linux/virtio_rpmb.h              |   54 +
 tools/Makefile                                |   16 +-
 tools/rpmb/.gitignore                         |    2 +
 tools/rpmb/Makefile                           |   41 +
 tools/rpmb/key                                |    1 +
 tools/rpmb/rpmb.c                             | 1083 +++++++++++++++++
 tools/rpmb/test.sh                            |   22 +
 19 files changed, 2828 insertions(+), 5 deletions(-)
 create mode 100644 drivers/rpmb/Kconfig
 create mode 100644 drivers/rpmb/Makefile
 create mode 100644 drivers/rpmb/cdev.c
 create mode 100644 drivers/rpmb/core.c
 create mode 100644 drivers/rpmb/rpmb-cdev.h
 create mode 100644 drivers/rpmb/virtio_rpmb.c
 create mode 100644 include/linux/rpmb.h
 create mode 100644 include/uapi/linux/rpmb.h
 create mode 100644 include/uapi/linux/virtio_rpmb.h
 create mode 100644 tools/rpmb/.gitignore
 create mode 100644 tools/rpmb/Makefile
 create mode 100644 tools/rpmb/key
 create mode 100644 tools/rpmb/rpmb.c
 create mode 100755 tools/rpmb/test.sh
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/4 rpmb: add Replay Protected Memory Block (RPMB) subsystem

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 RPMB layer aims to provide in-kernel API for Trusted Execution Environment (TEE) devices that are capable to securely compute block frame signature. In case a TEE device wishes to store a replay protected data, requests the storage device via RPMB layer to store the data.

A TEE device driver can claim the RPMB interface, for example, via class_interface_register(). The RPMB layer 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_count - 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.

[This is based-on Thomas Winkler's proposed API from:

https://lore.kernel.org/linux-mmc/[email protected]/

The principle difference is the framing details and HW specific bits (JDEC vs NVME frames) are left to the lower level TEE driver to worry about. The eventual userspace ioctl interface will aim to be similarly generic. This is an RFC to follow up on:

Subject: RPMB user space ABI
Date: Thu, 11 Feb 2021 14:07:00 +0000
Message-ID: <[email protected]>]

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]>

---
v2
- dropped keyid stuff
- moved from char to its own subdirectory driver/rpmb
- fixed compile errors for bisectability

---
 MAINTAINERS           |   7 +
 drivers/Kconfig       |   2 +
 drivers/Makefile      |   1 +
 drivers/rpmb/Kconfig  |  11 ++
 drivers/rpmb/Makefile |   7 +
 drivers/rpmb/core.c   | 434 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/rpmb.h  | 172 +++++++++++++++++
 7 files changed, 634 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 cd0f68d4a34a..9ab02b589005 100644
@@ -16744,6 +16744,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:	[email protected]
+S:	Supported
+F:	drivers/rpmb/*
+F:	include/linux/rpmb.h
+
 RPMSG TTY DRIVER
 M:	Arnaud Pouliquen <[email protected]>
 L:	[email protected]
drivers/Kconfig +2 -0
index 0d399ddaa185..90d18a8a0e72 100644
@@ -236,4 +236,6 @@ source "drivers/interconnect/Kconfig"
 source "drivers/counter/Kconfig"
 
 source "drivers/most/Kconfig"
+
+source "drivers/rpmb/Kconfig"
 endmenu
drivers/Makefile +1 -0
index a110338c860c..ade465c4589f 100644
@@ -187,3 +187,4 @@ obj-$(CONFIG_GNSS)		+= gnss/
 obj-$(CONFIG_INTERCONNECT)	+= interconnect/
 obj-$(CONFIG_COUNTER)		+= counter/
 obj-$(CONFIG_MOST)		+= most/
+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 +434 -0

434 lines not on this page · raw message

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

172 lines not on this page · raw message

Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH v2 1/4] rpmb: add Replay Protected Memory Block (RPMB) subsystem

Quoted 6 lines · Alex Bennée
drivers/rpmb/core.c new file +6 -0
+int rpmb_get_write_count(struct rpmb_dev *rdev, int len, u8 *request, int rlen, u8 *resp)
+{
+	int err;
+
+	if (!rdev)
+		return -EINVAL;

drivers/rpmb/core.c line 129

Quoted 10 lines
drivers/rpmb/core.c new file +10 -0
+
+	mutex_lock(&rdev->lock);
+	err = -EOPNOTSUPP;
+	if (rdev->ops && rdev->ops->get_write_count)
+		err = rdev->ops->get_write_count(rdev->dev.parent, rdev->target,
+						 len, request, rlen, resp);
+	mutex_unlock(&rdev->lock);
+
+	return err;
+}

The names rpmb_get_write_count() and get_write_count() look confusing to me since these functions query the write counter. How about adding "er" at the end of both function names?

Are there any plans to add an implementation of struct rpmb_ops for UFS devices?

Thanks,

Bart.

#3 lore raw

Re: [PATCH v2 1/4] rpmb: add Replay Protected Memory Block (RPMB) subsystem

Quoted 22 lines · Bart Van Assche
Quoted 6 lines · Alex Bennée
drivers/rpmb/core.c new file +6 -0
+int rpmb_get_write_count(struct rpmb_dev *rdev, int len, u8 *request, int rlen, u8 *resp)
+{
+	int err;
+
+	if (!rdev)
+		return -EINVAL;

drivers/rpmb/core.c line 129

Quoted 10 lines
drivers/rpmb/core.c new file +10 -0
+
+	mutex_lock(&rdev->lock);
+	err = -EOPNOTSUPP;
+	if (rdev->ops && rdev->ops->get_write_count)
+		err = rdev->ops->get_write_count(rdev->dev.parent, rdev->target,
+						 len, request, rlen, resp);
+	mutex_unlock(&rdev->lock);
+
+	return err;
+}

The names rpmb_get_write_count() and get_write_count() look confusing to me since these functions query the write counter. How about adding "er" at the end of both function names?

Quoted 2 lines

Are there any plans to add an implementation of struct rpmb_ops for UFS devices?

Not by me but I agree it would be a useful exercise to see if a unified API makes sense.

Signature · 1 line
Alex Bennée
#4 lore raw

PATCH v2 2/4 char: rpmb: provide a user space interface

In reply to Alex Bennée

The user space API is achieved via a number of synchronous IOCTLs.

* RPMB_IOC_VER_CMD - simple versioning API
* RPMB_IOC_CAP_CMD - query of underlying capabilities
* RPMB_IOC_PKEY_CMD - one time programming of access key
* RPMB_IOC_COUNTER_CMD - query the write counter
* RPMB_IOC_WBLOCKS_CMD - write blocks to device
* RPMB_IOC_RBLOCKS_CMD - read blocks from device

The operations which require authenticated frames or will respond with MAC hashes of nonce filled frames that userspace will need to verify share a common command frame format. The other operations can be considered generic and allow for common handling.

[AJB: here the are key difference is the avoiding a single ioctl where all the frame data is put together by user space. User space is still the only place where certain operations can be verified due to the need of a secret key]

Cc Ulf Hansson <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tomas Winkler <[email protected]>
Cc Alexander Usyskin <[email protected]>
Cc Avri Altman <[email protected]>

---
v2
- drop the key api stuff

---
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |   1 +
 drivers/rpmb/Kconfig                          |   7 +
 drivers/rpmb/Makefile                         |   1 +
 drivers/rpmb/cdev.c                           | 309 ++++++++++++++++++
 drivers/rpmb/core.c                           |   7 +-
 drivers/rpmb/rpmb-cdev.h                      |  17 +
 include/linux/rpmb.h                          |  10 +
 include/uapi/linux/rpmb.h                     |  99 ++++++
 9 files changed, 451 insertions(+), 1 deletion(-)
 create mode 100644 drivers/rpmb/cdev.c
 create mode 100644 drivers/rpmb/rpmb-cdev.h
 create mode 100644 include/uapi/linux/rpmb.h
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -0
index e6fce2cbd99e..874d01f11caf 100644
@@ -355,6 +355,7 @@ Code  Seq#    Include File                                           Comments
 0xB6  all    linux/fpga-dfl.h
 0xB7  all    uapi/linux/remoteproc_cdev.h                            <mailto:[email protected]>
 0xB7  all    uapi/linux/nsfs.h                                       <mailto:Andrei Vagin <[email protected]>>
+0xB8  80-8F  uapi/linux/rpmb.h                                       <mailto:[email protected]>
 0xC0  00-0F  linux/usb/iowarrior.h
 0xCA  00-0F  uapi/misc/cxl.h
 0xCA  10-2F  uapi/misc/ocxl.h
MAINTAINERS +1 -0
index 9ab02b589005..0a744da21817 100644
@@ -16749,6 +16749,7 @@ M:	?
 L:	[email protected]
 S:	Supported
 F:	drivers/rpmb/*
+F:	include/uapi/linux/rpmb.h
 F:	include/linux/rpmb.h
 
 RPMSG TTY DRIVER
drivers/rpmb/Kconfig +7 -0
index f2a9ebdc4435..126f336fe9ea 100644
@@ -9,3 +9,10 @@ config RPMB
 	  access RPMB partition.
 
 	  If unsure, select N.
+
+config RPMB_INTF_DEV
+	bool "RPMB character device interface /dev/rpmbN"
+	depends on RPMB
+	help
+	  Say yes here if you want to access RPMB from user space
+	  via character device interface /dev/rpmb%d
drivers/rpmb/Makefile +1 -0
index 24d4752a9a53..f54b3f30514b 100644
@@ -3,5 +3,6 @@
 
 obj-$(CONFIG_RPMB) += rpmb.o
 rpmb-objs += core.o
+rpmb-$(CONFIG_RPMB_INTF_DEV) += cdev.o
 
 ccflags-y += -D__CHECK_ENDIAN__
drivers/rpmb/cdev.c new file +309 -0

309 lines not on this page · raw message

drivers/rpmb/core.c +6 -1
index 50b358a14db6..969536ba53cc 100644
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 
 #include <linux/rpmb.h>
+#include "rpmb-cdev.h"
 
 static DEFINE_IDA(rpmb_ida);
 
@@ -282,6 +283,7 @@ int rpmb_dev_unregister(struct rpmb_dev *rdev)
 		return -EINVAL;
 
 	mutex_lock(&rdev->lock);
+	rpmb_cdev_del(rdev);
 	device_del(&rdev->dev);
 	mutex_unlock(&rdev->lock);
 
@@ -401,6 +403,8 @@ struct rpmb_dev *rpmb_dev_register(struct device *dev, u8 target,
 	if (ret)
 		goto exit;
 
+	rpmb_cdev_add(rdev);
+
 	dev_dbg(&rdev->dev, "registered device\n");
 
 	return rdev;
@@ -417,11 +421,12 @@ static int __init rpmb_init(void)
 {
 	ida_init(&rpmb_ida);
 	class_register(&rpmb_class);
-	return 0;
+	return rpmb_cdev_init();
 }
 
 static void __exit rpmb_exit(void)
 {
+	rpmb_cdev_exit();
 	class_unregister(&rpmb_class);
 	ida_destroy(&rpmb_ida);
 }
drivers/rpmb/rpmb-cdev.h new file +17 -0
new file mode 100644
index 000000000000..e59ff0c05e9d
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
+/*
+ * Copyright (C) 2015-2018 Intel Corp. All rights reserved
+ */
+#ifdef CONFIG_RPMB_INTF_DEV
+int __init rpmb_cdev_init(void);
+void __exit rpmb_cdev_exit(void);
+void rpmb_cdev_prepare(struct rpmb_dev *rdev);
+void rpmb_cdev_add(struct rpmb_dev *rdev);
+void rpmb_cdev_del(struct rpmb_dev *rdev);
+#else
+static inline int __init rpmb_cdev_init(void) { return 0; }
+static inline void __exit rpmb_cdev_exit(void) {}
+static inline void rpmb_cdev_prepare(struct rpmb_dev *rdev) {}
+static inline void rpmb_cdev_add(struct rpmb_dev *rdev) {}
+static inline void rpmb_cdev_del(struct rpmb_dev *rdev) {}
+#endif /* CONFIG_RPMB_INTF_DEV */
include/linux/rpmb.h +10 -0
index 4ed5e299623e..3b0731c07528 100644
@@ -8,8 +8,12 @@
 
 #include <linux/types.h>
 #include <linux/device.h>
+#include <linux/cdev.h>
+#include <uapi/linux/rpmb.h>
 #include <linux/kref.h>
 
+#define RPMB_API_VERSION 0x80000001
+
 /**
  * struct rpmb_ops - RPMB ops to be implemented by underlying block device
  *
@@ -54,6 +58,8 @@ struct rpmb_ops {
  * @dev        : device
  * @id         : device id
  * @target     : RPMB target/region within the physical device
+ * @cdev       : character dev
+ * @status     : device status
  * @ops        : operation exported by rpmb
  */
 struct rpmb_dev {
@@ -61,6 +67,10 @@ struct rpmb_dev {
 	struct device dev;
 	int id;
 	u8 target;
+#ifdef CONFIG_RPMB_INTF_DEV
+	struct cdev cdev;
+	unsigned long status;
+#endif /* CONFIG_RPMB_INTF_DEV */
 	const struct rpmb_ops *ops;
 };
 
include/uapi/linux/rpmb.h new file +99 -0

99 lines not on this page · raw message

Signature · 1 line
2.30.2
#5 lore raw

Re: [PATCH v2 2/4] char: rpmb: provide a user space interface

Hello,

Quoted 14 lines · Alex Bennée

The user space API is achieved via a number of synchronous IOCTLs.

* RPMB_IOC_VER_CMD - simple versioning API
* RPMB_IOC_CAP_CMD - query of underlying capabilities
* RPMB_IOC_PKEY_CMD - one time programming of access key
* RPMB_IOC_COUNTER_CMD - query the write counter
* RPMB_IOC_WBLOCKS_CMD - write blocks to device
* RPMB_IOC_RBLOCKS_CMD - read blocks from device

The operations which require authenticated frames or will respond with MAC hashes of nonce filled frames that userspace will need to verify share a common command frame format. The other operations can be considered generic and allow for common handling.

Quoted 4 lines

[AJB: here the are key difference is the avoiding a single ioctl where all the frame data is put together by user space. User space is still the only place where certain operations can be verified due to the need of a secret key]

I have less problems to understand this reworked ioctl() interface as I had with the older one. Nice.

drivers/rpmb/cdev.c line 88

Quoted 13 lines
drivers/rpmb/cdev.c +11 -0
...
+static long rpmb_ioctl_cap_cmd(struct rpmb_dev *rdev,
+			       struct rpmb_ioc_cap_cmd __user *ptr)
+{
+	struct rpmb_ioc_cap_cmd cap;
+
+	cap.target      = rdev->target;
+	cap.block_size  = rdev->ops->block_size;
+	cap.wr_cnt_max  = rdev->ops->wr_cnt_max;
+	cap.rd_cnt_max  = rdev->ops->rd_cnt_max;
+	cap.capacity    = rpmb_get_capacity(rdev);
+	cap.reserved    = 0;

auth_method is still part of the structure but not set. Means arbitrary data from the stack is copied to user land.

Quoted 25 lines
drivers/rpmb/cdev.c +23 -0
+
+	return copy_to_user(ptr, &cap, sizeof(cap)) ? -EFAULT : 0;
+}
...
+/**
+ * struct rpmb_ioc_cap_cmd - rpmb capabilities
+ *
+ * @target: rpmb target/region within RPMB partition.
+ * @capacity: storage capacity (in units of 128K)
+ * @block_size: storage data block size (in units of 256B)
+ * @wr_cnt_max: maximal number of block that can be written in a single request.
+ * @rd_cnt_max: maximal number of block that can be read in a single request.
+ * @auth_method: authentication method: currently always HMAC_SHA_256
+ * @reserved: reserved to align to 4 bytes.
+ */
+struct rpmb_ioc_cap_cmd {
+	__u16 target;
+	__u16 capacity;
+	__u16 block_size;
+	__u16 wr_cnt_max;
+	__u16 rd_cnt_max;
+	__u16 auth_method;
+	__u16 reserved;
+} __packed;

...+

Signature · 14 lines
Dipl.-Ing. Harald Mommer
Senior Software Engineer

OpenSynergy GmbH
Rotherstr. 20, 10245 Berlin

Phone:  +49 (30) 60 98 540-0 <== Zentrale
Fax:    +49 (30) 60 98 540-99
E-Mail: [email protected]

www.opensynergy.com

Handelsregister: Amtsgericht Charlottenburg, HRB 108616B
Geschäftsführer/Managing Director: Regis Adjamah
#6 lore raw

Re: [PATCH v2 2/4] char: rpmb: provide a user space interface

In reply to Alex Bennée
Quoted 7 lines · Alex Bennée
drivers/rpmb/cdev.c new file +7 -0
+static int rpmb_open(struct inode *inode, struct file *fp)
+{
+       struct rpmb_dev *rdev;
+
+       rdev = container_of(inode->i_cdev, struct rpmb_dev, cdev);
+       if (!rdev)
+               return -ENODEV;

drivers/rpmb/cdev.c line 46

Quoted 10 lines
drivers/rpmb/cdev.c new file +10 -0
+
+       /* the rpmb is single open! */
+       if (test_and_set_bit(RPMB_DEV_OPEN, &rdev->status))
+               return -EBUSY;
+
+       mutex_lock(&rdev->lock);
+
+       fp->private_data = rdev;
+
+       mutex_unlock(&rdev->lock);

The mutex here doesn't really do anything, as the file structure is not reachable from any other context.

I'm not sure the single-open protection gains you anything either, as it does not prevent the file structure to be shared between processes.

drivers/rpmb/cdev.c line 76

Quoted 9 lines
drivers/rpmb/cdev.c new file +9 -0
+static long rpmb_ioctl_ver_cmd(struct rpmb_dev *rdev,
+                              struct rpmb_ioc_ver_cmd __user *ptr)
+{
+       struct rpmb_ioc_ver_cmd ver = {
+               .api_version = RPMB_API_VERSION,
+       };
+
+       return copy_to_user(ptr, &ver, sizeof(ver)) ? -EFAULT : 0;
+}

API version ioctls are generally a bad idea, I think this should be skipped. The way to handle incompatible API changes is to introduce new ioctl commands.

Quoted 20 lines
drivers/rpmb/cdev.c new file +4 -0
+static const struct file_operations rpmb_fops = {
+       .open           = rpmb_open,
+       .release        = rpmb_release,
+       .unlocked_ioctl = rpmb_ioctl,
drivers/rpmb/rpmb-cdev.h new file +7 -0
new file mode 100644
index 000000000000..e59ff0c05e9d
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
+/*
+ * Copyright (C) 2015-2018 Intel Corp. All rights reserved
+ */
+#ifdef CONFIG_RPMB_INTF_DEV
+int __init rpmb_cdev_init(void);
+void __exit rpmb_cdev_exit(void);

drivers/rpmb/rpmb-cdev.h line 17

Quoted 10 lines
drivers/rpmb/rpmb-cdev.h new file +10 -0
+void rpmb_cdev_prepare(struct rpmb_dev *rdev);
+void rpmb_cdev_add(struct rpmb_dev *rdev);
+void rpmb_cdev_del(struct rpmb_dev *rdev);
+#else
+static inline int __init rpmb_cdev_init(void) { return 0; }
+static inline void __exit rpmb_cdev_exit(void) {}
+static inline void rpmb_cdev_prepare(struct rpmb_dev *rdev) {}
+static inline void rpmb_cdev_add(struct rpmb_dev *rdev) {}
+static inline void rpmb_cdev_del(struct rpmb_dev *rdev) {}
+#endif /* CONFIG_RPMB_INTF_DEV */

What is the purpose of the fallback? Would you ever build the code without the interface?

drivers/rpmb/rpmb-cdev.h

Quoted 8 lines
drivers/rpmb/rpmb-cdev.h new file +8 -0
+/**
+ * struct rpmb_ioc_ver_cmd - rpmb api version
+ *
+ * @api_version: rpmb API version.
+ */
+struct rpmb_ioc_ver_cmd {
+       __u32 api_version;
+} __packed;

Best remove this completely.

Quoted 14 lines
drivers/rpmb/rpmb-cdev.h new file +14 -0
+enum rpmb_auth_method {
+       RPMB_HMAC_ALGO_SHA_256 = 0,
+};
+
+/**
+ * struct rpmb_ioc_cap_cmd - rpmb capabilities
+ *
+ * @target: rpmb target/region within RPMB partition.
+ * @capacity: storage capacity (in units of 128K)
+ * @block_size: storage data block size (in units of 256B)
+ * @wr_cnt_max: maximal number of block that can be written in a single request.
+ * @rd_cnt_max: maximal number of block that can be read in a single request.
+ * @auth_method: authentication method: currently always HMAC_SHA_256
+ * @reserved: reserved to align to 4 bytes.

drivers/rpmb/rpmb-cdev.h

Quoted 10 lines
drivers/rpmb/rpmb-cdev.h new file +10 -0
+ */
+struct rpmb_ioc_cap_cmd {
+       __u16 target;
+       __u16 capacity;
+       __u16 block_size;
+       __u16 wr_cnt_max;
+       __u16 rd_cnt_max;
+       __u16 auth_method;
+       __u16 reserved;
+} __packed;

I would remove the __packed attribute here. If you want to keep it, then it needs to have a __aligned() attribute as well.

It seems strange to have an odd number of 16-bit fields in this, maybe make it two reserved fields to have a multiple of 32-bit.

Quoted 20 lines

+ * struct rpmb_ioc_reqresp_cmd - general purpose reqresp
+ *
+ * Most RPMB operations consist of a set of request frames and an
+ * optional response frame. If a response is requested the user must
+ * allocate enough space for the response, otherwise the fields should
+ * be set to 0/NULL.
+ *
+ * It is used for programming the key, reading the counter and writing
+ * blocks to the device. If the frames are malformed they may be
+ * rejected by the underlying driver or the device itself.
+ *
+ * Assuming the transaction succeeds it is still up to user space to
+ * validate the response and check MAC values correspond to the
+ * programmed keys.
+ *
+ * @len: length of write counter request
+ * @request: ptr to device specific request frame
+ * @rlen: length of response frame
+ * @resp: ptr to device specific response frame
+ */

drivers/rpmb/rpmb-cdev.h

Quoted 6 lines
drivers/rpmb/rpmb-cdev.h new file +6 -0
+struct rpmb_ioc_reqresp_cmd {
+       __u32 len;
+       __u8 __user *request;
+       __u32 rlen;
+       __u8 __user *response;
+} __packed;

Try to avoid indirect pointers in ioctl structures, they break compatibility with
32-bit processes. I think you can do this with a variable-length structure that has the two length fields followed by the actual data. If there is a reasonable upper bound for the length, it could also just be a fixed-length buffer.

If you end up having to use a pointer, make it a __u64 value and cast between that and the actual pointer value.

Whatever you do though, don't use misaligned pointers or implicit padding in the structure. You can have explicit padding by adding an extra __u32 before a __u64 pointer value, and then remove the __packed attribute, or reorder the members so each pointer is naturally aligned.

Arnd

#7 lore raw

PATCH v2 3/4 rpmb: create virtio rpmb frontend driver

In reply to Alex Bennée

This implements a virtio rpmb frontend driver for the RPMB subsystem. This driver conforms to the rpmb internal API which attempts to stay common for the majority of cases and only expose the low level frame details as required. In these cases it is up to something outside of the driver itself to do the appropriate MAC calculations.

The driver does do some basic verification of the incoming data and will reject frames which are the wrong size or have the wrong commands in them.

---
ajb:
- rewrite for new API

---
 drivers/rpmb/Kconfig             |  10 +
 drivers/rpmb/Makefile            |   1 +
 drivers/rpmb/virtio_rpmb.c       | 518 +++++++++++++++++++++++++++++++
 include/uapi/linux/virtio_rpmb.h |  54 ++++
 4 files changed, 583 insertions(+)
 create mode 100644 drivers/rpmb/virtio_rpmb.c
 create mode 100644 include/uapi/linux/virtio_rpmb.h
drivers/rpmb/Kconfig +10 -0
index 126f336fe9ea..cd0d1bb10910 100644
@@ -16,3 +16,13 @@ config RPMB_INTF_DEV
 	help
 	  Say yes here if you want to access RPMB from user space
 	  via character device interface /dev/rpmb%d
+
+config VIRTIO_RPMB
+	tristate "Virtio RPMB driver"
+	default n
+	depends on VIRTIO
+	select RPMB
+	help
+	  Say yes here if you have a Virtio aware RPMB device or want to use
+          RPMB from a Virtual Machine images.
+	  This device interface is only for guest/frontend virtio driver.
drivers/rpmb/Makefile +1 -0
index f54b3f30514b..4b397b50a42c 100644
@@ -4,5 +4,6 @@
 obj-$(CONFIG_RPMB) += rpmb.o
 rpmb-objs += core.o
 rpmb-$(CONFIG_RPMB_INTF_DEV) += cdev.o
+obj-$(CONFIG_VIRTIO_RPMB) += virtio_rpmb.o
 
 ccflags-y += -D__CHECK_ENDIAN__
drivers/rpmb/virtio_rpmb.c new file +518 -0

518 lines not on this page · raw message

include/uapi/linux/virtio_rpmb.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.30.2
#8 lore raw

Re: [PATCH v2 3/4] rpmb: create virtio rpmb frontend driver

Quoted 13 lines · Alex Bennée

+++ b/drivers/rpmb/virtio_rpmb.c
...

drivers/rpmb/virtio_rpmb.c new file +11 -0
+static int rpmb_virtio_write_blocks(struct device *dev, u8 target,
+				    int len, u8 *req, int rlen, u8 *resp)
+{
+	struct virtio_rpmb_info *vi = dev_get_drvdata(dev);
+	struct virtio_rpmb_frame *request = (struct virtio_rpmb_frame *) req;
+	struct virtio_rpmb_frame *response = (struct virtio_rpmb_frame *) resp;
+	struct scatterlist out_frame;
+	struct scatterlist in_frame;
+	struct scatterlist *sgs[2];
+	int blocks, data_len, received;
+

drivers/rpmb/virtio_rpmb.c line 255

Quoted 10 lines
drivers/rpmb/virtio_rpmb.c new file +10 -0
+	if (!len || (len % VIRTIO_RPMB_FRAME_SZ) != 0 || !request)
+		return -EINVAL;
+
+	/* The first frame will contain the details of the request */
+	if (be16_to_cpu(request->req_resp) != VIRTIO_RPMB_REQ_DATA_WRITE)
+		return -EINVAL;
+
+	blocks = be16_to_cpu(request->block_count);
+	if (blocks > vi->max_wr)
+		return -EINVAL;

Not exactly. The virtio specification reserves 0 for "unlimited". And I see no special handling for 0 in your code. Damned trap in the specification.

What's "unlimited"? As the blocks_count in the rpmb frame is a be16 I guess it's 65535. But if you consider this theoretically you have a possible max array allocation of 16 MB - 512B max. instead of the 16 KB - 512B you have with 255. Getting headache about this "unlimited" in the virtio specification. I don't like the theoretical possibility having to allocate 16MB dynamically for a moment due to this "unlimited".

And of course there is the same problem in virtio_rpmb_read_blocks() with max_rd.

A fix is needed, either 0 is 65535 or 0 is 255. Choosing 255 as implementation decision would be limiting down but maybe without any practical impact. For UFS it's a single byte bRPMBReadWriteSize only in JESD220C-2.2 GEOMETRY DESCRIPTOR and 0 is not defined there as "unlimited". Unfortunately I've no idea about the other possible underlying technologies (eMMC, NVMe, ...).

drivers/rpmb/virtio_rpmb.c line 338

Quoted 9 lines

...

drivers/rpmb/virtio_rpmb.c new file +7 -0
+}
+...
+static int rpmb_virtio_read_blocks(struct device *dev, u8 target,
+				   int addr, int count, int len, u8 *data)
+{
...
+	if (count > vi->max_rd)
+		return -EINVAL;

See above.

Quoted 1 line

...

Signature · 14 lines
Dipl.-Ing. Harald Mommer
Senior Software Engineer

OpenSynergy GmbH
Rotherstr. 20, 10245 Berlin

Phone:  +49 (30) 60 98 540-0 <== Zentrale
Fax:    +49 (30) 60 98 540-99
E-Mail: [email protected]

www.opensynergy.com

Handelsregister: Amtsgericht Charlottenburg, HRB 108616B
Geschäftsführer/Managing Director: Regis Adjamah
#9 lore raw

PATCH v2 4/4 tools rpmb: add RPBM access tool

In reply to Alex Bennée

Add simple RPMB host testing tool. It can be used to program key, write and read data block, and retrieve write counter. It's based on Tomas' original tool but only deals with the virtio-rpmb device. I've also split the RPMB specific functions (vrpmb_*) from the generic hooks (op_rpmb_*) to make it easier to add other RPMB implementations.

A simple test.sh script will exercise the interface (assuming a virgin RPMB device awaiting a programmed key).

Cc Tomas Winkler <[email protected]>
Cc Alexander Usyskin <[email protected]>

---
ajb:
- new per op ioctl API

---
 MAINTAINERS           |    1 +
 tools/Makefile        |   16 +-
 tools/rpmb/.gitignore |    2 +
 tools/rpmb/Makefile   |   41 ++
 tools/rpmb/key        |    1 +
 tools/rpmb/rpmb.c     | 1083 +++++++++++++++++++++++++++++++++++++++++
 tools/rpmb/test.sh    |   22 +
 7 files changed, 1161 insertions(+), 5 deletions(-)
 create mode 100644 tools/rpmb/.gitignore
 create mode 100644 tools/rpmb/Makefile
 create mode 100644 tools/rpmb/key
 create mode 100644 tools/rpmb/rpmb.c
 create mode 100755 tools/rpmb/test.sh
MAINTAINERS +1 -0
index 0a744da21817..70716250aa51 100644
@@ -16751,6 +16751,7 @@ S:	Supported
 F:	drivers/rpmb/*
 F:	include/uapi/linux/rpmb.h
 F:	include/linux/rpmb.h
+F:	tools/rpmb/
 
 RPMSG TTY DRIVER
 M:	Arnaud Pouliquen <[email protected]>
tools/Makefile +11 -5
index db2f7b8ebed5..0cc62dcae581 100644
@@ -27,6 +27,7 @@ help:
 	@echo '  objtool                - an ELF object analysis tool'
 	@echo '  pci                    - PCI tools'
 	@echo '  perf                   - Linux performance measurement and analysis tool'
+	@echo '  rpmb                   - Replay protected memory block access tool'
 	@echo '  selftests              - various kernel selftests'
 	@echo '  bootconfig             - boot config tool'
 	@echo '  spi                    - spi tools'
@@ -65,7 +66,9 @@ acpi: FORCE
 cpupower: FORCE
 	$(call descend,power/$@)
 
-cgroup counter firewire hv guest bootconfig spi usb virtio vm bpf iio gpio objtool leds wmi pci firmware debugging tracing: FORCE
+cgroup counter firewire hv guest bootconfig spi usb virtio vm bpf iio \
+  gpio objtool leds wmi pci firmware debugging tracing rpmb: FORCE
+
 	$(call descend,$@)
 
 bpf/%: FORCE
@@ -101,7 +104,7 @@ all: acpi cgroup counter cpupower gpio hv firewire \
 		perf selftests bootconfig spi turbostat usb \
 		virtio vm bpf x86_energy_perf_policy \
 		tmon freefall iio objtool kvm_stat wmi \
-		pci debugging tracing
+		pci debugging tracing rpmb
 
 acpi_install:
 	$(call descend,power/$(@:_install=),install)
@@ -109,7 +112,7 @@ acpi_install:
 cpupower_install:
 	$(call descend,power/$(@:_install=),install)
 
-cgroup_install counter_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install tracing_install:
+cgroup_install counter_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install tracing_install rpmb_install:
 	$(call descend,$(@:_install=),install)
 
 selftests_install:
@@ -129,7 +132,7 @@ kvm_stat_install:
 
 install: acpi_install cgroup_install counter_install cpupower_install gpio_install \
 		hv_install firewire_install iio_install \
-		perf_install selftests_install turbostat_install usb_install \
+		perf_install rpmb_install selftests_install turbostat_install usb_install \
 		virtio_install vm_install bpf_install x86_energy_perf_policy_install \
 		tmon_install freefall_install objtool_install kvm_stat_install \
 		wmi_install pci_install debugging_install intel-speed-select_install \
@@ -157,6 +160,9 @@ perf_clean:
 	$(Q)mkdir -p $(PERF_O) .
 	$(Q)$(MAKE) --no-print-directory -C perf O=$(PERF_O) subdir= clean
 
+rpmb_clean:
+	$(call descend,$(@:_clean=),clean)
+
 selftests_clean:
 	$(call descend,testing/$(@:_clean=),clean)
 
@@ -173,7 +179,7 @@ build_clean:
 	$(call descend,build,clean)
 
 clean: acpi_clean cgroup_clean counter_clean cpupower_clean hv_clean firewire_clean \
-		perf_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \
+		perf_clean rpmb_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \
 		vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
 		freefall_clean build_clean libbpf_clean libsubcmd_clean \
 		gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \
tools/rpmb/.gitignore new file +2 -0
new file mode 100644
index 000000000000..218f680548e6
@@ -0,0 +1,2 @@
+*.o
+rpmb
tools/rpmb/Makefile new file +41 -0

41 lines not on this page · raw message

tools/rpmb/key new file +1 -0
new file mode 100644
index 000000000000..2b6bd3bc3fe6
@@ -0,0 +1 @@
+����h�#ע��pRT࿮��\r|O�	�mo�
\ No newline at end of file
tools/rpmb/rpmb.c new file +1083 -0

1,083 lines not on this page · raw message

tools/rpmb/test.sh new file +22 -0
new file mode 100755
index 000000000000..2cbba5529618
@@ -0,0 +1,22 @@
+#!/bin/sh -e
+# SPDX-License-Identifier: GPL-2.0+
+echo "get info"
+./rpmb -v get-info /dev/rpmb0
+echo "program key"
+./rpmb -v program-key /dev/rpmb0 key
+echo "get write counter"
+./rpmb -v write-counter /dev/rpmb0
+echo "get write counter (and verify)"
+./rpmb -v write-counter /dev/rpmb0 key
+echo "generating data"
+dd if=/dev/urandom of=data.in count=4 bs=256
+echo "write data"
+./rpmb -v write-blocks /dev/rpmb0 0 4 data.in key
+echo "read data back"
+rm -f data.out
+./rpmb -v read-blocks /dev/rpmb0 0 4 data.out
+cmp data.in data.out
+echo "read data back with key check"
+truncate -s 0 data.out
+./rpmb -v read-blocks /dev/rpmb0 0 4 data.out key
+cmp data.in data.out
Signature · 1 line
2.30.2
#10 lore raw

Re: [PATCH v2 4/4] tools rpmb: add RPBM access tool

Hello,

tools/rpmb/rpmb.c line 93

Quoted 12 lines · Alex Bennée
tools/rpmb/rpmb.c new file +11 -0
+/*
+ * Utility functions
+ */
+static int open_dev_file(const char *devfile, struct rpmb_ioc_cap_cmd *cap)
+{
...
+	rpmb_dbg("RPMB rpmb_target = %d\n", cap->target);
+	rpmb_dbg("RPMB capacity    = %d\n", cap->capacity);
+	rpmb_dbg("RPMB block_size  = %d\n", cap->block_size);
+	rpmb_dbg("RPMB wr_cnt_max  = %d\n", cap->wr_cnt_max);
+	rpmb_dbg("RPMB rd_cnt_max  = %d\n", cap->rd_cnt_max);
+	rpmb_dbg("RPMB auth_method = %d\n", cap->auth_method);

The previously present device_type has already gone. Do we loose an opportunity to inform the user about anything which may not be virtio RPMB in the future or is this intentional? A new device type VIRTIO_RPMB instead and keeping the door open for UFS, NVMe, eMMC etc.?

And if the removal was intentional: rpmb_target, block_size, auth_method: Still needed and if so for what is it good for?

tools/rpmb/rpmb.c line 393

Quoted 10 lines

...

tools/rpmb/rpmb.c new file +9 -0
+}
+
+static struct virtio_rpmb_frame * vrpmb_alloc_frames(int n)
+{
+	struct virtio_rpmb_frame *frames;
+
+	frames = calloc(n, sizeof(struct virtio_rpmb_frame));
+	if (frames)
+		memset(frames, 0, n *  sizeof(struct virtio_rpmb_frame));

Very minor: calloc() already zeroes.

tools/rpmb/rpmb.c line 396

Quoted 3 lines
tools/rpmb/rpmb.c new file +3 -0
+	return frames;
+}
+

/*
+ * To read blocks we receive a bunch of frames from the vrpmb device
+ * which we need to validate and extract the actual data into
+ * requested buffer.
+ */
+static int vrpmb_read_blocks(int dev_fd, void *key, int addr, int count, void *data, int len) +{
+...
+ ret = ioctl(dev_fd, RPMB_IOC_RBLOCKS_CMD, &cmd);
+ if (ret < 0) {
+ rpmb_err("rblocks ioctl failure %d: %s.\n", ret,
+ strerror(errno));
+ goto out;
+ }

The (older) rpmb tool always puzzles me with complaining about the mismatch MAC when there was also a result != VIRTIO_RPMB_RES_OK. I guess the ioctl() returns 0 if the ioctl() as such succeeded but there is an error code indicated in the frame. Consider adding to print the result if it indicated a problem.

I can remember the old tool used the result of the last frame for this purpose which was probably not a good choice, not sure why this was that way, probably the first frame would be a better choice.

+ for (i = 0; i < count; i++) {
+ struct virtio_rpmb_frame *f = &frames[i];
+
+ vrpmb_dump_frame("block data", f);
+
+ if (key) {
+ ret = vrpmb_check_mac(key, f, 1);
+ if (ret) {
+ rpmb_err("%s: check mac error frame %d/%d\n", __func__, i, ret);
+ break;
+ }
+ }
+
+ memcpy(data, &f->data, RPMB_BLOCK_SIZE);
+ data += RPMB_BLOCK_SIZE;
+ }
+ ret = 0;
+
+ out:
+ free(frames);
+ return ret;
+}
+
+
+static void *read_key(const char *path)
+{
+ int key_fd = open_rd_file(path, "key file");
+ void *key;
+
+ if (key_fd < 0)
+ return NULL;
+
+ key = malloc(RPMB_KEY_SIZE);

Very minor: There's not a single free() for key in the code. Plays no role here as the program runs only for a fraction of a second, just saw it. You are making your life harder as necessary by using dynamic memory when it can be avoided, all those NULL pointer checks and the free(s) which have to be done...

Quoted 26 lines
tools/rpmb/rpmb.c new file +25 -0
+
+	if (!key) {
+		rpmb_err("out of memory for key\n");
+		return NULL;
+	}
+
+	if (read(key_fd, key, RPMB_KEY_SIZE) != RPMB_KEY_SIZE) {
+		rpmb_err("couldn't read key (%s)\n", strerror(errno));
+		return NULL;
+	}
+
+	close(key_fd);
+	return key;
+}
+
 
+
+static const struct rpmb_cmd cmds[] = {
+	{
+		"get-info",
+		op_get_info,
+		"<RPMB_DEVICE>",
+		"    Get RPMB device info\n",
+	},
+	{
+		"program-key",

tools/rpmb/rpmb.c

Quoted 10 lines
tools/rpmb/rpmb.c new file +10 -0
+		op_rpmb_program_key,
+		"<RPMB_DEVICE> <KEYFILE>",
+		"    Program authentication KEYFILE\n"
+		"    NOTE: This is a one-time programmable irreversible change.\n",
+	},
+	{
+		"write-counter",
+		op_rpmb_get_write_counter,
+		"<RPMB_DEVICE>",
+		"    Rertrive write counter value from the <RPMB_DEVICE> to stdout.\n"

Optional parameter explanation [KEYFILE] got lost in write-counter.

tools/rpmb/rpmb.c line 961

Quoted 8 lines
tools/rpmb/rpmb.c new file +8 -0
+	},
+	{
+		"write-blocks",
+		op_rpmb_write_blocks,
+		"<RPMB_DEVICE> <address> <block_count> <DATA_FILE> <KEYID>",
+		"    <block count> of 256 bytes will be written from the DATA_FILE\n"
+		"    to the <RPMB_DEVICE> at block offset <address>.\n"
+		"    When DATA_FILE is -, read from standard input.\n",

Puzzling naming change. The KEYID is indeed the <KEYFILE>.

tools/rpmb/rpmb.c line 969

Quoted 8 lines
tools/rpmb/rpmb.c new file +8 -0
+	},
+	{
+		"read-blocks",
+		op_rpmb_read_blocks,
+		"<RPMB_DEVICE> <address> <blocks count> <OUTPUT_FILE>",
+		"    <block count> of 256 bytes will be read from <RPMB_DEVICE>\n"
+		"    to the OUTPUT_FILE\n"
+		"    When OUTPUT_FILE is -, write to standard output\n",

Here also the optional parameter explanation [KEYFILE] got lost in read-blocks.

For people not knowing the tool trying to get into RPMB a complete and consistent help is helpful I can still remember when I was in the situation to understand more playing around with the (older) tool.

Quoted 4 lines
tools/rpmb/rpmb.c new file +4 -0
+	},
+
+	{ NULL, NULL, NULL, NULL }
+};
Signature · 14 lines
Dipl.-Ing. Harald Mommer
Senior Software Engineer

OpenSynergy GmbH
Rotherstr. 20, 10245 Berlin

Phone:  +49 (30) 60 98 540-0 <== Zentrale
Fax:    +49 (30) 60 98 540-99
E-Mail: [email protected]

www.opensynergy.com

Handelsregister: Amtsgericht Charlottenburg, HRB 108616B
Geschäftsführer/Managing Director: Regis Adjamah
#11 lore raw
In reply to Alex Bennée

Hi Alex,

Thanks for this unified RPMB interface, I wanted to verify this on our UFS, it seems you didn't add the UFS access interface in this version from your userspace tools, right?

Kind regards,
Bean

#12 lore raw
Quoted 5 lines · Bean Huo

Hi Alex,

Thanks for this unified RPMB interface, I wanted to verify this on our UFS, it seems you didn't add the UFS access interface in this version from your userspace tools, right?

No I didn't but it should be easy enough to add some function pointer redirection everywhere one of the op_* functions calls a vrpmb_* function. Do you already have a UFS RPMB device driver?

Signature · 1 line
Alex Bennée
#13 lore raw
Quoted 11 lines · Alex Bennée
Quoted 7 lines · Bean Huo

Hi Alex,

Thanks for this unified RPMB interface, I wanted to verify this on our
UFS, it seems you didn't add the UFS access interface in this version
from your userspace tools, right?

Quoted 4 lines

No I didn't but it should be easy enough to add some function pointer redirection everywhere one of the op_* functions calls a vrpmb_* function. Do you already have a UFS RPMB device driver?

Hi Alex,
Thanks for your feedback.

We now access UFS RPMB through the RPMB LUN BSG device, RPMB is a well- known LU and we have a userspace tool to access it.

I see that if we're going to use your interface, "static struct rpmb_ops" should be registered from a lower-level driver, for example in a UFS driver, yes there should be no problem with this registration, but I don't know with the current way Compared, what are the advantages to add a driver. maybe the main advantage is that we will have an unified user space tool for RPMB. right?

Kind regards,
Bean

#14 lore raw
Quoted 23 lines · Bean Huo
Quoted 11 lines · Alex Bennée
Quoted 7 lines · Bean Huo

Hi Alex,

Thanks for this unified RPMB interface, I wanted to verify this on our
UFS, it seems you didn't add the UFS access interface in this version
from your userspace tools, right?

Quoted 4 lines

No I didn't but it should be easy enough to add some function pointer redirection everywhere one of the op_* functions calls a vrpmb_* function. Do you already have a UFS RPMB device driver?

Hi Alex,
Thanks for your feedback.

We now access UFS RPMB through the RPMB LUN BSG device, RPMB is a well- known LU and we have a userspace tool to access it.

Quoted 6 lines

I see that if we're going to use your interface, "static struct rpmb_ops" should be registered from a lower-level driver, for example in a UFS driver, yes there should be no problem with this registration, but I don't know with the current way Compared, what are the advantages to add a driver. maybe the main advantage is that we will have an unified user space tool for RPMB. right?

Pretty much. The main issue for virtio-rpmb is it doesn't really fit neatly into the block stack because all it does is the RPMB part so a non-block orientate API makes sense.

Can you point be to where the UFS driver does it's current RPMB stuff?

Quoted 3 lines

Kind regards,
Bean

Signature · 1 line
Alex Bennée
#15 lore raw
Quoted 39 lines · Alex Bennée
Quoted 26 lines · Bean Huo
Quoted 12 lines · Alex Bennée
Quoted 8 lines · Bean Huo

Hi Alex,

Thanks for this unified RPMB interface, I wanted to verify this on
our
UFS, it seems you didn't add the UFS access interface in this version
from your userspace tools, right?

Quoted 5 lines

No I didn't but it should be easy enough to add some function pointer
redirection everywhere one of the op_* functions calls a vrpmb_* function. Do you already have a UFS RPMB device driver?

Hi Alex,
Thanks for your feedback.

We now access UFS RPMB through the RPMB LUN BSG device, RPMB is a well-
known LU and we have a userspace tool to access it.

Quoted 9 lines

I see that if we're going to use your interface, "static struct rpmb_ops" should be registered from a lower-level driver, for example
in a UFS driver, yes there should be no problem with this registration,
but I don't know with the current way Compared, what are the advantages
to add a driver. maybe the main advantage is that we will have an unified user space tool for RPMB. right?

Quoted 7 lines

Pretty much. The main issue for virtio-rpmb is it doesn't really fit neatly into the block stack because all it does is the RPMB part so a non-block orientate API makes sense.

Can you point be to where the UFS driver does it's current RPMB stuff?

It's the SCSI BSG driver, in fact, we don't have a dedicated UFS RPMB driver in the kernel. RPMB is a well known LU, we are using userspace tools to issue SCSI commands directly to the UFS RPMB LU via ioctl() from the BSG device node in the /dev/sg/ folder.

Here is the BSG part of the code in the userspace tools:

        io_hdr_v4.guard = 'Q';                                        
        io_hdr_v4.protocol = BSG_PROTOCOL_SCSI;                       
        io_hdr_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;            
        io_hdr_v4.response = (__u64)sense_buffer;                     
        io_hdr_v4.max_response_len = SENSE_BUFF_LEN;                  
        io_hdr_v4.request_len = cmd_len;                              
        io_hdr_v4.request = (__u64)cdb;                               
                                                                                                                          
                                                                                 
        ioctl(fd, SG_IO, &io_hdr_v4))

...

Quoted 5 lines
Quoted 3 lines

Kind regards,
Bean

#16 lore raw
Quoted 55 lines · Bean Huo
Quoted 39 lines · Alex Bennée
Quoted 26 lines · Bean Huo
Quoted 12 lines · Alex Bennée
Quoted 8 lines · Bean Huo

Hi Alex,

Thanks for this unified RPMB interface, I wanted to verify this on
our
UFS, it seems you didn't add the UFS access interface in this version
from your userspace tools, right?

Quoted 5 lines

No I didn't but it should be easy enough to add some function pointer
redirection everywhere one of the op_* functions calls a vrpmb_* function. Do you already have a UFS RPMB device driver?

Hi Alex,
Thanks for your feedback.

We now access UFS RPMB through the RPMB LUN BSG device, RPMB is a well-
known LU and we have a userspace tool to access it.

Quoted 9 lines

I see that if we're going to use your interface, "static struct rpmb_ops" should be registered from a lower-level driver, for example
in a UFS driver, yes there should be no problem with this registration,
but I don't know with the current way Compared, what are the advantages
to add a driver. maybe the main advantage is that we will have an unified user space tool for RPMB. right?

Quoted 7 lines

Pretty much. The main issue for virtio-rpmb is it doesn't really fit neatly into the block stack because all it does is the RPMB part so a non-block orientate API makes sense.

Can you point be to where the UFS driver does it's current RPMB stuff?

It's the SCSI BSG driver, in fact, we don't have a dedicated UFS RPMB driver in the kernel. RPMB is a well known LU, we are using userspace tools to issue SCSI commands directly to the UFS RPMB LU via ioctl() from the BSG device node in the /dev/sg/ folder.

Here is the BSG part of the code in the userspace tools:

Quoted 10 lines
         io_hdr_v4.guard = 'Q';
         io_hdr_v4.protocol = BSG_PROTOCOL_SCSI;
         io_hdr_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
         io_hdr_v4.response = (__u64)sense_buffer;
         io_hdr_v4.max_response_len = SENSE_BUFF_LEN;
         io_hdr_v4.request_len = cmd_len;
         io_hdr_v4.request = (__u64)cdb;
                                                                                                                           
                                                                                  
         ioctl(fd, SG_IO, &io_hdr_v4))

Hi Bean,

I'm not sure where the above comes from? The Android RPMB client uses slightly different code. Additionally, the retry loop around the submission of SG/IO commands is very important. See also the check_sg_io_hdr() call in send_ufs_rpmb_req(). See also https://cs.android.com/android/platform/superproject/+/master:system/core/trusty/storage/proxy/rpmb.c

Thanks,

Bart.

#17 lore raw
Quoted 23 lines · Bart Van Assche
Quoted 10 lines

It's the SCSI BSG driver, in fact, we don't have a dedicated UFS RPMB
driver in the kernel. RPMB is a well known LU, we are using userspace
tools to issue SCSI commands directly to the UFS RPMB LU via ioctl()
from the BSG device node in the /dev/sg/ folder.

Here is the BSG part of the code in the userspace tools:

Quoted 12 lines

          io_hdr_v4.guard = 'Q'; io_hdr_v4.protocol = BSG_PROTOCOL_SCSI; io_hdr_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD; io_hdr_v4.response = (__u64)sense_buffer; io_hdr_v4.max_response_len = SENSE_BUFF_LEN; io_hdr_v4.request_len = cmd_len; io_hdr_v4.request = (__u64)cdb;




          ioctl(fd, SG_IO, &io_hdr_v4))

Quoted 9 lines

Hi Bean,

I'm not sure where the above comes from? The Android RPMB client uses slightly different code. Additionally, the retry loop around the submission of SG/IO commands is very important. See also the check_sg_io_hdr() call in send_ufs_rpmb_req(). See also
https://cs.android.com/android/platform/superproject/+/master:system/core/trusty/storage/proxy/rpmb.c

Bart,

It is from the ufs-utils.

So, do you vote to add the UFS RPMB driver based on this new framework to resolve this conflict?

Kind regards,
Bean

Quoted 5 lines

Thanks,

Bart.

#18 lore raw
Quoted 4 lines · Bean Huo

It is from the ufs-utils.

So, do you vote to add the UFS RPMB driver based on this new framework to resolve this conflict?

Are any applications using the RPMB code from ufs-utils? It seems to me that the ufs-utils code doe not handle SCSI unit attentions correctly. If a POWER ON unit attention is received as reply to a SECURITY PROTOCOL OUT transaction, the write counter should be reread instead of retrying the SECURITY PROTOCOL OUT command with the same write counter.

Regarding adding a UFS RPMB driver: that seems useful to me since multiple applications make use of the UFS RPMB functionality. My understanding is that currently storageproxyd multiplexes UFS RPMB accesses in Android.

Thanks,

Bart.

#19 lore raw
Quoted 7 lines · Bart Van Assche
Quoted 5 lines · Bean Huo

It is from the ufs-utils.

So, do you vote to add the UFS RPMB driver based on this new framework
to resolve this conflict?

Quoted 10 lines

Are any applications using the RPMB code from ufs-utils? It seems to me
that the ufs-utils code doe not handle SCSI unit attentions correctly.
If a POWER ON unit attention is received as reply to a SECURITY PROTOCOL
OUT transaction, the write counter should be reread instead of retrying
the SECURITY PROTOCOL OUT command with the same write counter.

Not much sure how customers use this tool, based on my little information from the field, the customer developed their own RPMB code in the application. Here utils code is good example for them to study and verify RPMB functinalities.

Quoted 5 lines

Regarding adding a UFS RPMB driver: that seems useful to me since multiple applications make use of the UFS RPMB functionality. My understanding is that currently storageproxyd multiplexes UFS RPMB accesses in Android.

I have the same opinion with you, if we have an unified RPMB access interface, and adding RPMB driver in the kernel, thus is better to manage RPMB.

Kind regards,
Bean

Quoted 3 lines

Thanks,

Bart.

#21 lore raw
In reply to Alex Bennée
Quoted 4 lines · Alex Bennée

Hi,

This is another attempt to come up with an RPMB API for the kernel. The last discussion of this was in the thread:

Ping?

Any other comments or reviews? Is there a desire to make other devices that provide RPMB functionality visible via a common API?

Quoted 89 lines

Subject: [RFC PATCH 0/5] RPMB internal and user-space API + WIP virtio-rpmb frontend
Date: Wed, 3 Mar 2021 13:54:55 +0000
Message-Id: <[email protected]>

The series provides for the RPMB sub-system, a new chardev API driven by ioctls and a full multi-block capable virtio-rpmb driver. You can find a working vhost-user backend in my QEMU branch here:

https://github.com/stsquad/qemu/commits/virtio/vhost-user-rpmb-v2

The branch is a little messy but I'll be posting a cleaned up version in the following weeks. The only real changes to the backend is the multi-block awareness and some tweaks to deal with QEMU internals handling VirtIO config space messages which weren't previously exercised. The test.sh script in tools/rpmb works through the various transactions but isn't comprehensive.

Changes since the last posting:

- frame construction is mostly back in userspace

The previous discussion showed there wasn't any appetite for using the kernels keyctl() interface so userspace yet again takes responsibility for constructing most* frames. Currently these are all pure virtio-rpmb frames but the code is written so we can plug in additional frame types. The virtio-rpmb driver does some validation and in some cases (* read-blocks) constructs the request frame in the driver. It would take someone implementing a driver for another RPMB device type to see if this makes sense.

- user-space interface is still split across several ioctls

Although 3 of the ioctls share the common rpmb_ioc_reqresp_cmd structure it does mean things like capacity, write_count and read_blocks can have their own structure associated with the command.

As before I shall follow up with the QEMU based vhost-user backend and hopefully a rust-vmm re-implementation. However I've no direct interest in implementing the interfaces to real hardware. I leave that to people who have access to such things and are willing to take up the maintainer burden if this is merged.

Regards,

Alex

Alex Bennée (4):
rpmb: add Replay Protected Memory Block (RPMB) subsystem
char: rpmb: provide a user space interface
rpmb: create virtio rpmb frontend driver
tools rpmb: add RPBM access tool

 .../userspace-api/ioctl/ioctl-number.rst      |    1 +
 MAINTAINERS                                   |    9 +
 drivers/Kconfig                               |    2 +
 drivers/Makefile                              |    1 +
 drivers/rpmb/Kconfig                          |   28 +
 drivers/rpmb/Makefile                         |    9 +
 drivers/rpmb/cdev.c                           |  309 +++++
 drivers/rpmb/core.c                           |  439 +++++++
 drivers/rpmb/rpmb-cdev.h                      |   17 +
 drivers/rpmb/virtio_rpmb.c                    |  518 ++++++++
 include/linux/rpmb.h                          |  182 +++
 include/uapi/linux/rpmb.h                     |   99 ++
 include/uapi/linux/virtio_rpmb.h              |   54 +
 tools/Makefile                                |   16 +-
 tools/rpmb/.gitignore                         |    2 +
 tools/rpmb/Makefile                           |   41 +
 tools/rpmb/key                                |    1 +
 tools/rpmb/rpmb.c                             | 1083 +++++++++++++++++
 tools/rpmb/test.sh                            |   22 +
 19 files changed, 2828 insertions(+), 5 deletions(-)
 create mode 100644 drivers/rpmb/Kconfig
 create mode 100644 drivers/rpmb/Makefile
 create mode 100644 drivers/rpmb/cdev.c
 create mode 100644 drivers/rpmb/core.c
 create mode 100644 drivers/rpmb/rpmb-cdev.h
 create mode 100644 drivers/rpmb/virtio_rpmb.c
 create mode 100644 include/linux/rpmb.h
 create mode 100644 include/uapi/linux/rpmb.h
 create mode 100644 include/uapi/linux/virtio_rpmb.h
 create mode 100644 tools/rpmb/.gitignore
 create mode 100644 tools/rpmb/Makefile
 create mode 100644 tools/rpmb/key
 create mode 100644 tools/rpmb/rpmb.c
 create mode 100755 tools/rpmb/test.sh
Signature · 1 line
Alex Bennée
#22 lore raw

v2 cover rpmb subsystem, uapi and virtio-rpmb driver

In reply to Alex Bennée

Hi Alex,

[ Resending, Sorry for the noise ]

Are you still working on it or planning to resubmit it ?

[1] The current optee tee kernel driver implementation doesn't work when IMA is used with optee implemented ftpm.

The ftpm has dependency on tee-supplicant which comes once the user space is up and running and IMA attestation happens at boot time and it requires to extend ftpm PCRs.

But IMA can't use PCRs if ftpm use secure emmc RPMB partition. As optee can only access RPMB via tee-supplicant(user space). So, there should be a fast path to allow optee os to access the RPMB parititon without waiting for user-space tee supplicant.

To achieve this fast path linux optee driver and mmc driver needs some work and finally it will need RPMB driver which you posted.

Please let me know what's your plan on this.

[1] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Best Regards,
Shyam

#23 lore raw

As an alternative, Is it possible to change ftpm design not to depend on RPMB access at the earlier/boot stage? Because to my understanding, typically PCRs don't require persistent/NV storage (for example, before RPMB or tee-supplicant is ready, use TEE memory instead as temporary storage)

Bing

IPAS Security Brown Belt (https://www.credly.com/badges/69ea809f-3a96-4bc7-bb2f-442c1b17af26)
System Software Engineering
Software and Advanced Technology Group
Zizhu Science Park, Shanghai, China

-----Original Message-----
From: Shyam Saini <[email protected]>
Sent: Thursday, June 1, 2023 3:10 AM
To: alex.bennee(a)linaro.org
Cc: code(a)tyhicks.com; Matti.Moell(a)opensynergy.com; arnd(a)linaro.org; Zhu, Bing <[email protected]>; hmo(a)opensynergy.com; ilias.apalodimas(a)linaro.org; joakim.bech(a)linaro.org; linux-kernel(a)vger.kernel.org; linux-mmc(a)vger.kernel.org; linux-scsi(a)vger.kernel.org; maxim.uvarov(a)linaro.org; ruchika.gupta(a)linaro.org; Winkler, Tomas <[email protected]>; ulf.hansson(a)linaro.org; Huang, Yang <[email protected]>; sumit.garg(a)linaro.org; jens.wiklander(a)linaro.org; op-tee(a)lists.trustedfirmware.org
Subject: [PATCH v2 0/4] rpmb subsystem, uapi and virtio-rpmb driver

Hi Alex,

[ Resending, Sorry for the noise ]

Are you still working on it or planning to resubmit it ?

[1] The current optee tee kernel driver implementation doesn't work when IMA is used with optee implemented ftpm.

The ftpm has dependency on tee-supplicant which comes once the user space is up and running and IMA attestation happens at boot time and it requires to extend ftpm PCRs.

But IMA can't use PCRs if ftpm use secure emmc RPMB partition. As optee can only access RPMB via tee-supplicant(user space). So, there should be a fast path to allow optee os to access the RPMB parititon without waiting for user-space tee supplicant.

To achieve this fast path linux optee driver and mmc driver needs some work and finally it will need RPMB driver which you posted.

Please let me know what's your plan on this.

[1] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Best Regards,
Shyam

#24 lore raw

Hi Bing

Quoted 2 lines · Bing

As an alternative, Is it possible to change ftpm design not to depend on RPMB access at the earlier/boot stage? Because to my understanding, typically PCRs don't require persistent/NV storage (for example, before RPMB or tee-supplicant is ready, use TEE memory instead as temporary storage)

I am not entirely sure this will solve our problem here. You are right that we shouldn't depend on the supplicant to extend PCRs. But what happens if an object is sealed against certain PCR values? We are back to the same problem

Thanks
/Ilias

Quoted 35 lines

Bing

IPAS Security Brown Belt (https://www.credly.com/badges/69ea809f-3a96-4bc7-bb2f-442c1b17af26)
System Software Engineering
Software and Advanced Technology Group
Zizhu Science Park, Shanghai, China

-----Original Message-----
From: Shyam Saini <[email protected]>
Sent: Thursday, June 1, 2023 3:10 AM
To: alex.bennee(a)linaro.org
Cc: code(a)tyhicks.com; Matti.Moell(a)opensynergy.com; arnd(a)linaro.org; Zhu, Bing <[email protected]>; hmo(a)opensynergy.com; ilias.apalodimas(a)linaro.org; joakim.bech(a)linaro.org; linux-kernel(a)vger.kernel.org; linux-mmc(a)vger.kernel.org; linux-scsi(a)vger.kernel.org; maxim.uvarov(a)linaro.org; ruchika.gupta(a)linaro.org; Winkler, Tomas <[email protected]>; ulf.hansson(a)linaro.org; Huang, Yang <[email protected]>; sumit.garg(a)linaro.org; jens.wiklander(a)linaro.org; op-tee(a)lists.trustedfirmware.org
Subject: [PATCH v2 0/4] rpmb subsystem, uapi and virtio-rpmb driver

Hi Alex,

[ Resending, Sorry for the noise ]

Are you still working on it or planning to resubmit it ?

[1] The current optee tee kernel driver implementation doesn't work when IMA is used with optee implemented ftpm.

The ftpm has dependency on tee-supplicant which comes once the user space is up and running and IMA attestation happens at boot time and it requires to extend ftpm PCRs.

But IMA can't use PCRs if ftpm use secure emmc RPMB partition. As optee can only access RPMB via tee-supplicant(user space). So, there should be a fast path to allow optee os to access the RPMB parititon without waiting for user-space tee supplicant.

To achieve this fast path linux optee driver and mmc driver needs some work and finally it will need RPMB driver which you posted.

Please let me know what's your plan on this.

[1] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Best Regards,
Shyam

#25 lore raw
Quoted 11 lines · Ilias Apalodimas

Hi Bing

Quoted 2 lines · Bing

As an alternative, Is it possible to change ftpm design not to depend on RPMB access at the earlier/boot stage? Because to my understanding, typically PCRs don't require persistent/NV storage (for example, before RPMB or tee-supplicant is ready, use TEE memory instead as temporary storage)

I am not entirely sure this will solve our problem here. You are right that we shouldn't depend on the supplicant to extend PCRs. But what happens if an object is sealed against certain PCR values? We are back to the same problem

+1

Temporary storage may be a stop gap solution for some use-cases but having a fast path access to RPMB via kernel should be our final goal. I would suggest we start small with the MMC subsystem to expose RPMB access APIs for OP-TEE driver rather than a complete RPMB subsystem.

-Sumit

Quoted 38 lines

Thanks
/Ilias

Quoted 35 lines

Bing

IPAS Security Brown Belt (https://www.credly.com/badges/69ea809f-3a96-4bc7-bb2f-442c1b17af26)
System Software Engineering
Software and Advanced Technology Group
Zizhu Science Park, Shanghai, China

-----Original Message-----
From: Shyam Saini <[email protected]>
Sent: Thursday, June 1, 2023 3:10 AM
To: alex.bennee(a)linaro.org
Cc: code(a)tyhicks.com; Matti.Moell(a)opensynergy.com; arnd(a)linaro.org; Zhu, Bing <[email protected]>; hmo(a)opensynergy.com; ilias.apalodimas(a)linaro.org; joakim.bech(a)linaro.org; linux-kernel(a)vger.kernel.org; linux-mmc(a)vger.kernel.org; linux-scsi(a)vger.kernel.org; maxim.uvarov(a)linaro.org; ruchika.gupta(a)linaro.org; Winkler, Tomas <[email protected]>; ulf.hansson(a)linaro.org; Huang, Yang <[email protected]>; sumit.garg(a)linaro.org; jens.wiklander(a)linaro.org; op-tee(a)lists.trustedfirmware.org
Subject: [PATCH v2 0/4] rpmb subsystem, uapi and virtio-rpmb driver

Hi Alex,

[ Resending, Sorry for the noise ]

Are you still working on it or planning to resubmit it ?

[1] The current optee tee kernel driver implementation doesn't work when IMA is used with optee implemented ftpm.

The ftpm has dependency on tee-supplicant which comes once the user space is up and running and IMA attestation happens at boot time and it requires to extend ftpm PCRs.

But IMA can't use PCRs if ftpm use secure emmc RPMB partition. As optee can only access RPMB via tee-supplicant(user space). So, there should be a fast path to allow optee os to access the RPMB parititon without waiting for user-space tee supplicant.

To achieve this fast path linux optee driver and mmc driver needs some work and finally it will need RPMB driver which you posted.

Please let me know what's your plan on this.

[1] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Best Regards,
Shyam

#26 lore raw
Quoted 15 lines · Sumit Garg
Quoted 11 lines · Ilias Apalodimas

Hi Bing

Quoted 2 lines · Bing

As an alternative, Is it possible to change ftpm design not to depend on RPMB access at the earlier/boot stage? Because to my understanding, typically PCRs don't require persistent/NV storage (for example, before RPMB or tee-supplicant is ready, use TEE memory instead as temporary storage)

I am not entirely sure this will solve our problem here. You are right that we shouldn't depend on the supplicant to extend PCRs. But what happens if an object is sealed against certain PCR values? We are back to the same problem

Quoted 6 lines

+1

Temporary storage may be a stop gap solution for some use-cases but having a fast path access to RPMB via kernel should be our final goal. I would suggest we start small with the MMC subsystem to expose RPMB access APIs for OP-TEE driver rather than a complete RPMB subsystem.

I discussed with the OP-TEE maintainers about adding parts of the supplicant in the kernel. The supplicant 'just' sends an ioctl to store/read stuff anyway. So it would make sense to have a closer and see if that looks reasonable.
Thanks

/Ilias

Quoted 41 lines

-Sumit

Quoted 38 lines

Thanks
/Ilias

Quoted 35 lines

Bing

IPAS Security Brown Belt (https://www.credly.com/badges/69ea809f-3a96-4bc7-bb2f-442c1b17af26)
System Software Engineering
Software and Advanced Technology Group
Zizhu Science Park, Shanghai, China

-----Original Message-----
From: Shyam Saini <[email protected]>
Sent: Thursday, June 1, 2023 3:10 AM
To: alex.bennee(a)linaro.org
Cc: code(a)tyhicks.com; Matti.Moell(a)opensynergy.com; arnd(a)linaro.org; Zhu, Bing <[email protected]>; hmo(a)opensynergy.com; ilias.apalodimas(a)linaro.org; joakim.bech(a)linaro.org; linux-kernel(a)vger.kernel.org; linux-mmc(a)vger.kernel.org; linux-scsi(a)vger.kernel.org; maxim.uvarov(a)linaro.org; ruchika.gupta(a)linaro.org; Winkler, Tomas <[email protected]>; ulf.hansson(a)linaro.org; Huang, Yang <[email protected]>; sumit.garg(a)linaro.org; jens.wiklander(a)linaro.org; op-tee(a)lists.trustedfirmware.org
Subject: [PATCH v2 0/4] rpmb subsystem, uapi and virtio-rpmb driver

Hi Alex,

[ Resending, Sorry for the noise ]

Are you still working on it or planning to resubmit it ?

[1] The current optee tee kernel driver implementation doesn't work when IMA is used with optee implemented ftpm.

The ftpm has dependency on tee-supplicant which comes once the user space is up and running and IMA attestation happens at boot time and it requires to extend ftpm PCRs.

But IMA can't use PCRs if ftpm use secure emmc RPMB partition. As optee can only access RPMB via tee-supplicant(user space). So, there should be a fast path to allow optee os to access the RPMB parititon without waiting for user-space tee supplicant.

To achieve this fast path linux optee driver and mmc driver needs some work and finally it will need RPMB driver which you posted.

Please let me know what's your plan on this.

[1] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Best Regards,
Shyam

#27 lore raw

Hi Alex,

Quoted 24 lines · Ilias Apalodimas
Quoted 15 lines · Sumit Garg
Quoted 11 lines · Ilias Apalodimas

Hi Bing

Quoted 2 lines · Bing

As an alternative, Is it possible to change ftpm design not to depend on RPMB access at the earlier/boot stage? Because to my understanding, typically PCRs don't require persistent/NV storage (for example, before RPMB or tee-supplicant is ready, use TEE memory instead as temporary storage)

I am not entirely sure this will solve our problem here. You are right that we shouldn't depend on the supplicant to extend PCRs. But what happens if an object is sealed against certain PCR values? We are back to the same problem

Quoted 6 lines

+1

Temporary storage may be a stop gap solution for some use-cases but having a fast path access to RPMB via kernel should be our final goal. I would suggest we start small with the MMC subsystem to expose RPMB access APIs for OP-TEE driver rather than a complete RPMB subsystem.

Quoted 5 lines

I discussed with the OP-TEE maintainers about adding parts of the supplicant in the kernel. The supplicant 'just' sends an ioctl to store/read stuff anyway. So it would make sense to have a closer and see if that looks reasonable.
Thanks

I was trying to create a setup to test this. I've added the kernel patches on top of https://github.com/linaro-swg/linux/tree/optee. The QEMU branch is a bit dated and I had to add
3a845a214b42 target/arm: allow setting SCR_EL3.EnTP2 when FEAT_SME is implemented
d4a7b0ef1a03 hw/arm/boot: set CPTR_EL3.ESM and SCR_EL3.EnTP2 when booting Linux with EL3
9745a003f878 hw/intc/arm_gicv3: fix prio masking on pmr write beeec926d24a target/arm: mark SP_EL1 with ARM_CP_EL3_NO_EL2_KEEP on top of that branch to be able to boot to the Linux kernel.

I have the vhost-user-rpmb process running and connected with QEMU, but around (guessing really) when the RPMB subsystem is initializing the process dies with:
================ Vhost user message ================

Request: VHOST_USER_SET_VRING_ADDR (9)
Flags:   0x1
Size:    40
vhost-user-rpmb-INFO: 18:58:08.312: vrpmb_process_msg: msg
VHOST_USER_SET_VRING_ADDR(9)
vhost_vring_addr:
    index:  0
    flags:  0
    desc_user_addr:   0x00007ff15fa91000
    used_user_addr:   0x00007ff15fa91080
    avail_user_addr:  0x00007ff15fa91040
    log_guest_addr:   0x0000000041c91080

Setting virtq addresses:
vring_desc at (nil)
vring_used at (nil)
vring_avail at (nil)

(vhost-user-rpmb:3236474): vhost-user-rpmb-CRITICAL **: 18:58:08.312:
Invalid vring_addr message

Among other options, I'm starting QEMU with -machine virt,secure=on,mte=off,gic-version=3,virtualization=false to enable the secure world.

Do you have an idea of what might be wrong? Where should I start looking?

Thanks,
Jens

Quoted 44 lines

/Ilias

Quoted 41 lines

-Sumit

Quoted 38 lines

Thanks
/Ilias

Quoted 35 lines

Bing

IPAS Security Brown Belt (https://www.credly.com/badges/69ea809f-3a96-4bc7-bb2f-442c1b17af26)
System Software Engineering
Software and Advanced Technology Group
Zizhu Science Park, Shanghai, China

-----Original Message-----
From: Shyam Saini <[email protected]>
Sent: Thursday, June 1, 2023 3:10 AM
To: alex.bennee(a)linaro.org
Cc: code(a)tyhicks.com; Matti.Moell(a)opensynergy.com; arnd(a)linaro.org; Zhu, Bing <[email protected]>; hmo(a)opensynergy.com; ilias.apalodimas(a)linaro.org; joakim.bech(a)linaro.org; linux-kernel(a)vger.kernel.org; linux-mmc(a)vger.kernel.org; linux-scsi(a)vger.kernel.org; maxim.uvarov(a)linaro.org; ruchika.gupta(a)linaro.org; Winkler, Tomas <[email protected]>; ulf.hansson(a)linaro.org; Huang, Yang <[email protected]>; sumit.garg(a)linaro.org; jens.wiklander(a)linaro.org; op-tee(a)lists.trustedfirmware.org
Subject: [PATCH v2 0/4] rpmb subsystem, uapi and virtio-rpmb driver

Hi Alex,

[ Resending, Sorry for the noise ]

Are you still working on it or planning to resubmit it ?

[1] The current optee tee kernel driver implementation doesn't work when IMA is used with optee implemented ftpm.

The ftpm has dependency on tee-supplicant which comes once the user space is up and running and IMA attestation happens at boot time and it requires to extend ftpm PCRs.

But IMA can't use PCRs if ftpm use secure emmc RPMB partition. As optee can only access RPMB via tee-supplicant(user space). So, there should be a fast path to allow optee os to access the RPMB parititon without waiting for user-space tee supplicant.

To achieve this fast path linux optee driver and mmc driver needs some work and finally it will need RPMB driver which you posted.

Please let me know what's your plan on this.

[1] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Best Regards,
Shyam

#28 lore raw
In reply to Ilias Apalodimas

Thank you everyone for your valueable feedback.

Alex, are you planning submit this patch series ?
Please let me know.

Quoted 73 lines · Sumit Garg
Quoted 15 lines
Quoted 11 lines · Ilias Apalodimas

Hi Bing

Quoted 2 lines · Bing

As an alternative, Is it possible to change ftpm design not to depend on RPMB access at the earlier/boot stage? Because to my understanding, typically PCRs don't require persistent/NV storage (for example, before RPMB or tee-supplicant is ready, use TEE memory instead as temporary storage)

I am not entirely sure this will solve our problem here. You are right that we shouldn't depend on the supplicant to extend PCRs. But what happens if an object is sealed against certain PCR values? We are back to the same problem

Quoted 6 lines

+1

Temporary storage may be a stop gap solution for some use-cases but having a fast path access to RPMB via kernel should be our final goal. I would suggest we start small with the MMC subsystem to expose RPMB access APIs for OP-TEE driver rather than a complete RPMB subsystem.

I discussed with the OP-TEE maintainers about adding parts of the supplicant in the kernel. The supplicant 'just' sends an ioctl to store/read stuff anyway. So it would make sense to have a closer and see if that looks reasonable.
Thanks

/Ilias

Quoted 41 lines

-Sumit

Quoted 38 lines

Thanks
/Ilias

Quoted 35 lines

Bing

IPAS Security Brown Belt (https://www.credly.com/badges/69ea809f-3a96-4bc7-bb2f-442c1b17af26)
System Software Engineering
Software and Advanced Technology Group
Zizhu Science Park, Shanghai, China

-----Original Message-----
From: Shyam Saini <[email protected]>
Sent: Thursday, June 1, 2023 3:10 AM
To: alex.bennee(a)linaro.org
Cc: code(a)tyhicks.com; Matti.Moell(a)opensynergy.com; arnd(a)linaro.org; Zhu, Bing <[email protected]>; hmo(a)opensynergy.com; ilias.apalodimas(a)linaro.org; joakim.bech(a)linaro.org; linux-kernel(a)vger.kernel.org; linux-mmc(a)vger.kernel.org; linux-scsi(a)vger.kernel.org; maxim.uvarov(a)linaro.org; ruchika.gupta(a)linaro.org; Winkler, Tomas <[email protected]>; ulf.hansson(a)linaro.org; Huang, Yang <[email protected]>; sumit.garg(a)linaro.org; jens.wiklander(a)linaro.org; op-tee(a)lists.trustedfirmware.org
Subject: [PATCH v2 0/4] rpmb subsystem, uapi and virtio-rpmb driver

Hi Alex,

[ Resending, Sorry for the noise ]

Are you still working on it or planning to resubmit it ?

[1] The current optee tee kernel driver implementation doesn't work when IMA is used with optee implemented ftpm.

The ftpm has dependency on tee-supplicant which comes once the user space is up and running and IMA attestation happens at boot time and it requires to extend ftpm PCRs.

But IMA can't use PCRs if ftpm use secure emmc RPMB partition. As optee can only access RPMB via tee-supplicant(user space). So, there should be a fast path to allow optee os to access the RPMB parititon without waiting for user-space tee supplicant.

To achieve this fast path linux optee driver and mmc driver needs some work and finally it will need RPMB driver which you posted.

Please let me know what's your plan on this.

[1] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Best Regards,
Shyam

#29 lore raw
In reply to Zhu, Bing

Hi Bing,

Other than PCRs we also want to store Non volatile ftpm data (NVData), storing these in volatile DDR shared memory will be a spec violation.

Best Regards,
Shyam

Quoted 37 lines

As an alternative, Is it possible to change ftpm design not to depend on RPMB access at the earlier/boot stage? Because to my understanding, typically PCRs don't require persistent/NV storage (for example, before RPMB or tee-supplicant is ready, use TEE memory instead as temporary storage)

Bing

IPAS Security Brown Belt (https://www.credly.com/badges/69ea809f-3a96-4bc7-bb2f-442c1b17af26)
System Software Engineering
Software and Advanced Technology Group
Zizhu Science Park, Shanghai, China

-----Original Message-----
From: Shyam Saini <[email protected]>
Sent: Thursday, June 1, 2023 3:10 AM
To: alex.bennee(a)linaro.org
Cc: code(a)tyhicks.com; Matti.Moell(a)opensynergy.com; arnd(a)linaro.org; Zhu, Bing <[email protected]>; hmo(a)opensynergy.com; ilias.apalodimas(a)linaro.org; joakim.bech(a)linaro.org; linux-kernel(a)vger.kernel.org; linux-mmc(a)vger.kernel.org; linux-scsi(a)vger.kernel.org; maxim.uvarov(a)linaro.org; ruchika.gupta(a)linaro.org; Winkler, Tomas <[email protected]>; ulf.hansson(a)linaro.org; Huang, Yang <[email protected]>; sumit.garg(a)linaro.org; jens.wiklander(a)linaro.org; op-tee(a)lists.trustedfirmware.org
Subject: [PATCH v2 0/4] rpmb subsystem, uapi and virtio-rpmb driver

Hi Alex,

[ Resending, Sorry for the noise ]

Are you still working on it or planning to resubmit it ?

[1] The current optee tee kernel driver implementation doesn't work when IMA is used with optee implemented ftpm.

The ftpm has dependency on tee-supplicant which comes once the user space is up and running and IMA attestation happens at boot time and it requires to extend ftpm PCRs.

But IMA can't use PCRs if ftpm use secure emmc RPMB partition. As optee can only access RPMB via tee-supplicant(user space). So, there should be a fast path to allow optee os to access the RPMB parititon without waiting for user-space tee supplicant.

To achieve this fast path linux optee driver and mmc driver needs some work and finally it will need RPMB driver which you posted.

Please let me know what's your plan on this.

[1] https://optee.readthedocs.io/en/latest/architecture/secure_storage.html

Best Regards,
Shyam