Skip to contentSkip to conversation

tsm: Unified Measurement Register ABI for TVMs

RFC PATCH New Cedric Xing 2 participants 4 messages Dec 11, 2024 – Dec 12, 2024 Trusted execution environment security manager (tsm)

lore
Share & tools
lore
#0 lore raw

v3 cover tsm: Unified Measurement Register ABI for TVMs

NOTE: This patch series introduces the Measurement Register (MR) ABI, and is largely a continuation of Samuel Ortiz’s previous work on the RTMR ABI [1].

This patch series adds a unified interface to TSM core for confidential computing (CC) guest drivers to provide access to measurement registers (MRs), which are essential for relying parties (RPs) to verify the integrity of the computing environment. The interface is structured around struct tsm_measurement, which holds an array of struct tsm_measurement_register and includes operations for reading and updating MRs.

Each struct tsm_measurement_register features a mr_flags member that indicates the MR's properties, such as *Readable* (TSM_MR_F_R), *Extensible* (TSM_MR_F_X), etc. Please refer to Patch 1 in this series for more details. Patch 2 adds a sample module to demonstrate how to define and implement MRs in a CC guest driver.

MRs are made accessible to applications through a directory tree (rooted at /sys/kernel/tsm). An MR could be presented as either a file containing its value, or a directory containing the file digest under a subdirectory of the same name as the hash algorithm. By default, an MR will be presented as a directory unless TSM_MR_F_F is set in mr_flags.

[1]: https://patchwork.kernel.org/project/linux-integrity/cover/[email protected]/

---
Changes in v3:
- Added *Crypto Agility* support, see patch 1
- Fixed style issues in both commit messages and code
- Fixed incorrect assignment of files to commits
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Separated TSM MR code in a new file: tsm-mr.c.
- Removed RTMR event logging due to the lack of agreement on the log format.
- Default presentation of each MR as a directory, with the option to request an
MR as a file using TSM_MR_F_F.
- Reduced verbosity: Renamed struct tsm_measurement_provider to struct tsm_measurement, and tsm_(un)register_measurement_provider to tsm_(un)register_measurement.
- Added MODULE_DESCRIPTION for measurement-sample.
- Fixed several compiler warnings on 32-bit builds.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Cedric Xing (2):
tsm: Add TVM Measurement Register Support
tsm: Add TVM Measurement Sample Code

 MAINTAINERS                             |   3 +-
 drivers/virt/coco/Kconfig               |   3 +-
 drivers/virt/coco/Makefile              |   2 +
 drivers/virt/coco/{tsm.c => tsm-core.c} |   6 +-
 drivers/virt/coco/tsm-mr.c              | 376 ++++++++++++++++++++++++++++++++
 include/linux/tsm.h                     |  64 ++++++
 samples/Kconfig                         |   4 +
 samples/Makefile                        |   1 +
 samples/tsm/Makefile                    |   2 +
 samples/tsm/measurement-example.c       | 113 ++++++++++
 10 files changed, 571 insertions(+), 3 deletions(-)

---
base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4
change-id: 20240904-tsm-rtmr-7a45859d2a96

Best regards,

Signature · 1 line
Cedric Xing <[email protected]>
#1 lore raw

RFC PATCH v3 1/2 tsm: Add TVM Measurement Register Support

This commit extends the TSM core with support for CC measurement registers (MRs).

The newly added APIs are:

- tsm_register_measurement(struct tsm_measurement *): This API allows a CC guest driver to register a set of measurement registers with the TSM core.
- tsm_unregister_measurement(struct tsm_measurement *): This API enables a CC guest driver to unregister a previously registered set of measurement registers.

struct tsm_measurement has been defined to encapsulate the details of CC-specific MRs. It includes an array of struct tsm_measurement_registers and provides operations for reading and updating these registers. For a comprehensive understanding of the structure and its usage, refer to the detailed comments in include/linux/tsm.h.

Upon successful registration of a measurement provider, the TSM core exposes the MRs through a directory tree in the sysfs filesystem. The root of this tree is located at /sys/kernel/tsm/MR_PROVIDER/, where MR_PROVIDER is the name of the measurement provider (as specified by struct tsm_measurement::name). Each MR is made accessible as either a file or a directory of the specified name (i.e., tsm_measurement_register::mr_name). In the former case, the file content is the MR value; while in the latter case HASH_ALG/digest under the MR directory contains the MR value, where HASH_ALG specifies the hash algorithm (e.g., sha256, sha384, etc.) used by this MR.

*Crypto Agility* is supported as a set of independent MRs that share a common name. These MRs will be merged into a single MR directory and each will be represented by its respective HASH_ALG/digest file. Note that tsm_measurement_register::mr_hash must be distinct or the behavior is undefined.

---
 MAINTAINERS                             |   2 +-
 drivers/virt/coco/Kconfig               |   3 +-
 drivers/virt/coco/Makefile              |   2 +
 drivers/virt/coco/{tsm.c => tsm-core.c} |   6 +-
 drivers/virt/coco/tsm-mr.c              | 376 ++++++++++++++++++++++++++++++++
 include/linux/tsm.h                     |  64 ++++++
 6 files changed, 450 insertions(+), 3 deletions(-)
MAINTAINERS +1 -1
index 17daa9ee9384..4c833fa9e388 100644
@@ -23846,7 +23846,7 @@ M:	Dan Williams <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/ABI/testing/configfs-tsm
-F:	drivers/virt/coco/tsm.c
+F:	drivers/virt/coco/tsm*.c
 F:	include/linux/tsm.h
 
 TRUSTED SERVICES TEE DRIVER
drivers/virt/coco/Kconfig +2 -1
index ff869d883d95..6f3c0831680b 100644
@@ -5,7 +5,8 @@
 
 config TSM_REPORTS
 	select CONFIGFS_FS
-	tristate
+	select CRYPTO_HASH_INFO
+	tristate "Trusted Security Module (TSM) sysfs/configfs support"
 
 source "drivers/virt/coco/efi_secret/Kconfig"
 
drivers/virt/coco/Makefile +2 -0
index c3d07cfc087e..4b108d8df1bd 100644
@@ -2,6 +2,8 @@
 #
 # Confidential computing related collateral
 #
+tsm-y				+= tsm-core.o tsm-mr.o
+
 obj-$(CONFIG_TSM_REPORTS)	+= tsm.o
 obj-$(CONFIG_EFI_SECRET)	+= efi_secret/
 obj-$(CONFIG_ARM_PKVM_GUEST)	+= pkvm-guest/
drivers/virt/coco/tsm-core.c renamed from drivers/virt/coco/tsm.c +5 -1
similarity index 99%
rename from drivers/virt/coco/tsm.c
rename to drivers/virt/coco/tsm-core.c
index 9432d4e303f1..ab5269db9c13 100644
@@ -476,6 +476,9 @@ int tsm_unregister(const struct tsm_ops *ops)
 }
 EXPORT_SYMBOL_GPL(tsm_unregister);
 
+int tsm_mr_init(void);
+void tsm_mr_exit(void);
+
 static struct config_group *tsm_report_group;
 
 static int __init tsm_init(void)
@@ -497,12 +500,13 @@ static int __init tsm_init(void)
 	}
 	tsm_report_group = tsm;
 
-	return 0;
+	return tsm_mr_init();
 }
 module_init(tsm_init);
 
 static void __exit tsm_exit(void)
 {
+	tsm_mr_exit();
 	configfs_unregister_default_group(tsm_report_group);
 	configfs_unregister_subsystem(&tsm_configfs);
 }
drivers/virt/coco/tsm-mr.c new file +376 -0

376 lines not on this page · raw message

include/linux/tsm.h +64 -0

74 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH v3 2/2 tsm: Add TVM Measurement Sample Code

In reply to Cedric Xing

This sample kernel module demonstrates how to make MRs accessible to user mode through TSM.

Once loaded, this module registers a virtual measurement provider with the TSM core and will result in the directory tree below.

/sys/kernel/tsm

└── measurement-example
    ├── config_mr
    │   └── sha512
    │       └── digest
    ├── report_digest
    │   └── sha512
    │       └── digest
    ├── rtmr0
    │   └── sha256
    │       └── digest
    ├── rtmr1
    │   └── sha384
    │       └── digest
    ├── rtmr_crypto_agile
    │   ├── sha256
    │   │   └── digest
    │   └── sha384
    │       └── digest
    └── static_mr
        └── sha384
            └── digest

Among the MRs in this example:

- static_mr and config_mr are *Readonly* (static) MRs.
- rtmr0 is an RTMR with TSM_MR_F_W **cleared**, preventing direct extensions; as a result, rtmr0/sha256/digest is read-only.
- rtmr1 is an RTMR with TSM_MR_F_W **set**, permitting direct extensions; thus, rtmr1/sha384/digest is writable.
- rtmr_crypto_agile demonstrates a "single" MR that supports multiple hash algorithms. Each supported algorithm has a corresponding digest, usually referred to as a "bank" in TCG terminology. In this specific sample, the 2 banks are aliased to rtmr0 and rtmr1, respectively.
- report_digest contains the digest of the internal report structure living in this sample module's memory. It is to demonstrate the use of the TSM_MR_F_L flag. Its value changes each time an RTMR is extended.

More details can be found in samples/tsm/measurement-example.c.

---
 MAINTAINERS                       |   1 +
 samples/Kconfig                   |   4 ++
 samples/Makefile                  |   1 +
 samples/tsm/Makefile              |   2 +
 samples/tsm/measurement-example.c | 113 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 121 insertions(+)
MAINTAINERS +1 -0
index 4c833fa9e388..a4074cea0f16 100644
@@ -23848,6 +23848,7 @@ S:	Maintained
 F:	Documentation/ABI/testing/configfs-tsm
 F:	drivers/virt/coco/tsm*.c
 F:	include/linux/tsm.h
+F:	samples/tsm/*
 
 TRUSTED SERVICES TEE DRIVER
 M:	Balint Dobszay <[email protected]>
samples/Kconfig +4 -0
index b288d9991d27..8159d3ca6487 100644
@@ -184,6 +184,10 @@ config SAMPLE_TIMER
 	bool "Timer sample"
 	depends on CC_CAN_LINK && HEADERS_INSTALL
 
+config SAMPLE_TSM
+	tristate "TSM measurement sample"
+	depends on TSM_REPORTS
+
 config SAMPLE_UHID
 	bool "UHID sample"
 	depends on CC_CAN_LINK && HEADERS_INSTALL
samples/Makefile +1 -0
index b85fa64390c5..891f5c12cd39 100644
@@ -39,3 +39,4 @@ obj-$(CONFIG_SAMPLE_KMEMLEAK)		+= kmemleak/
 obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG)	+= coresight/
 obj-$(CONFIG_SAMPLE_FPROBE)		+= fprobe/
 obj-$(CONFIG_SAMPLES_RUST)		+= rust/
+obj-$(CONFIG_SAMPLE_TSM)		+= tsm/
samples/tsm/Makefile new file +2 -0
new file mode 100644
index 000000000000..3969a59221e9
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_SAMPLE_TSM) += measurement-example.o
samples/tsm/measurement-example.c new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH RFC v3 1/2] tsm: Add TVM Measurement Register Support

In reply to Cedric Xing
kernel test robot noticed the following build warnings:

Hi Cedric,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on fac04efc5c793dccbd07e2d59af9f90b7fc0dca4]

url:    https://github.com/intel-lab-lkp/linux/commits/Cedric-Xing/tsm-Add-TVM-Measurement-Register-Support/20241211-112420
base:   fac04efc5c793dccbd07e2d59af9f90b7fc0dca4
patch link:    https://lore.kernel.org/r/20241210-tsm-rtmr-v3-1-5997d4dbda73%40intel.com
patch subject: [PATCH RFC v3 1/2] tsm: Add TVM Measurement Register Support
config: nios2-kismet-CONFIG_CRYPTO_HASH_INFO-CONFIG_TSM_REPORTS-0-0 (https://download.01.org/0day-ci/archive/20241212/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20241212/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)

>> kismet: WARNING: unmet direct dependencies detected for CRYPTO_HASH_INFO when selected by TSM_REPORTS

WARNING: unmet direct dependencies detected for CRYPTO_HASH_INFO
Depends on [n]: CRYPTO [=n]
Selected by [y]:
- TSM_REPORTS [=y] && VIRT_DRIVERS [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki