Driver for Open Profile for DICE
Subsystems (2)
v4 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.16-rc5 and can also be found here:
https://android-kvm.googlesource.com/linux topic/dice_v4
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: firmware: Add Open Profile for DICE
misc: open-dice: Add driver to expose DICE data to userspace
.../bindings/firmware/google,open-dice.yaml | 51 +++++ drivers/misc/Kconfig | 12 ++ drivers/misc/Makefile | 1 + drivers/misc/open-dice.c | 197 ++++++++++++++++++ 4 files changed, 261 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/google,open-dice.yaml create mode 100644 drivers/misc/open-dice.c
--
2.34.1.173.g76aa8bc2d0-goog
PATCH v4 1/2 dt-bindings: firmware: Add 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 referenced by a compatible device node.
--- .../bindings/firmware/google,open-dice.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/google,open-dice.yaml
Documentation/devicetree/bindings/firmware/google,open-dice.yaml new file +51 -0
@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/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]> + +properties: + compatible: + enum: + - google,open-dice + + memory-region: + maxItems: 1 + description: | + phandle to the reserved memory node to be associated with the device + The reserved memory node should be defined as per the bindings, + Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml + +required: + - compatible + - memory-region + +additionalProperties: false + +examples: + - | + reserved-memory { + #address-cells = <2>; + #size-cells = <1>; + + dice_reserved: dice@12340000 { + reg = <0x00 0x12340000 0x2000>; + no-map; + }; + }; + + dice { + compatible = "google,open-dice"; + memory-region = <&dice_reserved>; + };
Signature · 1 line
2.34.1.173.g76aa8bc2d0-goog
PATCH v4 2/2 misc: open-dice: Add driver to expose DICE data to userspace
In reply to David BrazdilOpen 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 | 197 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 drivers/misc/open-dice.c
drivers/misc/Kconfig +12 -0
@@ -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 uses 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
@@ -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 +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.34.1.173.g76aa8bc2d0-goog
Greg Kroah-Hartman
maintainerRe: [PATCH v4 2/2] misc: open-dice: Add driver to expose DICE data to userspace
Quoted 5 lines · David Brazdil
drivers/misc/open-dice.c new file +5
-0+ drvdata =devm_kmalloc (dev,sizeof (*drvdata),GFP_KERNEL ); +if (!drvdata) +return -ENOMEM ; + + *drvdata = (struct open_dice_drvdata ){
drivers/misc/open-dice.c line 157
Quoted 10 lines
drivers/misc/open-dice.c new file +10
-0+ .lock = __SPIN_LOCK_UNLOCKED(drvdata->lock), + .rmem = rmem, + .misc = (struct miscdevice ){ + .parent = dev, + .name = drvdata->name, + .minor =MISC_DYNAMIC_MINOR , + .fops = &open_dice_fops, + .mode =0600 , + }, + };
That is a lovely abuse of an implicit memcpy(), took me a while to realize what it was doing here...
Anyway, this all looks great to me, I'll wait for the DT maintainers to review the dt change before being able to take this through my tree. Thanks for the cleanups based on the review, the driver is now almost 1/3 smaller than your first version with more functionality!
thanks,
greg k-h
Re: [PATCH v4 2/2] misc: open-dice: Add driver to expose DICE data to userspace
Quoted 20 lines · Greg Kroah-Hartman
Quoted 5 lines · David Brazdil
drivers/misc/open-dice.c new file +5
-0+ drvdata =devm_kmalloc (dev,sizeof (*drvdata),GFP_KERNEL ); +if (!drvdata) +return -ENOMEM ; + + *drvdata = (struct open_dice_drvdata ){drivers/misc/open-dice.c line 157
Quoted 10 lines
drivers/misc/open-dice.c new file +10
-0+ .lock = __SPIN_LOCK_UNLOCKED(drvdata->lock), + .rmem = rmem, + .misc = (struct miscdevice ){ + .parent = dev, + .name = drvdata->name, + .minor =MISC_DYNAMIC_MINOR , + .fops = &open_dice_fops, + .mode =0600 , + }, + };That is a lovely abuse of an implicit
memcpy(), took me a while to realize what it was doing here...
Quoted 4 lines
Anyway, this all looks great to me, I'll wait for the DT maintainers to review the dt change before being able to take this through my tree. Thanks for the cleanups based on the review, the driver is now almost 1/3 smaller than your first version with more functionality!
Thanks, and thank your for your help!
David