From nobody Thu Oct 9 08:59:11 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA002253941; Wed, 18 Jun 2025 10:23:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242190; cv=none; b=oFVB4L5surYQtOdJ++dp2u9nJFPFxg+2YowCmblRH5b2fuXgzV8oCiZeGAsKDQi3Jf5URqDNirV3+4g1m37vQzJRDP5gJWBE/tbONMZwwf5qc2ab+DEj4N7sjM7RYTKP6ctRcGXkJqJXP/xNWm+KIluZ2g9nhCF2U0N9CKDzvVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242190; c=relaxed/simple; bh=XFETnRwJszuY33IPOx4LdCSnsksBJu52kllSSQvTpnE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=G99zXebeySisrHaAdzQAKzhkXIhJvdmP7pt1iLdC8umGgyxpdmfiY1fCb+g0rNIezhj7nuTMq5BJCQ3EkJeBcLwezQ42HLORY6AG7f8p/unmieI9GkQa/FbiwZDHwUYETmysKigIrK9zTtq4lue40RxXkdkeilps0VI/JC8vFtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 418281BC0; Wed, 18 Jun 2025 03:22:47 -0700 (PDT) Received: from e129823.cambridge.arm.com (e129823.arm.com [10.1.197.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 78ADB3F66E; Wed, 18 Jun 2025 03:23:06 -0700 (PDT) From: Yeoreum Yun To: jarkko@kernel.org, sudeep.holla@arm.com, peterhuewe@gmx.de, jgg@ziepe.ca, stuart.yoder@arm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, Yeoreum Yun Subject: [PATCH v4 1/2] firmware: arm_ffa: Change initcall level of ffa_init() to rootfs_initcall Date: Wed, 18 Jun 2025 11:23:01 +0100 Message-Id: <20250618102302.2379029-2-yeoreum.yun@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250618102302.2379029-1-yeoreum.yun@arm.com> References: <20250618102302.2379029-1-yeoreum.yun@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The Linux IMA (Integrity Measurement Architecture) subsystem used for secure boot, file integrity, or remote attestation cannot be a loadable module for few reasons listed below: o Boot-Time Integrity: IMA=E2=80=99s main role is to measure and appraise = files before they are used. This includes measuring critical system files duri= ng early boot (e.g., init, init scripts, login binaries). If IMA were a mod= ule, it would be loaded too late to cover those. o TPM Dependency: IMA integrates tightly with the TPM to record measuremen= ts into PCRs. The TPM must be initialized early (ideally before init_ima()), which aligns with IMA being built-in. o Security Model: IMA is part of a Trusted Computing Base (TCB). Making it= a module would weaken the security model, as a potentially compromised sys= tem could delay or tamper with its initialization. IMA must be built-in to ensure it starts measuring from the earliest possib= le point in boot which inturn implies TPM must be initialised and ready to use before IMA. To enable integration of tpm_event_log with the IMA subsystem, the TPM driv= ers (tpm_crb and tpm_crb_ffa) also needs to be built-in. However with FF-A driv= er also being initialised at device initcall level, it can lead to an initialization order issue where: - crb_acpi_driver_init() may run before tpm_crb_ffa_driver()_init and ffa_= init() - As a result, probing the TPM device via CRB over FFA is deferred - ima_init() (called as a late initcall) runs before deferred probe comple= tes, IMA fails to find the TPM and logs the below error: | ima: No TPM chip found, activating TPM-bypass! Eventually it fails to generate boot_aggregate with PCR values. Because of the above stated dependency, the ffa driver needs to initialised before tpm_crb_ffa module to ensure IMA finds the TPM successfully when present. Signed-off-by: Yeoreum Yun Acked-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen Reviewed-by: Mimi Zohar Reviewed-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/d= river.c index fe55613a8ea9..1a690b8186df 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -2058,7 +2058,7 @@ static int __init ffa_init(void) kfree(drv_info); return ret; } -module_init(ffa_init); +rootfs_initcall(ffa_init); =20 static void __exit ffa_exit(void) { --=20 LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7} From nobody Thu Oct 9 08:59:11 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DEFB2DE1E2; Wed, 18 Jun 2025 10:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242191; cv=none; b=dICquCAR06qiU3T5DxjCa6Fqe1g2TnCsZlcFhFvJjL+CEeNFcSt0l038aT189ml4lAMAh8CTEsqo01MgHClWFbb8d7L1DUPWNK5FJVFmE4UldPomlk7KGRPXQbm3Mojacs81TsnWHvKDld7T7UULHbAKXb9ETKUUcmaKxCvy9A4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242191; c=relaxed/simple; bh=MTXa6A8nQtm2Tlld5BzWdCXG3mqQlWzGBq3MLCLaa50=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=gPsW/oAZEmkTfavMFoYXDJTLSpYAf+wpUEiSQSer0nNYkF1mxmL4jghNsz68/kdGkx/pn7f6M6D1MZ45k6Cm7Zw7ZhIeFf7l5g/QMqxzwNu41oky6qC/InEhETKYIgzt15H6hkn/YNjnCE0hlllqMN31yMzmjN5jN2652PX+IGg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E16731D13; Wed, 18 Jun 2025 03:22:48 -0700 (PDT) Received: from e129823.cambridge.arm.com (e129823.arm.com [10.1.197.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 24DD93F66E; Wed, 18 Jun 2025 03:23:08 -0700 (PDT) From: Yeoreum Yun To: jarkko@kernel.org, sudeep.holla@arm.com, peterhuewe@gmx.de, jgg@ziepe.ca, stuart.yoder@arm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, Yeoreum Yun Subject: [PATCH v4 2/2] tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in Date: Wed, 18 Jun 2025 11:23:02 +0100 Message-Id: <20250618102302.2379029-3-yeoreum.yun@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250618102302.2379029-1-yeoreum.yun@arm.com> References: <20250618102302.2379029-1-yeoreum.yun@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To generate the boot_aggregate log in the IMA subsystem using TPM PCR value= s, the TPM driver must be built as built-in and must be probed before the IMA subsystem is initialized. However, when the TPM device operates over the FF-A protocol using the CRB = interface, probing fails and returns -EPROBE_DEFER if the tpm_crb_ffa device =E2=80=94 an FF-A device that provides the communication interface to the tpm_crb driver =E2=80=94 has not yet bee= n probed. This issue occurs because both crb_acpi_driver_init() and tpm_crb_ffa_driver_init() are registered with device_initcall. As a result, crb_acpi_driver_init() may be invoked before tpm_crb_ffa_driver_init(), which is responsible for probing the tpm_crb_ffa= device. When this happens, IMA fails to detect the TPM device and logs the following message: | ima: No TPM chip found, activating TPM-bypass! Consequently, it cannot generate the boot_aggregate log with the PCR values provided by the TPM. To resolve this issue, the tpm_crb_ffa_init() function explicitly attempts = to probe the tpm_crb_ffa by register tpm_crb_ffa driver so that when tpm_crb_ffa device is created before tpm_crb_ffa_init(), probe the tpm_crb_ffa device in tpm_crb_ffa_init() to finish probe the TPM device completely. This ensures that the TPM device using CRB over FF-A can be successfully probed, even if crb_acpi_driver_init() is called first. Signed-off-by: Yeoreum Yun Reviewed-by: Jarkko Sakkinen Reviewed-by: Mimi Zohar Reviewed-by: Sudeep Holla --- drivers/char/tpm/tpm_crb_ffa.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/tpm_crb_ffa.c b/drivers/char/tpm/tpm_crb_ffa.c index 4ead61f01299..462fcf610020 100644 --- a/drivers/char/tpm/tpm_crb_ffa.c +++ b/drivers/char/tpm/tpm_crb_ffa.c @@ -115,6 +115,7 @@ struct tpm_crb_ffa { }; =20 static struct tpm_crb_ffa *tpm_crb_ffa; +static struct ffa_driver tpm_crb_ffa_driver; =20 static int tpm_crb_ffa_to_linux_errno(int errno) { @@ -168,13 +169,23 @@ static int tpm_crb_ffa_to_linux_errno(int errno) */ int tpm_crb_ffa_init(void) { + int ret =3D 0; + + if (!IS_MODULE(CONFIG_TCG_ARM_CRB_FFA)) { + ret =3D ffa_register(&tpm_crb_ffa_driver); + if (ret) { + tpm_crb_ffa =3D ERR_PTR(-ENODEV); + return ret; + } + } + if (!tpm_crb_ffa) - return -ENOENT; + ret =3D -ENOENT; =20 if (IS_ERR_VALUE(tpm_crb_ffa)) - return -ENODEV; + ret =3D -ENODEV; =20 - return 0; + return ret; } EXPORT_SYMBOL_GPL(tpm_crb_ffa_init); =20 @@ -369,7 +380,9 @@ static struct ffa_driver tpm_crb_ffa_driver =3D { .id_table =3D tpm_crb_ffa_device_id, }; =20 +#ifdef MODULE module_ffa_driver(tpm_crb_ffa_driver); +#endif =20 MODULE_AUTHOR("Arm"); MODULE_DESCRIPTION("TPM CRB FFA driver"); --=20 LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}