From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by mx.groups.io with SMTP id smtpd.web09.4927.1626768260151851069 for ; Tue, 20 Jul 2021 01:04:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=foltoo7e; spf=pass (domain: linux.ibm.com, ip: 148.163.156.1, mailfrom: dovmurik@linux.ibm.com) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16K840u3077263; Tue, 20 Jul 2021 04:04:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=jVOvmZcFtAo9B4CWkSrnVOjQA0xotNWpf226xWTK/oY=; b=foltoo7eQkVGPisP7HHHnPXY2Q0AWlHIjGY/coATUuikm+AHtSbL2CWEHjXUWjgCOfjz zp8+Bamsjg0zvIuV4ahnxcRxyrWFYYfa2+bNtf0VtiTy8l+yr8sfAwpfsNBgAJahTbbP 3jr1Qj2Jvotn/o5BqFNgAw2TTUETLs6ZbVMQsivqfh6GoC6k2xtpSbjvx0uMyRJm08j7 n5tFrJfAMYtjeKC4F9NXGErEvcBnDbXO1/RCnAUNiB15kwQYjbPK15FsDGul3EtrY24T +u452d2nuazrPVMk5X8Iyg5H8slcTQJKpSXWOdb0bMR0vJX4PGNQbQ1hqqYljE/GPb99 0Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 39wt3r102h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jul 2021 04:04:15 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 16K847K9078137; Tue, 20 Jul 2021 04:04:14 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 39wt3r1016-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jul 2021 04:04:14 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16K83Q8u014855; Tue, 20 Jul 2021 08:04:13 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma03wdc.us.ibm.com with ESMTP id 39vqdu42ep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jul 2021 08:04:13 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16K84BvZ32375186 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Jul 2021 08:04:11 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 64426136063; Tue, 20 Jul 2021 08:04:11 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A1E713605E; Tue, 20 Jul 2021 08:04:09 +0000 (GMT) Received: from localhost.localdomain (unknown [9.2.130.16]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 20 Jul 2021 08:04:09 +0000 (GMT) From: "Dov Murik" To: devel@edk2.groups.io Cc: Dov Murik , Tobin Feldman-Fitzthum , Tobin Feldman-Fitzthum , Jim Cadden , James Bottomley , Hubertus Franke , Ard Biesheuvel , Jordan Justen , Ashish Kalra , Brijesh Singh , Erdem Aktas , Jiewen Yao , Min Xu , Tom Lendacky , Leif Lindholm , Sami Mujawar Subject: [PATCH v3 00/11] Measured SEV boot with kernel/initrd/cmdline Date: Tue, 20 Jul 2021 08:03:50 +0000 Message-Id: <20210720080401.3662854-1-dovmurik@linux.ibm.com> X-Mailer: git-send-email 2.25.1 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: VmdSyG4mBMFY3Qu3iosSyOkUHpOOYhAo X-Proofpoint-ORIG-GUID: dNERGjD-T6x4t-Q0om1lWgq7Lm0tdC4X X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-20_04:2021-07-19,2021-07-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 spamscore=0 impostorscore=0 priorityscore=1501 adultscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107200047 Content-Transfer-Encoding: 8bit BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3457 Booting with SEV prevented the loading of kernel, initrd, and kernel command-line via QEMU fw_cfg interface because they arrive from the VMM which is untrusted in SEV. However, in some cases the kernel, initrd, and cmdline are not secret but should not be modified by the host. In such a case, we want to verify inside the trusted VM that the kernel, initrd, and cmdline are indeed the ones expected by the Guest Owner, and only if that is the case go on and boot them up (removing the need for grub inside OVMF in that mode). This patch series reserves an area in MEMFD (previously the last 1KB of the launch secret page) which will contain the hashes of these three blobs (kernel, initrd, cmdline), each under its own GUID entry. This tables of hashes is populated by QEMU before launch, and encrypted as part of the initial VM memory; this makes sure these hashes are part of the SEV measurement (which has to be approved by the Guest Owner for secret injection, for example). Note that populating the hashes table requires QEMU support [1]. OVMF parses the table of hashes populated by QEMU (patch 10), and as it reads the fw_cfg blobs from QEMU, it will verify each one against the expected hash. This is all done inside the trusted VM context. If all the hashes are correct, boot of the kernel is allowed to continue. Any attempt by QEMU to modify the kernel, initrd, cmdline (including dropping one of them), or to modify the OVMF code that verifies those hashes, will cause the initial SEV measurement to change and therefore will be detectable by the Guest Owner during launch before secret injection. Relevant part of OVMF serial log during boot with AmdSevX86 build and QEMU with -kernel/-initrd/-append: ... BlobVerifierLibSevHashesConstructor: Found injected hashes table in secure location Select Item: 0x17 Select Item: 0x8 FetchBlob: loading 7379328 bytes for "kernel" Select Item: 0x18 Select Item: 0x11 VerifyBlob: Found GUID 4DE79437-ABD2-427F-B835-D5B172D2045B in table VerifyBlob: Hash comparison succeeded for "kernel" Select Item: 0xB FetchBlob: loading 12483878 bytes for "initrd" Select Item: 0x12 VerifyBlob: Found GUID 44BAF731-3A2F-4BD7-9AF1-41E29169781D in table VerifyBlob: Hash comparison succeeded for "initrd" Select Item: 0x14 FetchBlob: loading 86 bytes for "cmdline" Select Item: 0x15 VerifyBlob: Found GUID 97D02DD8-BD20-4C94-AA78-E7714D36AB2A in table VerifyBlob: Hash comparison succeeded for "cmdline" ... The patch series is organized as follows: 1: Simple comment fix in adjacent area in the code. 2: Use GenericQemuLoadImageLib to gain one location for fw_cfg blob fetching. 3: Allow the (previously blocked) usage of -kernel in AmdSevX64. 4-7: Add BlobVerifierLib with null implementation and use it in the correct location in QemuKernelLoaderFsDxe. 8-9: Reserve memory for hashes table, declare this area in the reset vector. 10-11: Add the secure implementation BlobVerifierLibSevHashes and use it in AmdSevX64 builds. [1] https://lore.kernel.org/qemu-devel/20210624102040.2015280-1-dovmurik@linux.ibm.com/ Code is at https://github.com/confidential-containers-demo/edk2/tree/sev-hashes-v3 v3 changes: - Rename to BlobVerifierLibNull, use decimal INF_VERSION, remove unused DebugLib reference, fix doxygen comments, add missing IN attribute - Rename to BlobVerifierLibSevHashes, use decimal INF_VERSION, fix doxygen comments, add missing IN attribute, calculate buffer hash only when the guid is found in hashes table - SecretPei: use ALIGN_VALUE to round the hob size - Coding style fixes - Add missing 'Ref:' in patch 1 commit message - Fix phrasing and typos in commit messages - Remove Cc: Laszlo from series v2: https://edk2.groups.io/g/devel/message/77505 v2 changes: - Use the last 1KB of the existing SEV launch secret page for hashes table (instead of reserving a whole new MEMFD page). - Build on top of commit cf203024745f ("OvmfPkg/GenericQemuLoadImageLib: Read cmdline from QemuKernelLoaderFs", 2021-06-28) to have a single location in which all of kernel/initrd/cmdline are fetched from QEMU. - Use static linking of the two BlobVerifierLib implemenatations. - Reorganize series. v1: https://edk2.groups.io/g/devel/message/75567 Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Ashish Kalra Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Min Xu Cc: Tom Lendacky Cc: Leif Lindholm Cc: Sami Mujawar Dov Murik (8): OvmfPkg/AmdSev: use GenericQemuLoadImageLib in AmdSev builds OvmfPkg: add library class BlobVerifierLib with null implementation OvmfPkg: add BlobVerifierLibNull to DSC ArmVirtPkg: add BlobVerifierLibNull to DSC OvmfPkg/QemuKernelLoaderFsDxe: call VerifyBlob after fetch from fw_cfg OvmfPkg/AmdSev/SecretPei: build hob for full page OvmfPkg: add BlobVerifierLibSevHashes OvmfPkg/AmdSev: Enforce hash verification of kernel blobs James Bottomley (3): OvmfPkg/AmdSev/SecretDxe: fix header comment to generic naming OvmfPkg: PlatformBootManagerLibGrub: Allow executing kernel via fw_cfg OvmfPkg/AmdSev: reserve MEMFD space for for firmware config hashes OvmfPkg/OvmfPkg.dec | 9 + ArmVirtPkg/ArmVirtQemu.dsc | 5 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 5 +- OvmfPkg/AmdSev/AmdSevX64.dsc | 9 +- OvmfPkg/OvmfPkgIa32.dsc | 5 +- OvmfPkg/OvmfPkgIa32X64.dsc | 5 +- OvmfPkg/OvmfPkgX64.dsc | 5 +- OvmfPkg/AmdSev/AmdSevX64.fdf | 5 +- OvmfPkg/Library/BlobVerifierLib/BlobVerifierLibNull.inf | 24 +++ OvmfPkg/Library/BlobVerifierLib/BlobVerifierLibSevHashes.inf | 37 ++++ OvmfPkg/Library/PlatformBootManagerLibGrub/PlatformBootManagerLibGrub.inf | 2 + OvmfPkg/ResetVector/ResetVector.inf | 2 + OvmfPkg/Include/Library/BlobVerifierLib.h | 38 ++++ OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.h | 11 ++ OvmfPkg/AmdSev/SecretDxe/SecretDxe.c | 2 +- OvmfPkg/AmdSev/SecretPei/SecretPei.c | 3 +- OvmfPkg/Library/BlobVerifierLib/BlobVerifierNull.c | 33 ++++ OvmfPkg/Library/BlobVerifierLib/BlobVerifierSevHashes.c | 200 ++++++++++++++++++++ OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c | 5 + OvmfPkg/Library/{PlatformBootManagerLib => PlatformBootManagerLibGrub}/QemuKernel.c | 0 OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 9 + OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 20 ++ OvmfPkg/ResetVector/ResetVector.nasmb | 2 + 23 files changed, 426 insertions(+), 10 deletions(-) create mode 100644 OvmfPkg/Library/BlobVerifierLib/BlobVerifierLibNull.inf create mode 100644 OvmfPkg/Library/BlobVerifierLib/BlobVerifierLibSevHashes.inf create mode 100644 OvmfPkg/Include/Library/BlobVerifierLib.h create mode 100644 OvmfPkg/Library/BlobVerifierLib/BlobVerifierNull.c create mode 100644 OvmfPkg/Library/BlobVerifierLib/BlobVerifierSevHashes.c copy OvmfPkg/Library/{PlatformBootManagerLib => PlatformBootManagerLibGrub}/QemuKernel.c (100%) -- 2.25.1