Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1339886pxb; Wed, 2 Feb 2022 02:43:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9utzu/pyd2CkyiB5K9yxheX4dCTVosLutlHM0gLXMO1ntQ4MfluUdbdupLSzkrysKkvK6 X-Received: by 2002:a17:902:cec2:: with SMTP id d2mr30737234plg.153.1643798581951; Wed, 02 Feb 2022 02:43:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643798581; cv=none; d=google.com; s=arc-20160816; b=xcc3NGPR0pfNOYf9QELExu8P+XA/dHIy3QJ5tK5oBRiO3BnyaQPac92m5bHWYAO7N0 qyPs/1z3YSxo4HARrm/9pL4hfZq1r2OjS8/CrSEkJwjl8dkhJTs57rN1jIB+fhWOoknW O2sUxKnmcQqOS7C/p3Y50fubATPW68Pb8uOca3+skOmRGmR4mdlKHmoGVnyrjI9J70Co 9CnRbSr57SlPwGFGuHlChO/jZdM0z0zzuMGjzxh5qYWcvgVtxtb/DsINdOsWjp5mynU7 90odH9R/NZBtcqSzbprY0K2EEeCxQOGeUUlPT8ScYpDUKCFUMykSvtQFH6DHWDLGZdBu rTOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iTV4qKEjdbDa6WSM4yM7pSW2xXxTF8i676FiAx/YLIY=; b=qPxH20cZ7J1GEI7ztT5+QtPPtcBX4mrC/Ti+bQonBMP62H+6kzzL3JJf2fvGRcKGgg 9AfIqCw+K4LnUgw1mj4DoQtjUhmbwxStQJBznN4myrbXxjx80f1iage3CjTi0gine/5+ k8FkhDTnM0ntq9y8Csgt7euox82e0LUYWUEb3P6NvVu4pmXlxR0pF/TpsqgG2LL7eNml W6ebkabGPoysaBhNzPtPISGLSU0HqNmX1jSrVZkPMWL+vI9DABpctJmfs0UpQM+oteUI iVRubWeCZUNIDH7ENOa0qVVxT8HBxVI0UAggN8jZAHHJoncBEya0cj5CHyaCMYbVwWwx 4Nog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=mwqGE5HL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id on15si4795727pjb.91.2022.02.02.02.42.50; Wed, 02 Feb 2022 02:43:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=mwqGE5HL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238142AbiBAMpJ (ORCPT + 99 others); Tue, 1 Feb 2022 07:45:09 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:11582 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238177AbiBAMpD (ORCPT ); Tue, 1 Feb 2022 07:45:03 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 211CdUvb017127; Tue, 1 Feb 2022 12:44:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=iTV4qKEjdbDa6WSM4yM7pSW2xXxTF8i676FiAx/YLIY=; b=mwqGE5HLeTShArrroKwJ4CnGnbWWaqZr6NxNR4ym2C1xL3uyaNHqwIfaXgtUzcLjGlHx F4sx29/DliBJ/gTA1cy9dlgllfCVJwId966U6Zx/PZmRxKnnltSOXLVsr2M61TbDJLoY CQ4e80xV2a8TTSpODvX231KF5NRY+28jFJa4jX2I3Pjrh6nQzdmOqoJQxF1aTxxilypw XsvnZc8/RvvmmdzQ2JHTmvkkNxeH9OQFRmDpwH4seKErqxio/BAfNauH9PdW4ZLm2mf7 GwsvWfuRHxMlMmWaRisWd7eqd+teho6dPfDjJc8I2Mqt1Ujf8nFolValZQlaFZKki+qR Dg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dxj34e0f2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Feb 2022 12:44:52 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 211CfA3v026077; Tue, 1 Feb 2022 12:44:52 GMT 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 3dxj34e0ej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Feb 2022 12:44:51 +0000 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 211Ccs66014529; Tue, 1 Feb 2022 12:44:50 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma03wdc.us.ibm.com with ESMTP id 3dvw7afq7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Feb 2022 12:44:50 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 211Cimdh18350378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Feb 2022 12:44:48 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EBEF4BE063; Tue, 1 Feb 2022 12:44:47 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2C808BE05A; Tue, 1 Feb 2022 12:44:46 +0000 (GMT) Received: from amdrome3.watson.ibm.com (unknown [9.2.130.16]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 1 Feb 2022 12:44:46 +0000 (GMT) From: Dov Murik To: linux-efi@vger.kernel.org Cc: Dov Murik , Borislav Petkov , Ashish Kalra , Brijesh Singh , Tom Lendacky , Ard Biesheuvel , James Morris , "Serge E. Hallyn" , Andi Kleen , Greg KH , Andrew Scull , Dave Hansen , "Dr. David Alan Gilbert" , Gerd Hoffmann , Lenny Szubowicz , Peter Gonda , James Bottomley , Tobin Feldman-Fitzthum , Jim Cadden , Daniele Buono , linux-coco@lists.linux.dev, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 4/5] efi: Load efi_secret module if EFI secret area is populated Date: Tue, 1 Feb 2022 12:44:12 +0000 Message-Id: <20220201124413.1093099-5-dovmurik@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220201124413.1093099-1-dovmurik@linux.ibm.com> References: <20220201124413.1093099-1-dovmurik@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: zCHGyvBGKkltewj3n9q9_4j5UELREzLL X-Proofpoint-GUID: A8VY6Klct7kjbqf0XX0m0eGBZ_nh5CWa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-01_03,2022-02-01_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202010068 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the efi_secret module is built, register a late_initcall in the EFI driver which checks whether the EFI secret area is available and populated, and then requests to load the efi_secret module. This will cause the /coco/efi_secret directory to appear in guests into which secrets were injected; in other cases, the module is not loaded. Signed-off-by: Dov Murik --- drivers/firmware/efi/Makefile | 1 + drivers/firmware/efi/coco.c | 58 ++++++++++++++++++++++++++++ drivers/virt/coco/efi_secret/Kconfig | 3 ++ 3 files changed, 62 insertions(+) create mode 100644 drivers/firmware/efi/coco.c diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile index c02ff25dd477..49c4a8c0bfc4 100644 --- a/drivers/firmware/efi/Makefile +++ b/drivers/firmware/efi/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_APPLE_PROPERTIES) += apple-properties.o obj-$(CONFIG_EFI_RCI2_TABLE) += rci2-table.o obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE) += embedded-firmware.o obj-$(CONFIG_LOAD_UEFI_KEYS) += mokvar-table.o +obj-$(CONFIG_EFI_COCO_SECRET) += coco.o fake_map-y += fake_mem.o fake_map-$(CONFIG_X86) += x86_fake_mem.o diff --git a/drivers/firmware/efi/coco.c b/drivers/firmware/efi/coco.c new file mode 100644 index 000000000000..f8efd240ab05 --- /dev/null +++ b/drivers/firmware/efi/coco.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Confidential computing (coco) secret area handling + * + * Copyright (C) 2021 IBM Corporation + * Author: Dov Murik + */ + +#define pr_fmt(fmt) "efi: " fmt + +#include +#include +#include +#include + +#ifdef CONFIG_EFI_SECRET_MODULE + +/* + * Load the efi_secret module if the EFI secret area is populated + */ +static int __init load_efi_secret_module(void) +{ + struct linux_efi_coco_secret_area *area; + efi_guid_t *header_guid; + int ret = 0; + + if (efi.coco_secret == EFI_INVALID_TABLE_ADDR) + return 0; + + area = memremap(efi.coco_secret, sizeof(*area), MEMREMAP_WB); + if (!area) { + pr_err("Failed to map confidential computing secret area descriptor\n"); + return -ENOMEM; + } + if (!area->base_pa || area->size < sizeof(*header_guid)) + goto unmap_desc; + + header_guid = (void __force *)ioremap_encrypted(area->base_pa, sizeof(*header_guid)); + if (!header_guid) { + pr_err("Failed to map secret area\n"); + ret = -ENOMEM; + goto unmap_desc; + } + if (efi_guidcmp(*header_guid, EFI_SECRET_TABLE_HEADER_GUID)) + goto unmap_encrypted; + + ret = request_module("efi_secret"); + +unmap_encrypted: + iounmap((void __iomem *)header_guid); + +unmap_desc: + memunmap(area); + return ret; +} +late_initcall(load_efi_secret_module); + +#endif diff --git a/drivers/virt/coco/efi_secret/Kconfig b/drivers/virt/coco/efi_secret/Kconfig index ed181797ed86..068fdd1fccd7 100644 --- a/drivers/virt/coco/efi_secret/Kconfig +++ b/drivers/virt/coco/efi_secret/Kconfig @@ -14,3 +14,6 @@ config EFI_SECRET To compile this driver as a module, choose M here. The module will be called efi_secret. + + The module is loaded automatically by the EFI driver if the EFI + secret area is populated. -- 2.25.1