Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6767101rwd; Tue, 6 Jun 2023 01:21:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ53ePoChqNnZNVKLRZeFwZxfyi1VG591j22uhXWnENW6EvLiPuV+DY+vkbwXKuVdfDB8N8n X-Received: by 2002:a05:6214:c49:b0:5ef:8161:cb9a with SMTP id r9-20020a0562140c4900b005ef8161cb9amr9328292qvj.7.1686039700059; Tue, 06 Jun 2023 01:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686039700; cv=none; d=google.com; s=arc-20160816; b=vxnqf5LXWvqu+zWOqTltuVQEjA8pXAQQDDIj6kmW+QpY0QLDTUImk+57D3GGzwB6Aq odBBhG0AyxUx7kqt5gKRKrz0GGlJl6hCW6NCajVZM3fFrvDYEOIq8580JFU6OkRmkw0e JQX9vel9+kYNi/oZfxACqTkW9c1TlgUHpqe5Z8MulhTZ/qicaPhi+xggh+mWBnZvEb8G aFuTGuBzYmHcro21xjS0p+gjPLKXRsjEKExouQ5mU49QRVn8csFV1uyK4Hmq0BqdL0Fv 7MD6jnE8p3wafm57Y/tVCPdaLTS23wPQHbZkM6ZrRiU+Tn+jZuushw0iAQrQUBpey71t s4wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qEb8brDaVgEf6xNJnniCPIjPebxe7oNg6yfvYJTINhE=; b=a3wjHX5RkhS2+2rqGQxU1M+yG7Pxq7clkO7AKbUfOmO5SmZexHuzeNK+xHRi5/5I3W gHm5J0sjGlet+azFYQld9ggcUxivF3BoMk9NuQgNlzuFx97c3y/z6FAAINfzlBcqG/Yy htoVMUHVUkLHnFPltu7QUsR5u/Ptq1lhXdLuWysLHit6dggCIp74+aHEqPkZZxANM9/v aw0s02B8w6eDkriHVfDADNJsD9kuBGeyDggIHzeK8iaFxoQO8CxMNRFpVHlYmFtu0VQy VYerRqQsr2YGSQ+Q19PPWrA9sr8D2IVBtR/2/rqaD6pxEkeTZqBf2S46nFjQpnxJqQ8O qypQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zN1OwuYL; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n20-20020ac85b54000000b003f3902c8352si5960577qtw.584.2023.06.06.01.21.24; Tue, 06 Jun 2023 01:21:40 -0700 (PDT) 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=@linaro.org header.s=google header.b=zN1OwuYL; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236026AbjFFHzx (ORCPT + 99 others); Tue, 6 Jun 2023 03:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236155AbjFFHyF (ORCPT ); Tue, 6 Jun 2023 03:54:05 -0400 Received: from mail-ua1-x92e.google.com (mail-ua1-x92e.google.com [IPv6:2607:f8b0:4864:20::92e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2290171E for ; Tue, 6 Jun 2023 00:51:45 -0700 (PDT) Received: by mail-ua1-x92e.google.com with SMTP id a1e0cc1a2514c-7870821d9a1so3968294241.1 for ; Tue, 06 Jun 2023 00:51:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686037904; x=1688629904; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=qEb8brDaVgEf6xNJnniCPIjPebxe7oNg6yfvYJTINhE=; b=zN1OwuYLYtfiOXTEJ1n9kDh922zCa5AkwC7gHObCBmiHZik39QnJ+ROITrspCVlzuT YCJfrvXNBqRFXIHfImLkzYi2qMdfRttx2ZEF3U2DRyvMIR/P8VXcWTXHAn5WxnLbwXH4 /eTDKXJTmtViURLDpFr+hmoH+P47MsCb/pRFZJCMC3fkl3J7QqOl58m+RTX/CGThRxZJ IenCUv/YXAvAZ4xMO5Mz7aaM3Hz8uSkAPvgD0bLuPJmvHeRsHdlguS0XJZm1koQM0oR0 ZxYCGdzSm3eWZ/hYQVuOt1890nf2Kgm+TKQgs+bnZmVFtAE1BcGwnTsv84wSKMAhPS+r CPWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686037904; x=1688629904; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qEb8brDaVgEf6xNJnniCPIjPebxe7oNg6yfvYJTINhE=; b=giAicVDlM5fY1RU2A6zXypB0M5FPVMkeJ2A8jHAyDTr7ufFvoU16Z+yXEFZVBmFeTJ 59Eo90SgHHIUAXP7xccwG3wH67sdtGXPxmrwdLgDVkmAtnwG/c9V3T4BrDiHoZes8RVD FSrhh2+mp0AmmH9oA1hEXd62Toqw+QKcqLhb5tor1CQXbJkYn7S7E8z+PFTlnh69TOmA BDX+mnjp2G3kA6lj9YIMtew4y8y6U/QruFAx+8tBV2+2sVVCTU7f8o8O1+f2PUHedKDN 8TDaHPN4+Q1HLCirHtkhgIMoMBtMEZ3EtX4frJzWHtOvVD/oZy5mSJlHkJ0VEJW83ENM tKLg== X-Gm-Message-State: AC+VfDypGpM8r6c4+YAYqqiTYJ+yk5JmSyipoa7QMMUPlqNV1rvSpjK3 KcCvF9r06Uu/4zfcp4MWHrcnqC3GZoQeX8d9PS26nQ== X-Received: by 2002:a05:6102:3110:b0:436:4f07:fbe with SMTP id e16-20020a056102311000b004364f070fbemr775393vsh.15.1686037904296; Tue, 06 Jun 2023 00:51:44 -0700 (PDT) MIME-Version: 1.0 References: <20230526010748.1222-1-masahisa.kojima@linaro.org> <20230526010748.1222-4-masahisa.kojima@linaro.org> <0d3e0370-eb76-010f-3d30-9acc9b59645c@siemens.com> In-Reply-To: From: Sumit Garg Date: Tue, 6 Jun 2023 13:21:33 +0530 Message-ID: Subject: Re: [PATCH v5 3/3] efi: Add tee-based EFI variable driver To: Ard Biesheuvel Cc: Jan Kiszka , Masahisa Kojima , Jens Wiklander , linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, Ilias Apalodimas , Johan Hovold , Maxime Coquelin , Alexandre Torgue , linux-efi@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, "Su, Bao Cheng (RC-CN DF FA R&D)" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 6 Jun 2023 at 12:28, Ard Biesheuvel wrote: > > On Tue, 6 Jun 2023 at 08:52, Sumit Garg wrote: > > > > Hi Jan, > > > > On Tue, 6 Jun 2023 at 12:09, Jan Kiszka wrote: > > > > > > On 26.05.23 03:07, Masahisa Kojima wrote: > > > > When the flash is not owned by the non-secure world, accessing the EFI > > > > variables is straightforward and done via EFI Runtime Variable Services. > > > > In this case, critical variables for system integrity and security > > > > are normally stored in the dedicated secure storage and only accessible > > > > from the secure world. > > > > > > > > On the other hand, the small embedded devices don't have the special > > > > dedicated secure storage. The eMMC device with an RPMB partition is > > > > becoming more common, we can use an RPMB partition to store the > > > > EFI Variables. > > > > > > > > The eMMC device is typically owned by the non-secure world(linux in > > > > this case). There is an existing solution utilizing eMMC RPMB partition > > > > for EFI Variables, it is implemented by interacting with > > > > TEE(OP-TEE in this case), StandaloneMM(as EFI Variable Service Pseudo TA), > > > > eMMC driver and tee-supplicant. The last piece is the tee-based > > > > variable access driver to interact with TEE and StandaloneMM. > > > > > > > > So let's add the kernel functions needed. > > > > > > > > This feature is implemented as a kernel module. > > > > StMM PTA has TA_FLAG_DEVICE_ENUM_SUPP flag when registered to OP-TEE > > > > so that this tee_stmm_efi module is probed after tee-supplicant starts, > > > > since "SetVariable" EFI Runtime Variable Service requires to > > > > interact with tee-supplicant. > > > > > > > > Acked-by: Sumit Garg > > > > Co-developed-by: Ilias Apalodimas > > > > Signed-off-by: Ilias Apalodimas > > > > Signed-off-by: Masahisa Kojima > > > > --- > > > > drivers/firmware/efi/Kconfig | 15 + > > > > drivers/firmware/efi/Makefile | 1 + > > > > drivers/firmware/efi/stmm/mm_communication.h | 236 +++++++ > > > > drivers/firmware/efi/stmm/tee_stmm_efi.c | 638 +++++++++++++++++++ > > > > 4 files changed, 890 insertions(+) > > > > create mode 100644 drivers/firmware/efi/stmm/mm_communication.h > > > > create mode 100644 drivers/firmware/efi/stmm/tee_stmm_efi.c > > > > > ... > > > > > > I think we have a probe ordering issue with this driver: > > > efivarfs_fill_super() may be called before the TEE bus was probed, thus > > > with the default efivar ops still registered. And that means > > > efivar_supports_writes() will return false, and the fs declares itself > > > as readonly. I've seen systemd mounting it r/o initialling, and you need > > > to remount the fs to enable writability. > > > > > > Is there anything that could be done to re-order things reliably, probe > > > the tee bus earlier etc.? > > > > This driver has a dependency on user-space daemon: tee-supplicant to > > be running for RPMB access. So once you start that daemon the > > corresponding device will be enumerated on the TEE bus and this driver > > probe will be invoked. So I would suggest you to load this daemon very > > early in the boot process or better to make it a part of initramfs. > > > > That is not the point, really. > > If this dependency exists, the code should be aware of that, and made > to work correctly in spite of it. Requiring a module to be part of > initramfs is not a reasonable fix. I am not sure if I followed you here. Until we have the tee-stmm-efi module loaded we won't get corresponding EFI operations registered. The key here is that the underlying OP-TEE device won't be available until tee-supplicant (see enumeration with PTA_CMD_GET_DEVICES_SUPP) is running. Do you have any better ideas regarding how this should be handled? > > IIUC, this also means that the efivar ops are updated while there is > already a client. This seems less than ideal as well That's true. An ideal situation would be to allow in-kernel RPMB access APIs for OP-TEE or other kernel drivers to use. With that we should be able to remove this tee-supplicant dependency. I hope you are already aware about the earlier efforts to add the RPMB subsystem to the kernel. But with these real world use-cases emerging like EFI variables and fTPM, we should be able to convince corresponding subsystem maintainers. -Sumit