Skip to contentSkip to conversation

attestation: Add a common subsystem and TDX support

RFC PATCH In review Jiri Pirko 5 participants 21 messages Nov 13 – Nov 27

Subsystems (4)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

v2 cover attestation: Add a common subsystem and TDX support

From: Jiri Pirko <[email protected]>

Linux has several attestation interfaces, each tied to one technology. Extending a measurement takes device-specific flows for TPM, CCA, TDX and SEV, none of them discoverable, and requesting a signed quote takes another set, SPDM included. A new root of trust has no logical home short of squeezing it into tsm_report and tsm_mr: tsm_report covers reports alone, the MRs went to tsm_mr, and SPDM fits neither.

This series adds a common attestation subsystem. Its goal is to support platform, TEE and device roots of trust through one model, including TPM2, TDX, SEV-SNP, Arm CCA, FIRME, Caliptra and PCI/TSM-backed devices, so that a program extends a register or asks for evidence without knowing the hardware behind it. This first series implements the common subsystem and a TDX provider. The native TDX interfaces, /dev/tdx_guest, tsm_report and tsm_mr, stay as they are.

RFC v1 [1] posted this and CTLV as one patchset. For convenience, v2 splits it in two, and this series applies on top of the CTLV series, posted alongside as

[PATCH RFC v2 00/15] ctlv: Add a schema-driven TLV uAPI for character devices

Each attestation device has a node, /dev/attestation/attestationN, that speaks CTLV: a request is checked against the family's schema and executed at once, rather than assembled through several files. The base family, ctlv-attestation, has what every provider shares, so a tool written against it works with any provider. TDX's family, ctlv-attestation-tdx, inherits it and adds no ops. It fills the base family's extension points: device-get's info with the TD's MRCONFIGID, MROWNER and MROWNERCONFIG, and evidence-vendor-format with the two TDX Quote formats.

The base family's ops, as ctlvgen --signatures prints them, with the purpose of each:

# What the device supports, fixed for its life, and its family's fields. device-get() ->

      { caps: { evidence?: { objects[16]: { id, class, formats[4]?,
                                            vendor-formats[4]?, max-length,
                                            challenge-lengths[8]?: { length?,
                                                                     min-length?,
                                                                     max-length? } } },
                mr?: { flags } }, info: device-info }

# Evidence: each object named, written to a blob the caller supplies,

  # a signed one made by the call over the challenge.
  evidence-get(challenge?, objects[16]: { id, data: out blob }) ->
      { results[16]: { format?, vendor-format?, length }, mr-generation? }

# Describe every MR, or the one an ID names.
mr-get(id?) -> { items[]: { id, mr-desc } }

# One MR's values, a digest per bank, and the MR generation they

  # reflect.
  mr-read(id) -> { mr-generation, mr-values[hash-algo]: mr-value }

# Extend banks of one MR by the caller's digests. mr-extend(id, mr-values[hash-algo]: mr-value) -> { mr-generation }

An mr-desc is an MR's name, its banks, what it allows and its register index, and an mr-value one bank's hash algorithm and digest. The userspace ABI gives each op's request, reply, errors and access.

On TDX, evidence-get returns the Quote over a 64-byte challenge, labelled a legacy or a DICE one, and, where ACPI describes it, the CCEL event log. The MRs are MRTD, which cannot be extended, and RTMR0 to RTMR3, all SHA-384. With ctlvctl from the CTLV series and CTLV_SPEC_DIR pointing at Documentation/ctlv/specs, the simulator's output, rewritten for a TD, its lengths left out:

# The device and its family chain.

  $ ctlvctl list
  attestation/attestation0        ctlv/ctlv-attestation/ctlv-attestation-tdx

# What it supports.

  $ ctlvctl exec attestation/attestation0 device-get
  # device-get, 1 fragment, generation 0
    device-get caps
      device-get caps.evidence
        device-get caps.evidence.objects
          device-get caps.evidence.objects.id 0
          device-get caps.evidence.objects.class signed
          device-get caps.evidence.objects.vendor-formats quote
          device-get caps.evidence.objects.vendor-formats quote-dice
          device-get caps.evidence.objects.max-length 131048
          device-get caps.evidence.objects.challenge-lengths
            device-get caps.evidence.objects.challenge-lengths.length 64
        device-get caps.evidence.objects
          device-get caps.evidence.objects.id 1
          device-get caps.evidence.objects.class event-log
          device-get caps.evidence.objects.formats ccel
          device-get caps.evidence.objects.max-length ...
      device-get caps.mr
        device-get caps.mr.flags extend
    device-get info
      device-info.mrconfigid hex:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
      device-info.mrowner hex:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
      device-info.mrownerconfig hex:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  # A Quote over a 64-byte nonce, written to quote.bin.
  $ nonce=$(openssl rand -hex 64)
  $ ctlvctl exec attestation/attestation0 evidence-get --json \
          '{"challenge":"hex:'"$nonce"'",
            "objects":[{"id":0,"data":{"file":"quote.bin"}}]}'
  # evidence-get, 1 fragment, generation 0
    mr-generation 0
    evidence-get results
      evidence-get results.vendor-format quote
      evidence-get results.length ...

# Every MR.

  $ ctlvctl exec attestation/attestation0 mr-get
  # mr-get, 1 fragment, generation 0
    mr-get items
      mr-get items.id 0
      mr-desc.name mrtd
      mr-desc.supported-hash-algorithms HASH_ALGO_SHA384
      mr-desc.caps 0
    mr-get items
      mr-get items.id 1
      mr-desc.name rtmr0
      mr-desc.supported-hash-algorithms HASH_ALGO_SHA384
      mr-desc.register-index 0
      mr-desc.caps extend
    ...

# The value of RTMR0, MR 1.

  $ ctlvctl exec attestation/attestation0 mr-read id=1
  # mr-read, 1 fragment, generation 0
    mr-generation 0
    mr-values
      mr-value.hash-algo HASH_ALGO_SHA384
      mr-value.data hex:b57a300eac0c9b8593bafbadee812f8915456913c28010dab20d700446169bdd56e1af87ce94d66c8fd2d456b3e42826
  # Extend RTMR3, MR 4, by a file's SHA-384 digest.
  $ digest=$(sha384sum app.img | cut -d' ' -f1)
  $ ctlvctl exec attestation/attestation0 mr-extend --json \
          '{"id":4,"mr-values":[{"hash-algo":"HASH_ALGO_SHA384",
                                 "data":"hex:'"$digest"'"}]}'
  # mr-extend, 1 fragment, generation 0
    mr-generation 1

This series is the first part. The branch [2] has the whole work, building on it: CTLV's events, the MR journal with IMA as its first user, memfd and dma-buf evidence blobs, an mr-extend that hashes the caller's data, evidence acceptance and device security, a simulation provider, KUnit tests and selftests.

The series adds 3480 lines:

attestation core, C 1340

  generated files                    770
  TDX provider, C                    470
  docs                               462
  family specifications              206
  ABI snapshots                      170

registry, build 62

Changes since RFC v1, each patch listing its own:

- Each evidence object has an ID, a class, signed or event-log, and the formats it may have: from evidence-format for a layout a standard defines, from evidence-vendor-format, whose values the device's family gives, for a vendor's. A signed object lists the challenge lengths it takes.
- evidence-get names objects by ID, may omit the challenge, and takes output blobs of any length, failing with the length one needs.
- TDX labels each Quote, returns the CCEL log, and leaves the TDREPORT to /dev/tdx_guest.
- The MR journal and its notifications are left out, until IMA uses the subsystem.
- mr-extend may extend some of an MR's banks, and every MR can be read.
- mr-get, a query, describes every MR or the one its optional id names, and mr-dump is gone.
- Attestation has its own class and /dev/attestation/ nodes, and the TDX provider is part of tdx-guest instead of a module of its own.
- The specs are written as op trees and records, with a comment on every item, and a userspace ABI document describes the family.

The patches:

  1      the base family's specification and generated files
  2      the userspace ABI
  3-5    the provider and instance core, the MRs, and the CTLV ops
  6      how to write a provider
  7      tdx-guest's native attestation service, for the provider
  8-9    the TDX family's specification and implementation

Note to reviewers: the uAPI, in 1 and 2, and the provider API, in 3 and 6, matter most at this stage.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/jpirko/linux_mlxsw/commits/wip_attestation_all_2

Jiri Pirko (9):
attestation: Add the base family specification and generated files
Documentation: attestation: Add userspace ABI
attestation: Prepare provider and instance core
attestation: Prepare measurement registers
attestation: Add CTLV operation handling
Documentation: attestation: Describe how to write a provider
tdx-guest: Expose the native attestation service API
attestation: Add the TDX family specification and generated files
attestation: Add the TDX family implementation

 .../ctlv/abi/ctlv-attestation-tdx.yaml        |  21 +
 Documentation/ctlv/abi/ctlv-attestation.yaml  | 147 +++++
 Documentation/ctlv/abi/families.registry.yaml |   2 +
 Documentation/ctlv/families.yaml              |   2 +
 Documentation/ctlv/generated-files.yaml       |  14 +
 .../ctlv/specs/ctlv-attestation-tdx.yaml      |  25 +
 .../ctlv/specs/ctlv-attestation.yaml          | 181 +++++++
 Documentation/driver-api/attestation.rst      |  99 ++++
 Documentation/driver-api/index.rst            |   1 +
 .../userspace-api/attestation-tdx.rst         |  59 +++
 Documentation/userspace-api/attestation.rst   | 294 ++++++++++
 Documentation/userspace-api/index.rst         |   1 +
 Documentation/virt/coco/tdx-guest.rst         |   8 +
 MAINTAINERS                                   |  13 +
 drivers/Kconfig                               |   2 +
 drivers/Makefile                              |   1 +
 drivers/attestation/Kconfig                   |  16 +
 drivers/attestation/Makefile                  |   5 +
 drivers/attestation/core/core.c               | 500 ++++++++++++++++++
 drivers/attestation/core/ctlv.c               | 499 +++++++++++++++++
 drivers/attestation/core/internal.h           |  34 ++
 drivers/attestation/core/mr.c                 |  64 +++
 .../generated/ctlv_attestation_gen.c          | 179 +++++++
 .../generated/ctlv_attestation_gen.h          | 204 +++++++
 drivers/virt/coco/tdx-guest/Kconfig           |   4 +-
 drivers/virt/coco/tdx-guest/Makefile          |   6 +
 drivers/virt/coco/tdx-guest/attestation.c     | 313 +++++++++++
 .../coco/tdx-guest/ctlv_attestation_tdx_gen.c |  65 +++
 .../coco/tdx-guest/ctlv_attestation_tdx_gen.h |  44 ++
 drivers/virt/coco/tdx-guest/internal.h        |  48 ++
 .../coco/tdx-guest/{tdx-guest.c => main.c}    | 137 ++++-
 include/linux/attestation.h                   | 243 +++++++++
 include/uapi/ctlv/ctlv_attestation_gen.h      | 234 ++++++++
 include/uapi/ctlv/ctlv_attestation_tdx_gen.h  |  42 ++
 include/uapi/ctlv/ctlv_families_gen.h         |   2 +
 35 files changed, 3480 insertions(+), 29 deletions(-)
 create mode 100644 Documentation/ctlv/abi/ctlv-attestation-tdx.yaml
 create mode 100644 Documentation/ctlv/abi/ctlv-attestation.yaml
 create mode 100644 Documentation/ctlv/specs/ctlv-attestation-tdx.yaml
 create mode 100644 Documentation/ctlv/specs/ctlv-attestation.yaml
 create mode 100644 Documentation/driver-api/attestation.rst
 create mode 100644 Documentation/userspace-api/attestation-tdx.rst
 create mode 100644 Documentation/userspace-api/attestation.rst
 create mode 100644 drivers/attestation/Kconfig
 create mode 100644 drivers/attestation/Makefile
 create mode 100644 drivers/attestation/core/core.c
 create mode 100644 drivers/attestation/core/ctlv.c
 create mode 100644 drivers/attestation/core/internal.h
 create mode 100644 drivers/attestation/core/mr.c
 create mode 100644 drivers/attestation/generated/ctlv_attestation_gen.c
 create mode 100644 drivers/attestation/generated/ctlv_attestation_gen.h
 create mode 100644 drivers/virt/coco/tdx-guest/attestation.c
 create mode 100644 drivers/virt/coco/tdx-guest/ctlv_attestation_tdx_gen.c
 create mode 100644 drivers/virt/coco/tdx-guest/ctlv_attestation_tdx_gen.h
 create mode 100644 drivers/virt/coco/tdx-guest/internal.h
 rename drivers/virt/coco/tdx-guest/{tdx-guest.c => main.c} (79%)
 create mode 100644 include/linux/attestation.h
 create mode 100644 include/uapi/ctlv/ctlv_attestation_gen.h
 create mode 100644 include/uapi/ctlv/ctlv_attestation_tdx_gen.h
Signature · 1 line
2.56.0
author
#1 lore raw

RFC PATCH v2 1/9 attestation: Add the base family specification and generated files

From: Jiri Pirko <[email protected]>

Define the base attestation family. Reserve its family ID and add the ABI snapshot, registry entry and generated kernel and UAPI files.

The ABI is intentionally specification-first. The generated descriptor is linked after the provider and operation handlers arrive.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- dropped the MR log ops and the sets, groups and attrs only they use
- dropped the family's priv lifecycle hooks
- made the hash algorithm attrs an enum of <linux/hash_info.h>
- replaced the blob class and representation with an evidence class, signed or event-log
- dropped max-total-output-length
- renamed stubs to extension points
- commented the values, operations and fields
- wrote the spec as op trees and records
- reported each signed object's challenge lengths, in bytes, as a list of up to 8 lengths and ranges
- let evidence-get omit the challenge
- took output blobs of any length
- merged mr-dump into mr-get, a query whose id is an optional filter
- listed an MR's banks in the provider's order, each once
- let mr-extend extend some of an MR's banks
- dropped the MR read caps, as every MR can be read
- numbered every enum member and flag bit
- moved the generated UAPI headers to include/uapi/ctlv/
- documented every item of the spec
- put each field's doc above its generated helpers
- said that every evidence-get produces new evidence
- replaced the format strings with the evidence-format enum and the evidence-vendor-format enum extension point
- named an evidence-get object by its ID
- said message instead of wire
- bounded an MR's banks by hash-algo, not a number

---
 Documentation/ctlv/abi/ctlv-attestation.yaml  | 147 +++++++++++
 Documentation/ctlv/abi/families.registry.yaml |   1 +
 Documentation/ctlv/families.yaml              |   1 +
 Documentation/ctlv/generated-files.yaml       |   7 +
 .../ctlv/specs/ctlv-attestation.yaml          | 181 ++++++++++++++
 MAINTAINERS                                   |   9 +
 .../generated/ctlv_attestation_gen.c          | 179 ++++++++++++++
 .../generated/ctlv_attestation_gen.h          | 204 +++++++++++++++
 include/uapi/ctlv/ctlv_attestation_gen.h      | 234 ++++++++++++++++++
 include/uapi/ctlv/ctlv_families_gen.h         |   1 +
 10 files changed, 964 insertions(+)
 create mode 100644 Documentation/ctlv/abi/ctlv-attestation.yaml
 create mode 100644 Documentation/ctlv/specs/ctlv-attestation.yaml
 create mode 100644 drivers/attestation/generated/ctlv_attestation_gen.c
 create mode 100644 drivers/attestation/generated/ctlv_attestation_gen.h
 create mode 100644 include/uapi/ctlv/ctlv_attestation_gen.h
Documentation/ctlv/abi/ctlv-attestation.yaml new file +147 -0
new file mode 100644
index 000000000000..16b7be1fbc70
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
+---
+# Checked-in ABI snapshot of the ctlv-attestation family, from
+# Documentation/ctlv/specs/ctlv-attestation.yaml, written by
+# "make -C tools/ctlv regen".
+#
+# Updating the file is how a UAPI change gets reviewed; an update that
+# removes or renumbers anything, narrows a bound, or makes a member required
+# is an ABI break, whatever the file says afterwards.
+family: {name: ctlv-attestation, id: 1, inherits: ctlv}
+enums:
+  evidence-class: {signed: 1, event-log: 2}
+  evidence-format: {ccel: 1}
+  hash-algo: {$header: linux/hash_info.h, $enum: hash_algo,
+              $end: HASH_ALGO__LAST}
+flags:
+  mr-device-caps: {extend: 0}
+  mr-caps: {extend: 0}
+records:
+  mr-desc:
+    id: 0x00010000
+    fields:
+      name: {number: 1, type: string, min-length: 1, max-length: 128}
+      supported-hash-algorithms: {number: 2, enum: hash-algo,
+                                  max-occurrences: hash-algo}
+      caps: {number: 3, flags: mr-caps}
+      register-index: {number: 4, type: uint, max: u32-max, optional: true}
+  mr-value:
+    id: 0x00020000
+    fields:
+      hash-algo: {number: 1, enum: hash-algo}
+      data: {number: 2, type: binary, min-length: 16, max-length: 64}
+  mr-generation:
+    id: 0x00030000
+    fields:
+      mr-generation: {number: 1, type: uint, max: u32-max}
+  mr-values:
+    id: 0x00040000
+    fields:
+      mr-values: {number: 1, record: mr-value, max-occurrences: hash-algo}
+  device-get request:
+    id: 0x80010000
+  device-get reply:
+    id: 0xc0010000
+    fields:
+      caps: {number: 1, record: device-get caps}
+      info: {number: 2, extension: device-info}
+  device-get caps:
+    id: 0xc0011000
+    fields:
+      evidence: {number: 1, record: device-get caps.evidence, optional: true}
+      mr: {number: 2, record: device-get caps.mr, optional: true}
+  device-get caps.evidence:
+    id: 0xc0011100
+    fields:
+      objects: {number: 1, record: device-get caps.evidence.objects,
+                max-occurrences: 16}
+  device-get caps.evidence.objects:
+    id: 0xc0011110
+    fields:
+      id: {number: 1, type: uint, max: 15}
+      class: {number: 2, enum: evidence-class}
+      formats: {number: 3, enum: evidence-format, max-occurrences: 4,
+                optional: true}
+      vendor-formats: {number: 4, enum: evidence-vendor-format,
+                       max-occurrences: 4, optional: true}
+      max-length: {number: 5, type: uint}
+      challenge-lengths:
+        {number: 6, record: device-get caps.evidence.objects.challenge-lengths,
+         max-occurrences: 8, optional: true}
+  device-get caps.evidence.objects.challenge-lengths:
+    id: 0xc0011111
+    fields:
+      length: {number: 1, type: uint, min: 1, max: 4K, unit: bytes,
+               optional: true}
+      min-length: {number: 2, type: uint, min: 1, max: 4K, unit: bytes,
+                   optional: true}
+      max-length: {number: 3, type: uint, min: 1, max: 4K, unit: bytes,
+                   optional: true}
+  device-get caps.mr:
+    id: 0xc0011200
+    fields:
+      flags: {number: 1, flags: mr-device-caps}
+  evidence-get request:
+    id: 0x80020000
+    fields:
+      challenge: {number: 1, type: binary, min-length: 1, max-length: 4K,
+                  optional: true}
+      objects: {number: 2, record: evidence-get objects, max-occurrences: 16}
+  evidence-get objects:
+    id: 0x80021000
+    fields:
+      id: {number: 1, type: uint, max: 15}
+      data: {number: 2, blob: output, backings: [va], max-length: u32-max}
+  evidence-get reply:
+    id: 0xc0020000
+    fields:
+      results: {number: 1, record: evidence-get results, max-occurrences: 16}
+    members: ['record mr-generation?']
+  evidence-get results:
+    id: 0xc0021000
+    fields:
+      format: {number: 1, enum: evidence-format, optional: true}
+      vendor-format: {number: 2, enum: evidence-vendor-format, optional: true}
+      length: {number: 3, type: uint}
+  mr-get request:
+    id: 0x80030000
+    fields:
+      id: {number: 1, type: uint, max: u32-max, optional: true}
+  mr-get reply:
+    id: 0xc0030000
+    fields:
+      items: {number: 1, record: mr-get items, max-occurrences: unlimited}
+  mr-get items:
+    id: 0xc0031000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+    members: [$include mr-desc]
+  mr-read request:
+    id: 0x80040000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+  mr-read reply:
+    id: 0xc0040000
+    members: [record mr-generation, record mr-values]
+  mr-extend request:
+    id: 0x80050000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+    members: [record mr-values]
+  mr-extend reply:
+    id: 0xc0050000
+    members: [record mr-generation]
+extensions: {device-info: 1}
+enum-extensions: {evidence-vendor-format: 1}
+ops:
+  device-get: {id: 1, type: action, fd-access: read,
+               request: device-get request, reply: device-get reply}
+  evidence-get: {id: 2, type: action, availability: dynamic, optional: true,
+                 request: evidence-get request, reply: evidence-get reply}
+  mr-get: {id: 3, type: query, fd-access: read, optional: true,
+           request: mr-get request, reply: mr-get reply}
+  mr-read: {id: 4, type: query, fd-access: read, optional: true,
+            request: mr-read request, reply: mr-read reply}
+  mr-extend: {id: 5, type: action, optional: true, request: mr-extend request,
+              reply: mr-extend reply}
Documentation/ctlv/abi/families.registry.yaml +1 -0
index 5845e7457771..7a5c6af29565 100644
@@ -5,3 +5,4 @@
 # Written by "make -C tools/ctlv regen".
 families:
   - ctlv
+  - ctlv-attestation
Documentation/ctlv/families.yaml +1 -0
index 4d219d7af74a..dbb0243b873d 100644
@@ -15,3 +15,4 @@
 
 families:
   - ctlv
+  - ctlv-attestation
Documentation/ctlv/generated-files.yaml +7 -0
index d4766b176ceb..00a56634805d 100644
@@ -16,3 +16,10 @@ families:
       kernel-header: include/linux/ctlv_gen.h
       kernel-source: lib/ctlv/ctlv_gen.c
       user-source: tools/ctlv/libctlv/ctlv_user_gen.c
+
+  - name: ctlv-attestation
+    source: Documentation/ctlv/specs/ctlv-attestation.yaml
+    outputs:
+      uapi-header: include/uapi/ctlv/ctlv_attestation_gen.h
+      kernel-header: drivers/attestation/generated/ctlv_attestation_gen.h
+      kernel-source: drivers/attestation/generated/ctlv_attestation_gen.c
Documentation/ctlv/specs/ctlv-attestation.yaml new file +181 -0

181 lines not on this page · raw message

MAINTAINERS +9 -0
index b16bedbbe0b6..fa450924b921 100644
@@ -4433,6 +4433,15 @@ F:	rust/kernel/sync/atomic.rs
 F:	rust/kernel/sync/atomic/
 F:	rust/kernel/sync/refcount.rs
 
+ATTESTATION SUBSYSTEM
+M:	Jiri Pirko <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/ctlv/abi/ctlv-attestation*
+F:	Documentation/ctlv/specs/ctlv-attestation*
+F:	drivers/attestation/
+F:	include/uapi/ctlv/ctlv_attestation*
+
 ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
 M:	Bradley Grove <[email protected]>
 L:	[email protected]
drivers/attestation/generated/ctlv_attestation_gen.c new file +179 -0

179 lines not on this page · raw message

drivers/attestation/generated/ctlv_attestation_gen.h new file +204 -0

204 lines not on this page · raw message

include/uapi/ctlv/ctlv_attestation_gen.h new file +234 -0

234 lines not on this page · raw message

include/uapi/ctlv/ctlv_families_gen.h +1 -0
index 83f1719c89aa..83f6a257ddf2 100644
@@ -12,6 +12,7 @@
 
 enum _ctlv_family {
 	CTLV_FAMILY_ROOT = 0,
+	CTLV_FAMILY_ATTESTATION = 1,
 };
 
 #endif /* _UAPI_CTLV_CTLV_FAMILIES_GEN_H */
Signature · 1 line
2.56.0
#2 lore raw

Re: [PATCH RFC v2 1/9] attestation: Add the base family specification and generated files

Quoted 9 lines

[ ... 60 lines skipped ... ]
+++ b/Documentation/ctlv/abi/ctlv-attestation.yaml

Documentation/ctlv/abi/ctlv-attestation.yaml new file +6 -0
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
+---
+# Checked-in ABI snapshot of the ctlv-attestation family, from
+# Documentation/ctlv/specs/ctlv-attestation.yaml, written by
+# "make -C tools/ctlv regen".

Documentation/ctlv/abi/ctlv-attestation.yaml line 16

Quoted 10 lines
Documentation/ctlv/abi/ctlv-attestation.yaml new file +10 -0
+#
+# Updating the file is how a UAPI change gets reviewed; an update that
+# removes or renumbers anything, narrows a bound, or makes a member required
+# is an ABI break, whatever the file says afterwards.
+family: {name: ctlv-attestation, id: 1, inherits: ctlv}
+enums:
+  evidence-class: {signed: 1, event-log: 2}
+  evidence-format: {ccel: 1}
+  hash-algo: {$header: linux/hash_info.h, $enum: hash_algo,
+              $end: HASH_ALGO__LAST}

I feel like this should parse the C enum into numbers here so the ABI can be checked too?

Quoted 170 lines
Documentation/ctlv/abi/ctlv-attestation.yaml new file +131 -0
+flags:
+  mr-device-caps: {extend: 0}
+  mr-caps: {extend: 0}
+records:
+  mr-desc:
+    id: 0x00010000
+    fields:
+      name: {number: 1, type: string, min-length: 1, max-length: 128}
+      supported-hash-algorithms: {number: 2, enum: hash-algo,
+                                  max-occurrences: hash-algo}
+      caps: {number: 3, flags: mr-caps}
+      register-index: {number: 4, type: uint, max: u32-max, optional: true}
+  mr-value:
+    id: 0x00020000
+    fields:
+      hash-algo: {number: 1, enum: hash-algo}
+      data: {number: 2, type: binary, min-length: 16, max-length: 64}
+  mr-generation:
+    id: 0x00030000
+    fields:
+      mr-generation: {number: 1, type: uint, max: u32-max}
+  mr-values:
+    id: 0x00040000
+    fields:
+      mr-values: {number: 1, record: mr-value, max-occurrences: hash-algo}
+  device-get request:
+    id: 0x80010000
+  device-get reply:
+    id: 0xc0010000
+    fields:
+      caps: {number: 1, record: device-get caps}
+      info: {number: 2, extension: device-info}
+  device-get caps:
+    id: 0xc0011000
+    fields:
+      evidence: {number: 1, record: device-get caps.evidence, optional: true}
+      mr: {number: 2, record: device-get caps.mr, optional: true}
+  device-get caps.evidence:
+    id: 0xc0011100
+    fields:
+      objects: {number: 1, record: device-get caps.evidence.objects,
+                max-occurrences: 16}
+  device-get caps.evidence.objects:
+    id: 0xc0011110
+    fields:
+      id: {number: 1, type: uint, max: 15}
+      class: {number: 2, enum: evidence-class}
+      formats: {number: 3, enum: evidence-format, max-occurrences: 4,
+                optional: true}
+      vendor-formats: {number: 4, enum: evidence-vendor-format,
+                       max-occurrences: 4, optional: true}
+      max-length: {number: 5, type: uint}
+      challenge-lengths:
+        {number: 6, record: device-get caps.evidence.objects.challenge-lengths,
+         max-occurrences: 8, optional: true}
+  device-get caps.evidence.objects.challenge-lengths:
+    id: 0xc0011111
+    fields:
+      length: {number: 1, type: uint, min: 1, max: 4K, unit: bytes,
+               optional: true}
+      min-length: {number: 2, type: uint, min: 1, max: 4K, unit: bytes,
+                   optional: true}
+      max-length: {number: 3, type: uint, min: 1, max: 4K, unit: bytes,
+                   optional: true}
+  device-get caps.mr:
+    id: 0xc0011200
+    fields:
+      flags: {number: 1, flags: mr-device-caps}
+  evidence-get request:
+    id: 0x80020000
+    fields:
+      challenge: {number: 1, type: binary, min-length: 1, max-length: 4K,
+                  optional: true}
+      objects: {number: 2, record: evidence-get objects, max-occurrences: 16}
+  evidence-get objects:
+    id: 0x80021000
+    fields:
+      id: {number: 1, type: uint, max: 15}
+      data: {number: 2, blob: output, backings: [va], max-length: u32-max}
+  evidence-get reply:
+    id: 0xc0020000
+    fields:
+      results: {number: 1, record: evidence-get results, max-occurrences: 16}
+    members: ['record mr-generation?']
+  evidence-get results:
+    id: 0xc0021000
+    fields:
+      format: {number: 1, enum: evidence-format, optional: true}
+      vendor-format: {number: 2, enum: evidence-vendor-format, optional: true}
+      length: {number: 3, type: uint}
+  mr-get request:
+    id: 0x80030000
+    fields:
+      id: {number: 1, type: uint, max: u32-max, optional: true}
+  mr-get reply:
+    id: 0xc0030000
+    fields:
+      items: {number: 1, record: mr-get items, max-occurrences: unlimited}
+  mr-get items:
+    id: 0xc0031000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+    members: [$include mr-desc]
+  mr-read request:
+    id: 0x80040000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+  mr-read reply:
+    id: 0xc0040000
+    members: [record mr-generation, record mr-values]
+  mr-extend request:
+    id: 0x80050000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+    members: [record mr-values]
+  mr-extend reply:
+    id: 0xc0050000
+    members: [record mr-generation]
+extensions: {device-info: 1}
+enum-extensions: {evidence-vendor-format: 1}
+ops:
+  device-get: {id: 1, type: action, fd-access: read,
+               request: device-get request, reply: device-get reply}
+  evidence-get: {id: 2, type: action, availability: dynamic, optional: true,
+                 request: evidence-get request, reply: evidence-get reply}
+  mr-get: {id: 3, type: query, fd-access: read, optional: true,
+           request: mr-get request, reply: mr-get reply}
+  mr-read: {id: 4, type: query, fd-access: read, optional: true,
+            request: mr-read request, reply: mr-read reply}
+  mr-extend: {id: 5, type: action, optional: true, request: mr-extend request,
+              reply: mr-extend reply}
Documentation/ctlv/abi/families.registry.yaml +1 -0
index 5845e745777150..7a5c6af2956578 100644
@@ -5,3 +5,4 @@
 # Written by "make -C tools/ctlv regen".
 families:
   - ctlv
+  - ctlv-attestation
Documentation/ctlv/families.yaml +1 -0
index 4d219d7af74a79..dbb0243b873d68 100644
@@ -15,3 +15,4 @@
 
 families:
   - ctlv
+  - ctlv-attestation
Documentation/ctlv/generated-files.yaml +7 -0
index d4766b176ceb98..00a56634805d40 100644
@@ -16,3 +16,10 @@ families:
       kernel-header: include/linux/ctlv_gen.h
       kernel-source: lib/ctlv/ctlv_gen.c
       user-source: tools/ctlv/libctlv/ctlv_user_gen.c
+
+  - name: ctlv-attestation
+    source: Documentation/ctlv/specs/ctlv-attestation.yaml
+    outputs:
+      uapi-header: include/uapi/ctlv/ctlv_attestation_gen.h
+      kernel-header: drivers/attestation/generated/ctlv_attestation_gen.h
+      kernel-source: drivers/attestation/generated/ctlv_attestation_gen.c
Documentation/ctlv/specs/ctlv-attestation.yaml new file +0 -0
new file mode 100644
index 00000000000000..78b2dad6318a6f

Documentation/ctlv/specs/ctlv-attestation.yaml line 8

Quoted 8 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +8 -0
@@ -0,0 +1,181 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
+---
+# Attestation devices: evidence and measurement registers (MRs). The device's
+# family inherits this one, fills device-info and gives evidence-vendor-format
+# the formats its vendor defines.
+family: ctlv-attestation
+inherits: ctlv

This is much easier to read, I think it works well like this!

Quoted 4 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +4 -0
+
+enums:
+  # What an evidence object is.
+  evidence-class:

Documentation/ctlv/specs/ctlv-attestation.yaml line 22

Quoted 10 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +10 -0
+    # Made by evidence-get over its challenge, and signed by the root of
+    # trust.
+    - signed
+    # The platform's log of what firmware and the boot chain measured into
+    # the MRs. Later extends, through mr-extend or otherwise, are not in it.
+    - event-log
+  # A layout of an evidence object that a standard defines.
+  evidence-format:
+    # The log area of an ACPI CCEL table, a TCG crypto-agile event log.
+    - ccel

Lets be in the habit of including a detailed spec reference for things that are standards.

Documentation/ctlv/specs/ctlv-attestation.yaml line 25

Quoted 3 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +3 -0
+  # A layout of an evidence object that one vendor defines, given by the
+  # device's family.
+  evidence-vendor-format: extension

I find this 'standard' 'vendor' distinction confusing. Is this an artifact of the compilation process?

This would be more usable if there was one enum but both this yaml and the driver yaml can contribute values to it. If we made an 'extendable enum' then the values could be full 64 bit ID numbers with the tree coding so that the extension works the same way as a op and record?

Though I'm a bit nervous about what happens if something in a driver turns into a standard. It would be nice to be able to make the driver's ID promoted to a global ID without changing the ID. That sounds like something the generator could learn to do later I guess.

The comment should be improved to define what consitutes a 'format'. I was advocating that the format should define enough to check the signature and the challenge universally.

Like Peter described the new TDX evidence as "tdx-quote-eat-cwt-1.0".

Poking at the IETF RFCs with AI a bit I think it should be described as "CWT EAT" in this language. The EAT RFC defines the location of the challenge and uses the CWT packaging which defines how the signature is placed.

I think ARM uses this format too, IDK what AMD uses.

The EAT itself should have information inside that describes the "tdx-quote-1.0" idea, so we don't need it externally.

Documentation/ctlv/specs/ctlv-attestation.yaml line 36

Quoted 11 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +11 -0
+  # The kernel's hash algorithms.
+  hash-algo:
+    $header: linux/hash_info.h
+    $enum: hash_algo
+    $end: HASH_ALGO__LAST
+
+flags:
+  # What a device offers for its MRs.
+  mr-device-caps:
+    # mr-extend is provided.
+    - extend

I guessed the userspace should learn what operations are supported using introspection directly on the operation? Do we need to specify what ops are implemented in device-get?

Documentation/ctlv/specs/ctlv-attestation.yaml line 48

Quoted 8 lines

[ ... 5 lines skipped ... ]

Documentation/ctlv/specs/ctlv-attestation.yaml new file +7 -0
+records:
+  # One MR, as mr-get describes it.
+  mr-desc:
+    # The platform's name for the MR, such as rtmr0.
+    name: string(1..128)
+    # Its banks, each once, in the provider's order.
+    supported-hash-algorithms[hash-algo]: hash-algo

I wonder if it would be wise to put a bit more syntax here:
supported-hash-algorithms[num_entries(hash-algo)]: hash-algo

Just to be clear about exactly what is being extracted from hash_algo.. It is the total number of entries, not the maximum value or something else.

Quoted 29 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +29 -0
+    # What it allows.
+    caps: mr-caps
+    # The hardware's number for the MR, where it has one: 0 for rtmr0.
+    register-index?: uint(..u32-max)
+
+  # One bank of an MR.
+  mr-value:
+    # The bank's algorithm.
+    hash-algo: hash-algo
+    # The digest, as long as hash-algo's.
+    data: binary(16..64)
+
+  # The device's MR generation, which each extend bumps.
+  mr-generation: uint(..u32-max)
+
+  # Values for banks of the MR, each bank once.
+  mr-values[hash-algo]: record mr-value
+
+ops:
+  # What the device can do, and its family's fields.
+  device-get:
+    type: action
+    fd-access: read
+    reply:
+      # What the device supports, fixed for its life.
+      caps:
+        # Present when the device produces evidence.
+        evidence?:
+          # One per object evidence-get can produce.

Documentation/ctlv/specs/ctlv-attestation.yaml line 87

Quoted 10 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +10 -0
+          objects[16]:
+            # The device's handle for the object in requests.
+            id: uint(..15)
+            # What the object is.
+            class: evidence-class
+            # The layouts a standard defines that the object may have. At
+            # least one of formats and vendor-formats is present.
+            formats[4]?: evidence-format
+            # The layouts its vendor defines that the object may have.
+            vendor-formats[4]?: evidence-vendor-format

How do we want to fit AMD's unique GUID scheme into this?

I'm not sure we should be passing a GUID from userspace to select an opaque blob. If not then the kernel could have the GUID list and report the correct evidence formats as options here?

But then this is maybe a bit limiting because the format is supposed to be the basic envelope, but the AMD version uses almost the same format but they are still different. Though I suppose the difference in the nonce calculation warrants a second format.

And then how does generic userspace even know which one to pick? List them all? Should kernel give some 'default signed evidence' ID ?

So many questions :(

Documentation/ctlv/specs/ctlv-attestation.yaml line 98

Quoted 11 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +11 -0
+            # The longest the object gets; a blob this long always holds it.
+            max-length: uint
+            # A signed object's challenge lengths: each entry is one length,
+            # or a range from min-length to max-length.
+            challenge-lengths[8]?:
+              # A single length.
+              length?: uint(1..4K, bytes)
+              # The shortest of a range.
+              min-length?: uint(1..4K, bytes)
+              # The longest of a range.
+              max-length?: uint(1..4K, bytes)

The comments should be more prescriptive on how userspace has to handle this. I guess if length appears then that length must be used, otherwise within the range described by min/max length

But I wonder if this is worth some additional schema support to define a tagged union?

Quoted 18 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +18 -0
+        # Present when the device has MRs.
+        mr?:
+          # The MR operations the device provides.
+          flags: mr-device-caps
+      # The device's family's fields.
+      info: extension device-info
+
+  # Evidence objects, written into the caller's blobs. A signed object is made
+  # by the call, over the challenge, and never reused; the others are read as
+  # they stand at the call.
+  evidence-get:
+    type: action
+    fd-access: read-write
+    availability: dynamic
+    optional: true
+    request:
+      # Bound into each signed object named: pass a verifier's nonce, or a hash
+      # binding one to your context, never data a peer chose. Present exactly

Documentation/ctlv/specs/ctlv-attestation.yaml line 126

Quoted 10 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +10 -0
+      # when a signed object is named, and of a length each of them takes.
+      challenge?: binary(1..4K)
+      # The objects to produce, each named once.
+      objects[16]:
+        # The object, by the ID device-get lists.
+        id: uint(..15)
+        # Where the object is written. One too short for it fails the op with
+        # EMSGSIZE, and error-info's required-length says how long it has to
+        # be.
+        data: blob(out, va)

What will this be like when we add memfd later?

Documentation/ctlv/specs/ctlv-attestation.yaml line 138

Quoted 12 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +12 -0
+    reply:
+      # One per object, in request order.
+      results[16]:
+        # The layout it came in, where a standard defines it. Exactly one of
+        # format and vendor-format is present.
+        format?: evidence-format
+        # The layout it came in, where its vendor defines it.
+        vendor-format?: evidence-vendor-format
+        # The bytes written to its blob.
+        length: uint
+      # Present when the evidence depends on the MRs.
+      mr-generation?: record

Later we will need to add 'tsm controlled challenge' meaning the challenge is an output not an input,

Quoted 20 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +20 -0
+
+  # The MRs' IDs and descriptions, which do not change; mr-read returns
+  # values, which change with every extension and are read from the hardware.
+  mr-get:
+    type: query
+    fd-access: read
+    optional: true
+    suggested-reply-length: 4K
+    request:
+      # Only this MR; every MR without it.
+      id?: uint(..u32-max)
+    reply:
+      # One per MR, ordered by ID.
+      items[]:
+        # The device's handle for the MR in requests.
+        id: uint(..u32-max)
+        $include: mr-desc
+
+  # One MR's values, and the MR generation they belong to.
+  mr-read:

Documentation/ctlv/specs/ctlv-attestation.yaml line 168

Quoted 10 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +10 -0
+    type: query
+    fd-access: read
+    optional: true
+    suggested-reply-length: 4K
+    request:
+      # The MR to read, by the ID mr-get lists.
+      id: uint(..u32-max)
+    reply:
+      mr-generation: record
+      mr-values: record

Can we leave the generation for a followup with more understanding what it will be used for and how it is computed?

Documentation/ctlv/specs/ctlv-attestation.yaml line 181

Quoted 13 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +13 -0
+
+  # Extends banks of the MR by digests, as TPM2_PCR_Extend.
+  mr-extend:
+    type: action
+    fd-access: read-write
+    optional: true
+    request:
+      # The MR to extend, by the ID mr-get lists.
+      id: uint(..u32-max)
+      # For the banks to extend, each once, in any order.
+      mr-values: record
+    reply:
+      mr-generation: record

The comment should say that mr-values must include exactly every bank inside the MR, not more or less.

If we want to later add something like a log entry as an option this is easy to extend for that, right?

This API eventually needs certificates. I expect that Intel is including the certificates embedded within the EAT returned here as signed evidence. AFAIK ARM does the same

But AMD seems to pass them through 'auxblob' in tsm_report, so there should be a certificates API here to get them. SPDM also has them detached from the evidence.

Signature · 1 line
Jason
author
#3 lore raw

Re: [PATCH RFC v2 1/9] attestation: Add the base family specification and generated files

Quoted 14 lines · Fri, Nov 27, 2026 at 01:25:39AM +0100, [email protected] wrote:
Quoted 14 lines

[ ... 60 lines skipped ... ]
+++ b/Documentation/ctlv/abi/ctlv-attestation.yaml

Documentation/ctlv/abi/ctlv-attestation.yaml new file +11 -0
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
+---
+# Checked-in ABI snapshot of the ctlv-attestation family, from
+# Documentation/ctlv/specs/ctlv-attestation.yaml, written by
+# "make -C tools/ctlv regen".
+#
+# Updating the file is how a UAPI change gets reviewed; an update that
+# removes or renumbers anything, narrows a bound, or makes a member required
+# is an ABI break, whatever the file says afterwards.
+family: {name: ctlv-attestation, id: 1, inherits: ctlv}
Quoted 8 lines

Documentation/ctlv/abi/ctlv-attestation.yaml line 16

Quoted 5 lines
Documentation/ctlv/abi/ctlv-attestation.yaml new file +5 -0
+enums:
+  evidence-class: {signed: 1, event-log: 2}
+  evidence-format: {ccel: 1}
+  hash-algo: {$header: linux/hash_info.h, $enum: hash_algo,
+              $end: HASH_ALGO__LAST}

I feel like this should parse the C enum into numbers here so the ABI can be checked too?

Well, note that this only works for uapi/ enums. So those are already part of ABI. I don't think we need to do anything extra here.

Quoted 173 lines
Quoted 173 lines
Documentation/ctlv/abi/ctlv-attestation.yaml new file +131 -0
+flags:
+  mr-device-caps: {extend: 0}
+  mr-caps: {extend: 0}
+records:
+  mr-desc:
+    id: 0x00010000
+    fields:
+      name: {number: 1, type: string, min-length: 1, max-length: 128}
+      supported-hash-algorithms: {number: 2, enum: hash-algo,
+                                  max-occurrences: hash-algo}
+      caps: {number: 3, flags: mr-caps}
+      register-index: {number: 4, type: uint, max: u32-max, optional: true}
+  mr-value:
+    id: 0x00020000
+    fields:
+      hash-algo: {number: 1, enum: hash-algo}
+      data: {number: 2, type: binary, min-length: 16, max-length: 64}
+  mr-generation:
+    id: 0x00030000
+    fields:
+      mr-generation: {number: 1, type: uint, max: u32-max}
+  mr-values:
+    id: 0x00040000
+    fields:
+      mr-values: {number: 1, record: mr-value, max-occurrences: hash-algo}
+  device-get request:
+    id: 0x80010000
+  device-get reply:
+    id: 0xc0010000
+    fields:
+      caps: {number: 1, record: device-get caps}
+      info: {number: 2, extension: device-info}
+  device-get caps:
+    id: 0xc0011000
+    fields:
+      evidence: {number: 1, record: device-get caps.evidence, optional: true}
+      mr: {number: 2, record: device-get caps.mr, optional: true}
+  device-get caps.evidence:
+    id: 0xc0011100
+    fields:
+      objects: {number: 1, record: device-get caps.evidence.objects,
+                max-occurrences: 16}
+  device-get caps.evidence.objects:
+    id: 0xc0011110
+    fields:
+      id: {number: 1, type: uint, max: 15}
+      class: {number: 2, enum: evidence-class}
+      formats: {number: 3, enum: evidence-format, max-occurrences: 4,
+                optional: true}
+      vendor-formats: {number: 4, enum: evidence-vendor-format,
+                       max-occurrences: 4, optional: true}
+      max-length: {number: 5, type: uint}
+      challenge-lengths:
+        {number: 6, record: device-get caps.evidence.objects.challenge-lengths,
+         max-occurrences: 8, optional: true}
+  device-get caps.evidence.objects.challenge-lengths:
+    id: 0xc0011111
+    fields:
+      length: {number: 1, type: uint, min: 1, max: 4K, unit: bytes,
+               optional: true}
+      min-length: {number: 2, type: uint, min: 1, max: 4K, unit: bytes,
+                   optional: true}
+      max-length: {number: 3, type: uint, min: 1, max: 4K, unit: bytes,
+                   optional: true}
+  device-get caps.mr:
+    id: 0xc0011200
+    fields:
+      flags: {number: 1, flags: mr-device-caps}
+  evidence-get request:
+    id: 0x80020000
+    fields:
+      challenge: {number: 1, type: binary, min-length: 1, max-length: 4K,
+                  optional: true}
+      objects: {number: 2, record: evidence-get objects, max-occurrences: 16}
+  evidence-get objects:
+    id: 0x80021000
+    fields:
+      id: {number: 1, type: uint, max: 15}
+      data: {number: 2, blob: output, backings: [va], max-length: u32-max}
+  evidence-get reply:
+    id: 0xc0020000
+    fields:
+      results: {number: 1, record: evidence-get results, max-occurrences: 16}
+    members: ['record mr-generation?']
+  evidence-get results:
+    id: 0xc0021000
+    fields:
+      format: {number: 1, enum: evidence-format, optional: true}
+      vendor-format: {number: 2, enum: evidence-vendor-format, optional: true}
+      length: {number: 3, type: uint}
+  mr-get request:
+    id: 0x80030000
+    fields:
+      id: {number: 1, type: uint, max: u32-max, optional: true}
+  mr-get reply:
+    id: 0xc0030000
+    fields:
+      items: {number: 1, record: mr-get items, max-occurrences: unlimited}
+  mr-get items:
+    id: 0xc0031000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+    members: [$include mr-desc]
+  mr-read request:
+    id: 0x80040000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+  mr-read reply:
+    id: 0xc0040000
+    members: [record mr-generation, record mr-values]
+  mr-extend request:
+    id: 0x80050000
+    fields:
+      id: {number: 1, type: uint, max: u32-max}
+    members: [record mr-values]
+  mr-extend reply:
+    id: 0xc0050000
+    members: [record mr-generation]
+extensions: {device-info: 1}
+enum-extensions: {evidence-vendor-format: 1}
+ops:
+  device-get: {id: 1, type: action, fd-access: read,
+               request: device-get request, reply: device-get reply}
+  evidence-get: {id: 2, type: action, availability: dynamic, optional: true,
+                 request: evidence-get request, reply: evidence-get reply}
+  mr-get: {id: 3, type: query, fd-access: read, optional: true,
+           request: mr-get request, reply: mr-get reply}
+  mr-read: {id: 4, type: query, fd-access: read, optional: true,
+            request: mr-read request, reply: mr-read reply}
+  mr-extend: {id: 5, type: action, optional: true, request: mr-extend request,
+              reply: mr-extend reply}
Documentation/ctlv/abi/families.registry.yaml +1 -0
index 5845e745777150..7a5c6af2956578 100644
@@ -5,3 +5,4 @@
 # Written by "make -C tools/ctlv regen".
 families:
   - ctlv
+  - ctlv-attestation
Documentation/ctlv/families.yaml +1 -0
index 4d219d7af74a79..dbb0243b873d68 100644
@@ -15,3 +15,4 @@
 
 families:
   - ctlv
+  - ctlv-attestation
Documentation/ctlv/generated-files.yaml +7 -0
index d4766b176ceb98..00a56634805d40 100644
@@ -16,3 +16,10 @@ families:
       kernel-header: include/linux/ctlv_gen.h
       kernel-source: lib/ctlv/ctlv_gen.c
       user-source: tools/ctlv/libctlv/ctlv_user_gen.c
+
+  - name: ctlv-attestation
+    source: Documentation/ctlv/specs/ctlv-attestation.yaml
+    outputs:
+      uapi-header: include/uapi/ctlv/ctlv_attestation_gen.h
+      kernel-header: drivers/attestation/generated/ctlv_attestation_gen.h
+      kernel-source: drivers/attestation/generated/ctlv_attestation_gen.c
Documentation/ctlv/specs/ctlv-attestation.yaml new file +2 -0
new file mode 100644
index 00000000000000..78b2dad6318a6f
@@ -0,0 +1,181 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
Quoted 8 lines

Documentation/ctlv/specs/ctlv-attestation.yaml line 8

Quoted 6 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +6 -0
+---
+# Attestation devices: evidence and measurement registers (MRs). The device's
+# family inherits this one, fills device-info and gives evidence-vendor-format
+# the formats its vendor defines.
+family: ctlv-attestation
+inherits: ctlv

This is much easier to read, I think it works well like this!

Yeah, pretty happy with it as well. Thanks for the suggestion!

Quoted 10 lines
Quoted 10 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +9 -0
+
+enums:
+  # What an evidence object is.
+  evidence-class:
+    # Made by evidence-get over its challenge, and signed by the root of
+    # trust.
+    - signed
+    # The platform's log of what firmware and the boot chain measured into
+    # the MRs. Later extends, through mr-extend or otherwise, are not in it.
Quoted 8 lines

Documentation/ctlv/specs/ctlv-attestation.yaml line 22

Quoted 5 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +5 -0
+    - event-log
+  # A layout of an evidence object that a standard defines.
+  evidence-format:
+    # The log area of an ACPI CCEL table, a TCG crypto-agile event log.
+    - ccel

Lets be in the habit of including a detailed spec reference for things that are standards.

Agreed. Will add it.

Quoted 13 lines

Documentation/ctlv/specs/ctlv-attestation.yaml line 25

Quoted 4 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +3 -0
+  # A layout of an evidence object that one vendor defines, given by the
+  # device's family.
+  evidence-vendor-format: extension

I find this 'standard' 'vendor' distinction confusing. Is this an artifact of the compilation process?

This would be more usable if there was one enum but both this yaml and the driver yaml can contribute values to it. If we made an 'extendable enum' then the values could be full 64 bit ID numbers with the tree coding so that the extension works the same way as a op and record?

Quoted 4 lines

Though I'm a bit nervous about what happens if something in a driver turns into a standard. It would be nice to be able to make the driver's ID promoted to a global ID without changing the ID. That sounds like something the generator could learn to do later I guess.

I see your point. Bit if we have 64bit enum value what included the family id, we still have per-family namespace of enum values. Hard to "promote to global id". We would have to have one range of enum values, some of which would be driver, some global. How exactly you see this happening?

Quoted 12 lines

The comment should be improved to define what consitutes a 'format'. I was advocating that the format should define enough to check the signature and the challenge universally.

Like Peter described the new TDX evidence as "tdx-quote-eat-cwt-1.0".

Poking at the IETF RFCs with AI a bit I think it should be described as "CWT EAT" in this language. The EAT RFC defines the location of the challenge and uses the CWT packaging which defines how the signature is placed.

Quoted 4 lines

I think ARM uses this format too, IDK what AMD uses.

The EAT itself should have information inside that describes the "tdx-quote-1.0" idea, so we don't need it externally.

Perhaps we need 2 attributes, "evidence-packaging" and "evidence-format"? This is a bit unclear to me to be honest.

Quoted 16 lines

Documentation/ctlv/specs/ctlv-attestation.yaml line 36

Quoted 12 lines
Documentation/ctlv/specs/ctlv-attestation.yaml new file +11 -0
+  # The kernel's hash algorithms.
+  hash-algo:
+    $header: linux/hash_info.h
+    $enum: hash_algo
+    $end: HASH_ALGO__LAST
+
+flags:
+  # What a device offers for its MRs.
+  mr-device-caps:
+    # mr-extend is provided.
+    - extend

I guessed the userspace should learn what operations are supported using introspection directly on the operation? Do we need to specify what ops are implemented in device-get?

True, will remove this leftover.

Quoted 10 lines

Documentation/ctlv/specs/ctlv-attestation.yaml line 48

Quoted 9 lines

[ ... 5 lines skipped ... ]

Documentation/ctlv/specs/ctlv-attestation.yaml new file +7 -0
+records:
+  # One MR, as mr-get describes it.
+  mr-desc:
+    # The platform's name for the MR, such as rtmr0.
+    name: string(1..128)
+    # Its banks, each once, in the provider's order.
+    supported-hash-algorithms[hash-algo]: hash-algo
Quoted 6 lines

I wonder if it would be wise to put a bit more syntax here:
supported-hash-algorithms[num_entries(hash-algo)]: hash-algo

Just to be clear about exactly what is being extracted from hash_algo.. It is the total number of entries, not the maximum value or something else.

I already have this changed in my work tree as:
"supported-hash-algorithms[enum hash-algo]: enum hash-algo". I think it is enough, what do you think?

[...]

author
#4 lore raw

RFC PATCH v2 2/9 Documentation: attestation: Add userspace ABI

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Describe the attestation family for userspace: its operations and their errors, the evidence objects and the measurement registers.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5
---
 Documentation/userspace-api/attestation.rst | 283 ++++++++++++++++++++
 Documentation/userspace-api/index.rst       |   1 +
 MAINTAINERS                                 |   1 +
 3 files changed, 285 insertions(+)
 create mode 100644 Documentation/userspace-api/attestation.rst
Documentation/userspace-api/attestation.rst new file +283 -0
new file mode 100644
index 000000000000..3c610acc3382
@@ -0,0 +1,283 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=========================
+Attestation userspace ABI
+=========================
+
+A confidential guest proves what it runs to a remote verifier with evidence: a
+statement of its measurements, signed by its root of trust and carrying a
+challenge the verifier chose, and the logs behind those measurements. An
+attestation provider gives its device a node, ``/dev/attestation/attestationN``.
+Through it a program asks for evidence, and reads and extends the measurement
+registers (MRs) the evidence reports.
+
+The node speaks CTLV, described in :doc:`ctlv`, as a descendant of the
+``ctlv-attestation`` family, one family per provider. Every operation below
+belongs to ``ctlv-attestation``, so a tool written against it works with any
+provider. The specification is
+``Documentation/ctlv/specs/ctlv-attestation.yaml`` and the constants are in
+``include/uapi/ctlv/ctlv_attestation_gen.h``.
+
+======================  ======  ==========  ================================
+Operation               Type    Access      Purpose
+======================  ======  ==========  ================================
+device-get              action  read        what the device supports
+evidence-get            action  read-write  evidence objects
+mr-get                  query   read        describe the MRs
+mr-read                 query   read        one MR's values
+mr-extend               action  read-write  extend one MR
+======================  ======  ==========  ================================
+
+``device-get`` is always provided. Every other operation is optional, and a
+device provides those its provider implements, which ``op-get`` lists. The
+errors below are the family's own. Those of the transport, such as ``EACCES``
+for a descriptor without the access an operation needs, are in :doc:`ctlv`,
+and once a device is gone or has stopped, every operation fails with
+``ENODEV``. A provider's own failure returns its errno, such as ``EIO``.
+
+Generations
+===========
+
+A counter tells a program whether what it holds is still current. It is 32
+bits wide. An operation that would advance it past its maximum fails with
+``EOVERFLOW`` and stops the device.
+
+``mr-generation``
+    The state of the MRs. It advances with every extension, and a reply that
+    depends on MR state carries the generation it reflects.
+
+Evidence
+========
+
+``device-get``
+--------------
+
+Describes the device: what it supports and the provider's own information. It
+takes no request. The reply carries:
+
+``caps``
+    A record for each part the device has:
+
+    ``caps.evidence``
+        With ``evidence-get``: one of ``objects`` for each object the device
+        produces, up to 16, as `Objects`_ describes.
+
+    ``caps.mr``
+        With MRs: ``flags``, which has ``extend`` where ``mr-extend`` is
+        provided. ``mr-read`` is always provided with MRs.
+
+``info``
+    The device's family's fields, its ``device-info``.
+
+``evidence-get``
+----------------
+
+Writes each object the request names into a blob the caller supplies. A
+signed object is made by the call, over the challenge, and never reused. The
+others, such as an event log, are read as they stand at the call. One call so
+returns signed evidence with the log needed to check it. The request carries:
+
+``challenge``
+    The challenge, described below. Present exactly when a signed object is
+    named.
+
+``objects``
+    1 to 16 objects, each naming one of the ``caps.evidence.objects`` of
+    ``device-get`` by its ``id`` and giving ``data``, the output blob it is
+    written to, sized as described below.
+
+The reply carries:
+
+``results``
+    One per object, in request order, each giving the object's format in
+    exactly one of ``format`` and ``vendor-format``, and its ``length``, the
+    bytes written to its blob.
+
+``mr-generation``
+    Where an object binds MRs, the MR generation the evidence reflects.
+
+``EINVAL``
+    A signed object is named without a challenge, a challenge is given
+    without one, or its length is one a signed object named does not take.
+    Two objects are the same.
+
+``EMSGSIZE``
+    An object's blob is too short for it. The error information's
+    ``required-length`` says how long it has to be.
+
+``ENOENT``
+    An object's ``id`` is not one ``device-get`` lists.
+
+``EPROTO``
+    The root of trust returned an object in a format the device does not
+    list for it.
+
+Access is read-write. Availability is dynamic: a device may switch the
+operation off for a time, and meanwhile it fails with ``EOPNOTSUPP``.
+
+The challenge
+~~~~~~~~~~~~~
+
+A signed object binds the challenge. Each signed object lists its
+``challenge-lengths``, up to 8, each one ``length`` or a range from
+``min-length`` to ``max-length``, and the subsystem keeps them within 1 to 4K.
+The challenge has to be of a length every signed object named lists.
+
+Pass a nonce from the verifier, or a hash that binds such a nonce to the
+caller's own context, such as a key the evidence is to vouch for. Never pass
+data a peer chose. Any process that can run ``evidence-get`` can have the
+device sign what it passes, and one that passes a peer's bytes makes the
+device a signing oracle for that peer.
+
+Objects
+~~~~~~~
+
+Each of ``caps.evidence.objects`` describes one object:
+
+``id``
+    0 to 15, which a request names it by.
+
+``class``
+    What the object is, as ``evidence-class`` below says.
+
+``formats`` and ``vendor-formats``
+    The formats it may have.
+
+``max-length``
+    The longest it gets, however many objects a call asks for.
+
+``challenge-lengths``
+    For a signed object, the challenge lengths it takes.
+
+``evidence-class`` says what an object is:
+
+``signed``
+    Evidence the root of trust signs over the challenge. It carries its own
+    signature.
+
+``event-log``
+    The platform's log of what firmware and the boot chain measured into the
+    MRs, for a verifier to replay. Later extends, through ``mr-extend`` or
+    otherwise, are not in it.
+
+A blob of the object's ``max-length`` always holds it. A shorter one saves
+memory where objects run shorter than their bound, as certificate chains do:
+where the object does not fit, ``evidence-get`` fails with ``EMSGSIZE`` and
+returns no evidence, and ``required-length`` in the error information is the
+length to retry with. The retry collects the evidence anew, and may pass the
+same challenge.
+
+Two enums name the formats:
+
+``evidence-format``
+    ``ctlv-attestation``'s, for a layout a standard defines, such as the
+    CCEL, so every family that produces it uses the same value.
+
+``evidence-vendor-format``
+    For a layout one vendor defines, whose values the device's family gives
+    through a CTLV enum extension point.
+
+The ABI check of ``regen`` covers both enums. An object lists the formats it
+may have, from either enum, in ``formats`` and ``vendor-formats``, and the
+reply names the one written in exactly one of ``format`` and
+``vendor-format``. A new layout is a new value.
+
+Measurement registers
+=====================
+
+Extending an MR folds a digest into its value, so the value commits to every
+extension in order. An MR has a value for each hash algorithm it supports, a
+bank. An MR's ``id`` is the device's handle for it, and ``mr-desc`` describes
+it:
+
+``name``
+    The platform's name for the MR, such as ``rtmr0``.
+
+``supported-hash-algorithms``
+    One for each bank, in the provider's order.
+
+``register-index``
+    The hardware's number for the MR, where it has one.
+
+``caps``
+    ``extend`` where the MR may be extended. A provider still refuses an
+    extend the platform forbids at the time, as with ``EPERM`` for a TPM PCR
+    the current locality may not extend.
+
+Every MR can be read, though a read can still fail, as when the caller lacks
+authorization or the platform's state forbids it.
+
+The name, banks, caps and register index describe an MR, and do not change.
+The values change with every extension, so the two are read apart.
+``mr-get`` describes every MR, which is how a program learns the IDs, or the
+one an ID names. It is answered from what the device keeps, while
+``mr-read``, which returns one MR's values, asks the hardware. ``mr-read`` and
+``mr-extend`` take only the ID.
+
+A hash algorithm is a constant of ``enum hash_algo`` in
+``include/uapi/linux/hash_info.h``, such as ``HASH_ALGO_SHA384``.
+
+Nothing reserves an MR, and the kernel does not arbitrate between its
+writers. Any program with a read-write descriptor can extend it, and so can
+the register's own interface, as for a TPM's PCRs. A program that replays an
+MR from its own records has to make sure, through the system's configuration,
+that it is the only writer; ``mr-generation`` counts only the extensions made
+through the device.
+
+``mr-get``
+----------
+
+Describes every MR, in fragments ordered by ID, or only the MR whose ``id``
+the request carries. Each is one of ``items``, with its ``id`` and its
+``mr-desc``, as `Measurement registers`_ lists it. The query's generation is
+the MR generation, so a continuation fails with ``ESTALE`` once any MR has
+changed.
+
+``ENOENT``
+    No MR has that ID.
+
+Access is read.
+
+``mr-read``
+-----------
+
+Returns the current values of the MR whose ``id`` the request carries. The
+reply carries:
+
+``mr-generation``
+    The MR generation of the values.
+
+``mr-values``
+    One for each bank, in ``mr-get``'s order, with its ``hash-algo`` and
+    ``data``.
+
+``ENOENT``
+    No MR has that ID.
+
+Access is read.
+
+``mr-extend``
+-------------
+
+Extends the MR whose ``id`` the request carries. The request carries one of
+``mr-values`` for each bank of the MR to extend, in any order, each a
+``hash-algo`` and a ``data`` of exactly that algorithm's digest size. The
+banks left out keep their values. The device hashes nothing for the caller.
+
+The reply carries ``mr-generation``, the MR generation after the extension.
+
+``ENOENT``
+    No MR has that ID.
+
+``EOPNOTSUPP``
+    The MR cannot be extended, or the provider cannot extend only some of its
+    banks.
+
+``EPERM``
+    The platform forbids extending the MR at the time.
+
+``EINVAL``
+    The request carries no ``mr-values``, a value is for a bank the MR does not
+    have or repeats one, or a digest has the wrong length.
+
+Access is read-write.
Documentation/userspace-api/index.rst +1 -0
index d1b53c4e16eb..61051cd28fd1 100644
@@ -36,6 +36,7 @@ Security-related interfaces
    mfd_noexec
    spec_ctrl
    tee
+   attestation
    check_exec
 
 Devices and I/O
MAINTAINERS +1 -0
index fa450924b921..0c1778e676ed 100644
@@ -4439,6 +4439,7 @@ L:	[email protected]
 S:	Supported
 F:	Documentation/ctlv/abi/ctlv-attestation*
 F:	Documentation/ctlv/specs/ctlv-attestation*
+F:	Documentation/userspace-api/attestation*.rst
 F:	drivers/attestation/
 F:	include/uapi/ctlv/ctlv_attestation*
 
Signature · 1 line
2.56.0
author
#5 lore raw

RFC PATCH v2 3/9 attestation: Prepare provider and instance core

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add provider validation, instance registration and lifecycle management for the attestation family. Each instance is a device of the attestation class, with a node under /dev/attestation/, and embeds its CTLV instance and node.

The provider descriptor is one immutable evidence and MR contract; MR state follows in the next patch. The core object can be compile-checked here. CONFIG_ATTESTATION remains unwired until the CTLV handlers land.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- gave attestation its own device, class and /dev/attestation/ nodes, each a struct ctlv_device
- dropped the goto from attestation_registry_insert()
- noted that instance indexes are never reused
- selected CRYPTO_HASH_INFO
- selected CTLV instead of depending on it
- kept each guard() on one line
- dropped the journal from the Kconfig help
- dropped read(), poll() and the event teardown
- refused hash algorithms the hash-algo enum does not list
- gave each evidence object a class and the formats it may have
- dropped max_total_output_length
- took each signed object's challenge lengths as a list, ascending and disjoint
- left the object count and challenge length limits to CTLV
- added attestation_evidence_write(), for blobs of any length
- let a request omit the challenge
- separated the steps of the longer functions
- took an MR's algorithms in any order, each once
- let mr_extend get the digests of some of an MR's banks
- required mr_read of a provider with MRs, as every MR can be read
- said that an MR's extend cap is fixed
- took the UAPI headers from include/uapi/ctlv/
- named evidence objects by ID, and had the provider give each result's format

---
 MAINTAINERS                         |   1 +
 drivers/attestation/Kconfig         |  12 +
 drivers/attestation/Makefile        |   4 +
 drivers/attestation/core/core.c     | 429 ++++++++++++++++++++++++++++
 drivers/attestation/core/internal.h |  21 ++
 include/linux/attestation.h         | 240 ++++++++++++++++
 6 files changed, 707 insertions(+)
 create mode 100644 drivers/attestation/Kconfig
 create mode 100644 drivers/attestation/Makefile
 create mode 100644 drivers/attestation/core/core.c
 create mode 100644 drivers/attestation/core/internal.h
 create mode 100644 include/linux/attestation.h
MAINTAINERS +1 -0
index 0c1778e676ed..e57fc8bb9c1d 100644
@@ -4441,6 +4441,7 @@ F:	Documentation/ctlv/abi/ctlv-attestation*
 F:	Documentation/ctlv/specs/ctlv-attestation*
 F:	Documentation/userspace-api/attestation*.rst
 F:	drivers/attestation/
+F:	include/linux/attestation*
 F:	include/uapi/ctlv/ctlv_attestation*
 
 ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
drivers/attestation/Kconfig new file +12 -0
new file mode 100644
index 000000000000..a6bfb17dd480
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-only
+menuconfig ATTESTATION
+	tristate "Attestation"
+	select CRYPTO_HASH_INFO
+	select CTLV
+	help
+	  Provides a CTLV family for evidence and measurement registers.
+
+	  Providers register one instance for a physical or logical device and
+	  translate the common operations to their native service.
+
+	  If you are unsure, say N.
drivers/attestation/Makefile new file +4 -0
new file mode 100644
index 000000000000..8a75558a7013
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_ATTESTATION) += attestation.o
+
+attestation-y := core/core.o
drivers/attestation/core/core.c new file +429 -0

429 lines not on this page · raw message

drivers/attestation/core/internal.h new file +21 -0
new file mode 100644
index 000000000000..f42bc3cd9a35
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _ATTESTATION_INTERNAL_H
+#define _ATTESTATION_INTERNAL_H
+
+#include <linux/attestation.h>
+#include <linux/ctlv.h>
+#include <linux/mutex.h>
+#include <linux/xarray.h>
+
+#include "../generated/ctlv_attestation_gen.h"
+
+#define ATTESTATION_REGISTERED XA_MARK_1
+
+bool attestation_registered(struct attestation_dev *att);
+void attestation_stop(struct attestation_dev *att);
+
+int attestation_provider_validate(const struct attestation_provider *provider,
+				  const struct ctlv_family *family);
+void attestation_provide_ops(struct attestation_dev *att);
+
+#endif /* _ATTESTATION_INTERNAL_H */
include/linux/attestation.h new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
2.56.0
#6 lore raw

Re: [PATCH RFC v2 3/9] attestation: Prepare provider and instance core

Quoted 39 lines

Add provider validation, instance registration and lifecycle management for the attestation family. Each instance is a device of the attestation class, with a node under /dev/attestation/, and embeds its CTLV instance and node.

The provider descriptor is one immutable evidence and MR contract; MR state follows in the next patch. The core object can be compile-checked here. CONFIG_ATTESTATION remains unwired until the CTLV handlers land.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- gave attestation its own device, class and /dev/attestation/ nodes, each a struct ctlv_device
- dropped the goto from attestation_registry_insert()
- noted that instance indexes are never reused
- selected CRYPTO_HASH_INFO
- selected CTLV instead of depending on it
- kept each guard() on one line
- dropped the journal from the Kconfig help
- dropped read(), poll() and the event teardown
- refused hash algorithms the hash-algo enum does not list
- gave each evidence object a class and the formats it may have
- dropped max_total_output_length
- took each signed object's challenge lengths as a list, ascending and disjoint
- left the object count and challenge length limits to CTLV
- added attestation_evidence_write(), for blobs of any length
- let a request omit the challenge
- separated the steps of the longer functions
- took an MR's algorithms in any order, each once
- let mr_extend get the digests of some of an MR's banks
- required mr_read of a provider with MRs, as every MR can be read
- said that an MR's extend cap is fixed
- took the UAPI headers from include/uapi/ctlv/
- named evidence objects by ID, and had the provider give each result's format

Quoted 6 lines
---
 MAINTAINERS                         |   1 +
 drivers/attestation/Kconfig         |  12 +
 drivers/attestation/Makefile        |   4 +
 drivers/attestation/core/core.c     | 429 ++++++++++++++++++++++++++++
 drivers/attestation/core/internal.h |  21 ++

Traditionally subsystems put their core code in the top dir and drivers in sub dirs, or loose in the main dir too. The really big big subsystems use a subdir for core.

I think in this case we should skip the core/ subdir. Linus has also complained about the directory name stuttering like core/core.c in the past.

drivers/attestation/core/core.c line 29

Quoted 6 lines

[ ... 78 lines skipped ... ]

drivers/attestation/core/core.c new file +5 -0
+/* A reply carries only what hash-algo in ctlv-attestation.yaml lists. */
+static bool attestation_algorithm_valid(enum hash_algo algorithm)
+{
+	return algorithm >= 0 && algorithm <= HASH_ALGO_SHA3_512 && hash_digest_size[algorithm] &&
+	       hash_digest_size[algorithm] <= HASH_MAX_DIGESTSIZE;

<= HASH_ALGO_SHA3_512 should be < ARRAY_SIZE(hash_digest_size) ?

drivers/attestation/core/core.c line 40

Quoted 11 lines
drivers/attestation/core/core.c new file +11 -0
+}
+
+static int attestation_mr_props_validate(const struct attestation_provider *provider,
+					 const struct attestation_mr_props *props)
+{
+	DECLARE_BITMAP(seen, HASH_ALGO__LAST) = {};
+	size_t index;
+
+	if (!props || !props->name || !*props->name || strlen(props->name) > 128 ||
+	    !props->algorithms || !props->algorithms_count || props->algorithms_count > 23)
+		return -EINVAL;

The magic numbers should come from someplace..

Quoted 10 lines
drivers/attestation/core/core.c new file +10 -0
+	for (index = 0; index < props->algorithms_count; index++) {
+		enum hash_algo algorithm = props->algorithms[index];
+
+		if (!attestation_algorithm_valid(algorithm) ||
+		    __test_and_set_bit(algorithm, seen))
+			return -EINVAL;
+	}
+	if (props->extendable && !provider->mr_extend)
+		return -EINVAL;
+	return 0;

drivers/attestation/core/core.c line 59

Quoted 10 lines
drivers/attestation/core/core.c new file +9 -0
+}
+
+/* What device-get and evidence-get carry, as ctlv-attestation.yaml bounds it. */
+#define ATTESTATION_EVIDENCE_OBJECTS_MAX 16
+#define ATTESTATION_EVIDENCE_FORMATS_MAX 4
+#define ATTESTATION_CHALLENGE_LENGTHS_MAX 8
+#define ATTESTATION_CHALLENGE_MAX 4096
 
+/* Moves with each value appended to evidence-format. */
+#define ATTESTATION_EVIDENCE_FORMAT_LAST CTLV_ATTESTATION_EVIDENCE_FORMAT_CCEL

Should the general schema processor be checking these? Seems odd they are just open coded here when it has the information..

drivers/attestation/core/core.c line 180

Quoted 12 lines

[ ... 110 lines skipped ... ]

drivers/attestation/core/core.c new file +11 -0
+static int attestation_registry_insert(struct attestation_dev *att)
+{
+	unsigned long index;
+	void *old;
+	int ret;
+
+	guard(mutex)(&attestation_registry_lock);
+	if (attestation_next_index > UINT_MAX)
+		return -ENOSPC;
+	index = attestation_next_index;
+	ret = xa_reserve(&attestation_instances, index, GFP_KERNEL);

This is usually written as xa_alloc_cyclic()

drivers/attestation/core/core.c line 185

Quoted 5 lines
drivers/attestation/core/core.c new file +5 -0
+	if (ret)
+		return ret;
+
+	xa_lock(&attestation_instances);
+	if (attestation_parent_exists(att->node.dev.parent)) {

Why? What's the issue if a device wants a bunch of attestation end points?

drivers/attestation/core/core.c line 212

Quoted 9 lines

[ ... 19 lines skipped ... ]

drivers/attestation/core/core.c new file +8 -0
+bool attestation_registered(struct attestation_dev *att)
+{
+	bool registered;
+
+	lockdep_assert_held(&att->lock);
+	xa_lock(&attestation_instances);
+	registered = xa_get_mark(&attestation_instances, att->index, ATTESTATION_REGISTERED);
+	xa_unlock(&attestation_instances);

No need for the spinlock here

drivers/attestation/core/core.c line 271

Quoted 10 lines

[ ... 50 lines skipped ... ]

drivers/attestation/core/core.c new file +9 -0
+static int attestation_op_pre(struct ctlv *ctlv, struct ctlv_op_ctx *ctx)
+{
+	struct attestation_dev *att = attestation_from_ctlv(ctlv);
+
+	mutex_lock(&att->lock);
+	if (!attestation_registered(att)) {
+		mutex_unlock(&att->lock);
+		return -ENODEV;
+	}

I'm struggling to figure out why there is an xa mark, it doesn't seem needed by anything?

The revoke flow is already handled by the common code with:

	scoped_guard(rwsem_read, &ctlv->registration_lock) {
		if (!ctlv->registered || !ctlv->family)
			return -ENODEV;
		ret = ctlv_op_exec(cfile, &exec, snapshot, &reply, &reply_len);
	}

Why does it need two layers of the same thing?

In fact, why does the xarray exist at all? Its only purpose is to de-duplicate the parent, which seems pointless and not something a subsystem should do. Seems like it can be removed. It is confusing that the xarray gives an id but then the ctlv has an idr which then gives a different id.

drivers/attestation/core/core.c line 426

Quoted 10 lines

[ ... 146 lines skipped ... ]

drivers/attestation/core/core.c new file +9 -0
+static void __exit attestation_module_exit(void)
+{
+	WARN_ON_ONCE(!xa_empty(&attestation_instances));
+	xa_destroy(&attestation_instances);
+	ctlv_device_class_unregister(&attestation_class);
+}
+
+module_init(attestation_module_init);
+module_exit(attestation_module_exit);

subsys_init

Signature · 1 line
Jason
author
#7 lore raw

RFC PATCH v2 4/9 attestation: Prepare measurement registers

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add the fixed MRs from the provider descriptor, their lookup and MR extension, which advances an instance-wide MR generation.

The MR objects can be compile-checked here. CONFIG_ATTESTATION remains unwired until the CTLV operation handlers complete the module.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- kept the MR state in struct attestation_dev, which providers embed
- dropped the MR journal and its notifications
- counted MR changes in a plain MR generation
- retitled from "Prepare measurement register journal"
- used the helpers generated for the rewritten spec
- let an extend carry values for some of an MR's banks
- always provided mr-read with MRs

---
 drivers/attestation/Makefile        |  2 +-
 drivers/attestation/core/core.c     | 71 +++++++++++++++++++++++++++++
 drivers/attestation/core/internal.h | 13 ++++++
 drivers/attestation/core/mr.c       | 64 ++++++++++++++++++++++++++
 include/linux/attestation.h         |  5 +-
 5 files changed, 153 insertions(+), 2 deletions(-)
 create mode 100644 drivers/attestation/core/mr.c
drivers/attestation/Makefile +1 -1
index 8a75558a7013..28036586f5d8 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_ATTESTATION) += attestation.o
 
-attestation-y := core/core.o
+attestation-y := core/core.o core/mr.o
drivers/attestation/core/core.c +71 -0

105 lines not on this page · raw message

drivers/attestation/core/internal.h +13 -0
index f42bc3cd9a35..19c2ade5e6db 100644
@@ -11,11 +11,24 @@
 
 #define ATTESTATION_REGISTERED XA_MARK_1
 
+struct attestation_mr {
+	const struct attestation_mr_props *props;
+};
+
 bool attestation_registered(struct attestation_dev *att);
 void attestation_stop(struct attestation_dev *att);
+void attestation_mr_changed(struct attestation_dev *att);
 
 int attestation_provider_validate(const struct attestation_provider *provider,
 				  const struct ctlv_family *family);
 void attestation_provide_ops(struct attestation_dev *att);
 
+struct attestation_mr *attestation_mr_lookup_live(struct attestation_dev *att, unsigned int mr_id);
+int attestation_mr_values_validate(const struct attestation_mr_props *props,
+				   const struct attestation_digest_set *values, bool all_banks);
+int attestation_mr_extend_locked(struct attestation_dev *att, struct attestation_mr *mr,
+				 const struct attestation_digest_set *values);
+
+int attestation_mr_props_encode(struct ctlv_cursor *reply, const struct attestation_mr *mr);
+
 #endif /* _ATTESTATION_INTERNAL_H */
drivers/attestation/core/mr.c new file +64 -0

64 lines not on this page · raw message

include/linux/attestation.h +4 -1
index 29bb776bfb41..7745938092c7 100644
@@ -9,6 +9,7 @@
 #include <linux/device.h>
 #include <linux/mutex.h>
 #include <linux/types.h>
+#include <linux/xarray.h>
 
 #include <uapi/ctlv/ctlv_attestation_gen.h>
 #include <uapi/linux/hash_info.h>
@@ -200,9 +201,11 @@ struct attestation_dev {
 	const struct attestation_provider *provider;
 	unsigned int index;
 
-	/* Mutable instance state. */
+	/* Mutable instance and MR state. */
 	struct mutex lock;
+	unsigned int mr_generation;
 
+	struct xarray mrs;
 };
 
 /* What a CTLV callback of a family inheriting ctlv-attestation was handed. */
Signature · 1 line
2.56.0
author
#8 lore raw

RFC PATCH v2 5/9 attestation: Add CTLV operation handling

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Translate CTLV evidence and MR operations to the provider core and wire the attestation family into the kernel build.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- handed the op handlers the CTLV instance
- put resolved blobs on evidence decode errors
- continued an MR dump past an MR that does not fit
- dropped the MR log query
- dropped the total output length check and its E2BIG
- reported each evidence object's class and formats
- reported each signed object's challenge lengths as a list, and took a challenge of a length every signed object named lists
- left the MR ID and hash algorithm bounds to CTLV
- used the helpers generated for the rewritten spec
- let evidence-get omit the challenge
- took output blobs of any length
- separated the steps of the longer functions
- let mr-extend extend some of an MR's banks, in any order
- replied to mr-read in the provider's bank order
- dropped the MR read caps, as every MR can be read
- said record instead of nest, the root being one
- took evidence-get's objects by ID, and replied with each one's format and length

---
 drivers/Kconfig                 |   2 +
 drivers/Makefile                |   1 +
 drivers/attestation/Makefile    |   3 +-
 drivers/attestation/core/ctlv.c | 499 ++++++++++++++++++++++++++++++++
 4 files changed, 504 insertions(+), 1 deletion(-)
 create mode 100644 drivers/attestation/core/ctlv.c
drivers/Kconfig +2 -0
index f2bed2ddeb66..5458886b0110 100644
@@ -25,6 +25,8 @@ source "drivers/cache/Kconfig"
 
 source "drivers/connector/Kconfig"
 
+source "drivers/attestation/Kconfig"
+
 source "drivers/firmware/Kconfig"
 
 source "drivers/fwctl/Kconfig"
drivers/Makefile +1 -0
index 0841ea851847..597db8c49da9 100644
@@ -135,6 +135,7 @@ obj-$(CONFIG_MEMSTICK)		+= memstick/
 obj-$(CONFIG_INFINIBAND)	+= infiniband/
 obj-y				+= firmware/
 obj-$(CONFIG_FWCTL)		+= fwctl/
+obj-$(CONFIG_ATTESTATION)	+= attestation/
 obj-$(CONFIG_CRYPTO)		+= crypto/
 obj-$(CONFIG_SUPERH)		+= sh/
 obj-y				+= clocksource/
drivers/attestation/Makefile +2 -1
index 28036586f5d8..e4bff7633d18 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_ATTESTATION) += attestation.o
 
-attestation-y := core/core.o core/mr.o
+attestation-y := core/core.o core/ctlv.o core/mr.o \
+		 generated/ctlv_attestation_gen.o
drivers/attestation/core/ctlv.c new file +499 -0

499 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#9 lore raw

RFC PATCH v2 6/9 Documentation: attestation: Describe how to write a provider

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Describe how a provider registers with the attestation core, how other writers share its MRs and how it is torn down, with the kernel-doc of the provider API.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- split out of the provider and instance core patch
- dropped the journal from the overview
- said how other writers extend the same MRs
- added the kernel-doc to the driver API page

---
 Documentation/driver-api/attestation.rst    | 99 +++++++++++++++++++++
 Documentation/driver-api/index.rst          |  1 +
 Documentation/userspace-api/attestation.rst |  3 +-
 MAINTAINERS                                 |  1 +
 4 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/driver-api/attestation.rst
Documentation/driver-api/attestation.rst new file +99 -0
new file mode 100644
index 000000000000..4137a856aea9
@@ -0,0 +1,99 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+===========
+Attestation
+===========
+
+The attestation subsystem gives each provider device a node of the
+``attestation`` class, ``/dev/attestation/attestationN``, which answers as a
+descendant of the ``ctlv-attestation`` family, one family per provider.  A
+program tells providers apart by the last entry of ``family-get`` on the
+open device, and generic tools use the ``ctlv-attestation`` operations on any
+of them.  The subsystem owns common evidence retrieval and
+measurement-register topology.  Providers retain ownership of native hardware
+access and immutable capability descriptions.
+
+Registering a provider
+======================
+
+A provider embeds ``struct attestation_dev`` first in its own structure and
+allocates both with ``attestation_alloc()``, passing its
+``struct attestation_provider`` and its family descriptor, which inherits
+``ctlv-attestation``:
+
+.. code-block:: c
+
+    struct foo {
+            struct attestation_dev att;
+            struct foo_hw *hw;
+    };
+
+    foo = attestation_alloc(parent, &foo_provider,
+                            &ctlv_attestation_foo_family, struct foo, att);
+    if (IS_ERR(foo))
+            return PTR_ERR(foo);
+    foo->hw = hw;
+    ret = attestation_register(&foo->att);
+    if (ret) {
+            attestation_put(&foo->att);
+            return ret;
+    }
+
+A provider callback gets the ``struct attestation_dev`` and reaches the
+provider's structure with ``container_of()``.  A CTLV callback of the
+provider's own family gets the CTLV instance, which
+``attestation_from_ctlv()`` turns into the device.  No provider callback runs
+before ``attestation_register()``, so the provider finishes its own setup in
+between.  The descriptor, evidence capabilities, fixed MR properties, strings
+and arrays remain immutable until the last ``attestation_put()``.
+
+The subsystem embeds the CTLV instance, and its hooks run every operation,
+those of the device's family included, under one instance mutex.  That
+serializes an operation and its native callback.
+
+Every MR can be read, so a provider with MRs implements ``mr_read``.
+Fixed MRs are listed in the provider descriptor.  Their property storage
+remains valid until the last ``attestation_put()``.
+
+The evidence capabilities list the objects ``evidence-get`` produces, each
+object's ID being its index.  An object gives its class and the formats it
+may have, ``ctlv-attestation``'s ``evidence-format`` or its family's
+``evidence-vendor-format``, and a signed object its challenge lengths.
+``attestation_alloc()`` refuses a format the family does not give.
+
+``evidence_get`` writes each object with ``attestation_evidence_write()``,
+which fails the operation with ``-EMSGSIZE`` where the caller's blob is too
+short, and tells the caller how long it has to be.  It fills in each object's
+result: the format written and its length.  A format the object does not list
+fails the call with ``-EPROTO``.
+
+Other writers
+=============
+
+This interface is not the only way to extend a measurement register, and it
+does not arbitrate between the ways there are.  Every program holding a
+read-write descriptor of the device can extend a register through
+``mr-extend``, and a register with a native interface of its own can be
+extended through that too, as a TPM's PCRs are by programs using
+``/dev/tpm0`` or ``/dev/tpmrm0`` and by IMA.  Nothing reserves a register for
+one writer.  A register two writers extend holds the extensions of both, in
+the order they arrived, and ``mr-read`` and the evidence report it as it is.
+A program that replays a register from its own records has to be its only
+writer, by agreement with whatever else runs on the system.
+
+Teardown
+========
+
+``attestation_unregister()`` first removes the node, so nothing opens the
+device again.  It then withdraws the device from the kernel registry, refusing
+the operations of files still open.  Only then does it unpublish the CTLV
+instance, which drains the operations in flight.  No provider callback runs
+once it returns, so the provider may release its native state before
+``attestation_put()``.  Open files keep the structure until they close.
+
+Kernel API
+==========
+
+.. kernel-doc:: include/linux/attestation.h
+.. kernel-doc:: drivers/attestation/core/core.c
+   :export:
Documentation/driver-api/index.rst +1 -0
index 0c5b9d2165d8..625355c504ef 100644
@@ -38,6 +38,7 @@ of interest to most developers working on device drivers.
    early-userspace/index
    connector
    ctlv
+   attestation
    device-io
    devfreq
    dma-buf
Documentation/userspace-api/attestation.rst +2 -1
index 3c610acc3382..16646d8b60d7 100644
@@ -16,7 +16,8 @@ The node speaks CTLV, described in :doc:`ctlv`, as a descendant of the
 belongs to ``ctlv-attestation``, so a tool written against it works with any
 provider. The specification is
 ``Documentation/ctlv/specs/ctlv-attestation.yaml`` and the constants are in
-``include/uapi/ctlv/ctlv_attestation_gen.h``.
+``include/uapi/ctlv/ctlv_attestation_gen.h``. Writing a provider is
+:doc:`/driver-api/attestation`.
 
 ======================  ======  ==========  ================================
 Operation               Type    Access      Purpose
MAINTAINERS +1 -0
index e57fc8bb9c1d..172b20d5fdd1 100644
@@ -4439,6 +4439,7 @@ L:	[email protected]
 S:	Supported
 F:	Documentation/ctlv/abi/ctlv-attestation*
 F:	Documentation/ctlv/specs/ctlv-attestation*
+F:	Documentation/driver-api/attestation.rst
 F:	Documentation/userspace-api/attestation*.rst
 F:	drivers/attestation/
 F:	include/linux/attestation*
Signature · 1 line
2.56.0
author
#10 lore raw

RFC PATCH v2 7/9 tdx-guest: Expose the native attestation service API

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Factor the Quote and measurement-register operations of the misc, TSM report and TSM MR interfaces into helpers declared in a driver-internal header, for an attestation provider built into the driver to share.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- kept the helpers inside tdx-guest, in place of a client API and its header
- dropped the MAINTAINERS lines, which N: tdx already covers
- sized the TSM report outblob to its Quote
- dropped an unreachable return in tdx_do_report()
- dropped the stale kernel client section from tdx-guest.rst
- numbered every enum member

---
 drivers/virt/coco/tdx-guest/internal.h  |  30 ++++++
 drivers/virt/coco/tdx-guest/tdx-guest.c | 130 +++++++++++++++++++-----
 2 files changed, 132 insertions(+), 28 deletions(-)
 create mode 100644 drivers/virt/coco/tdx-guest/internal.h
drivers/virt/coco/tdx-guest/internal.h new file +30 -0
new file mode 100644
index 000000000000..d57a8c385aff
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _TDX_GUEST_INTERNAL_H
+#define _TDX_GUEST_INTERNAL_H
+
+#include <crypto/sha2.h>
+#include <linux/types.h>
+
+#define TDX_GUEST_QUOTE_MAX_LEN ((128 * 1024) - 24)
+
+struct tdx_guest_info {
+	u8 mrconfigid[SHA384_DIGEST_SIZE];
+	u8 mrowner[SHA384_DIGEST_SIZE];
+	u8 mrownerconfig[SHA384_DIGEST_SIZE];
+};
+
+enum tdx_guest_mr {
+	TDX_GUEST_MR_MRTD = 0,
+	TDX_GUEST_MR_RTMR0 = 1,
+	TDX_GUEST_MR_RTMR1 = 2,
+	TDX_GUEST_MR_RTMR2 = 3,
+	TDX_GUEST_MR_RTMR3 = 4,
+};
+
+/* @reportdata is TDX_REPORTDATA_LEN bytes, and @out holds TDX_GUEST_QUOTE_MAX_LEN. */
+int tdx_guest_quote_get(const u8 *reportdata, void *out, size_t *out_length);
+int tdx_guest_mr_read(enum tdx_guest_mr mr, u8 value[SHA384_DIGEST_SIZE]);
+int tdx_guest_rtmr_extend(unsigned int rtmr,
+			  const u8 value[SHA384_DIGEST_SIZE]);
+
+#endif /* _TDX_GUEST_INTERNAL_H */
drivers/virt/coco/tdx-guest/tdx-guest.c +102 -28

205 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#11 lore raw

RFC PATCH v2 8/9 attestation: Add the TDX family specification and generated files

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Define the TDX attestation family and reserve family ID 2. Add its ABI snapshot, registry entry and generated kernel and UAPI files.

The ABI is intentionally specification-first. The generated descriptor is linked with the provider implementation in the following patch.

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- generated the kernel files into drivers/virt/coco/tdx-guest/
- dropped the family's priv lifecycle hook
- generated an extension fill in place of a stub fill
- wrote the spec as op trees and records
- numbered every enum member
- moved the generated UAPI headers to include/uapi/ctlv/
- documented every item of the spec
- put each field's doc above its generated helpers
- gave the legacy and DICE Quote formats as evidence-vendor-format values
- said message instead of wire

---
 .../ctlv/abi/ctlv-attestation-tdx.yaml        | 21 ++++++
 Documentation/ctlv/abi/families.registry.yaml |  1 +
 Documentation/ctlv/families.yaml              |  1 +
 Documentation/ctlv/generated-files.yaml       |  7 ++
 .../ctlv/specs/ctlv-attestation-tdx.yaml      | 25 +++++++
 MAINTAINERS                                   |  1 +
 .../coco/tdx-guest/ctlv_attestation_tdx_gen.c | 65 +++++++++++++++++++
 .../coco/tdx-guest/ctlv_attestation_tdx_gen.h | 44 +++++++++++++
 include/uapi/ctlv/ctlv_attestation_tdx_gen.h  | 42 ++++++++++++
 include/uapi/ctlv/ctlv_families_gen.h         |  1 +
 10 files changed, 208 insertions(+)
 create mode 100644 Documentation/ctlv/abi/ctlv-attestation-tdx.yaml
 create mode 100644 Documentation/ctlv/specs/ctlv-attestation-tdx.yaml
 create mode 100644 drivers/virt/coco/tdx-guest/ctlv_attestation_tdx_gen.c
 create mode 100644 drivers/virt/coco/tdx-guest/ctlv_attestation_tdx_gen.h
 create mode 100644 include/uapi/ctlv/ctlv_attestation_tdx_gen.h
Documentation/ctlv/abi/ctlv-attestation-tdx.yaml new file +21 -0
new file mode 100644
index 000000000000..f8dc3c085c71
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
+---
+# Checked-in ABI snapshot of the ctlv-attestation-tdx family, from
+# Documentation/ctlv/specs/ctlv-attestation-tdx.yaml, written by
+# "make -C tools/ctlv regen".
+#
+# Updating the file is how a UAPI change gets reviewed; an update that
+# removes or renumbers anything, narrows a bound, or makes a member required
+# is an ABI break, whatever the file says afterwards.
+family: {name: ctlv-attestation-tdx, id: 2, inherits: ctlv-attestation}
+enums:
+  evidence-vendor-format: {quote: 1, quote-dice: 2}
+records:
+  device-info:
+    id: 0x00010000
+    fields:
+      mrconfigid: {number: 1, type: binary, length: 48}
+      mrowner: {number: 2, type: binary, length: 48}
+      mrownerconfig: {number: 3, type: binary, length: 48}
+fills: {device-info: device-info}
Documentation/ctlv/abi/families.registry.yaml +1 -0
index 7a5c6af29565..0f55cc4f2e35 100644
@@ -6,3 +6,4 @@
 families:
   - ctlv
   - ctlv-attestation
+  - ctlv-attestation-tdx
Documentation/ctlv/families.yaml +1 -0
index dbb0243b873d..27bafae3ca66 100644
@@ -16,3 +16,4 @@
 families:
   - ctlv
   - ctlv-attestation
+  - ctlv-attestation-tdx
Documentation/ctlv/generated-files.yaml +7 -0
index 00a56634805d..e78997f13334 100644
@@ -23,3 +23,10 @@ families:
       uapi-header: include/uapi/ctlv/ctlv_attestation_gen.h
       kernel-header: drivers/attestation/generated/ctlv_attestation_gen.h
       kernel-source: drivers/attestation/generated/ctlv_attestation_gen.c
+
+  - name: ctlv-attestation-tdx
+    source: Documentation/ctlv/specs/ctlv-attestation-tdx.yaml
+    outputs:
+      uapi-header: include/uapi/ctlv/ctlv_attestation_tdx_gen.h
+      kernel-header: drivers/virt/coco/tdx-guest/ctlv_attestation_tdx_gen.h
+      kernel-source: drivers/virt/coco/tdx-guest/ctlv_attestation_tdx_gen.c
Documentation/ctlv/specs/ctlv-attestation-tdx.yaml new file +25 -0
new file mode 100644
index 000000000000..0093015b4991
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
+---
+# The attestation device of an Intel TDX guest: Quotes of its TDREPORT, the
+# CCEL event log, MRTD and RTMR0 to RTMR3.
+family: ctlv-attestation-tdx
+inherits: ctlv-attestation
+
+enums:
+  # Fills ctlv-attestation's evidence-vendor-format.
+  evidence-vendor-format:
+    # An Intel TDX DCAP Quote, from the host's quoting enclave.
+    - quote
+    # A DICE-based TDX Quote, an EAT in a CBOR Web Token.
+    - quote-dice
+
+records:
+  # Fills ctlv-attestation's device-info.
+  device-info:
+    # MRCONFIGID of the TD, the ID of its non-owner configuration.
+    mrconfigid: binary(48)
+    # MROWNER of the TD, the ID of its owner.
+    mrowner: binary(48)
+    # MROWNERCONFIG of the TD, the ID of its owner's configuration.
+    mrownerconfig: binary(48)
MAINTAINERS +1 -0
index 172b20d5fdd1..0734efa1a78f 100644
@@ -4442,6 +4442,7 @@ F:	Documentation/ctlv/specs/ctlv-attestation*
 F:	Documentation/driver-api/attestation.rst
 F:	Documentation/userspace-api/attestation*.rst
 F:	drivers/attestation/
+F:	drivers/virt/coco/tdx-guest/*attestation*
 F:	include/linux/attestation*
 F:	include/uapi/ctlv/ctlv_attestation*
 
drivers/virt/coco/tdx-guest/ctlv_attestation_tdx_gen.c new file +65 -0

65 lines not on this page · raw message

drivers/virt/coco/tdx-guest/ctlv_attestation_tdx_gen.h new file +44 -0

44 lines not on this page · raw message

include/uapi/ctlv/ctlv_attestation_tdx_gen.h new file +42 -0

42 lines not on this page · raw message

include/uapi/ctlv/ctlv_families_gen.h +1 -0
index 83f6a257ddf2..849671f8681d 100644
@@ -13,6 +13,7 @@
 enum _ctlv_family {
 	CTLV_FAMILY_ROOT = 0,
 	CTLV_FAMILY_ATTESTATION = 1,
+	CTLV_FAMILY_ATTESTATION_TDX = 2,
 };
 
 #endif /* _UAPI_CTLV_CTLV_FAMILIES_GEN_H */
Signature · 1 line
2.56.0
author
#12 lore raw

RFC PATCH v2 9/9 attestation: Add the TDX family implementation

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Build the TDX attestation provider into tdx-guest when attestation is enabled. Expose the Quote, MRTD and RTMR operations through the same helpers as the native interfaces, which stay as they are, and label each Quote as a legacy or a DICE one by its first bytes [1]. Where ACPI describes a CCEL table, also return the firmware's event log as evidence, for a verifier replaying the RTMRs.

[1] https://lore.kernel.org/all/[email protected]/

Assisted-by Cursor: GPT-5.6 Sol
Assisted-by Cursor: Claude Opus 5.5

---
RFC->RFCv2:
- built the provider into tdx-guest in place of the attestation-tdx module
- embedded struct attestation_dev in the provider's state
- accounted the evidence buffer to its caller's memcg
- dropped the MR-journal boundary claim from the TDX documentation
- returned the CCEL event log as an event-log evidence object
- dropped the total output length
- documented the provider as part of tdx-guest
- reported the 64-byte challenge length as a list entry
- used the helpers generated for the rewritten spec
- wrote the evidence objects with attestation_evidence_write()
- dropped the RTMR read caps, as every MR can be read
- said record instead of nest, the root being one
- took the UAPI headers from include/uapi/ctlv/
- dropped the TDREPORT evidence object, which /dev/tdx_guest keeps, and labelled each Quote as a legacy or a DICE one
- described the provider for userspace in a document of its own

---
 .../userspace-api/attestation-tdx.rst         |  59 ++++
 Documentation/userspace-api/attestation.rst   |  10 +
 Documentation/virt/coco/tdx-guest.rst         |   8 +
 drivers/attestation/Kconfig                   |   4 +
 drivers/virt/coco/tdx-guest/Kconfig           |   4 +-
 drivers/virt/coco/tdx-guest/Makefile          |   6 +
 drivers/virt/coco/tdx-guest/attestation.c     | 313 ++++++++++++++++++
 drivers/virt/coco/tdx-guest/internal.h        |  18 +
 .../coco/tdx-guest/{tdx-guest.c => main.c}    |   7 +
 9 files changed, 428 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/userspace-api/attestation-tdx.rst
 create mode 100644 drivers/virt/coco/tdx-guest/attestation.c
 rename drivers/virt/coco/tdx-guest/{tdx-guest.c => main.c} (98%)
Documentation/userspace-api/attestation-tdx.rst new file +59 -0
new file mode 100644
index 000000000000..ca0ed209143b
@@ -0,0 +1,59 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===============
+TDX attestation
+===============
+
+With ``CONFIG_ATTESTATION``, the TDX guest driver registers an attestation
+device of the ``ctlv-attestation-tdx`` family, whose specification is
+``Documentation/ctlv/specs/ctlv-attestation-tdx.yaml``. Its ``device-info``,
+the ``info`` of ``device-get``, carries ``mrconfigid``, ``mrowner`` and
+``mrownerconfig``, 48 bytes each.
+
+Measurement registers
+=====================
+
+==  =====  ==============  =======  ======
+ID  Name   Register index  Bank     Extend
+==  =====  ==============  =======  ======
+0   mrtd   none            SHA-384  no
+1   rtmr0  0               SHA-384  yes
+2   rtmr1  1               SHA-384  yes
+3   rtmr2  2               SHA-384  yes
+4   rtmr3  3               SHA-384  yes
+==  =====  ==============  =======  ======
+
+Each ``mr-read`` takes a TDREPORT.
+
+The TSM-MR files,
+``/sys/devices/virtual/misc/tdx_guest/measurements/rtmr[0123]:sha384``, extend
+the same RTMRs as ``mr-extend``. Firmware and the boot loader usually extend
+RTMR0 to RTMR2 before the kernel starts, which leaves RTMR3 to the running
+system.
+
+Evidence
+========
+
+==  ========  =========  =================  =========  ========
+ID  Object    Class      Formats            Challenge  Binds
+==  ========  =========  =================  =========  ========
+0   Quote     signed     quote, quote-dice  64 bytes   every MR
+1   CCEL log  event-log  ccel               none       no MR
+==  ========  =========  =================  =========  ========
+
+The challenge goes into the REPORTDATA the Quote carries. The host's quoting
+service returns a DCAP Quote or a DICE-based one, and the device names it
+``quote`` by its header's version and TEE type, or ``quote-dice`` by the CBOR
+magic it starts with. Both are ``ctlv-attestation-tdx``'s vendor formats. A
+Quote of neither fails ``evidence-get`` with ``EPROTO``.
+
+The log is there where the firmware describes its CC event log with an ACPI
+CCEL table, and is the whole log area. It does not change after boot, and one
+call returns it with the Quote.
+
+The TDREPORT is MAC'd for the platform, not signed, so it is no object;
+``TDX_CMD_GET_REPORT0`` of ``/dev/tdx_guest`` returns it.
+
+A guest has one TDX device, which a udev rule can give a stable name::
+
+    ENV{CTLV_FAMILY}=="ctlv-attestation-tdx", SYMLINK+="attestation/tdx"
Documentation/userspace-api/attestation.rst +10 -0
index 16646d8b60d7..32ecaf5cba35 100644
@@ -282,3 +282,13 @@ The reply carries ``mr-generation``, the MR generation after the extension.
     have or repeats one, or a digest has the wrong length.
 
 Access is read-write.
+
+Providers
+=========
+
+What each provider's family adds, and what its device produces:
+
+.. toctree::
+   :maxdepth: 1
+
+   attestation-tdx
Documentation/virt/coco/tdx-guest.rst +8 -0
index 46e316db6bb4..16afc8e5a6ef 100644
@@ -50,3 +50,11 @@ TDX reference material is collected here:
 https://www.intel.com/content/www/us/en/developer/articles/technical/intel-trust-domain-extensions.html
 
 The driver is based on TDX module specification v1.0 and TDX GHCI specification v1.0.
+
+Attestation device
+==================
+
+With ``CONFIG_ATTESTATION``, the driver also registers an attestation device,
+described in Documentation/userspace-api/attestation-tdx.rst. It shares the
+TDREPORT, Quote and RTMR paths, and their locks, with the misc ioctl, the
+TSM-report configfs interface and the TSM-MR sysfs attributes.
drivers/attestation/Kconfig +4 -0
index a6bfb17dd480..4307b28e679e 100644
@@ -10,3 +10,7 @@ menuconfig ATTESTATION
 	  translate the common operations to their native service.
 
 	  If you are unsure, say N.
+
+if ATTESTATION
+
+endif # ATTESTATION
drivers/virt/coco/tdx-guest/Kconfig +3 -1
index dbbdc14383b1..aa6687979a6f 100644
@@ -1,12 +1,14 @@
 config TDX_GUEST_DRIVER
 	tristate "TDX Guest driver"
 	depends on INTEL_TDX_GUEST
+	depends on ATTESTATION || !ATTESTATION
 	select TSM_REPORTS
 	select TSM_MEASUREMENTS
 	help
 	  The driver provides userspace interface to communicate with
 	  the TDX module to request the TDX guest details like attestation
-	  report.
+	  report. With ATTESTATION, it also registers a TDX attestation
+	  device.
 
 	  To compile this driver as module, choose M here. The module will
 	  be called tdx-guest.
drivers/virt/coco/tdx-guest/Makefile +6 -0
index 775cb463f9c8..027cc16e1df3 100644
@@ -1,2 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_TDX_GUEST_DRIVER) += tdx-guest.o
+
+tdx-guest-y := main.o
+tdx-guest-$(CONFIG_ATTESTATION) += attestation.o ctlv_attestation_tdx_gen.o
+
+# The generated family header includes its parent's.
+ccflags-y += -I $(srctree)/drivers/attestation/generated
drivers/virt/coco/tdx-guest/attestation.c new file +313 -0

313 lines not on this page · raw message

drivers/virt/coco/tdx-guest/internal.h +18 -0
index d57a8c385aff..fc10e68d231a 100644
@@ -5,6 +5,8 @@
 #include <crypto/sha2.h>
 #include <linux/types.h>
 
+struct device;
+
 #define TDX_GUEST_QUOTE_MAX_LEN ((128 * 1024) - 24)
 
 struct tdx_guest_info {
@@ -27,4 +29,20 @@ int tdx_guest_mr_read(enum tdx_guest_mr mr, u8 value[SHA384_DIGEST_SIZE]);
 int tdx_guest_rtmr_extend(unsigned int rtmr,
 			  const u8 value[SHA384_DIGEST_SIZE]);
 
+#if IS_ENABLED(CONFIG_ATTESTATION)
+int tdx_attestation_register(struct device *parent,
+			     const struct tdx_guest_info *info);
+void tdx_attestation_unregister(void);
+#else
+static inline int tdx_attestation_register(struct device *parent,
+					   const struct tdx_guest_info *info)
+{
+	return 0;
+}
+
+static inline void tdx_attestation_unregister(void)
+{
+}
+#endif
+
 #endif /* _TDX_GUEST_INTERNAL_H */
drivers/virt/coco/tdx-guest/main.c renamed from drivers/virt/coco/tdx-guest/tdx-guest.c +7 -0
similarity index 98%
rename from drivers/virt/coco/tdx-guest/tdx-guest.c
rename to drivers/virt/coco/tdx-guest/main.c
index c49454ec0b18..bcda631a0232 100644
@@ -522,6 +522,12 @@ static int __init tdx_guest_init(void)
 	if (ret)
 		goto free_quote;
 
+	/* The other interfaces stay up without the attestation device. */
+	ret = tdx_attestation_register(tdx_misc_dev.this_device,
+				       &tdx_guest_info);
+	if (ret)
+		pr_warn("attestation device registration failed: %d\n", ret);
+
 	return 0;
 
 free_quote:
@@ -537,6 +543,7 @@ module_init(tdx_guest_init);
 
 static void __exit tdx_guest_exit(void)
 {
+	tdx_attestation_unregister();
 	tsm_report_unregister(&tdx_tsm_ops);
 	free_quote_buf(quote_buf);
 	misc_deregister(&tdx_misc_dev);
Signature · 1 line
2.56.0
#13 lore raw

Re: [PATCH RFC v2 9/9] attestation: Add the TDX family implementation

Hi Jiri,

[...]

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+static void __iomem *tdx_attestation_log_map(size_t *length)
+{
+	struct acpi_table_header *header;
+	struct acpi_table_ccel *ccel;
+	void __iomem *log = NULL;
+
+	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_CCEL, 0, &header)))
+		return NULL;
+	ccel = container_of(header, struct acpi_table_ccel, header);
+	if (header->length >= sizeof(*ccel) && ccel->log_area_start_address &&

drivers/virt/coco/tdx-guest/attestation.c line 162

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+	    ccel->log_area_minimum_length &&
+	    ccel->log_area_minimum_length <= UINT_MAX)
+		log = acpi_os_map_iomem(ccel->log_area_start_address,
+					ccel->log_area_minimum_length);
+	if (log)
+		*length = ccel->log_area_minimum_length;
+	acpi_put_table(header);
+	return log;
+}
+

I think we don't need to dump log area with the log_area_minimum_length since the area would include none-event otherwise, pre-exist tool (i.e. tpm2_eventlog) reports error for them like:

...
- EventNum: 21
PCRIndex: 2
EventType: EV_EFI_ACTION
DigestCount: 1
Digests:
- AlgorithmId: sha256
Digest: "b54f7542cbd872a81a9d9dea839b2b8d747c7ebd5ea6615c40f42f44a6dbeba0"
EventSize: 40
Event: |-
Exit Boot Services Returned with Success
ERROR: corrupted log, insufficient size for event header: 3
ERROR: failed to parse tpm2 eventlog
ERROR: Unable to run tpm2_eventlog

So, what about export *real size* of eventlog like tpm2_calc_event_log_size()?

Otherwise, look good to me.

[...]

Thanks!

Signature · 2 lines
Sincerely,
Yeoreum Yun
#14 lore raw

Re: [PATCH RFC v2 9/9] attestation: Add the TDX family implementation

Quoted 45 lines · Yeoreum Yun

Hi Jiri,

[...]

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+static void __iomem *tdx_attestation_log_map(size_t *length)
+{
+	struct acpi_table_header *header;
+	struct acpi_table_ccel *ccel;
+	void __iomem *log = NULL;
+
+	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_CCEL, 0, &header)))
+		return NULL;
+	ccel = container_of(header, struct acpi_table_ccel, header);
+	if (header->length >= sizeof(*ccel) && ccel->log_area_start_address &&

drivers/virt/coco/tdx-guest/attestation.c line 162

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+	    ccel->log_area_minimum_length &&
+	    ccel->log_area_minimum_length <= UINT_MAX)
+		log = acpi_os_map_iomem(ccel->log_area_start_address,
+					ccel->log_area_minimum_length);
+	if (log)
+		*length = ccel->log_area_minimum_length;
+	acpi_put_table(header);
+	return log;
+}
+

I think we don't need to dump log area with the log_area_minimum_length since the area would include none-event otherwise, pre-exist tool (i.e. tpm2_eventlog) reports error for them like:

...
- EventNum: 21
PCRIndex: 2
EventType: EV_EFI_ACTION
DigestCount: 1
Digests:
- AlgorithmId: sha256
Digest: "b54f7542cbd872a81a9d9dea839b2b8d747c7ebd5ea6615c40f42f44a6dbeba0"
EventSize: 40
Event: |-
Exit Boot Services Returned with Success
ERROR: corrupted log, insufficient size for event header: 3
ERROR: failed to parse tpm2 eventlog
ERROR: Unable to run tpm2_eventlog

Quoted 2 lines

So, what about export *real size* of eventlog like tpm2_calc_event_log_size()?

Nothing in the patch (neither commit message nor any comment in code) says that TDX attestion registers share the same format as TPM2 even log.

I was just trying to understand where does this derive from but since there is no reference, I'm confused.

As per the function, perhaps tpm2_calc_event_log_size() should be relocated to lib and have non-TPM name like firmware_event_log_size() or something.

Quoted 12 lines

Otherwise, look good to me.

[...]

Thanks!

Signature · 2 lines
Sincerely,
Yeoreum Yun

Br, Jarkko

#15 lore raw

Re: [PATCH RFC v2 9/9] attestation: Add the TDX family implementation

Quoted 46 lines · Jarkko Sakkinen
Quoted 45 lines · Yeoreum Yun

Hi Jiri,

[...]

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+static void __iomem *tdx_attestation_log_map(size_t *length)
+{
+	struct acpi_table_header *header;
+	struct acpi_table_ccel *ccel;
+	void __iomem *log = NULL;
+
+	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_CCEL, 0, &header)))
+		return NULL;
+	ccel = container_of(header, struct acpi_table_ccel, header);
+	if (header->length >= sizeof(*ccel) && ccel->log_area_start_address &&

drivers/virt/coco/tdx-guest/attestation.c line 162

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+	    ccel->log_area_minimum_length &&
+	    ccel->log_area_minimum_length <= UINT_MAX)
+		log = acpi_os_map_iomem(ccel->log_area_start_address,
+					ccel->log_area_minimum_length);
+	if (log)
+		*length = ccel->log_area_minimum_length;
+	acpi_put_table(header);
+	return log;
+}
+

I think we don't need to dump log area with the log_area_minimum_length since the area would include none-event otherwise, pre-exist tool (i.e. tpm2_eventlog) reports error for them like:

...
- EventNum: 21
PCRIndex: 2
EventType: EV_EFI_ACTION
DigestCount: 1
Digests:
- AlgorithmId: sha256
Digest: "b54f7542cbd872a81a9d9dea839b2b8d747c7ebd5ea6615c40f42f44a6dbeba0"
EventSize: 40
Event: |-
Exit Boot Services Returned with Success
ERROR: corrupted log, insufficient size for event header: 3
ERROR: failed to parse tpm2 eventlog
ERROR: Unable to run tpm2_eventlog

Quoted 6 lines
Quoted 2 lines

So, what about export *real size* of eventlog like tpm2_calc_event_log_size()?

Nothing in the patch (neither commit message nor any comment in code) says that TDX attestion registers share the same format as TPM2 even log.

It comes from the UEFI spec's definition of CCEL:

38.1 Virtual Platform CC Event Log

If a virtual firmware with confidential computing (CC) capability supports measurement and an event is created, virtual firmware should report the event log with the same data structure in TCG Platform Firmware Profile (PFP) specification with EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 format. The index created by the virtual firmware in the event log should be the index for the confidential computing (CC) measurement register. It is CC vendor specific.

It makes sense that the kernel would size it correctly.

Quoted 3 lines

As per the function, perhaps tpm2_calc_event_log_size() should be relocated to lib and have non-TPM name like firmware_event_log_size() or something.

Probably under drivers/attestation since that is where all the TCG formatted logs should end up. It should be 'tcg_event_log_size()' or something. Maybe a tiny module for it like we would have done in lib/

Jason

#16 lore raw

Re: [PATCH RFC v2 9/9] attestation: Add the TDX family implementation

Quoted 69 lines · Jason Gunthorpe
Quoted 46 lines · Jarkko Sakkinen
Quoted 45 lines · Yeoreum Yun

Hi Jiri,

[...]

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+static void __iomem *tdx_attestation_log_map(size_t *length)
+{
+	struct acpi_table_header *header;
+	struct acpi_table_ccel *ccel;
+	void __iomem *log = NULL;
+
+	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_CCEL, 0, &header)))
+		return NULL;
+	ccel = container_of(header, struct acpi_table_ccel, header);
+	if (header->length >= sizeof(*ccel) && ccel->log_area_start_address &&

drivers/virt/coco/tdx-guest/attestation.c line 162

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+	    ccel->log_area_minimum_length &&
+	    ccel->log_area_minimum_length <= UINT_MAX)
+		log = acpi_os_map_iomem(ccel->log_area_start_address,
+					ccel->log_area_minimum_length);
+	if (log)
+		*length = ccel->log_area_minimum_length;
+	acpi_put_table(header);
+	return log;
+}
+

I think we don't need to dump log area with the log_area_minimum_length since the area would include none-event otherwise, pre-exist tool (i.e. tpm2_eventlog) reports error for them like:

...
- EventNum: 21
PCRIndex: 2
EventType: EV_EFI_ACTION
DigestCount: 1
Digests:
- AlgorithmId: sha256
Digest: "b54f7542cbd872a81a9d9dea839b2b8d747c7ebd5ea6615c40f42f44a6dbeba0"
EventSize: 40
Event: |-
Exit Boot Services Returned with Success
ERROR: corrupted log, insufficient size for event header: 3
ERROR: failed to parse tpm2 eventlog
ERROR: Unable to run tpm2_eventlog

Quoted 6 lines
Quoted 2 lines

So, what about export *real size* of eventlog like tpm2_calc_event_log_size()?

Nothing in the patch (neither commit message nor any comment in code) says that TDX attestion registers share the same format as TPM2 even log.

It comes from the UEFI spec's definition of CCEL:

38.1 Virtual Platform CC Event Log

If a virtual firmware with confidential computing (CC) capability supports measurement and an event is created, virtual firmware should report the event log with the same data structure in TCG Platform Firmware Profile (PFP) specification with EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 format. The index created by the virtual firmware in the event log should be the index for the confidential computing (CC) measurement register. It is CC vendor specific.

It makes sense that the kernel would size it correctly.

Quoted 7 lines
Quoted 3 lines

As per the function, perhaps tpm2_calc_event_log_size() should be relocated to lib and have non-TPM name like firmware_event_log_size() or something.

Probably under drivers/attestation since that is where all the TCG formatted logs should end up. It should be 'tcg_event_log_size()' or something. Maybe a tiny module for it like we would have done in lib/

+1 for the name, as it is obviously more accurate prefix.

Quoted 2 lines

Jason

Br, Jarkko

#17 lore raw

Re: [PATCH RFC v2 9/9] attestation: Add the TDX family implementation

Quoted 74 lines · Jarkko Sakkinen
Quoted 73 lines · Jason Gunthorpe
Quoted 46 lines · Jarkko Sakkinen
Quoted 45 lines · Yeoreum Yun

Hi Jiri,

[...]

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+static void __iomem *tdx_attestation_log_map(size_t *length)
+{
+	struct acpi_table_header *header;
+	struct acpi_table_ccel *ccel;
+	void __iomem *log = NULL;
+
+	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_CCEL, 0, &header)))
+		return NULL;
+	ccel = container_of(header, struct acpi_table_ccel, header);
+	if (header->length >= sizeof(*ccel) && ccel->log_area_start_address &&

drivers/virt/coco/tdx-guest/attestation.c line 162

Quoted 10 lines
drivers/virt/coco/tdx-guest/attestation.c new file +10 -0
+	    ccel->log_area_minimum_length &&
+	    ccel->log_area_minimum_length <= UINT_MAX)
+		log = acpi_os_map_iomem(ccel->log_area_start_address,
+					ccel->log_area_minimum_length);
+	if (log)
+		*length = ccel->log_area_minimum_length;
+	acpi_put_table(header);
+	return log;
+}
+

I think we don't need to dump log area with the log_area_minimum_length since the area would include none-event otherwise, pre-exist tool (i.e. tpm2_eventlog) reports error for them like:

...
- EventNum: 21
PCRIndex: 2
EventType: EV_EFI_ACTION
DigestCount: 1
Digests:
- AlgorithmId: sha256
Digest: "b54f7542cbd872a81a9d9dea839b2b8d747c7ebd5ea6615c40f42f44a6dbeba0"
EventSize: 40
Event: |-
Exit Boot Services Returned with Success
ERROR: corrupted log, insufficient size for event header: 3
ERROR: failed to parse tpm2 eventlog
ERROR: Unable to run tpm2_eventlog

Quoted 6 lines
Quoted 2 lines

So, what about export *real size* of eventlog like tpm2_calc_event_log_size()?

Nothing in the patch (neither commit message nor any comment in code) says that TDX attestion registers share the same format as TPM2 even log.

It comes from the UEFI spec's definition of CCEL:

38.1 Virtual Platform CC Event Log

If a virtual firmware with confidential computing (CC) capability supports measurement and an event is created, virtual firmware should report the event log with the same data structure in TCG Platform Firmware Profile (PFP) specification with EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 format. The index created by the virtual firmware in the event log should be the index for the confidential computing (CC) measurement register. It is CC vendor specific.

It makes sense that the kernel would size it correctly.

Quoted 3 lines

As per the function, perhaps tpm2_calc_event_log_size() should be relocated to lib and have non-TPM name like firmware_event_log_size() or something.

Quoted 5 lines
Quoted 3 lines

Probably under drivers/attestation since that is where all the TCG formatted logs should end up. It should be 'tcg_event_log_size()' or something. Maybe a tiny module for it like we would have done in lib/

+1 for the name, as it is obviously more accurate prefix.

Location, I don't know. I was thinking something like "lib/tcg.c" with routines that are plain calculations based on TCG/TPM data. And perhaps for tpm_buf (both stack/heap allocatable), if Trenchboot ever moves forward.

Br, Jarkko

#18 lore raw

Re: [PATCH RFC v2 9/9] attestation: Add the TDX family implementation

Quoted 4 lines · Jarkko Sakkinen
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

As per the function, perhaps tpm2_calc_event_log_size() should be relocated to lib and have non-TPM name like firmware_event_log_size() or something.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Probably under drivers/attestation since that is where all the TCG formatted logs should end up. It should be 'tcg_event_log_size()' or something. Maybe a tiny module for it like we would have done in lib/

+1 for the name, as it is obviously more accurate prefix.

Location, I don't know. I was thinking something like "lib/tcg.c" with routines that are plain calculations based on TCG/TPM data.

I think we should not have new users outside attestation subsystem, but the legacy onces will still exist obviously..

IDK either, but this is my guess..

Quoted 2 lines

And perhaps for tpm_buf (both stack/heap allocatable), if Trenchboot ever moves forward.

DRTM users will route through attestation subsystem to do their extends so the tpm_buf user would be the TPM driver inside attestation. We definitely need this for ROT agility.

We should be able to build the attestation TPM driver without any trenchboot stuff to motivate it.

Jason

#19 lore raw

Re: [PATCH RFC v2 9/9] attestation: Add the TDX family implementation

Quoted 11 lines · Jason Gunthorpe
Quoted 10 lines · Jarkko Sakkinen
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

As per the function, perhaps tpm2_calc_event_log_size() should be relocated to lib and have non-TPM name like firmware_event_log_size() or something.

Probably under drivers/attestation since that is where all the TCG formatted logs should end up. It should be 'tcg_event_log_size()' or something. Maybe a tiny module for it like we would have done in lib/

+1 for the name, as it is obviously more accurate prefix.

Quoted 7 lines
Quoted 2 lines

Location, I don't know. I was thinking something like "lib/tcg.c" with routines that are plain calculations based on TCG/TPM data.

I think we should not have new users outside attestation subsystem, but the legacy onces will still exist obviously..

IDK either, but this is my guess..

No strong opinions on this; just unpurging my thoughts.

Quoted 10 lines
Quoted 3 lines

And perhaps for tpm_buf (both stack/heap allocatable), if Trenchboot ever moves forward.

DRTM users will route through attestation subsystem to do their extends so the tpm_buf user would be the TPM driver inside attestation. We definitely need this for ROT agility.

We should be able to build the attestation TPM driver without any trenchboot stuff to motivate it.

OK, this was my guess but did not know it by fact.

Quoted 2 lines

Jason

Br, Jarkko

author
#20 lore raw

Re: [PATCH RFC v2 9/9] attestation: Add the TDX family implementation

Quoted 15 lines · Mon, Nov 23, 2026 at 04:42:48PM +0100, [email protected] wrote:
Quoted 14 lines · Jason Gunthorpe
Quoted 12 lines · Jarkko Sakkinen
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

As per the function, perhaps tpm2_calc_event_log_size() should be relocated to lib and have non-TPM name like firmware_event_log_size() or something.

Probably under drivers/attestation since that is where all the TCG formatted logs should end up. It should be 'tcg_event_log_size()' or something. Maybe a tiny module for it like we would have done in lib/

+1 for the name, as it is obviously more accurate prefix.

Location, I don't know. I was thinking something like "lib/tcg.c" with routines that are plain calculations based on TCG/TPM data.

Quoted 6 lines
Quoted 4 lines

I think we should not have new users outside attestation subsystem, but the legacy onces will still exist obviously..

IDK either, but this is my guess..

No strong opinions on this; just unpurging my thoughts.

Okay, will put have this in a helper lib.

Quoted 19 lines
Quoted 11 lines
Quoted 4 lines

And perhaps for tpm_buf (both stack/heap allocatable), if Trenchboot ever moves forward.

DRTM users will route through attestation subsystem to do their extends so the tpm_buf user would be the TPM driver inside attestation. We definitely need this for ROT agility.

We should be able to build the attestation TPM driver without any trenchboot stuff to motivate it.

OK, this was my guess but did not know it by fact.

Quoted 2 lines

Jason

Br, Jarkko