Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1146697rwd; Thu, 8 Jun 2023 12:58:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6jo2K8/7yaTUe4fbXEeaezCT9L9oCeAV8yQk/2XiLXCql8e/9NihqLYSOxYgNW/W2Oy7hC X-Received: by 2002:a05:6a20:7d99:b0:10c:9e35:857a with SMTP id v25-20020a056a207d9900b0010c9e35857amr8741232pzj.49.1686254337564; Thu, 08 Jun 2023 12:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686254337; cv=none; d=google.com; s=arc-20160816; b=JH2/OT6NF2qd64TIetkQamwfknPO5mDRYkt4vwRcsTHx/0k1ipaYijfz3Xl6Y8zY5b lxf4/Gt6Oxo9f5IwzRpnNb2g5WcjPLYsKbdtbQMQka6QHfYpdDXmqpTsYT8CiPXLRcJ0 SodT27IGPFCOajJruUrTwcMxGrpc6SCAdISBFvo30fP4kjQdKo9Pd6rbeEwPHcA6EF7p HtwTP7JueuLdIZmdZVtXkXMdugKUWBskMUEpairorzSeQU36vV7QgH5zfmZKonO6vvnB VqalYg2U6pJs5vZIlclPZne0DtLMLt764ueCFCPNWLdxnporv5YV0CxR5+YTuyKT+zez qVUg== 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=rRPRuQnm3+oJHVqcDvP4QLGvWW7hCToB0kEigLBi5Sw=; b=Xt0nVxEob+lZlLyV9UPX+cih6HaNK5NOC6FFXUVgWyNOZIGjoFi7vTL28Ohjagmcq7 QW0Y4W3hbWmbQzEUjs2wiBo7k5OClqFDM1eCVaJ5/u9A1gOjy9cgqAdcBe+GU3nl6KBT kQLoMQdf/jil8vsHpnKI6wYAkQkD6GRGE/JFdoSwhY6r0ld1QCqGPRnzK+hmOgit/9Be poJ1BLo+ezLpnYkmUjIlc+R61xGXvWwNXu5kPbVP5eNUdGl5EZ+yRl7860TMpoLB6a1v HnOb+f1PhDqT4YsywewQwfx35d0rSorK2nbS/ptxUTe6hcBI+QPTffHfMf27NU7ynxiD s8Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mqtfuwrw; 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 z17-20020a637e11000000b005348549fae5si1451879pgc.252.2023.06.08.12.58.43; Thu, 08 Jun 2023 12:58:57 -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=Mqtfuwrw; 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 S230247AbjFHTji (ORCPT + 99 others); Thu, 8 Jun 2023 15:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjFHTjg (ORCPT ); Thu, 8 Jun 2023 15:39:36 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64F1318C for ; Thu, 8 Jun 2023 12:39:34 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f620583bc2so1222281e87.1 for ; Thu, 08 Jun 2023 12:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686253172; x=1688845172; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rRPRuQnm3+oJHVqcDvP4QLGvWW7hCToB0kEigLBi5Sw=; b=MqtfuwrwoXunFIgZ/c0qiydszJ0AunfmOWkPIYtoDzZbt1FvUCW8J8P8MWgWG+UvvY pq3YMyEm8LDbLx+Bdfb/WW4XHbSTlbhNF28HjkBjoN0WRwtccaQKcIG96BHYgXK9vS3J r3IzsK66JFIuwHM5y1stPv7X2q9w1t1xEMQmaSbagOeGl0bsTAZnmZstkRwwxRRy8ZEu /3Ygc/aPl4s+7MFsViqFVH2k30CsnTwjGVmFpSPFxjk8XHDkpzBFUPA5F+vaeFVA4zsd 1MJ0pK839LaeX4CB4b6w2F2/AJ6GgaP4Pom0Es/PhcXeTaYN+6OSElfKBo3nK7/jn+Bc xMng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686253172; x=1688845172; 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=rRPRuQnm3+oJHVqcDvP4QLGvWW7hCToB0kEigLBi5Sw=; b=Si36Okiodcf1HbaFwCCBEZV19T2JfwDspG2PD+TQlq9Ja6kOcOFCvFE1fkH8mDxnFC uFcdthkHP3jRVH7S/tE+0yuXg4+Tglw+6nenEv2cKvuHKlIfXUHP455OxEKuaaM66/KM mV1PnkZsCgbOU3T5sxsAkPdnAwPCP8IsqdCqeTk4xK7ml+ZG8TDIHX+BJNL0uTpV3kXZ Nvvy+rfOLriQLe0JPtHSSSfwwl9XS3sb8nkQ8x/bOO9g8ckObv3pkHLeF4D9DxLbDjMd XSdyIWgAvi0bHiXgo8Oy7LSG7tYBSKtM3BeqOxn4Mz2Kv7HYKxbO/TX9kZNyAkFi4bIV Dn6Q== X-Gm-Message-State: AC+VfDzF3P2sy8s1tUnC6H7pjhk/X6IbfU5TOgtGe/5JECJYCGNI+zBX 9jvYtADxK0ALa2Ymm7q61VY/8QsYsHYxSXGyp8XGrQ== X-Received: by 2002:a2e:a408:0:b0:2b2:52:7eea with SMTP id p8-20020a2ea408000000b002b200527eeamr2350364ljn.48.1686253172550; Thu, 08 Jun 2023 12:39:32 -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> <4ff09002-e871-38b9-43ec-227a64bac731@siemens.com> <76da826f-b608-6add-5401-6de818b180e3@siemens.com> <871ece13-7d6e-44d4-3bda-317658202f6f@siemens.com> In-Reply-To: From: Ilias Apalodimas Date: Thu, 8 Jun 2023 22:38:56 +0300 Message-ID: Subject: Re: [PATCH v5 3/3] efi: Add tee-based EFI variable driver To: Ard Biesheuvel Cc: Jan Kiszka , Sumit Garg , Masahisa Kojima , Jens Wiklander , linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, 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 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 Thu, 8 Jun 2023 at 16:52, Ard Biesheuvel wrote: > > On Thu, 8 Jun 2023 at 08:22, Ilias Apalodimas > wrote: > > > > Hi Jan > > > > > > On Wed, 7 Jun 2023 at 22:46, Jan Kiszka wrote: > > > > > > On 07.06.23 20:17, Ilias Apalodimas wrote: > > > > On Wed, 7 Jun 2023 at 20:14, Jan Kiszka wrote: > > > >> > > > >> On 07.06.23 18:59, Ilias Apalodimas wrote: > > > >>> On Wed, 7 Jun 2023 at 19:09, Ilias Apalodimas > > > >>> wrote: > > > >>>> > > > >>>> Hi Jan, > > > >>>> > > > >>>> [...] > > > >>>>>>>> No I don't, this will work reliably without the need to remount the efivarfs. > > > >>>>>>>> As you point out you will still have this dependency if you end up > > > >>>>>>>> building them as modules and you manage to mount the efivarfs before > > > >>>>>>>> those get inserted. Does anyone see a reasonable workaround? > > > >>>>>>>> Deceiving the kernel and making the bootloader set the RT property bit > > > >>>>>>>> to force the filesystem being mounted as rw is a nasty hack that we > > > >>>>>>>> should avoid. Maybe adding a kernel command line parameter that says > > > >>>>>>>> "Ignore the RTPROP I know what I am doing"? I don't particularly love > > > >>>>>>>> this either, but it's not unreasonable. > > > >>>>>>> > > > >>>>>>> In the context of https://github.com/OP-TEE/optee_os/issues/6094, > > > >>>>>>> basically this issue mapped on reboot/shutdown, I would really love to > > > >>>>>>> see the unhandy tee-supplicant daemon to be overcome. > > > >>>>>> > > > >>>>>> I have seen this error before and it has been on my todo list. So I > > > >>>>>> have tried to fix it here [1]. Feel free to test it and let me know if > > > >>>>>> you see any further issues. > > > >>>>>> > > > >>>>>> [1] https://lkml.org/lkml/2023/6/7/927 > > > >>>>>> > > > >>>>> > > > >>>>> Ah, nice, will test ASAP! > > > >>>>> > > > >>>>> Meanwhile more food: I managed to build a firmware that was missing > > > >>>>> STMM. But the driver loaded, and I got this: > > > >>>> > > > >>>> Thanks for the testing. I'll try to reproduce it locally and get back to you > > > >>> > > > >>> Can you provide a bit more info on how that was triggered btw? I would > > > >>> be helpful to know > > > >>> > > > >>> - OP-TEE version > > > >> > > > >> Today's master, 145953d55. > > > >> > > > >>> - was it compiled as a module or built-in? > > > >> > > > >> Sorry, not sure anymore, switching back and forth right now. I think it > > > >> was built-in. > > > >> > > > >>> - was the supplicant running? > > > >> > > > >> Yes. > > > >> > > > > > > > > Ok thanks, that helps. I guess this also means U-Boot was compiled to > > > > store the variables in a file in the ESP instead of the RPMB right? > > > > Otherwise, I can't see how the device booted in the first place. > > > > > > U-Boot was not configured to perform secure booting in this case. It had > > > RPMB support enabled, just didn't have to use it. > > > > In your initial mail you said you managed to build a firmware without > > StMM. If U-boot isn't reconfigured accordingly -- iow skip the EFI > > variable storage in an RPMB, the EFI subsystem will fail to start. > > > > In any case, I don't think the ooops you are seeing is not connected > > to this patchset. Looking at the kernel EFI stub we only set the > > SetVariableRT if the RTPROP table is set accordingly by the firmware. > > U-Boot never sets the EFI_RT_SUPPORTED_SET_VARIABLE property since it > > can't support it. What you are doing is remount the efivarfs as rw > > and then trying to set a variable, but the callback for it is NULL. > > I think you'll be able to replicate the same behavior on the kernel > > without even inserting the new module. > > > > I have dropped this series from efi/next for now, given that it > obviously has problems in its current state. > > The risk of merging this now and fixing it later is that it may cause > regressions for early adopters that rely on the behavior we are > introducing here. Better to get this in shape first. The ooops Jan was seeing is reproducible in the current code with $ sudo mount -o remount,rw /sys/firmware/efi/efivars $ sudo efi-updatevar -f PK.auth PK So the only real problem we are discussing here is users having to remount the efivarfs once the module is inserted and the supplicant is running right? We could do something along the lines of the patch below. That would solve both of the problems. However, the patch changes the way efivarfs is mounted -- it's now always mounted as RW. What I am worried about is userspace tools that rely on this. I know fwupd uses it and looks for a RO mounted efivarfs on it's initial checking, but since userspace apps are already dealing with firmware that exposes SetVariableRT but always returns EFI_UNSUPPORTED this should be safe ?(famous last words) Jan can you please apply this and see if it solves your problem? diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 4cc8d0e7d0fd..37accd9e885c 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -206,6 +206,13 @@ static bool generic_ops_supported(void) return true; } +efi_status_t set_variable_int(efi_char16_t *name, efi_guid_t *vendor, + u32 attributes, unsigned long data_size, + void *data) +{ + return EFI_UNSUPPORTED; +} + static int generic_ops_register(void) { if (!generic_ops_supported()) @@ -219,6 +226,9 @@ static int generic_ops_register(void) if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) { generic_ops.set_variable = efi.set_variable; generic_ops.set_variable_nonblocking = efi.set_variable_nonblocking; + } else { + generic_ops.set_variable = set_variable_int; + generic_ops.set_variable_nonblocking = set_variable_int; } return efivars_register(&generic_efivars, &generic_ops); } diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c index e9dc7116daf1..c75eff3f409d 100644 --- a/drivers/firmware/efi/vars.c +++ b/drivers/firmware/efi/vars.c @@ -123,7 +123,7 @@ EXPORT_SYMBOL_GPL(efivars_unregister); bool efivar_supports_writes(void) { - return __efivars && __efivars->ops->set_variable; + return __efivars && __efivars->ops->set_variable != set_variable_int; } EXPORT_SYMBOL_GPL(efivar_supports_writes); diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c index e028fafa04f3..e40b5c4c5106 100644 --- a/fs/efivarfs/super.c +++ b/fs/efivarfs/super.c @@ -242,9 +242,6 @@ static int efivarfs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_d_op = &efivarfs_d_ops; sb->s_time_gran = 1; - if (!efivar_supports_writes()) - sb->s_flags |= SB_RDONLY; - inode = efivarfs_get_inode(sb, NULL, S_IFDIR | 0755, 0, true); if (!inode) return -ENOMEM; diff --git a/include/linux/efi.h b/include/linux/efi.h index 58d1c271d3b0..ec0ac6ef50a3 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1084,6 +1084,10 @@ int efivars_register(struct efivars *efivars, const struct efivar_operations *ops); int efivars_unregister(struct efivars *efivars); +efi_status_t set_variable_int(efi_char16_t *name, efi_guid_t *vendor, + u32 attributes, unsigned long data_size, + void *data); + void efivars_generic_ops_register(void); void efivars_generic_ops_unregister(void); apalos@hades:~/work/linux-next>; apalos@hades:~/work/linux-next>git diff diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 4cc8d0e7d0fd..37accd9e885c 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -206,6 +206,13 @@ static bool generic_ops_supported(void) return true; } +efi_status_t set_variable_int(efi_char16_t *name, efi_guid_t *vendor, + u32 attributes, unsigned long data_size, + void *data) +{ + return EFI_UNSUPPORTED; +} + static int generic_ops_register(void) { if (!generic_ops_supported()) @@ -219,6 +226,9 @@ static int generic_ops_register(void) if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) { generic_ops.set_variable = efi.set_variable; generic_ops.set_variable_nonblocking = efi.set_variable_nonblocking; + } else { + generic_ops.set_variable = set_variable_int; + generic_ops.set_variable_nonblocking = set_variable_int; } return efivars_register(&generic_efivars, &generic_ops); } diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c index e9dc7116daf1..c75eff3f409d 100644 --- a/drivers/firmware/efi/vars.c +++ b/drivers/firmware/efi/vars.c @@ -123,7 +123,7 @@ EXPORT_SYMBOL_GPL(efivars_unregister); bool efivar_supports_writes(void) { - return __efivars && __efivars->ops->set_variable; + return __efivars && __efivars->ops->set_variable != set_variable_int; } EXPORT_SYMBOL_GPL(efivar_supports_writes); diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c index e028fafa04f3..e40b5c4c5106 100644 --- a/fs/efivarfs/super.c +++ b/fs/efivarfs/super.c @@ -242,9 +242,6 @@ static int efivarfs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_d_op = &efivarfs_d_ops; sb->s_time_gran = 1; - if (!efivar_supports_writes()) - sb->s_flags |= SB_RDONLY; - inode = efivarfs_get_inode(sb, NULL, S_IFDIR | 0755, 0, true); if (!inode) return -ENOMEM; diff --git a/include/linux/efi.h b/include/linux/efi.h index 58d1c271d3b0..ec0ac6ef50a3 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1084,6 +1084,10 @@ int efivars_register(struct efivars *efivars, const struct efivar_operations *ops); int efivars_unregister(struct efivars *efivars); +efi_status_t set_variable_int(efi_char16_t *name, efi_guid_t *vendor, + u32 attributes, unsigned long data_size, + void *data); + void efivars_generic_ops_register(void); void efivars_generic_ops_unregister(void); Thanks /Ilias