Add Nitro Secure Module support
Subsystems (4)
Alexander Graf
maintainercover Add Nitro Secure Module support
We already have support for the Nitro Enclave kernel module in upstream Linux, which is needed to control a Nitro Enclave's lifecycle.
However, users typically want to run Linux inside the Enclave as well. To do that well, they need the ability to communicate to the Nitro Secure
Module: A virtio based PV device that provides access to PCRs, an attestation document as well as access to entropy.
These patches add driver support for NSM. With them in place, upstream Linux has everything that's needed to run as a Nitro Enclave kernel.
Alex
Alexander Graf (2):
misc: Add Nitro Secure Module driver
hwrng: Add support for Nitro Secure Module
MAINTAINERS | 10 + drivers/char/hw_random/Kconfig | 12 + drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/nsm-rng.c | 284 +++++++++++++++++++ drivers/misc/Kconfig | 11 + drivers/misc/Makefile | 1 + drivers/misc/nsm.c | 469 +++++++++++++++++++++++++++++++ include/linux/nsm.h | 42 +++ 8 files changed, 830 insertions(+) create mode 100644 drivers/char/hw_random/nsm-rng.c create mode 100644 drivers/misc/nsm.c create mode 100644 include/linux/nsm.h
Signature · 12 lines
2.40.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879
Alexander Graf
maintainerPATCH 1/2 misc: Add Nitro Secure Module driver
When running Linux inside a Nitro Enclave, the hypervisor provides a special virtio device called "NSM". This device has 2 main functions:
1) Provide attestation reports
2) Modify PCR state
3) Provide entropy
This patch adds the core NSM driver that exposes a /dev/nsm device node which user space can use to request attestation documents and influence PCR states. A follow up patch will add a hwrng driver to feed its entropy into the kernel.
--- MAINTAINERS | 9 + drivers/misc/Kconfig | 11 + drivers/misc/Makefile | 1 + drivers/misc/nsm.c | 470 ++++++++++++++++++++++++++++++++++++++++++ include/linux/nsm.h | 42 ++++ 5 files changed, 533 insertions(+) create mode 100644 drivers/misc/nsm.c create mode 100644 include/linux/nsm.h
MAINTAINERS +9 -0
@@ -15098,6 +15098,15 @@ F: include/linux/nitro_enclaves.h F: include/uapi/linux/nitro_enclaves.h F: samples/nitro_enclaves/ +NITRO SECURE MODULE (NSM) +M: Alexander Graf <[email protected]> +L: [email protected] +L: The AWS Nitro Enclaves Team <[email protected]> +S: Supported +W: https://aws.amazon.com/ec2/nitro/nitro-enclaves/ +F: drivers/misc/nsm.c +F: include/linux/nsm.h + NOHZ, DYNTICKS SUPPORT M: Frederic Weisbecker <[email protected]> M: Thomas Gleixner <[email protected]>
drivers/misc/Kconfig +11 -0
@@ -562,6 +562,17 @@ config TPS6594_PFSM This driver can also be built as a module. If so, the module will be called tps6594-pfsm. +config NSM + tristate "Nitro (Enclaves) Security Module support" + depends on VIRTIO + help + This driver provides support for the Nitro Security Module + in AWS EC2 Nitro based Enclaves. The driver exposes a /dev/nsm + device user space can use to communicate with the hypervisor. + + To compile this driver as a module, choose M here. + The module will be called nsm. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -67,3 +67,4 @@ obj-$(CONFIG_TMR_MANAGER) += xilinx_tmr_manager.o obj-$(CONFIG_TMR_INJECT) += xilinx_tmr_inject.o obj-$(CONFIG_TPS6594_ESM) += tps6594-esm.o obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o +obj-$(CONFIG_NSM) += nsm.o
drivers/misc/nsm.c new file +470 -0
470 lines not on this page · raw message
include/linux/nsm.h new file +42 -0
42 lines not on this page · raw message
Signature · 12 lines
2.40.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879
Greg Kroah-Hartman
maintainerRe: [PATCH 1/2] misc: Add Nitro Secure Module driver
Quoted 7 lines · Alexander Graf
When running Linux inside a Nitro Enclave, the hypervisor provides a special virtio device called "NSM". This device has 2 main functions:
1) Provide attestation reports
2) Modify PCR state
3) Provide entropy
Quoted 6 lines
This patch adds the core NSM driver that exposes a
/dev/nsmdevice node which user space can use to request attestation documents and influence PCR states. A follow up patch will add a hwrng driver to feed its entropy into the kernel.Originally-by Petre Eftime <[email protected]>
Hasn't this been submitted a long time ago? What changed from that submission? Or am I mis-remembering things?
Quoted 10 lines
drivers/misc/nsm.c new file +7
-0@@ -0,0 +1,470 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Amazon Nitro Secure Module driver. +* +* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify it
drivers/misc/nsm.c line 17
Quoted 10 lines
drivers/misc/nsm.c new file +10
-0+* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>.
Please drop the license "boiler-plate" text, the SPDX line is sufficient.
thanks,
greg k-h
Alexander Graf
maintainerRe: [PATCH 1/2] misc: Add Nitro Secure Module driver
Hey Greg,
Quoted 9 lines · Greg Kroah-Hartman
Quoted 7 lines · Alexander Graf
When running Linux inside a Nitro Enclave, the hypervisor provides a special virtio device called "NSM". This device has 2 main functions:
1) Provide attestation reports
2) Modify PCR state
3) Provide entropy
Quoted 8 lines
Quoted 6 lines
This patch adds the core NSM driver that exposes a
/dev/nsmdevice node which user space can use to request attestation documents and influence PCR states. A follow up patch will add a hwrng driver to feed its entropy into the kernel.Originally-by Petre Eftime <[email protected]>Hasn't this been submitted a long time ago? What changed from that submission? Or am I mis-remembering things?
With Nitro Enclaves, there are 2 parties: Parent and Enclave.
The parent launches the Enclave. To do so, it creates a sibling VM using a special Enclaves PCI device. The driver for that is in drivers/virt/nitro_enclaves and you helped to upstream that back then.
The enclave is what is running inside the sibling VM. It sees a Firecracker like device model with virtio-vsock to communicate to the parent as well as a special virtio-mmio device called "NSM" to communicate to the hypervisor. This driver is for the latter.
I'm now aware of previous attempts to upstream it.
Quoted 15 lines
Quoted 15 lines
drivers/misc/nsm.c new file +11
-0@@ -0,0 +1,470 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Amazon Nitro Secure Module driver. +* +* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful,
Quoted 8 lines
drivers/misc/nsm.c line 17
Quoted 6 lines
drivers/misc/nsm.c new file +6
-0+* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. Please drop the license "boiler-plate" text, the SPDX line is sufficient.
Sure, happy to! :)
Alex
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
Greg Kroah-Hartman
maintainerRe: [PATCH 1/2] misc: Add Nitro Secure Module driver
In reply to Alexander Grafdrivers/misc/nsm.c line 38
Quoted 4 lines · Alexander Graf
drivers/misc/nsm.c new file +4
-0+/* Register this as a misc driver */ +#define NSM_DEV_NAME "nsm" +#define NSM_IOCTL_MAGIC 0x0A +#define NSM_IO_REQUEST _IOWR(NSM_IOCTL_MAGIC, 0, struct nsm_message)
You have an ioctl for this driver, yet no include/uapi/ file for it? How is userspace supposed to know about this and use it?
thanks,
greg k-h
Alexander Graf
maintainerRe: [PATCH 1/2] misc: Add Nitro Secure Module driver
Quoted 8 lines · Greg Kroah-Hartman
drivers/misc/nsm.c line 38
Quoted 4 lines · Alexander Graf
drivers/misc/nsm.c new file +4
-0+/* Register this as a misc driver */ +#define NSM_DEV_NAME "nsm" +#define NSM_IOCTL_MAGIC 0x0A +#define NSM_IO_REQUEST _IOWR(NSM_IOCTL_MAGIC, 0, struct nsm_message)You have an ioctl for this driver, yet no
include/uapi/file for it? How is userspace supposed to know about this and use it?
D'oh. Will fix :). Thanks!
Alex
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
Alexander Graf
maintainerPATCH 2/2 hwrng: Add support for Nitro Secure Module
In reply to Alexander GrafWhen running Linux inside a Nitro Enclave, the Nitro Secure Module provides a virtio message that can be used to receive entropy. This patch adds support to read that entropy on demand and expose it through the hwrng device.
--- MAINTAINERS | 1 + drivers/char/hw_random/Kconfig | 12 ++ drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/nsm-rng.c | 282 +++++++++++++++++++++++++++++++ 4 files changed, 296 insertions(+) create mode 100644 drivers/char/hw_random/nsm-rng.c
MAINTAINERS +1 -0
@@ -15104,6 +15104,7 @@ L: [email protected] L: The AWS Nitro Enclaves Team <[email protected]> S: Supported W: https://aws.amazon.com/ec2/nitro/nitro-enclaves/ +F: drivers/char/hw_random/nsm-rng.c F: drivers/misc/nsm.c F: include/linux/nsm.h
drivers/char/hw_random/Kconfig +12 -0
@@ -573,6 +573,18 @@ config HW_RANDOM_JH7110 To compile this driver as a module, choose M here. The module will be called jh7110-trng. +config HW_RANDOM_NSM + tristate "Nitro (Enclaves) Security Module support" + depends on NSM + help + This driver provides support for the Nitro Security Module + in AWS EC2 Nitro based Enclaves. The driver enables support + for reading RNG data as well as a generic communication + mechanism with the hypervisor. + + To compile this driver as a module, choose M here. + The module will be called nsm_rng. + endif # HW_RANDOM config UML_RANDOM
drivers/char/hw_random/Makefile +1 -0
@@ -49,3 +49,4 @@ obj-$(CONFIG_HW_RANDOM_ARM_SMCCC_TRNG) += arm_smccc_trng.o obj-$(CONFIG_HW_RANDOM_CN10K) += cn10k-rng.o obj-$(CONFIG_HW_RANDOM_POLARFIRE_SOC) += mpfs-rng.o obj-$(CONFIG_HW_RANDOM_JH7110) += jh7110-trng.o +obj-$(CONFIG_HW_RANDOM_NSM) += nsm-rng.o
drivers/char/hw_random/nsm-rng.c new file +282 -0
282 lines not on this page · raw message
Signature · 12 lines
2.40.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879
kernel test robot
build botRe: [PATCH 2/2] hwrng: Add support for Nitro Secure Module
kernel test robot noticed the following build warnings:
Hi Alexander,
kernel test robot noticed the following build warnings:
[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus herbert-cryptodev-2.6/master soc/for-next linus/master v6.6-rc3 next-20230928] [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#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Alexander-Graf/misc-Add-Nitro-Secure-Module-driver/20230929-064844 base: char-misc/char-misc-testing patch link: https://lore.kernel.org/r/20230928224645.19768-3-graf%40amazon.com patch subject: [PATCH 2/2] hwrng: Add support for Nitro Secure Module config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230929/[email protected]/config) compiler: sparc64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230929/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/char/hw_random/nsm-rng.c:275:38: warning: 'nsm_id_table' defined but not used [-Wunused-const-variable=]
275 | static const struct virtio_device_id nsm_id_table[] = {
| ^~~~~~~~~~~~vim +/nsm_id_table +275 drivers/char/hw_random/nsm-rng.c
274
> 275 static const struct virtio_device_id nsm_id_table[] = { 276 { VIRTIO_ID_NITRO_SEC_MOD, VIRTIO_DEV_ANY_ID },
277 { 0 },
278 };
279
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki