From nobody Fri Dec 19 20:55:28 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 123E027FB35; Fri, 6 Jun 2025 10:57:59 +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=1749207481; cv=none; b=oNxluDzidvc6u5vGOfHwM7T5HkEB34HAiMX9ut6bV3LVS8cmIr8YSA5Lh2oRUQvbq7oaEcilBOIFAhmH+Z78bremNxIhaux/FzfkRKEi0uxbCJis8jci6KH/qu0figER70IxP/OWZF88XtGkqSACSfaCo4YBL6fcLZB8lyYrtZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749207481; c=relaxed/simple; bh=XFETnRwJszuY33IPOx4LdCSnsksBJu52kllSSQvTpnE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=TKR/fM1Ft44f4LjyDOMfK7+21Au0UEIDjVgY7xV4SGdQAEWwCU7jjtlsMGiG53p1RBr8IRvNslc2yoDC2QTZK+HnQJx0SW1Ug87ExJtc+1YxqT2U6w2FZaJ/Ktsyru3xZPeeQX+tKHrG8fY7HxziNTj/dyo4bkioKmqFQyzGFWM= 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 95ADC1595; Fri, 6 Jun 2025 03:57:41 -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 0ADA23F59E; Fri, 6 Jun 2025 03:57:57 -0700 (PDT) From: Yeoreum Yun To: sudeep.holla@arm.com, peterhuewe@gmx.de, jarkko@kernel.org, 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 1/2] firmware: arm_ffa: Change initcall level of ffa_init() to rootfs_initcall Date: Fri, 6 Jun 2025 11:57:53 +0100 Message-Id: <20250606105754.1202649-2-yeoreum.yun@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250606105754.1202649-1-yeoreum.yun@arm.com> References: <20250606105754.1202649-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 --- 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 Fri Dec 19 20:55:28 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C15762882A2; Fri, 6 Jun 2025 10:58:01 +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=1749207483; cv=none; b=aMO6JFfdu2s1fFpA7Z2t2d2gnH/ZIAQQ+S2HNQ3ciUS5CwPbT2NkP36GGnwQ5mnVKFzfQzctEH+fcb0wyMsUklSFe2KyHI6OHOvtz4DMJrG8+COBcu/WniLYw0lK73A/WDAccxbyUHa/asUWNH3oxLbYAAf0cG5lHDL3EkWZ4K0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749207483; c=relaxed/simple; bh=LdC86cJWlp6U1sDvJ8jk50YwXi2SHmaCJx6IuM9Udl8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dFJV0O024QEK2IY82PCMg4gXpWMNQp/uvncAMiB1UVEbRsL2/cmD2pQSgjGL/MwcTQbkStZgDrro2LiCf0ZVQblb0mOT++4n/gY0TqaqkUrirveJonkErVP9pI7oscz8/trlnvqp4x1TYzLXvG03esrX31aQ1PQj+8jCTL5KLas= 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 40E4A1BD0; Fri, 6 Jun 2025 03:57:43 -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 AA4313F59E; Fri, 6 Jun 2025 03:57:59 -0700 (PDT) From: Yeoreum Yun To: sudeep.holla@arm.com, peterhuewe@gmx.de, jarkko@kernel.org, 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 2/2] tpm: tpm_crb_ffa: maunally register tpm_crb_ffa driver when it's built-in Date: Fri, 6 Jun 2025 11:57:54 +0100 Message-Id: <20250606105754.1202649-3-yeoreum.yun@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250606105754.1202649-1-yeoreum.yun@arm.com> References: <20250606105754.1202649-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To integrate tpm_event_log with IMA subsystem, tpm_crb and tpm_crb_ffa driver should be built as built-in (CONFIG_TCG_CRB=3Dy && CONFIG_TCG_CRB_FFA=3Dy). However, this could make failure for ima_init() gets tpm chip when each initcall function deployed like: 0000000000000888 l .initcall6.init 0000000000000000 crb_acpi_driver_i= nit 000000000000088c l .initcall6.init 0000000000000000 tpm_crb_ffa_drive= r_init If crb_api_driver_init() is called first, probing tpm device using CRB over FFA method is deferred since tpm_crb_ffa_driver_init() isn't called yet. Deferred probe of the tpm device will be probed by system workqueue in proper time after deferred_probe_initcall() registers the work. However, ima_init() could be called first if they're deployed like: 000000000000012c l .initcall7.init 0000000000000000 init_ima 000000000000016c l .initcall7.init 0000000000000000 deferred_probe_in= itcall7 In this situation, ima_init() failed to find tpm device and it failed to generate boot_aggregate with PCR values. That's why kernel prints log this situation though tpm device exists: [ 3.080786] ima: No TPM chip found, activating TPM-bypass! To resolve this, call ffa_register() in tpm_crb_ffa_init() when it was built with built-in so that ima can generate boot_aggregate log with PCR values properly. Signed-off-by: Yeoreum Yun --- drivers/char/tpm/tpm_crb_ffa.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm_crb_ffa.c b/drivers/char/tpm/tpm_crb_ffa.c index 4ead61f01299..2ef29b66fa5d 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,22 @@ static int tpm_crb_ffa_to_linux_errno(int errno) */ int tpm_crb_ffa_init(void) { - if (!tpm_crb_ffa) - return -ENOENT; + int ret =3D 0; =20 - if (IS_ERR_VALUE(tpm_crb_ffa)) - return -ENODEV; + if (IS_MODULE(CONFIG_TCG_ARM_CRB_FFA)) { + if (!tpm_crb_ffa) + ret =3D -ENOENT; =20 - return 0; + if (IS_ERR_VALUE(tpm_crb_ffa)) + ret =3D -ENODEV; + + return ret; + } + + ret =3D ffa_register(&tpm_crb_ffa_driver); + BUG_ON(!ret && !tpm_crb_ffa); + + return ret; } EXPORT_SYMBOL_GPL(tpm_crb_ffa_init); =20 @@ -369,7 +379,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}