AWS Nitro Enclave emulation support
Subsystems (2)
v7 cover AWS Nitro Enclave emulation support
This is v7 submission for AWS Nitro Enclave emulation in QEMU. From the QEMU side the implementation for nitro enclaves is complete. v6 is at:
https://lore.kernel.org/qemu-devel/[email protected]/T/#t
Changes in v7:
- rebased with master as the first 3 crypto patches got in master now
- had to change some QCRYPTO_HASH_ALG refs to QCRYPTO_HASH_ALGO (with an 'O')
as that got changed in master
- had to re-do the libvirt-ci update patch as I got a conflict from master
- renamed handle_* functions in virtio-nsm.c to be not camel case
Changes in v6:
- updated MAINTAINERS in the commit that introduced eif.c, eif.h files
- used iov_to_buf and iov_from_buf in virtio-nsm.c handle_input
- used g_new0 for iovec_list instead of g_malloc
- updated documentation as now the vsock backend work[6] has been merged in
rust-vmm's vhost-device-vsock
Changes in v5:
- bunch of use of glib utilities like g_autofree, g_memdup2, GList etc
- updated libvirt-ci and added libcbor dependency
- files in this patch are built under libcbor and gnutls dependency check now and
libcbor dependency has been moved to root meson.build file
- separated and re-ordered commits as suggested
- user_data and nonce are added as null to attestation when empty and payload_map_size is fixed
- variables in eif.c have been shortened for readability
Changes in v4:
- fixed error_setv assertion failed. I could not reproduce this but I think
this was happening because I did not set Error *err = NULL in x86_load_eif
- qemu_cbor.. helpers moved to a separate file now
- libcbor version requirement reduced from 0.8.0 to 0.7.0
- replaced GChecksum uses with qcrypto apis
- timestamp multiplied by 1000 in virtio-nsm
- user_data and nonce are now included in attestation even when they are empty
- added x509-utils in crypto
- added G_CHECKSUM_SHA384 support in hash-glib.c
- PCR3 and PCR4 can be set from nitro-enclave machine options. I did not add
the options for virtio-nsm device though. I think the PCR states are set by machines so it made sense to add the options for machine only.
Changes in v3:
- Support for virtio-nsm device
- The EIF related logic has been removed from microvm.c i.e., the logic is
contained in enclave related code
- For vsock emulation in nitro-enclave, now vhost-user-vsock is being used
instead of vhost-vsock (more details in the cover-letter below)
- updated documentation accordingly
Changes in v2:
- moved eif.c and eif.h files from hw/i386 to hw/core
Hi,
Hope everyone is doing well. This is a patch series adding AWS Nitro Enclave[1] emulation support in QEMU. Alexander Graf is mentoring me on this work. I have a gitlab branch where you can view the patches in the gitlab web UI for each commit:
https://gitlab.com/dorjoy03/qemu/-/tree/nitro-enclave-emulation
AWS nitro enclaves is an Amazon EC2[2] feature that allows creating isolated execution environments, called enclaves, from Amazon EC2 instances, which are used for processing highly sensitive data. Enclaves have no persistent storage and no external networking. The enclave VMs are based on Firecracker microvm and have a vhost-vsock device for communication with the parent EC2 instance that spawned it and a Nitro Secure Module (NSM) device for cryptographic attestation. The parent instance VM always has CID 3 while the enclave VM gets a dynamic CID. The enclave VMs can communicate with the parent instance over various ports to CID 3, for example, the init process inside an enclave sends a heartbeat to port 9000 upon boot, expecting a heartbeat reply, letting the parent instance know that the enclave VM has successfully booted.
From inside an EC2 instance, nitro-cli[3] is used to spawn an enclave VM using an EIF (Enclave Image Format)[4] file. EIF files can be built using nitro-cli as well. The EIF specification can be found in the README of the github aws-nitro-enclaves-image-format repository[4]. An EIF file contains the kernel, cmdline and ramdisk(s) in different sections which are used to boot the enclave VM.
Adding nitro enclave emulation support in QEMU will make the life of AWS Nitro Enclave users easier as they will be able to test their EIF images locally without having to run real nitro enclaves which can be difficult for debugging due to its roots in security. This will also make quick prototyping easier.
In QEMU, the new nitro-enclave machine type is implemented based on the microvm machine type similar to how AWS Nitro Enclaves are based on Firecracker microvm.
The vsock emulation support is added using vhost-user-vsock device. This is needed as nitro VMs always talk to parent VM (CID 3) but there is no support for sibling VM communication in vhost-vsock. So to run nitro-enclave, a process that does vsock emulation in user-space like vhost-device-vsock[5] from rust-vmm must be run. I am working on adding proxying using vsock (right now it uses unix domain socket) to the host machine in vhost-device-vsock which I have already posted a PR[6] in rust-vmm repo. This will allow users to run the necessary parent VM applications in the host machine instead of a separate VM with CID 3. Update:
this has been merged now.
A new device virtio-nsm support has been added to QEMU. This device is built-into the nitro-enclave VM. The virtio-nsm spec can be found here[7].
For local testing you need to generate a hello.eif image by first building nitro-cli locally[8]. Then you can use nitro-cli to build a hello.eif image[9]. More details about testing can be found in the docs/system/i386/nitro-enclave.rst file.
Thanks.
Regards,
Dorjoy
[1] https://docs.aws.amazon.com/enclaves/latest/user/nitro-enclave.html
[2] https://aws.amazon.com/ec2/
[3] https://docs.aws.amazon.com/enclaves/latest/user/getting-started.html
[4] https://github.com/aws/aws-nitro-enclaves-image-format?tab=readme-ov-file#enclave-image-file-eif-specification
[5] https://github.com/rust-vmm/vhost-device/tree/main/vhost-device-vsock
[6] https://github.com/rust-vmm/vhost-device/pull/706
[7] https://lists.oasis-open.org/archives/virtio-comment/202310/msg00387.html
[8] https://github.com/aws/aws-nitro-enclaves-cli/blob/main/docs/ubuntu_20.04_how_to_install_nitro_cli_from_github_sources.md
[9] https://github.com/aws/aws-nitro-enclaves-cli/blob/main/examples/x86_64/hello/README.md
Dorjoy Chowdhury (5):
tests/lcitool: Update libvirt-ci and add libcbor dependency device/virtio-nsm: Support for Nitro Secure Module device hw/core: Add Enclave Image Format (EIF) related helpers machine/nitro-enclave: New machine type for AWS Nitro Enclaves docs/nitro-enclave: Documentation for nitro-enclave machine type
.gitlab-ci.d/cirrus/macos-13.vars | 2 +- .gitlab-ci.d/cirrus/macos-14.vars | 2 +- MAINTAINERS | 20 + backends/hostmem-memfd.c | 2 - configs/devices/i386-softmmu/default.mak | 1 + docs/system/i386/nitro-enclave.rst | 78 + hw/core/eif.c | 719 +++++++ hw/core/eif.h | 22 + hw/core/machine.c | 71 +- hw/core/meson.build | 3 + hw/i386/Kconfig | 6 + hw/i386/meson.build | 3 + hw/i386/microvm.c | 6 +- hw/i386/nitro_enclave.c | 355 ++++ hw/virtio/Kconfig | 5 + hw/virtio/cbor-helpers.c | 326 ++++ hw/virtio/meson.build | 6 + hw/virtio/virtio-nsm-pci.c | 73 + hw/virtio/virtio-nsm.c | 1665 +++++++++++++++++ include/hw/boards.h | 2 + include/hw/i386/microvm.h | 2 + include/hw/i386/nitro_enclave.h | 62 + include/hw/virtio/cbor-helpers.h | 46 + include/hw/virtio/virtio-nsm.h | 59 + include/sysemu/hostmem.h | 2 + meson.build | 2 + .../ci/setup/ubuntu/ubuntu-2204-aarch64.yaml | 1 + .../ci/setup/ubuntu/ubuntu-2204-s390x.yaml | 1 + tests/docker/dockerfiles/alpine.docker | 1 + .../dockerfiles/debian-amd64-cross.docker | 1 + .../dockerfiles/debian-arm64-cross.docker | 1 + .../dockerfiles/debian-armhf-cross.docker | 1 + .../dockerfiles/debian-i686-cross.docker | 1 + .../dockerfiles/debian-mips64el-cross.docker | 1 + .../dockerfiles/debian-mipsel-cross.docker | 1 + .../dockerfiles/debian-ppc64el-cross.docker | 1 + .../dockerfiles/debian-s390x-cross.docker | 1 + tests/docker/dockerfiles/debian.docker | 1 + tests/docker/dockerfiles/fedora.docker | 1 + tests/docker/dockerfiles/opensuse-leap.docker | 3 +- tests/docker/dockerfiles/ubuntu2204.docker | 1 + tests/lcitool/libvirt-ci | 2 +- tests/lcitool/projects/qemu.yml | 1 + 43 files changed, 3520 insertions(+), 40 deletions(-) create mode 100644 docs/system/i386/nitro-enclave.rst create mode 100644 hw/core/eif.c create mode 100644 hw/core/eif.h create mode 100644 hw/i386/nitro_enclave.c create mode 100644 hw/virtio/cbor-helpers.c create mode 100644 hw/virtio/virtio-nsm-pci.c create mode 100644 hw/virtio/virtio-nsm.c create mode 100644 include/hw/i386/nitro_enclave.h create mode 100644 include/hw/virtio/cbor-helpers.h create mode 100644 include/hw/virtio/virtio-nsm.h
Signature · 1 line
2.39.5
PATCH v7 1/5 tests/lcitool: Update libvirt-ci and add libcbor dependency
libcbor dependecy is necessary for adding virtio-nsm and nitro-enclave machine support in the following commits. libvirt-ci has already been updated with the dependency upstream and this commit updates libvirt-ci submodule in QEMU to latest upstream. Also the libcbor dependency has been added to tests/lcitool/projects/qemu.yml.
--- .gitlab-ci.d/cirrus/macos-13.vars | 2 +- .gitlab-ci.d/cirrus/macos-14.vars | 2 +- scripts/ci/setup/ubuntu/ubuntu-2204-aarch64.yaml | 1 + scripts/ci/setup/ubuntu/ubuntu-2204-s390x.yaml | 1 + tests/docker/dockerfiles/alpine.docker | 1 + tests/docker/dockerfiles/debian-amd64-cross.docker | 1 + tests/docker/dockerfiles/debian-arm64-cross.docker | 1 + tests/docker/dockerfiles/debian-armhf-cross.docker | 1 + tests/docker/dockerfiles/debian-i686-cross.docker | 1 + tests/docker/dockerfiles/debian-mips64el-cross.docker | 1 + tests/docker/dockerfiles/debian-mipsel-cross.docker | 1 + tests/docker/dockerfiles/debian-ppc64el-cross.docker | 1 + tests/docker/dockerfiles/debian-s390x-cross.docker | 1 + tests/docker/dockerfiles/debian.docker | 1 + tests/docker/dockerfiles/fedora.docker | 1 + tests/docker/dockerfiles/opensuse-leap.docker | 3 ++- tests/docker/dockerfiles/ubuntu2204.docker | 1 + tests/lcitool/libvirt-ci | 2 +- tests/lcitool/projects/qemu.yml | 1 + 19 files changed, 20 insertions(+), 4 deletions(-)
.gitlab-ci.d/cirrus/macos-13.vars +1 -1
@@ -11,6 +11,6 @@ MAKE='/opt/homebrew/bin/gmake' NINJA='/opt/homebrew/bin/ninja' PACKAGING_COMMAND='brew' PIP3='/opt/homebrew/bin/pip3' -PKGS='bash bc bison bzip2 capstone ccache cmocka ctags curl dbus diffutils dtc flex gcovr gettext git glib gnu-sed gnutls gtk+3 gtk-vnc jemalloc jpeg-turbo json-c libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson mtools ncurses nettle ninja pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy socat sparse spice-protocol swtpm tesseract usbredir vde vte3 xorriso zlib zstd' +PKGS='bash bc bison bzip2 capstone ccache cmocka ctags curl dbus diffutils dtc flex gcovr gettext git glib gnu-sed gnutls gtk+3 gtk-vnc jemalloc jpeg-turbo json-c libcbor libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson mtools ncurses nettle ninja pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy socat sparse spice-protocol swtpm tesseract usbredir vde vte3 xorriso zlib zstd' PYPI_PKGS='PyYAML numpy pillow sphinx sphinx-rtd-theme tomli' PYTHON='/opt/homebrew/bin/python3'
.gitlab-ci.d/cirrus/macos-14.vars +1 -1
@@ -11,6 +11,6 @@ MAKE='/opt/homebrew/bin/gmake' NINJA='/opt/homebrew/bin/ninja' PACKAGING_COMMAND='brew' PIP3='/opt/homebrew/bin/pip3' -PKGS='bash bc bison bzip2 capstone ccache cmocka ctags curl dbus diffutils dtc flex gcovr gettext git glib gnu-sed gnutls gtk+3 gtk-vnc jemalloc jpeg-turbo json-c libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson mtools ncurses nettle ninja pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy socat sparse spice-protocol swtpm tesseract usbredir vde vte3 xorriso zlib zstd' +PKGS='bash bc bison bzip2 capstone ccache cmocka ctags curl dbus diffutils dtc flex gcovr gettext git glib gnu-sed gnutls gtk+3 gtk-vnc jemalloc jpeg-turbo json-c libcbor libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson mtools ncurses nettle ninja pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy socat sparse spice-protocol swtpm tesseract usbredir vde vte3 xorriso zlib zstd' PYPI_PKGS='PyYAML numpy pillow sphinx sphinx-rtd-theme tomli' PYTHON='/opt/homebrew/bin/python3'
scripts/ci/setup/ubuntu/ubuntu-2204-aarch64.yaml +1 -0
@@ -35,6 +35,7 @@ packages: - libcacard-dev - libcap-ng-dev - libcapstone-dev + - libcbor-dev - libcmocka-dev - libcurl4-gnutls-dev - libdaxctl-dev
scripts/ci/setup/ubuntu/ubuntu-2204-s390x.yaml +1 -0
@@ -35,6 +35,7 @@ packages: - libcacard-dev - libcap-ng-dev - libcapstone-dev + - libcbor-dev - libcmocka-dev - libcurl4-gnutls-dev - libdaxctl-dev
tests/docker/dockerfiles/alpine.docker +1 -0
@@ -45,6 +45,7 @@ RUN apk update && \ libaio-dev \ libbpf-dev \ libcap-ng-dev \ + libcbor-dev \ libdrm-dev \ libepoxy-dev \ libffi-dev \
tests/docker/dockerfiles/debian-amd64-cross.docker +1 -0
@@ -92,6 +92,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev:amd64 \ libcap-ng-dev:amd64 \ libcapstone-dev:amd64 \ + libcbor-dev:amd64 \ libcmocka-dev:amd64 \ libcurl4-gnutls-dev:amd64 \ libdaxctl-dev:amd64 \
tests/docker/dockerfiles/debian-arm64-cross.docker +1 -0
@@ -92,6 +92,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev:arm64 \ libcap-ng-dev:arm64 \ libcapstone-dev:arm64 \ + libcbor-dev:arm64 \ libcmocka-dev:arm64 \ libcurl4-gnutls-dev:arm64 \ libdaxctl-dev:arm64 \
tests/docker/dockerfiles/debian-armhf-cross.docker +1 -0
@@ -92,6 +92,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev:armhf \ libcap-ng-dev:armhf \ libcapstone-dev:armhf \ + libcbor-dev:armhf \ libcmocka-dev:armhf \ libcurl4-gnutls-dev:armhf \ libdaxctl-dev:armhf \
tests/docker/dockerfiles/debian-i686-cross.docker +1 -0
@@ -92,6 +92,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev:i386 \ libcap-ng-dev:i386 \ libcapstone-dev:i386 \ + libcbor-dev:i386 \ libcmocka-dev:i386 \ libcurl4-gnutls-dev:i386 \ libdaxctl-dev:i386 \
tests/docker/dockerfiles/debian-mips64el-cross.docker +1 -0
@@ -94,6 +94,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev:mips64el \ libcap-ng-dev:mips64el \ libcapstone-dev:mips64el \ + libcbor-dev:mips64el \ libcmocka-dev:mips64el \ libcurl4-gnutls-dev:mips64el \ libdaxctl-dev:mips64el \
tests/docker/dockerfiles/debian-mipsel-cross.docker +1 -0
@@ -91,6 +91,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev:mipsel \ libcap-ng-dev:mipsel \ libcapstone-dev:mipsel \ + libcbor-dev:mipsel \ libcmocka-dev:mipsel \ libcurl4-gnutls-dev:mipsel \ libdaxctl-dev:mipsel \
tests/docker/dockerfiles/debian-ppc64el-cross.docker +1 -0
@@ -92,6 +92,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev:ppc64el \ libcap-ng-dev:ppc64el \ libcapstone-dev:ppc64el \ + libcbor-dev:ppc64el \ libcmocka-dev:ppc64el \ libcurl4-gnutls-dev:ppc64el \ libdaxctl-dev:ppc64el \
tests/docker/dockerfiles/debian-s390x-cross.docker +1 -0
@@ -92,6 +92,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev:s390x \ libcap-ng-dev:s390x \ libcapstone-dev:s390x \ + libcbor-dev:s390x \ libcmocka-dev:s390x \ libcurl4-gnutls-dev:s390x \ libdaxctl-dev:s390x \
tests/docker/dockerfiles/debian.docker +1 -0
@@ -41,6 +41,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev \ libcap-ng-dev \ libcapstone-dev \ + libcbor-dev \ libcmocka-dev \ libcurl4-gnutls-dev \ libdaxctl-dev \
tests/docker/dockerfiles/fedora.docker +1 -0
@@ -61,6 +61,7 @@ exec "$@"\n' > /usr/bin/nosync && \ libbpf-devel \ libcacard-devel \ libcap-ng-devel \ + libcbor-devel \ libcmocka-devel \ libcurl-devel \ libdrm-devel \
tests/docker/dockerfiles/opensuse-leap.docker +2 -1
@@ -4,7 +4,7 @@ # # https://gitlab.com/libvirt/libvirt-ci -FROM registry.opensuse.org/opensuse/leap:15.5 +FROM registry.opensuse.org/opensuse/leap:15.6 RUN zypper update -y && \ zypper install -y \
@@ -46,6 +46,7 @@ RUN zypper update -y && \ libbz2-devel \ libcacard-devel \ libcap-ng-devel \ + libcbor-devel \ libcmocka-devel \ libcurl-devel \ libdrm-devel \
tests/docker/dockerfiles/ubuntu2204.docker +1 -0
@@ -41,6 +41,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ libcacard-dev \ libcap-ng-dev \ libcapstone-dev \ + libcbor-dev \ libcmocka-dev \ libcurl4-gnutls-dev \ libdaxctl-dev \
tests/lcitool/libvirt-ci +1 -1
@@ -1 +1 @@ -Subproject commit 789b4601bce4e01f43fdb6ad4ce5ab4e46674440 +Subproject commit a8253ca5656c34c1d91f2c1170bd0cbf117358f1
tests/lcitool/projects/qemu.yml +1 -0
@@ -42,6 +42,7 @@ packages: - libc-static - libcacard - libcap-ng + - libcbor - libcurl - libdrm - libepoxy
Signature · 1 line
2.39.5
PATCH v7 2/5 device/virtio-nsm: Support for Nitro Secure Module device
In reply to Dorjoy ChowdhuryNitro Secure Module (NSM)[1] device is used in AWS Nitro Enclaves[2] for stripped down TPM functionality like cryptographic attestation. The requests to and responses from NSM device are CBOR[3] encoded.
This commit adds support for NSM device in QEMU. Although related to AWS Nitro Enclaves, the virito-nsm device is independent and can be used in other machine types as well. The libcbor[4] library has been used for the CBOR encoding and decoding functionalities.
[1] https://lists.oasis-open.org/archives/virtio-comment/202310/msg00387.html
[2] https://docs.aws.amazon.com/enclaves/latest/user/nitro-enclave.html
[3] http://cbor.io/
[4] https://libcbor.readthedocs.io/en/latest/
--- MAINTAINERS | 10 + hw/virtio/Kconfig | 5 + hw/virtio/cbor-helpers.c | 326 ++++++ hw/virtio/meson.build | 6 + hw/virtio/virtio-nsm-pci.c | 73 ++ hw/virtio/virtio-nsm.c | 1665 ++++++++++++++++++++++++++++++ include/hw/virtio/cbor-helpers.h | 46 + include/hw/virtio/virtio-nsm.h | 59 ++ meson.build | 2 + 9 files changed, 2192 insertions(+) create mode 100644 hw/virtio/cbor-helpers.c create mode 100644 hw/virtio/virtio-nsm-pci.c create mode 100644 hw/virtio/virtio-nsm.c create mode 100644 include/hw/virtio/cbor-helpers.h create mode 100644 include/hw/virtio/virtio-nsm.h
MAINTAINERS +10 -0
@@ -2335,6 +2335,16 @@ F: include/sysemu/rng*.h F: backends/rng*.c F: tests/qtest/virtio-rng-test.c +virtio-nsm +M: Alexander Graf <[email protected]> +M: Dorjoy Chowdhury <[email protected]> +S: Maintained +F: hw/virtio/cbor-helpers.c +F: hw/virtio/virtio-nsm.c +F: hw/virtio/virtio-nsm-pci.c +F: include/hw/virtio/cbor-helpers.h +F: include/hw/virtio/virtio-nsm.h + vhost-user-stubs M: Alex Bennée <[email protected]> S: Maintained
hw/virtio/Kconfig +5 -0
@@ -6,6 +6,11 @@ config VIRTIO_RNG default y depends on VIRTIO +config VIRTIO_NSM + bool + default y + depends on VIRTIO + config VIRTIO_IOMMU bool default y
hw/virtio/cbor-helpers.c new file +326 -0
326 lines not on this page · raw message
hw/virtio/meson.build +6 -0
@@ -54,6 +54,9 @@ specific_virtio_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem.c specific_virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock.c')) specific_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) +if libcbor.found() + specific_virtio_ss.add(when: 'CONFIG_VIRTIO_NSM', if_true: [files('virtio-nsm.c', 'cbor-helpers.c'), libcbor]) +endif specific_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_SCMI', if_true: files('vhost-user-scmi.c')) specific_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SCMI'], if_true: files('vhost-user-scmi-pci.c'))
@@ -70,6 +73,9 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('virtio-crypto-pc virtio_pci_ss.add(when: 'CONFIG_VIRTIO_INPUT_HOST', if_true: files('virtio-input-host-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_INPUT', if_true: files('virtio-input-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng-pci.c')) +if libcbor.found() + virtio_pci_ss.add(when: 'CONFIG_VIRTIO_NSM', if_true: [files('virtio-nsm-pci.c', 'cbor-helpers.c'), libcbor]) +endif virtio_pci_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_9P', if_true: files('virtio-9p-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_SCSI', if_true: files('virtio-scsi-pci.c'))
hw/virtio/virtio-nsm-pci.c new file +73 -0
73 lines not on this page · raw message
hw/virtio/virtio-nsm.c new file +1665 -0
1,665 lines not on this page · raw message
include/hw/virtio/cbor-helpers.h new file +46 -0
46 lines not on this page · raw message
include/hw/virtio/virtio-nsm.h new file +59 -0
59 lines not on this page · raw message
meson.build +2 -0
@@ -1683,6 +1683,8 @@ if (have_system or have_tools) and (virgl.found() or opengl.found()) endif have_vhost_user_gpu = have_vhost_user_gpu and virgl.found() and opengl.found() and gbm.found() +libcbor = dependency('libcbor', version: '>=0.7.0', required: false) + gnutls = not_found gnutls_crypto = not_found if get_option('gnutls').enabled() or (get_option('gnutls').auto() and have_system)
Signature · 1 line
2.39.5
PATCH v7 4/5 machine/nitro-enclave: New machine type for AWS Nitro Enclaves
In reply to Dorjoy ChowdhuryAWS nitro enclaves[1] is an Amazon EC2[2] feature that allows creating isolated execution environments, called enclaves, from Amazon EC2 instances which are used for processing highly sensitive data. Enclaves have no persistent storage and no external networking. The enclave VMs are based on the Firecracker microvm with a vhost-vsock device for communication with the parent EC2 instance that spawned it and a Nitro Secure Module (NSM) device for cryptographic attestation. The parent instance VM always has CID 3 while the enclave VM gets a dynamic CID.
An EIF (Enclave Image Format)[3] file is used to boot an AWS nitro enclave virtual machine. This commit adds support for AWS nitro enclave emulation using a new machine type option '-M nitro-enclave'. This new machine type is based on the 'microvm' machine type, similar to how real nitro enclave VMs are based on Firecracker microvm. For nitro-enclave to boot from an EIF file, the kernel and ramdisk(s) are extracted into a temporary kernel and a temporary initrd file which are then hooked into the regular x86 boot mechanism along with the extracted cmdline. The EIF file path should be provided using the '-kernel' QEMU option.
In QEMU, the vsock emulation for nitro enclave is added using vhost-user- vsock as opposed to vhost-vsock. vhost-vsock doesn't support sibling VM communication which is needed for nitro enclaves. So for the vsock communication to CID 3 to work, another process that does the vsock emulation in userspace must be run, for example, vhost-device-vsock[4] from rust-vmm, with necessary vsock communication support in another guest VM with CID 3. Using vhost-user-vsock also enables the possibility to implement some proxying support in the vhost-user-vsock daemon that will forward all the packets to the host machine instead of CID 3 so that users of nitro-enclave can run the necessary applications in their host machine instead of running another whole VM with CID 3. The following mandatory nitro-enclave machine option has been added related to the vhost-user-vsock device.
- 'vsock': The chardev id from the '-chardev' option for the
vhost-user-vsock device.
AWS Nitro Enclaves have built-in Nitro Secure Module (NSM) device which has been added using the virtio-nsm device added in a previous commit. In Nitro Enclaves, all the PCRs start in a known zero state and the first 16 PCRs are locked from boot and reserved. The PCR0, PCR1, PCR2 and PCR8 contain the SHA384 hashes related to the EIF file used to boot the VM for validation. The following optional nitro-enclave machine options have been added related to the NSM device.
- 'id': Enclave identifier, reflected in the module-id of the NSM
device. If not provided, a default id will be set.
- 'parent-role': Parent instance IAM role ARN, reflected in PCR3
of the NSM device.
- 'parent-id': Parent instance identifier, reflected in PCR4 of the
NSM device.
[1] https://docs.aws.amazon.com/enclaves/latest/user/nitro-enclave.html
[2] https://aws.amazon.com/ec2/
[3] https://github.com/aws/aws-nitro-enclaves-image-format
[4] https://github.com/rust-vmm/vhost-device/tree/main/vhost-device-vsock
--- MAINTAINERS | 2 + backends/hostmem-memfd.c | 2 - configs/devices/i386-softmmu/default.mak | 1 + hw/core/machine.c | 71 ++--- hw/core/meson.build | 3 + hw/i386/Kconfig | 6 + hw/i386/meson.build | 3 + hw/i386/microvm.c | 6 +- hw/i386/nitro_enclave.c | 355 +++++++++++++++++++++++ include/hw/boards.h | 2 + include/hw/i386/microvm.h | 2 + include/hw/i386/nitro_enclave.h | 62 ++++ include/sysemu/hostmem.h | 2 + 13 files changed, 481 insertions(+), 36 deletions(-) create mode 100644 hw/i386/nitro_enclave.c create mode 100644 include/hw/i386/nitro_enclave.h
MAINTAINERS +2 -0
@@ -1875,6 +1875,8 @@ M: Dorjoy Chowdhury <[email protected]> S: Maintained F: hw/core/eif.c F: hw/core/eif.h +F: hw/i386/nitro_enclave.c +F: include/hw/i386/nitro_enclave.h Machine core M: Eduardo Habkost <[email protected]>
backends/hostmem-memfd.c +0 -2
@@ -18,8 +18,6 @@#include "qapi/error.h" #include "qom/object.h" -#define TYPE_MEMORY_BACKEND_MEMFD "memory-backend-memfd" -OBJECT_DECLARE_SIMPLE_TYPE (HostMemoryBackendMemfd,MEMORY_BACKEND_MEMFD )
configs/devices/i386-softmmu/default.mak +1 -0
@@ -29,3 +29,4 @@ # CONFIG_I440FX=n # CONFIG_Q35=n # CONFIG_MICROVM=n +# CONFIG_NITRO_ENCLAVE=n
hw/core/machine.c +38 -33
95 lines not on this page · raw message
hw/core/meson.build +3 -0
@@ -24,6 +24,9 @@ system_ss.add(when: 'CONFIG_REGISTER', if_true: files('register.c')) system_ss.add(when: 'CONFIG_SPLIT_IRQ', if_true: files('split-irq.c')) system_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files('stream.c')) system_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c')) +if libcbor.found() and gnutls.found() + system_ss.add(when: 'CONFIG_NITRO_ENCLAVE', if_true: [files('eif.c'), zlib, libcbor, gnutls]) +endif system_ss.add(files( 'cpu-sysemu.c',
hw/i386/Kconfig +6 -0
@@ -129,6 +129,12 @@ config MICROVM select USB_XHCI_SYSBUS select I8254 +config NITRO_ENCLAVE + default y + depends on MICROVM + select VHOST_USER_VSOCK + select VIRTIO_NSM + config X86_IOMMU bool depends on PC
hw/i386/meson.build +3 -0
@@ -15,6 +15,9 @@ i386_ss.add(when: 'CONFIG_AMD_IOMMU', if_true: files('amd_iommu.c'), if_false: files('amd_iommu-stub.c')) i386_ss.add(when: 'CONFIG_I440FX', if_true: files('pc_piix.c')) i386_ss.add(when: 'CONFIG_MICROVM', if_true: files('x86-common.c', 'microvm.c', 'acpi-microvm.c', 'microvm-dt.c')) +if libcbor.found() and gnutls.found() + i386_ss.add(when: 'CONFIG_NITRO_ENCLAVE', if_true: files('nitro_enclave.c')) +endif i386_ss.add(when: 'CONFIG_Q35', if_true: files('pc_q35.c')) i386_ss.add(when: 'CONFIG_VMMOUSE', if_true: files('vmmouse.c')) i386_ss.add(when: 'CONFIG_VMPORT', if_true: files('vmport.c'))
hw/i386/microvm.c +5 -1
@@ -283,6 +283,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)static void microvm_memory_init (MicrovmMachineState *mms) { +MicrovmMachineClass *mmc =MICROVM_MACHINE_GET_CLASS (mms);MachineState *machine =MACHINE (mms);X86MachineState *x86ms =X86_MACHINE (mms);MemoryRegion *ram_below_4g, *ram_above_4g;
@@ -328,7 +329,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)rom_set_fw (fw_cfg);if (machine->kernel_filename !=NULL ) { -x86_load_linux (x86ms, fw_cfg,0 , true); + mmc->x86_load_linux (x86ms, fw_cfg,0 , true); }if (mms->option_roms) {
@@ -637,9 +638,12 @@ GlobalProperty microvm_properties[] = {static void microvm_class_init (ObjectClass *oc,void *data) {X86MachineClass *x86mc =X86_MACHINE_CLASS (oc); +MicrovmMachineClass *mmc =MICROVM_MACHINE_CLASS (oc);MachineClass *mc =MACHINE_CLASS (oc);HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc); + mmc->x86_load_linux = x86_load_linux; + mc->init = microvm_machine_state_init; mc->family ="microvm_i386" ;
hw/i386/nitro_enclave.c new file +355 -0
355 lines not on this page · raw message
include/hw/boards.h +2 -0
@@ -313,6 +313,8 @@ struct MachineClass {int64_t (*get_default_cpu_node_id)(const MachineState *ms,int idx);ram_addr_t (*fixup_ram_size)(ram_addr_t size);uint64_t smbios_memory_device_size; +bool (*create_default_memdev)(MachineState *ms,const char *path, +Error **errp); };/**
include/hw/i386/microvm.h +2 -0
@@ -78,6 +78,8 @@ struct MicrovmMachineClass {X86MachineClass parent; HotplugHandler *(*orig_hotplug_handler)(MachineState *machine, DeviceState *dev); +void (*x86_load_linux)(X86MachineState *x86ms,FWCfgState *fw_cfg, +int acpi_data_size,bool pvh_enabled); };struct MicrovmMachineState {
include/hw/i386/nitro_enclave.h new file +62 -0
62 lines not on this page · raw message
include/sysemu/hostmem.h +2 -0
@@ -39,6 +39,8 @@ OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,*/ #define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" +#define TYPE_MEMORY_BACKEND_MEMFD "memory-backend-memfd" +/** * HostMemoryBackendClass:
Signature · 1 line
2.39.5
PATCH v7 5/5 docs/nitro-enclave: Documentation for nitro-enclave machine type
In reply to Dorjoy Chowdhury--- MAINTAINERS | 1 + docs/system/i386/nitro-enclave.rst | 78 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 docs/system/i386/nitro-enclave.rst
MAINTAINERS +1 -0
@@ -1877,6 +1877,7 @@ F: hw/core/eif.c F: hw/core/eif.h F: hw/i386/nitro_enclave.c F: include/hw/i386/nitro_enclave.h +F: docs/system/i386/nitro-enclave.rst Machine core M: Eduardo Habkost <[email protected]>
docs/system/i386/nitro-enclave.rst new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH v7 3/5 hw/core: Add Enclave Image Format (EIF) related helpers
In reply to Dorjoy ChowdhuryAn EIF (Enclave Image Format)[1] file is used to boot an AWS nitro enclave[2] virtual machine. The EIF file contains the necessary kernel, cmdline, ramdisk(s) sections to boot.
Some helper functions have been introduced for extracting the necessary sections from an EIF file and then writing them to temporary files as well as computing SHA384 hashes from the section data. These will be used in the following commit to add support for nitro-enclave machine type in QEMU.
The files added in this commit are not compiled yet but will be added to the hw/core/meson.build file in the following commit where CONFIG_NITRO_ENCLAVE will be introduced.
[1] https://github.com/aws/aws-nitro-enclaves-image-format
[2] https://docs.aws.amazon.com/enclaves/latest/user/nitro-enclave.html
--- MAINTAINERS | 7 + hw/core/eif.c | 719 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/core/eif.h | 22 ++ 3 files changed, 748 insertions(+) create mode 100644 hw/core/eif.c create mode 100644 hw/core/eif.h
MAINTAINERS +7 -0
@@ -1869,6 +1869,13 @@ F: hw/i386/microvm.c F: include/hw/i386/microvm.h F: pc-bios/bios-microvm.bin +nitro-enclave +M: Alexander Graf <[email protected]> +M: Dorjoy Chowdhury <[email protected]> +S: Maintained +F: hw/core/eif.c +F: hw/core/eif.h + Machine core M: Eduardo Habkost <[email protected]> M: Marcel Apfelbaum <[email protected]>
hw/core/eif.c new file +719 -0
719 lines not on this page · raw message
hw/core/eif.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* EIF (Enclave Image Format) related helpers +* +* Copyright (c) 2024 Dorjoy Chowdhury <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* (at your option) any later version. See the COPYING file in the +* top-level directory. +*/ + +#ifndef HW_CORE_EIF_H +#define HW_CORE_EIF_H + +bool read_eif_file (const char *eif_path,const char *machine_initrd, +char **kernel_path,char **initrd_path, +char **kernel_cmdline,uint8_t *image_sha384, +uint8_t *bootstrap_sha384,uint8_t *app_sha384, +uint8_t *fingerprint_sha384,bool *signature_found, +Error **errp); + +#endif +
Signature · 1 line
2.39.5
Ping
Requesting for review on this one.
v7 thread URL for convenience:
https://lore.kernel.org/qemu-devel/[email protected]/T/#t
Thanks!
Regards,
Dorjoy
Quoted 1 line · Dorjoy Chowdhury
[7] https://lists.oasis-open.org/archives/virtio-comment/202310/msg00387.html
That list is dead, would you mind reposting to the new list, so we can vote on it?
Thanks!
Signature · 1 line
MST
Quoted 6 lines · Michael S. Tsirkin
Quoted 1 line · Dorjoy Chowdhury
[7] https://lists.oasis-open.org/archives/virtio-comment/202310/msg00387.html
That list is dead, would you mind reposting to the new list, so we can vote on it?
Yeah the URL seems to be dead too but I found the lore URL:
https://lore.kernel.org/virtio-comment/[email protected]/
Probably Alex needs to repost, right?
cc Alex
Regards,
Dorjoy
Thanks for reviewing. I have now submitted a v8.
https://lore.kernel.org/qemu-devel/[email protected]/T/#t
Regards,
Dorjoy