Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	 Suzuki Poulose <suzuki.poulose@arm.com>,
	 Steven Price <steven.price@arm.com>,
	Sami Mujawar <sami.mujawar@arm.com>,
	 "Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
	Jiri Pirko <jiri@resnulli.us>,
	 GONG Ruiqi <gongruiqi1@huawei.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,  Mark Brown <broonie@kernel.org>,
	Yeoreum Yun <yeoreum.yun@arm.com>
Subject: [PATCH RFC v2 5/6] attestation: providers: introduce FIRME attestation provider
Date: Fri, 27 Nov 2026 15:28:35 +0000	[thread overview]
Message-ID: <20261127-firme_interface-v2-5-ab88b2d0b4e0@arm.com> (raw)
In-Reply-To: <20261127-firme_interface-v2-0-ab88b2d0b4e0@arm.com>

Introduce FIRME attestation provider for retrieving an attestation
token for host.

When a evidence-get is requested, firme attestation provider invokes
the appropriate FIRME interfaces to query an attestation token.

The steps to retrieve an attestation token are as follows:

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
 drivers/attestation/Kconfig           |   9 ++
 drivers/attestation/Makefile          |   5 +
 drivers/attestation/providers/firme.c | 292 ++++++++++++++++++++++++++++++++++
 3 files changed, 306 insertions(+)

diff --git a/drivers/attestation/Kconfig b/drivers/attestation/Kconfig
index e9c1d7865f2a0..e2391ef4aee2d 100644
--- a/drivers/attestation/Kconfig
+++ b/drivers/attestation/Kconfig
@@ -43,4 +43,13 @@ config ATTESTATION_SIM
 
 	  If you are unsure, say N.
 
+config ATTESTATION_FIRME
+	tristate "FIRME attestation provider"
+	depends on ARM_FIRME
+	help
+	  Exposes FIRME platform token get (PAT) operations through the common
+	  attestation CTLV family.
+
+	  If you are unsure, say N.
+
 endif # ATTESTATION
diff --git a/drivers/attestation/Makefile b/drivers/attestation/Makefile
index 448fe4a3856d4..2c7a1a09daaed 100644
--- a/drivers/attestation/Makefile
+++ b/drivers/attestation/Makefile
@@ -12,3 +12,8 @@ obj-$(CONFIG_ATTESTATION_SIM) += attestation-sim.o
 
 attestation-sim-y := providers/sim.o \
 		     generated/ctlv_attestation_sim_gen.o
+
+obj-$(CONFIG_ATTESTATION_FIRME) += attestation-firme.o
+
+attestation-firme-y := providers/firme.o \
+		       generated/ctlv_attestation_firme_gen.o
diff --git a/drivers/attestation/providers/firme.c b/drivers/attestation/providers/firme.c
new file mode 100644
index 0000000000000..b8de3e14aff5a
--- /dev/null
+++ b/drivers/attestation/providers/firme.c
@@ -0,0 +1,292 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <crypto/sha2.h>
+#include <linux/arm_firme.h>
+#include <linux/arm-smccc-bus.h>
+#include <linux/attestation.h>
+#include <linux/ctlv.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include "../generated/ctlv_attestation_firme_gen.h"
+
+struct firme_attestation {
+	struct attestation_dev att;
+	u32 version;
+	size_t max_pat_size;
+};
+
+static struct firme_attestation *to_firme_attestation(struct attestation_dev *att)
+{
+	return container_of(att, struct firme_attestation, att);
+}
+
+static const struct attestation_evidence_format firme_attestation_pat_format[] = {
+	{ .vendor = true, .value = CTLV_ATTESTATION_FIRME_EVIDENCE_VENDOR_FORMAT_PLATFORM_ATTESTATION_TOKEN },
+};
+
+static const struct attestation_evidence_challenge_length
+firme_attestation_challenge_lengths[] = {
+	{ .min = 1, .max = SHA512_DIGEST_SIZE },
+};
+
+static struct attestation_evidence_supported_object
+firme_attestation_evidence_objects[] = {
+	{
+		.evidence_class = ATTESTATION_EVIDENCE_SIGNED,
+		.formats = firme_attestation_pat_format,
+		.formats_count = ARRAY_SIZE(firme_attestation_pat_format),
+		.challenge_lengths = firme_attestation_challenge_lengths,
+		.challenge_lengths_count =
+			ARRAY_SIZE(firme_attestation_challenge_lengths),
+		.max_length = 0,
+	},
+	/*
+	 * TODO: add LFA log and need to call
+	 * attestation_device_changed_locked() when LFA is done.
+	 */
+};
+
+static const struct attestation_evidence_caps firme_attestation_evidence_caps = {
+	.objects = firme_attestation_evidence_objects,
+	.objects_count = ARRAY_SIZE(firme_attestation_evidence_objects),
+};
+
+static int firme_get_platform_attestion_token(struct firme_attestation *firme_att,
+					      const void *challenge,
+					      size_t challenge_size,
+					      void *token, size_t *token_size)
+{
+	firme_status_t status;
+	firme_value_t ret;
+	struct firme_shared_buf_info shbuf_info;
+	void *buffer;
+	size_t alloc_size, buffer_size, buffer_pgcnt;
+	size_t read_size, total_size;
+
+	if (firme_get_shared_buffer_info(&shbuf_info))
+		return -EOPNOTSUPP;
+
+	if ((challenge_size > 0) && !challenge)
+		return -EINVAL;
+
+	buffer_size = min(firme_att->max_pat_size, shbuf_info.max_size);
+	if (WARN_ON_ONCE(buffer_size & (shbuf_info.min_size - 1)))
+		return -ENOBUFS;
+
+	alloc_size = buffer_size;
+
+	buffer = firme_alloc_shared_buffer(&alloc_size, GFP_KERNEL | __GFP_ZERO);
+	if (!buffer)
+		return -ENOMEM;
+
+	if (alloc_size < buffer_size)
+		buffer_size = alloc_size;
+
+	buffer_pgcnt = buffer_size / shbuf_info.min_size;
+
+	if (challenge_size > 0) {
+		memcpy(buffer, challenge, challenge_size);
+		/*
+		 * According to Realm Management Monitor specification, S-PNCRK,
+		 * maximum chanllege size should be 64 bytes (SHA512_DIGEST_SIZE).
+		 * If less than, pad with zero.
+		 */
+		challenge_size = SHA512_DIGEST_SIZE;
+	}
+
+	guard(migrate)();
+
+	total_size = 0;
+
+	do {
+		invoke_firme_service((firme_value_t) {
+				     .a0 = FIRME_ATTEST_PAT_GET,
+				     .a1 = virt_to_phys(buffer),
+				     .a2 = 0,
+				     .a3 = buffer_pgcnt - 1,
+				     .a4 = challenge_size,
+				     .a5 = 0,  /**< binding size must be 0 for normal world. */
+				     }, &ret);
+		status = ret.a0;
+		if ((status != FIRME_RET_SUCCESS) &&
+		    (status != FIRME_RET_INCOMPLETE))
+			break;
+
+		challenge_size = 0;
+		read_size = ret.a1;
+		memcpy(token + total_size, buffer, read_size);
+		total_size += read_size;
+	} while (status == FIRME_RET_INCOMPLETE);
+
+	if (status == FIRME_RET_SUCCESS)
+		*token_size = total_size;
+
+	firme_free_shared_buffer(buffer, alloc_size);
+
+	return firme_status_to_errno(status);
+}
+
+static int
+firme_attestation_evidence_get(struct attestation_dev *att,
+			       const struct attestation_evidence_request *request,
+			       struct attestation_evidence_result *result)
+{
+	const struct attestation_evidence_object_request *object;
+	struct attestation_evidence_object_result *produced;
+	struct firme_attestation *firme_att = to_firme_attestation(att);
+	void *token;
+	size_t token_size;
+	int ret;
+
+	if (request->objects_count != 1)
+		return -EOPNOTSUPP;
+
+	object = &request->objects[0];
+	produced = &result->objects[0];
+
+	token_size = object->supported_object->max_length;
+	token = kvmalloc(token_size, GFP_KERNEL);
+	if (!token)
+		return -ENOMEM;
+	if (object->supported_object == &firme_attestation_evidence_objects[0]) {
+		ret = firme_get_platform_attestion_token(firme_att,
+							 request->challenge,
+							 request->challenge_length,
+							 token, &token_size);
+		if (!ret) {
+			produced->format.vendor = true;
+			produced->format.value = CTLV_ATTESTATION_FIRME_EVIDENCE_VENDOR_FORMAT_PLATFORM_ATTESTATION_TOKEN;
+		}
+	} else {
+		ret = -EOPNOTSUPP;
+	}
+
+	if (!ret)
+		ret = attestation_evidence_write(object, token, token_size);
+	if (!ret)
+		produced->length = token_size;
+	kvfree(token);
+
+	return ret;
+}
+
+static const struct attestation_provider firme_attestation_provider = {
+	.evidence_get = firme_attestation_evidence_get,
+	.evidence_caps = &firme_attestation_evidence_caps,
+};
+
+int ctlv_attestation_firme_device_info_fill(struct ctlv *ctlv,
+					  struct ctlv_op_ctx *ctx,
+					  const struct ctlv_cursor *request,
+					  struct ctlv_cursor *record)
+{
+	const struct firme_attestation *firme_att =
+		to_firme_attestation(attestation_from_ctlv(ctlv));
+	bool ok;
+
+	ok = ctlv_attestation_firme_device_info_version_put(record, firme_att->version);
+	return ok ? 0 : -EMSGSIZE;
+}
+
+void ctlv_attestation_firme_device_info_read(struct ctlv *ctlv,
+					   struct ctlv_op_ctx *ctx,
+					   const struct ctlv_cursor *record)
+{
+}
+
+static bool firme_attest_drv_match(const struct arm_smccc_device *sdev)
+{
+	const enum firme_service_id id = (const enum firme_service_id)sdev->match_params;
+
+	if (id == FIRME_ATTEST_SERVICE_ID)
+		return true;
+	return false;
+}
+
+static int firme_attest_drv_probe(struct arm_smccc_device *sdev)
+{
+	int ret;
+	u32 version;
+	unsigned long feature;
+	struct firme_shared_buf_info shbuf_info;
+	u8 max_pat_pgcnt;
+	size_t max_pat_size;
+	struct firme_attestation *firme_att;
+
+	ret = firme_get_shared_buffer_info(&shbuf_info);
+	if (ret)
+		return ret;
+
+	ret = firme_get_version(FIRME_ATTEST_SERVICE_ID, &version);
+	if (ret)
+		return ret;
+
+	ret = firme_get_feature(FIRME_ATTEST_SERVICE_ID, 0x01, &feature);
+	if (ret)
+		return ret;
+
+	max_pat_pgcnt = FIELD_GET(FIRME_ATTEST_FEAT1_MAX_PAT_PG_CNT_MASK, feature);
+	max_pat_size = (max_pat_pgcnt + 1) * shbuf_info.min_size;
+	firme_attestation_evidence_objects[0].max_length = max_pat_size;
+
+	pr_info("FIRME attest service version %d.%d\n",
+		FIRME_MAJOR_VERSION(version),
+		FIRME_MINOR_VERSION(version));
+	pr_info("Maximum PAT size: 0x%lx\n", max_pat_size);
+
+	firme_att = attestation_alloc(&sdev->dev,
+				      &firme_attestation_provider,
+				      &ctlv_attestation_firme_family,
+				      struct firme_attestation, att);
+	if (IS_ERR(firme_att))
+		return PTR_ERR(firme_att);
+
+	firme_att->version = version;
+	firme_att->max_pat_size = max_pat_size;
+
+	ret = attestation_register(&firme_att->att);
+	if (ret) {
+		attestation_put(&firme_att->att);
+		return ret;
+	}
+
+	dev_set_drvdata(&sdev->dev, firme_att);
+
+	pr_info("FIRME attestation ctlvdev is registered\n");
+
+	return 0;
+}
+
+static void firme_attest_drv_remove(struct arm_smccc_device *sdev)
+{
+	struct firme_attestation *firme_att = dev_get_drvdata(&sdev->dev);
+
+	if (!firme_att)
+		return;
+
+	attestation_unregister(&firme_att->att);
+	attestation_put(&firme_att->att);
+	dev_set_drvdata(&sdev->dev, NULL);
+}
+
+static const struct arm_smccc_device_id firme_attest_id_table[] = {
+	{ .func_id = FIRME_SERVICE_VERSION, },
+	{ },
+};
+MODULE_DEVICE_TABLE(arm_smccc, firme_attest_id_table);
+
+static struct arm_smccc_driver firme_attest_drv = {
+	.name = KBUILD_MODNAME,
+	.probe = firme_attest_drv_probe,
+	.remove = firme_attest_drv_remove,
+	.match = firme_attest_drv_match,
+	.id_table = firme_attest_id_table,
+};
+module_arm_smccc_driver(firme_attest_drv);
+
+MODULE_DESCRIPTION("FIRME attestation provider");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("ATTESTATION");
+MODULE_IMPORT_NS("CTLV");
+MODULE_IMPORT_NS("FIRME");

-- 
2.43.0



      parent reply	other threads:[~2026-11-27 15:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 15:28 [PATCH RFC v2 0/6] firmware: arm_firme: introduce FIRME support for host attestation Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 1/6] firmware: arm-smccc: introduce match function Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 2/6] firmware: arm_firme: introduce arm_firme Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 3/6] Documentation/ctlv: introduce ctlv-attestation-firme family Yeoreum Yun
2026-11-27 15:28 ` Yeoreum Yun [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127-firme_interface-v2-5-ab88b2d0b4e0@arm.com \
    --to=yeoreum.yun@arm.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=gongruiqi1@huawei.com \
    --cc=jgg@ziepe.ca \
    --cc=jiri@resnulli.us \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=sami.mujawar@arm.com \
    --cc=steven.price@arm.com \
    --cc=suzuki.poulose@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox