Add Nitro Secure Module support
Subsystems (4)
Alexander Graf
maintainerv3 cover 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
v1 -> v2:
- Remove boilerplate
- Add uapi header
v2 -> v3:
- Move globals to device struct
- Add compat handling
- Simplify some naming
- Remove debug prints
- Use module_virtio_driver
- Ensure remove only happens on target device
- Drop use of uio.h
Alexander Graf (2):
misc: Add Nitro Secure Module driver
hwrng: Add support for Nitro Secure Module
MAINTAINERS | 11 + drivers/char/hw_random/Kconfig | 12 + drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/nsm-rng.c | 275 ++++++++++++++++++++ drivers/misc/Kconfig | 11 + drivers/misc/Makefile | 1 + drivers/misc/nsm.c | 423 +++++++++++++++++++++++++++++++ include/linux/nsm.h | 35 +++ include/uapi/linux/nsm.h | 30 +++ 9 files changed, 799 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 create mode 100644 include/uapi/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 v3 2/2 hwrng: Add support for Nitro Secure Module
When 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.
---
v1 -> v2:
- Remove boilerplate
v2 -> v3:
- Ensure remove only happens on target device
--- MAINTAINERS | 1 + drivers/char/hw_random/Kconfig | 12 ++ drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/nsm-rng.c | 275 +++++++++++++++++++++++++++++++ 4 files changed, 289 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 F: include/uapi/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 +275 -0
275 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
Alexander Graf
maintainerPATCH v3 1/2 misc: Add Nitro Secure Module driver
In reply to Alexander GrafWhen 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.
---
v1 -> v2:
- Remove boilerplate
- Add uapi header
v2 -> v3:
- Move globals to device struct
- Add compat handling
- Simplify some naming
- Remove debug prints
- Use module_virtio_driver
- Drop use of uio.h
--- MAINTAINERS | 10 + drivers/misc/Kconfig | 11 + drivers/misc/Makefile | 1 + drivers/misc/nsm.c | 423 +++++++++++++++++++++++++++++++++++++++ include/linux/nsm.h | 35 ++++ include/uapi/linux/nsm.h | 29 +++ 6 files changed, 509 insertions(+) create mode 100644 drivers/misc/nsm.c create mode 100644 include/linux/nsm.h create mode 100644 include/uapi/linux/nsm.h
MAINTAINERS +10 -0
@@ -15098,6 +15098,16 @@ 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 +F: include/uapi/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 +423 -0
423 lines not on this page · raw message
include/linux/nsm.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Amazon Nitro Secure Module driver. +* +* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +*/ + +#ifndef __LINUX_NSM_H +#define __LINUX_NSM_H + +#include <linux/uio.h> +#include <linux/virtio.h> + +#define NSM_RESPONSE_MAX_SIZE 0x3000 + +struct nsm_hwrng { +int (*probe)(struct virtio_device *dev); +void (*remove)(struct virtio_device *dev); +}; + +int nsm_register_hwrng (struct nsm_hwrng *nsm_hwrng); +void nsm_unregister_hwrng (struct nsm_hwrng *nsm_hwrng); + +/* Copy of NSM message in kernel-space */ +struct nsm_kernel_message { +/* Copy of user request in kernel memory */ +struct kvec request; +/* Copy of user response in kernel memory */ +struct kvec response; +}; + +int nsm_communicate_with_device (struct virtio_device *dev, +struct nsm_kernel_message *message); + +#endif /* __LINUX_NSM_H */
include/uapi/linux/nsm.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +*/ + +#ifndef __UAPI_LINUX_NSM_H +#define __UAPI_LINUX_NSM_H + +#include <linux/ioctl.h> +#include <linux/types.h> + +struct nsm_iovec +{ +__u64 addr;/* Virtual address of target buffer */ +__u64 len;/* Length of target buffer */ +}; + +/* NSM message from user-space */ +struct nsm_message { +/* Request from user */ +struct nsm_iovec request; +/* Response to user */ +struct nsm_iovec response; +}; + +#define NSM_MAGIC 0x0A +#define NSM_IOCTL_REQUEST _IOWR(NSM_MAGIC, 0, struct nsm_message) + +#endif /* __UAPI_LINUX_MISC_BCM_VK_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