Skip to contentSkip to conversation

Driver for Open Profile for DICE

PATCH In review David Brazdil 2 participants 5 messages Jan 26, 2022 – Feb 1, 2022

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

v7 cover Driver for Open Profile for DICE

Open Profile for DICE is an open protocol for measured boot compatible with the Trusted Computing Group's Device Identifier Composition Engine (DICE) specification. The generated Compound Device Identifier (CDI) certificates represent the measured hardware/software combination and can be used by userspace for remote attestation and sealing.

This patchset adds DeviceTree bindings for the DICE device referencing a reserved memory region containing the CDIs, and a driver that exposes the memory region to userspace via a misc device.

See https://pigweed.googlesource.com/open-dice for more details.

The patches are based on top of v5.17-rc1 and can also be found here:
https://android-kvm.googlesource.com/linux topic/dice_v7

Changes since v6:
* replace spinlock with mutex because devm_memremap can sleep
* prevent write+shared mapping via mprotect/mremap
* fail gracefully when no instances found
* no-map required in DT bindings to ensure mem region not treated as RAM

Changes since v5:
* replaced 'additionalProperties' with 'unevaluatedProperties' in DT YAML

Changes since v4:
* registered compatible in 'reserved_mem_matches'
* removed unnecessary DT node, only reserved-memory
* fixed typos in comments

Changes since v3:
* align with semantics of read/write
* fix kerneldoc warnings
* fix printf format warnings

Changes since v2:
* renamed from 'dice' to 'open-dice'
* replaced ioctls with read/write
* replaced memzero_explicit with memset
* allowed multiple instances
* expanded Kconfig description

Changes since v1:
* converted to miscdevice
* all mappings now write-combine to simplify semantics
* removed atomic state, any attempt at exclusive access
* simplified wipe, applied on ioctl, not on release
* fixed ioctl return value

David Brazdil (2):
dt-bindings: reserved-memory: Open Profile for DICE
misc: open-dice: Add driver to expose DICE data to userspace

 .../reserved-memory/google,open-dice.yaml     |  46 ++++
 drivers/misc/Kconfig                          |  12 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/open-dice.c                      | 208 ++++++++++++++++++
 drivers/of/platform.c                         |   1 +
 5 files changed, 268 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml
 create mode 100644 drivers/misc/open-dice.c

--
2.35.0.rc0.227.g00780c9af4-goog

#1 lore raw

PATCH v7 1/2 dt-bindings: reserved-memory: Open Profile for DICE

Add DeviceTree bindings for Open Profile for DICE, an open protocol for measured boot. Firmware uses DICE to measure the hardware/software combination and generates Compound Device Identifier (CDI) certificates. These are stored in memory and the buffer is described in the DT as a reserved memory region compatible with 'google,open-dice'.

'no-map' is required to ensure the memory region is never treated by the kernel as system memory.

---
 .../reserved-memory/google,open-dice.yaml     | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml
Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml new file +46 -0
new file mode 100644
index 000000000000..257a0b51994a
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/reserved-memory/google,open-dice.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Open Profile for DICE Device Tree Bindings
+
+description: |
+  This binding represents a reserved memory region containing data
+  generated by the Open Profile for DICE protocol.
+
+  See https://pigweed.googlesource.com/open-dice/
+
+maintainers:
+  - David Brazdil <[email protected]>
+
+allOf:
+  - $ref: "reserved-memory.yaml"
+
+properties:
+  compatible:
+    const: google,open-dice
+
+  reg:
+    description: page-aligned region of memory containing DICE data
+
+required:
+  - compatible
+  - reg
+  - no-map
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    reserved-memory {
+        #address-cells = <2>;
+        #size-cells = <1>;
+
+        dice: dice@12340000 {
+            compatible = "google,open-dice";
+            reg = <0x00 0x12340000 0x2000>;
+            no-map;
+        };
+    };
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
#4 lore raw

PATCH v7 2/2 misc: open-dice: Add driver to expose DICE data to userspace

In reply to David Brazdil

Open Profile for DICE is an open protocol for measured boot compatible with the Trusted Computing Group's Device Identifier Composition Engine (DICE) specification. The generated Compound Device Identifier (CDI) certificates represent the hardware/software combination measured by DICE, and can be used for remote attestation and sealing.

Add a driver that exposes reserved memory regions populated by firmware with DICE CDIs and exposes them to userspace via a character device.

Userspace obtains the memory region's size from read() and calls mmap() to create a mapping of the memory region in its address space. The mapping is not allowed to be write+shared, giving userspace a guarantee that the data were not overwritten by another process.

Userspace can also call write(), which triggers a wipe of the DICE data by the driver. Because both the kernel and userspace mappings use write-combine semantics, all clients observe the memory as zeroed after the syscall has returned.

---
 drivers/misc/Kconfig     |  12 +++
 drivers/misc/Makefile    |   1 +
 drivers/misc/open-dice.c | 208 +++++++++++++++++++++++++++++++++++++++
 drivers/of/platform.c    |   1 +
 4 files changed, 222 insertions(+)
 create mode 100644 drivers/misc/open-dice.c
drivers/misc/Kconfig +12 -0
index 0f5a49fc7c9e..a2b26426efba 100644
@@ -470,6 +470,18 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host ports
 	  using only one USB controller.
 
+config OPEN_DICE
+	tristate "Open Profile for DICE driver"
+	depends on OF_RESERVED_MEM
+	help
+	  This driver exposes a DICE reserved memory region to userspace via
+	  a character device. The memory region contains Compound Device
+	  Identifiers (CDIs) generated by firmware as an output of DICE
+	  measured boot flow. Userspace can use CDIs for remote attestation
+	  and sealing.
+
+	  If unsure, say N.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index a086197af544..70e800e9127f 100644
@@ -59,3 +59,4 @@ obj-$(CONFIG_UACCE)		+= uacce/
 obj-$(CONFIG_XILINX_SDFEC)	+= xilinx_sdfec.o
 obj-$(CONFIG_HISI_HIKEY_USB)	+= hisi_hikey_usb.o
 obj-$(CONFIG_HI6421V600_IRQ)	+= hi6421v600-irq.o
+obj-$(CONFIG_OPEN_DICE)		+= open-dice.o
drivers/misc/open-dice.c new file +208 -0

208 lines not on this page · raw message

drivers/of/platform.c +1 -0
index 793350028906..a16b74f32aa9 100644
@@ -514,6 +514,7 @@ static const struct of_device_id reserved_mem_matches[] = {
 	{ .compatible = "qcom,smem" },
 	{ .compatible = "ramoops" },
 	{ .compatible = "nvmem-rmem" },
+	{ .compatible = "google,open-dice" },
 	{}
 };
 
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
#2 lore raw

Re: [PATCH v7 1/2] dt-bindings: reserved-memory: Open Profile for DICE

In reply to David Brazdil

Hi Rob,

Quoted 42 lines · David Brazdil

Add DeviceTree bindings for Open Profile for DICE, an open protocol for measured boot. Firmware uses DICE to measure the hardware/software combination and generates Compound Device Identifier (CDI) certificates. These are stored in memory and the buffer is described in the DT as a reserved memory region compatible with 'google,open-dice'.

'no-map' is required to ensure the memory region is never treated by the kernel as system memory.

---
 .../reserved-memory/google,open-dice.yaml     | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml
Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml new file +21 -0
new file mode 100644
index 000000000000..257a0b51994a
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/reserved-memory/google,open-dice.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Open Profile for DICE Device Tree Bindings
+
+description: |
+  This binding represents a reserved memory region containing data
+  generated by the Open Profile for DICE protocol.
+
+  See https://pigweed.googlesource.com/open-dice/
+
+maintainers:
+  - David Brazdil <[email protected]>
+
+allOf:
+  - $ref: "reserved-memory.yaml"
+
+properties:

Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml new file +10 -0
+  compatible:
+    const: google,open-dice
+
+  reg:
+    description: page-aligned region of memory containing DICE data
+
+required:
+  - compatible
+  - reg
+  - no-map

You already gave this a Reviewed-by in v6. Just want to mention that I didn't pick it up because I added a required no-map here. It was always included in our DTs but I made it required because the kernel should never treat that region as system memory. The kernel will warn when the driver tries to wipe the memory otherwise.

David

maintainer Reviewed-by
#3 lore raw

Re: [PATCH v7 1/2] dt-bindings: reserved-memory: Open Profile for DICE

Quoted 53 lines · David Brazdil

Hi Rob,

Quoted 50 lines · David Brazdil

Add DeviceTree bindings for Open Profile for DICE, an open protocol for measured boot. Firmware uses DICE to measure the hardware/software combination and generates Compound Device Identifier (CDI) certificates. These are stored in memory and the buffer is described in the DT as a reserved memory region compatible with 'google,open-dice'.

'no-map' is required to ensure the memory region is never treated by the kernel as system memory.

---
 .../reserved-memory/google,open-dice.yaml     | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml
Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml new file +29 -0
new file mode 100644
index 000000000000..257a0b51994a
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/reserved-memory/google,open-dice.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Open Profile for DICE Device Tree Bindings
+
+description: |
+  This binding represents a reserved memory region containing data
+  generated by the Open Profile for DICE protocol.
+
+  See https://pigweed.googlesource.com/open-dice/
+
+maintainers:
+  - David Brazdil <[email protected]>
+
+allOf:
+  - $ref: "reserved-memory.yaml"
+
+properties:
+  compatible:
+    const: google,open-dice
+
+  reg:
+    description: page-aligned region of memory containing DICE data
+
+required:
+  - compatible
Quoted 8 lines

Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml line 31

Quoted 2 lines
Documentation/devicetree/bindings/reserved-memory/google,open-dice.yaml new file +2 -0
+  - reg
+  - no-map

You already gave this a Reviewed-by in v6. Just want to mention that I didn't pick it up because I added a required no-map here. It was always included in our DTs but I made it required because the kernel should never treat that region as system memory. The kernel will warn when the driver tries to wipe the memory otherwise.

That's small enough change to keep tags.