1*7419995aSDov Murik.. SPDX-License-Identifier: GPL-2.0 2*7419995aSDov Murik 3*7419995aSDov Murik============================== 4*7419995aSDov MurikConfidential Computing secrets 5*7419995aSDov Murik============================== 6*7419995aSDov Murik 7*7419995aSDov MurikThis document describes how Confidential Computing secret injection is handled 8*7419995aSDov Murikfrom the firmware to the operating system, in the EFI driver and the efi_secret 9*7419995aSDov Murikkernel module. 10*7419995aSDov Murik 11*7419995aSDov Murik 12*7419995aSDov MurikIntroduction 13*7419995aSDov Murik============ 14*7419995aSDov Murik 15*7419995aSDov MurikConfidential Computing (coco) hardware such as AMD SEV (Secure Encrypted 16*7419995aSDov MurikVirtualization) allows guest owners to inject secrets into the VMs 17*7419995aSDov Murikmemory without the host/hypervisor being able to read them. In SEV, 18*7419995aSDov Muriksecret injection is performed early in the VM launch process, before the 19*7419995aSDov Murikguest starts running. 20*7419995aSDov Murik 21*7419995aSDov MurikThe efi_secret kernel module allows userspace applications to access these 22*7419995aSDov Muriksecrets via securityfs. 23*7419995aSDov Murik 24*7419995aSDov Murik 25*7419995aSDov MurikSecret data flow 26*7419995aSDov Murik================ 27*7419995aSDov Murik 28*7419995aSDov MurikThe guest firmware may reserve a designated memory area for secret injection, 29*7419995aSDov Murikand publish its location (base GPA and length) in the EFI configuration table 30*7419995aSDov Murikunder a ``LINUX_EFI_COCO_SECRET_AREA_GUID`` entry 31*7419995aSDov Murik(``adf956ad-e98c-484c-ae11-b51c7d336447``). This memory area should be marked 32*7419995aSDov Murikby the firmware as ``EFI_RESERVED_TYPE``, and therefore the kernel should not 33*7419995aSDov Murikbe use it for its own purposes. 34*7419995aSDov Murik 35*7419995aSDov MurikDuring the VM's launch, the virtual machine manager may inject a secret to that 36*7419995aSDov Murikarea. In AMD SEV and SEV-ES this is performed using the 37*7419995aSDov Murik``KVM_SEV_LAUNCH_SECRET`` command (see [sev]_). The strucutre of the injected 38*7419995aSDov MurikGuest Owner secret data should be a GUIDed table of secret values; the binary 39*7419995aSDov Murikformat is described in ``drivers/virt/coco/efi_secret/efi_secret.c`` under 40*7419995aSDov Murik"Structure of the EFI secret area". 41*7419995aSDov Murik 42*7419995aSDov MurikOn kernel start, the kernel's EFI driver saves the location of the secret area 43*7419995aSDov Murik(taken from the EFI configuration table) in the ``efi.coco_secret`` field. 44*7419995aSDov MurikLater it checks if the secret area is populated: it maps the area and checks 45*7419995aSDov Murikwhether its content begins with ``EFI_SECRET_TABLE_HEADER_GUID`` 46*7419995aSDov Murik(``1e74f542-71dd-4d66-963e-ef4287ff173b``). If the secret area is populated, 47*7419995aSDov Murikthe EFI driver will autoload the efi_secret kernel module, which exposes the 48*7419995aSDov Muriksecrets to userspace applications via securityfs. The details of the 49*7419995aSDov Murikefi_secret filesystem interface are in [secrets-coco-abi]_. 50*7419995aSDov Murik 51*7419995aSDov Murik 52*7419995aSDov MurikApplication usage example 53*7419995aSDov Murik========================= 54*7419995aSDov Murik 55*7419995aSDov MurikConsider a guest performing computations on encrypted files. The Guest Owner 56*7419995aSDov Murikprovides the decryption key (= secret) using the secret injection mechanism. 57*7419995aSDov MurikThe guest application reads the secret from the efi_secret filesystem and 58*7419995aSDov Murikproceeds to decrypt the files into memory and then performs the needed 59*7419995aSDov Murikcomputations on the content. 60*7419995aSDov Murik 61*7419995aSDov MurikIn this example, the host can't read the files from the disk image 62*7419995aSDov Murikbecause they are encrypted. Host can't read the decryption key because 63*7419995aSDov Murikit is passed using the secret injection mechanism (= secure channel). 64*7419995aSDov MurikHost can't read the decrypted content from memory because it's a 65*7419995aSDov Murikconfidential (memory-encrypted) guest. 66*7419995aSDov Murik 67*7419995aSDov MurikHere is a simple example for usage of the efi_secret module in a guest 68*7419995aSDov Murikto which an EFI secret area with 4 secrets was injected during launch:: 69*7419995aSDov Murik 70*7419995aSDov Murik # ls -la /sys/kernel/security/secrets/coco 71*7419995aSDov Murik total 0 72*7419995aSDov Murik drwxr-xr-x 2 root root 0 Jun 28 11:54 . 73*7419995aSDov Murik drwxr-xr-x 3 root root 0 Jun 28 11:54 .. 74*7419995aSDov Murik -r--r----- 1 root root 0 Jun 28 11:54 736870e5-84f0-4973-92ec-06879ce3da0b 75*7419995aSDov Murik -r--r----- 1 root root 0 Jun 28 11:54 83c83f7f-1356-4975-8b7e-d3a0b54312c6 76*7419995aSDov Murik -r--r----- 1 root root 0 Jun 28 11:54 9553f55d-3da2-43ee-ab5d-ff17f78864d2 77*7419995aSDov Murik -r--r----- 1 root root 0 Jun 28 11:54 e6f5a162-d67f-4750-a67c-5d065f2a9910 78*7419995aSDov Murik 79*7419995aSDov Murik # hd /sys/kernel/security/secrets/coco/e6f5a162-d67f-4750-a67c-5d065f2a9910 80*7419995aSDov Murik 00000000 74 68 65 73 65 2d 61 72 65 2d 74 68 65 2d 6b 61 |these-are-the-ka| 81*7419995aSDov Murik 00000010 74 61 2d 73 65 63 72 65 74 73 00 01 02 03 04 05 |ta-secrets......| 82*7419995aSDov Murik 00000020 06 07 |..| 83*7419995aSDov Murik 00000022 84*7419995aSDov Murik 85*7419995aSDov Murik # rm /sys/kernel/security/secrets/coco/e6f5a162-d67f-4750-a67c-5d065f2a9910 86*7419995aSDov Murik 87*7419995aSDov Murik # ls -la /sys/kernel/security/secrets/coco 88*7419995aSDov Murik total 0 89*7419995aSDov Murik drwxr-xr-x 2 root root 0 Jun 28 11:55 . 90*7419995aSDov Murik drwxr-xr-x 3 root root 0 Jun 28 11:54 .. 91*7419995aSDov Murik -r--r----- 1 root root 0 Jun 28 11:54 736870e5-84f0-4973-92ec-06879ce3da0b 92*7419995aSDov Murik -r--r----- 1 root root 0 Jun 28 11:54 83c83f7f-1356-4975-8b7e-d3a0b54312c6 93*7419995aSDov Murik -r--r----- 1 root root 0 Jun 28 11:54 9553f55d-3da2-43ee-ab5d-ff17f78864d2 94*7419995aSDov Murik 95*7419995aSDov Murik 96*7419995aSDov MurikReferences 97*7419995aSDov Murik========== 98*7419995aSDov Murik 99*7419995aSDov MurikSee [sev-api-spec]_ for more info regarding SEV ``LAUNCH_SECRET`` operation. 100*7419995aSDov Murik 101*7419995aSDov Murik.. [sev] Documentation/virt/kvm/amd-memory-encryption.rst 102*7419995aSDov Murik.. [secrets-coco-abi] Documentation/ABI/testing/securityfs-secrets-coco 103*7419995aSDov Murik.. [sev-api-spec] https://www.amd.com/system/files/TechDocs/55766_SEV-KM_API_Specification.pdf 104