* [PATCH v3 0/2] Driver for Open Profile for DICE @ 2021-12-13 19:58 David Brazdil 2021-12-13 19:58 ` [PATCH v3 1/2] dt-bindings: firmware: Add " David Brazdil 2021-12-13 19:58 ` [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace David Brazdil 0 siblings, 2 replies; 11+ messages in thread From: David Brazdil @ 2021-12-13 19:58 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rob Herring, Arnd Bergmann, David Brazdil, Will Deacon, Andrew Scull, devicetree, linux-kernel 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_v3 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/2] dt-bindings: firmware: Add Open Profile for DICE 2021-12-13 19:58 [PATCH v3 0/2] Driver for Open Profile for DICE David Brazdil @ 2021-12-13 19:58 ` David Brazdil 2021-12-15 20:26 ` Rob Herring 2021-12-13 19:58 ` [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace David Brazdil 1 sibling, 1 reply; 11+ messages in thread From: David Brazdil @ 2021-12-13 19:58 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rob Herring, Arnd Bergmann, David Brazdil, Will Deacon, Andrew Scull, devicetree, linux-kernel 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. Signed-off-by: David Brazdil <dbrazdil@google.com> --- .../bindings/firmware/google,open-dice.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/google,open-dice.yaml diff --git a/Documentation/devicetree/bindings/firmware/google,open-dice.yaml b/Documentation/devicetree/bindings/firmware/google,open-dice.yaml new file mode 100644 index 000000000000..1aa69f381b8c --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/google,open-dice.yaml @@ -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 <dbrazdil@google.com> + +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>; + }; -- 2.34.1.173.g76aa8bc2d0-goog ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/2] dt-bindings: firmware: Add Open Profile for DICE 2021-12-13 19:58 ` [PATCH v3 1/2] dt-bindings: firmware: Add " David Brazdil @ 2021-12-15 20:26 ` Rob Herring 2021-12-15 21:08 ` David Brazdil 0 siblings, 1 reply; 11+ messages in thread From: Rob Herring @ 2021-12-15 20:26 UTC (permalink / raw) To: David Brazdil Cc: Greg Kroah-Hartman, Arnd Bergmann, Will Deacon, Andrew Scull, devicetree, linux-kernel On Mon, Dec 13, 2021 at 07:58:32PM +0000, David Brazdil wrote: > 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. > > Signed-off-by: David Brazdil <dbrazdil@google.com> > --- > .../bindings/firmware/google,open-dice.yaml | 51 +++++++++++++++++++ > 1 file changed, 51 insertions(+) > create mode 100644 Documentation/devicetree/bindings/firmware/google,open-dice.yaml > > diff --git a/Documentation/devicetree/bindings/firmware/google,open-dice.yaml b/Documentation/devicetree/bindings/firmware/google,open-dice.yaml > new file mode 100644 > index 000000000000..1aa69f381b8c > --- /dev/null > +++ b/Documentation/devicetree/bindings/firmware/google,open-dice.yaml > @@ -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 <dbrazdil@google.com> > + > +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>; There's no need for this indirection. Just add the compatible to the dice@12340000 node. You can bind drivers to /reserved-memory nodes. Rob ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/2] dt-bindings: firmware: Add Open Profile for DICE 2021-12-15 20:26 ` Rob Herring @ 2021-12-15 21:08 ` David Brazdil 2021-12-16 15:21 ` Rob Herring 0 siblings, 1 reply; 11+ messages in thread From: David Brazdil @ 2021-12-15 21:08 UTC (permalink / raw) To: Rob Herring Cc: Greg Kroah-Hartman, Arnd Bergmann, Will Deacon, Andrew Scull, devicetree, linux-kernel Hi Rob, > > + dice_reserved: dice@12340000 { > > + reg = <0x00 0x12340000 0x2000>; > > + no-map; > > + }; > > + }; > > + > > + dice { > > + compatible = "google,open-dice"; > > + memory-region = <&dice_reserved>; > > There's no need for this indirection. Just add the compatible to the > dice@12340000 node. You can bind drivers to /reserved-memory nodes. I have not found a way to make that work for kernel modules. Built-in drivers can bind with RESERVEDMEM_OF_DECLARE, which puts an entry in __reservedmem_of_table and __reserved_mem_init_node() iterates find it there. A good case study might be CONFIG_TEGRA210_EMC, where the driver itself can be a module but the rmem parsing is always built-in under CONFIG_TEGRA210_EMC_TABLE. I don't think that's worth the trouble with this driver. David ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/2] dt-bindings: firmware: Add Open Profile for DICE 2021-12-15 21:08 ` David Brazdil @ 2021-12-16 15:21 ` Rob Herring 2021-12-21 17:43 ` David Brazdil 0 siblings, 1 reply; 11+ messages in thread From: Rob Herring @ 2021-12-16 15:21 UTC (permalink / raw) To: David Brazdil Cc: Greg Kroah-Hartman, Arnd Bergmann, Will Deacon, Andrew Scull, devicetree, linux-kernel@vger.kernel.org On Wed, Dec 15, 2021 at 3:08 PM David Brazdil <dbrazdil@google.com> wrote: > > Hi Rob, > > > > + dice_reserved: dice@12340000 { > > > + reg = <0x00 0x12340000 0x2000>; > > > + no-map; > > > + }; > > > + }; > > > + > > > + dice { > > > + compatible = "google,open-dice"; > > > + memory-region = <&dice_reserved>; > > > > There's no need for this indirection. Just add the compatible to the > > dice@12340000 node. You can bind drivers to /reserved-memory nodes. > > I have not found a way to make that work for kernel modules. Built-in > drivers can bind with RESERVEDMEM_OF_DECLARE, which puts an entry in > __reservedmem_of_table and __reserved_mem_init_node() iterates find it > there. A good case study might be CONFIG_TEGRA210_EMC, where the driver > itself can be a module but the rmem parsing is always built-in under > CONFIG_TEGRA210_EMC_TABLE. I don't think that's worth the trouble with > this driver. I forgot you have to add the compatible to reserved_mem_matches in drivers/of/platform.c. Rob ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/2] dt-bindings: firmware: Add Open Profile for DICE 2021-12-16 15:21 ` Rob Herring @ 2021-12-21 17:43 ` David Brazdil 0 siblings, 0 replies; 11+ messages in thread From: David Brazdil @ 2021-12-21 17:43 UTC (permalink / raw) To: Rob Herring Cc: Greg Kroah-Hartman, Arnd Bergmann, Will Deacon, Andrew Scull, devicetree, linux-kernel@vger.kernel.org On Thu, Dec 16, 2021 at 09:21:00AM -0600, Rob Herring wrote: > On Wed, Dec 15, 2021 at 3:08 PM David Brazdil <dbrazdil@google.com> wrote: > > > > Hi Rob, > > > > > > + dice_reserved: dice@12340000 { > > > > + reg = <0x00 0x12340000 0x2000>; > > > > + no-map; > > > > + }; > > > > + }; > > > > + > > > > + dice { > > > > + compatible = "google,open-dice"; > > > > + memory-region = <&dice_reserved>; > > > > > > There's no need for this indirection. Just add the compatible to the > > > dice@12340000 node. You can bind drivers to /reserved-memory nodes. > > > > I have not found a way to make that work for kernel modules. Built-in > > drivers can bind with RESERVEDMEM_OF_DECLARE, which puts an entry in > > __reservedmem_of_table and __reserved_mem_init_node() iterates find it > > there. A good case study might be CONFIG_TEGRA210_EMC, where the driver > > itself can be a module but the rmem parsing is always built-in under > > CONFIG_TEGRA210_EMC_TABLE. I don't think that's worth the trouble with > > this driver. > > I forgot you have to add the compatible to reserved_mem_matches in > drivers/of/platform.c. Oh nice! Exactly what I was looking for, thanks. I'll respin shortly. David ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace 2021-12-13 19:58 [PATCH v3 0/2] Driver for Open Profile for DICE David Brazdil 2021-12-13 19:58 ` [PATCH v3 1/2] dt-bindings: firmware: Add " David Brazdil @ 2021-12-13 19:58 ` David Brazdil 2021-12-14 3:25 ` kernel test robot ` (2 more replies) 1 sibling, 3 replies; 11+ messages in thread From: David Brazdil @ 2021-12-13 19:58 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rob Herring, Arnd Bergmann, David Brazdil, Will Deacon, Andrew Scull, devicetree, linux-kernel 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. Cc: Andrew Scull <ascull@google.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: David Brazdil <dbrazdil@google.com> --- 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 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 0f5a49fc7c9e..4d996485f5a7 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -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" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index a086197af544..70e800e9127f 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -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 diff --git a/drivers/misc/open-dice.c b/drivers/misc/open-dice.c new file mode 100644 index 000000000000..ea7b1a8d49ac --- /dev/null +++ b/drivers/misc/open-dice.c @@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 - Google LLC + * Author: David Brazdil <dbrazdil@google.com> + * + * Driver for Open Profile for DICE. + * + * This driver takes ownership of a reserved memory region containing secrets + * derived following the Open Profile for DICE. The contents of the memory + * region are not interpreted by the kernel but can be mapped into a userspace + * process via a misc device. The memory region can also be wiped, removing + * the secrets from memory. + * + * Userspace can access the data by (w/o error handling): + * + * fd = open("/dev/open-dice0", O_RDWR); + * size = read(fd, NULL, 0); + * data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + * write(fd, NULL, 0); // wipe + * close(fd); + */ + +#include <linux/io.h> +#include <linux/miscdevice.h> +#include <linux/mm.h> +#include <linux/module.h> +#include <linux/of_reserved_mem.h> +#include <linux/platform_device.h> + +#define DRIVER_NAME "open-dice" + +struct open_dice_drvdata { + spinlock_t lock; + char name[16]; + struct reserved_mem *rmem; + struct miscdevice misc; +}; + +static inline struct open_dice_drvdata *to_open_dice_drvdata(struct file *filp) +{ + return container_of(filp->private_data, struct open_dice_drvdata, misc); +} + +static int open_dice_size(struct open_dice_drvdata *drvdata) +{ + /* '0 < size <= INT_MAX' is checked in the probe function. */ + return drvdata->rmem->size; +} + +static int open_dice_wipe(struct open_dice_drvdata *drvdata) +{ + void *kaddr; + + spin_lock(&drvdata->lock); + kaddr = devm_memremap(drvdata->misc.this_device, drvdata->rmem->base, + drvdata->rmem->size, MEMREMAP_WC); + if (IS_ERR(kaddr)) { + spin_unlock(&drvdata->lock); + return PTR_ERR(kaddr); + } + + memset(kaddr, 0, drvdata->rmem->size); + devm_memunmap(drvdata->misc.this_device, kaddr); + spin_unlock(&drvdata->lock); + return 0; +} + +/** + * Returns the size of the reserved memory region. The user-provided pointer is + * never dereferenced. + */ +static ssize_t open_dice_read(struct file *filp, char __user *ptr, size_t len, + loff_t *off) +{ + return open_dice_size(to_open_dice_drvdata(filp)); +} + +/** + * Triggers a wipe of the reserved memory region. The user-provided pointer is + * never dereferenced. + */ +static ssize_t open_dice_write(struct file *filp, const char __user *ptr, + size_t len, loff_t *off) +{ + return open_dice_wipe(to_open_dice_drvdata(filp)); +} + +/** + * Creates a mapping of the reserved memory region in a user address space. + */ +static int open_dice_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct open_dice_drvdata *drvdata = to_open_dice_drvdata(filp); + + /* Do not allow userspace to modify the underlying data. */ + if ((vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_SHARED)) + return -EPERM; + + /* Create write-combine mapping so all clients observe a wipe. */ + vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); + vma->vm_flags |= VM_DONTCOPY | VM_DONTDUMP; + return vm_iomap_memory(vma, drvdata->rmem->base, drvdata->rmem->size); +} + +static const struct file_operations open_dice_fops = { + .read = open_dice_read, + .write = open_dice_write, + .mmap = open_dice_mmap, +}; + +static int __init open_dice_probe(struct platform_device *pdev) +{ + static size_t dev_idx; + struct device *dev = &pdev->dev; + struct device_node *rmem_np; + struct reserved_mem *rmem; + struct open_dice_drvdata *drvdata; + int ret; + + rmem_np = of_parse_phandle(dev->of_node, "memory-region", 0); + if (!rmem_np) { + dev_err(dev, "missing 'memory-region' property\n"); + return -EINVAL; + } + + rmem = of_reserved_mem_lookup(rmem_np); + of_node_put(rmem_np); + if (!rmem) { + dev_err(dev, "failed to lookup reserved memory\n"); + return -EINVAL; + } + + if (!rmem->size || (rmem->size > INT_MAX)) { + dev_err(dev, "invalid memory region size\n"); + return -EINVAL; + } + + if (!PAGE_ALIGNED(rmem->base) || !PAGE_ALIGNED(rmem->size)) { + dev_err(dev, "memory region must be page-aligned\n"); + return -EINVAL; + } + + drvdata = devm_kmalloc(dev, sizeof(*drvdata), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; + + *drvdata = (struct open_dice_drvdata){ + .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, + }, + }; + + /* Index overflow check not needed. misc_register() will fail. */ + snprintf(drvdata->name, sizeof(drvdata->name), DRIVER_NAME"%d", dev_idx++); + + ret = misc_register(&drvdata->misc); + if (ret) { + dev_err(dev, "failed to register misc device '%s': %d\n", + drvdata->name, ret); + return ret; + } + + platform_set_drvdata(pdev, drvdata); + return 0; +} + +static int open_dice_remove(struct platform_device *pdev) +{ + struct open_dice_drvdata *drvdata = platform_get_drvdata(pdev); + + misc_deregister(&drvdata->misc); + return 0; +} + +static const struct of_device_id open_dice_of_match[] = { + { .compatible = "google,open-dice" }, + {}, +}; + +static struct platform_driver open_dice_driver = { + .remove = open_dice_remove, + .driver = { + .name = DRIVER_NAME, + .of_match_table = open_dice_of_match, + }, +}; + +module_platform_driver_probe(open_dice_driver, open_dice_probe); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("David Brazdil <dbrazdil@google.com>"); -- 2.34.1.173.g76aa8bc2d0-goog ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace 2021-12-13 19:58 ` [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace David Brazdil @ 2021-12-14 3:25 ` kernel test robot 2021-12-14 3:56 ` kernel test robot 2021-12-14 7:18 ` Greg Kroah-Hartman 2 siblings, 0 replies; 11+ messages in thread From: kernel test robot @ 2021-12-14 3:25 UTC (permalink / raw) To: David Brazdil, Greg Kroah-Hartman Cc: kbuild-all, Rob Herring, Arnd Bergmann, David Brazdil, Will Deacon, Andrew Scull, devicetree, linux-kernel Hi David, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on robh/for-next] [also build test WARNING on char-misc/char-misc-testing soc/for-next v5.16-rc5] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/David-Brazdil/Driver-for-Open-Profile-for-DICE/20211214-040051 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20211214/202112141128.lBBmmIuE-lkp@intel.com/config) compiler: sh4-linux-gcc (GCC) 11.2.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/6fb8e9472d98abcc2dfabd43e95fc4ec5819ecd0 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review David-Brazdil/Driver-for-Open-Profile-for-DICE/20211214-040051 git checkout 6fb8e9472d98abcc2dfabd43e95fc4ec5819ecd0 # save the config file to linux build tree mkdir build_dir COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=sh SHELL=/bin/bash drivers/misc/ If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): drivers/misc/open-dice.c:74: warning: Function parameter or member 'filp' not described in 'open_dice_read' drivers/misc/open-dice.c:74: warning: Function parameter or member 'ptr' not described in 'open_dice_read' drivers/misc/open-dice.c:74: warning: Function parameter or member 'len' not described in 'open_dice_read' drivers/misc/open-dice.c:74: warning: Function parameter or member 'off' not described in 'open_dice_read' >> drivers/misc/open-dice.c:74: warning: expecting prototype for Returns the size of the reserved memory region. The user(). Prototype was for open_dice_read() instead drivers/misc/open-dice.c:84: warning: Function parameter or member 'filp' not described in 'open_dice_write' drivers/misc/open-dice.c:84: warning: Function parameter or member 'ptr' not described in 'open_dice_write' drivers/misc/open-dice.c:84: warning: Function parameter or member 'len' not described in 'open_dice_write' drivers/misc/open-dice.c:84: warning: Function parameter or member 'off' not described in 'open_dice_write' >> drivers/misc/open-dice.c:84: warning: expecting prototype for Triggers a wipe of the reserved memory region. The user(). Prototype was for open_dice_write() instead >> drivers/misc/open-dice.c:89: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst * Creates a mapping of the reserved memory region in a user address space. vim +74 drivers/misc/open-dice.c 67 68 /** 69 * Returns the size of the reserved memory region. The user-provided pointer is 70 * never dereferenced. 71 */ 72 static ssize_t open_dice_read(struct file *filp, char __user *ptr, size_t len, 73 loff_t *off) > 74 { 75 return open_dice_size(to_open_dice_drvdata(filp)); 76 } 77 78 /** 79 * Triggers a wipe of the reserved memory region. The user-provided pointer is 80 * never dereferenced. 81 */ 82 static ssize_t open_dice_write(struct file *filp, const char __user *ptr, 83 size_t len, loff_t *off) > 84 { 85 return open_dice_wipe(to_open_dice_drvdata(filp)); 86 } 87 88 /** > 89 * Creates a mapping of the reserved memory region in a user address space. 90 */ 91 static int open_dice_mmap(struct file *filp, struct vm_area_struct *vma) 92 { 93 struct open_dice_drvdata *drvdata = to_open_dice_drvdata(filp); 94 95 /* Do not allow userspace to modify the underlying data. */ 96 if ((vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_SHARED)) 97 return -EPERM; 98 99 /* Create write-combine mapping so all clients observe a wipe. */ 100 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); 101 vma->vm_flags |= VM_DONTCOPY | VM_DONTDUMP; 102 return vm_iomap_memory(vma, drvdata->rmem->base, drvdata->rmem->size); 103 } 104 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace 2021-12-13 19:58 ` [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace David Brazdil 2021-12-14 3:25 ` kernel test robot @ 2021-12-14 3:56 ` kernel test robot 2021-12-14 7:18 ` Greg Kroah-Hartman 2 siblings, 0 replies; 11+ messages in thread From: kernel test robot @ 2021-12-14 3:56 UTC (permalink / raw) To: David Brazdil, Greg Kroah-Hartman Cc: kbuild-all, Rob Herring, Arnd Bergmann, David Brazdil, Will Deacon, Andrew Scull, devicetree, linux-kernel Hi David, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on robh/for-next] [also build test WARNING on char-misc/char-misc-testing soc/for-next v5.16-rc5] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/David-Brazdil/Driver-for-Open-Profile-for-DICE/20211214-040051 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20211214/202112141150.Hh48OleF-lkp@intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/6fb8e9472d98abcc2dfabd43e95fc4ec5819ecd0 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review David-Brazdil/Driver-for-Open-Profile-for-DICE/20211214-040051 git checkout 6fb8e9472d98abcc2dfabd43e95fc4ec5819ecd0 # save the config file to linux build tree mkdir build_dir make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/misc/ If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): drivers/misc/open-dice.c: In function 'open_dice_probe': >> drivers/misc/open-dice.c:30:21: warning: format '%d' expects argument of type 'int', but argument 4 has type 'size_t' {aka 'long unsigned int'} [-Wformat=] 30 | #define DRIVER_NAME "open-dice" | ^~~~~~~~~~~ drivers/misc/open-dice.c:160:49: note: in expansion of macro 'DRIVER_NAME' 160 | snprintf(drvdata->name, sizeof(drvdata->name), DRIVER_NAME"%d", dev_idx++); | ^~~~~~~~~~~ drivers/misc/open-dice.c:160:62: note: format string is defined here 160 | snprintf(drvdata->name, sizeof(drvdata->name), DRIVER_NAME"%d", dev_idx++); | ~^ | | | int | %ld vim +30 drivers/misc/open-dice.c 29 > 30 #define DRIVER_NAME "open-dice" 31 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace 2021-12-13 19:58 ` [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace David Brazdil 2021-12-14 3:25 ` kernel test robot 2021-12-14 3:56 ` kernel test robot @ 2021-12-14 7:18 ` Greg Kroah-Hartman 2021-12-14 14:37 ` David Brazdil 2 siblings, 1 reply; 11+ messages in thread From: Greg Kroah-Hartman @ 2021-12-14 7:18 UTC (permalink / raw) To: David Brazdil Cc: Rob Herring, Arnd Bergmann, Will Deacon, Andrew Scull, devicetree, linux-kernel On Mon, Dec 13, 2021 at 07:58:33PM +0000, David Brazdil wrote: > 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. > > Cc: Andrew Scull <ascull@google.com> > Cc: Will Deacon <will@kernel.org> > Signed-off-by: David Brazdil <dbrazdil@google.com> > --- > 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 > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > index 0f5a49fc7c9e..4d996485f5a7 100644 > --- a/drivers/misc/Kconfig > +++ b/drivers/misc/Kconfig > @@ -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" > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile > index a086197af544..70e800e9127f 100644 > --- a/drivers/misc/Makefile > +++ b/drivers/misc/Makefile > @@ -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 > diff --git a/drivers/misc/open-dice.c b/drivers/misc/open-dice.c > new file mode 100644 > index 000000000000..ea7b1a8d49ac > --- /dev/null > +++ b/drivers/misc/open-dice.c > @@ -0,0 +1,197 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2021 - Google LLC > + * Author: David Brazdil <dbrazdil@google.com> > + * > + * Driver for Open Profile for DICE. > + * > + * This driver takes ownership of a reserved memory region containing secrets > + * derived following the Open Profile for DICE. The contents of the memory > + * region are not interpreted by the kernel but can be mapped into a userspace > + * process via a misc device. The memory region can also be wiped, removing > + * the secrets from memory. > + * > + * Userspace can access the data by (w/o error handling): > + * > + * fd = open("/dev/open-dice0", O_RDWR); > + * size = read(fd, NULL, 0); I was thinking you would return the value as a string in the buffer provided to the read call, not as the return value itself. That is odd and probably breaks something. What would happen if you ran 'cat' on the device node? thanks, greg k-h ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace 2021-12-14 7:18 ` Greg Kroah-Hartman @ 2021-12-14 14:37 ` David Brazdil 0 siblings, 0 replies; 11+ messages in thread From: David Brazdil @ 2021-12-14 14:37 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rob Herring, Arnd Bergmann, Will Deacon, Andrew Scull, devicetree, linux-kernel On Tue, Dec 14, 2021 at 08:18:38AM +0100, Greg Kroah-Hartman wrote: > On Mon, Dec 13, 2021 at 07:58:33PM +0000, David Brazdil wrote: > > 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. > > > > Cc: Andrew Scull <ascull@google.com> > > Cc: Will Deacon <will@kernel.org> > > Signed-off-by: David Brazdil <dbrazdil@google.com> > > --- > > 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 > > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > > index 0f5a49fc7c9e..4d996485f5a7 100644 > > --- a/drivers/misc/Kconfig > > +++ b/drivers/misc/Kconfig > > @@ -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" > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile > > index a086197af544..70e800e9127f 100644 > > --- a/drivers/misc/Makefile > > +++ b/drivers/misc/Makefile > > @@ -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 > > diff --git a/drivers/misc/open-dice.c b/drivers/misc/open-dice.c > > new file mode 100644 > > index 000000000000..ea7b1a8d49ac > > --- /dev/null > > +++ b/drivers/misc/open-dice.c > > @@ -0,0 +1,197 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > +/* > > + * Copyright (C) 2021 - Google LLC > > + * Author: David Brazdil <dbrazdil@google.com> > > + * > > + * Driver for Open Profile for DICE. > > + * > > + * This driver takes ownership of a reserved memory region containing secrets > > + * derived following the Open Profile for DICE. The contents of the memory > > + * region are not interpreted by the kernel but can be mapped into a userspace > > + * process via a misc device. The memory region can also be wiped, removing > > + * the secrets from memory. > > + * > > + * Userspace can access the data by (w/o error handling): > > + * > > + * fd = open("/dev/open-dice0", O_RDWR); > > + * size = read(fd, NULL, 0); > > I was thinking you would return the value as a string in the buffer > provided to the read call, not as the return value itself. That is odd > and probably breaks something. What would happen if you ran 'cat' on > the device node? Ah, I misunderstood. Yeah, running `cat` will endlessly print garbage. I'll do a quick respin and also change write() to appear to consume the buffer because 'echo 1 > /dev/open-dice0' currently blocks. David ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-12-21 17:43 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-12-13 19:58 [PATCH v3 0/2] Driver for Open Profile for DICE David Brazdil 2021-12-13 19:58 ` [PATCH v3 1/2] dt-bindings: firmware: Add " David Brazdil 2021-12-15 20:26 ` Rob Herring 2021-12-15 21:08 ` David Brazdil 2021-12-16 15:21 ` Rob Herring 2021-12-21 17:43 ` David Brazdil 2021-12-13 19:58 ` [PATCH v3 2/2] misc: open-dice: Add driver to expose DICE data to userspace David Brazdil 2021-12-14 3:25 ` kernel test robot 2021-12-14 3:56 ` kernel test robot 2021-12-14 7:18 ` Greg Kroah-Hartman 2021-12-14 14:37 ` David Brazdil
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).