From: Samuel Ortiz <sameo@rivosinc.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v1 3/4] tsm: Allow for mapping RTMRs to TCG TPM PCRs
Date: Sun, 14 Jan 2024 23:35:29 +0100 [thread overview]
Message-ID: <20240114223532.290550-4-sameo@rivosinc.com> (raw)
In-Reply-To: <20240114223532.290550-1-sameo@rivosinc.com>
Many user space and internal kernel subsystems (e.g. the Linux IMA)
expect a Root of Trust for Storage (RTS) that allows for extending
and reading measurement registers that are compatible with the TCG TPM
PCRs layout, e.g. a TPM. In order to allow those components to
alternatively use a platform TSM as their RTS, a TVM could map the
available RTMRs to one or more TCG TPM PCRs. Once configured, those PCR
to RTMR mappings give the kernel TSM layer all the necessary information
to be a RTS for e.g. the Linux IMA or any other components that expects
a TCG compliant TPM PCRs layout.
TPM PCR mappings are configured through configfs:
// Create and configure 2 RTMRs
mkdir /sys/kernel/config/tsm/rtmrs/rtmr0
mkdir /sys/kernel/config/tsm/rtmrs/rtmr1
echo 0 > /sys/kernel/config/tsm/rtmrs/rtmr0/index
echo 1 > /sys/kernel/config/tsm/rtmrs/rtmr1/index
// Map RTMR 0 to PCRs 4, 5, 6, 7 and 8
echo 4-8 > /sys/kernel/config/tsm/rtmrs/rtmr0/tcg_map
// Map RTMR 1 to PCRs 16, 17 and 18
echo 16-18 > /sys/kernel/config/tsm/rtmrs/rtmr1/tcg_map
Signed-off-by: Samuel Ortiz <sameo@rivosinc.com>
---
drivers/virt/coco/tsm.c | 60 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c
index 15b67d99fd54..f35f91cb7bd3 100644
--- a/drivers/virt/coco/tsm.c
+++ b/drivers/virt/coco/tsm.c
@@ -472,8 +472,68 @@ static ssize_t tsm_rtmr_index_show(struct config_item *cfg,
}
CONFIGFS_ATTR(tsm_rtmr_, index);
+static ssize_t tsm_rtmr_tcg_map_store(struct config_item *cfg,
+ const char *buf, size_t len)
+{
+ struct tsm_rtmr_state *rtmr_state = to_tsm_rtmr_state(cfg);
+ int i, pcrs[TPM2_PLATFORM_PCR + 1];
+
+ get_options(buf, ARRAY_SIZE(pcrs), pcrs);
+
+ if (pcrs[0] > TPM2_PLATFORM_PCR - 1)
+ return -EINVAL;
+
+ guard(rwsem_write)(&tsm_rwsem);
+ /* Check that the PCR list is valid */
+ for (i = 0; i < pcrs[0]; i++) {
+ /* It must be a valid TPM2 PCR number */
+ if (pcrs[i] > TPM2_PLATFORM_PCR - 1)
+ return -EINVAL;
+
+ /* If another RTMR maps to this PCR, the list is discarded */
+ if (tsm_rtmrs->tcg_map[pcrs[i + 1]] &&
+ tsm_rtmrs->tcg_map[pcrs[i + 1]] != rtmr_state)
+ return -EBUSY;
+ }
+
+ for (i = 0; i < pcrs[0]; i++)
+ tsm_rtmrs->tcg_map[pcrs[i + 1]] = rtmr_state;
+
+ return len;
+}
+
+static ssize_t tsm_rtmr_tcg_map_show(struct config_item *cfg,
+ char *buf)
+{
+ struct tsm_rtmr_state *rtmr_state = to_tsm_rtmr_state(cfg);
+ unsigned int nr_pcrs = ARRAY_SIZE(tsm_rtmrs->tcg_map), i;
+ unsigned long *pcr_mask;
+ ssize_t len;
+
+ /* Build a bitmap mask of all PCRs that this RTMR covers */
+ pcr_mask = bitmap_zalloc(nr_pcrs, GFP_KERNEL);
+ if (!pcr_mask)
+ return -ENOMEM;
+
+ guard(rwsem_read)(&tsm_rwsem);
+ for (i = 0; i < nr_pcrs; i++) {
+ if (tsm_rtmrs->tcg_map[i] != rtmr_state)
+ continue;
+
+ __set_bit(i, pcr_mask);
+ }
+
+ len = bitmap_print_list_to_buf(buf, pcr_mask, nr_pcrs, 0,
+ nr_pcrs * 3 /* 2 ASCII digits and one comma */);
+ bitmap_free(pcr_mask);
+
+ return len;
+}
+CONFIGFS_ATTR(tsm_rtmr_, tcg_map);
+
static struct configfs_attribute *tsm_rtmr_attrs[] = {
&tsm_rtmr_attr_index,
+ &tsm_rtmr_attr_tcg_map,
NULL,
};
--
2.42.0
next prev parent reply other threads:[~2024-01-14 22:37 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-14 22:35 [RFC PATCH v1 0/4] tsm: Runtime measurement registers ABI Samuel Ortiz
2024-01-14 22:35 ` [RFC PATCH v1 1/4] tsm: Runtime measurement register support Samuel Ortiz
2024-01-14 22:35 ` [RFC PATCH v1 2/4] tsm: Add RTMRs to the configfs-tsm hierarchy Samuel Ortiz
2024-01-14 22:35 ` Samuel Ortiz [this message]
2024-01-16 22:28 ` [RFC PATCH v1 3/4] tsm: Allow for mapping RTMRs to TCG TPM PCRs Kuppuswamy Sathyanarayanan
2024-01-17 1:24 ` Dan Williams
2024-01-17 3:35 ` Kuppuswamy Sathyanarayanan
2024-01-21 16:31 ` Samuel Ortiz
2024-01-22 2:13 ` Qinkun Bao
2024-01-22 2:23 ` Yao, Jiewen
2024-01-22 7:49 ` Samuel Ortiz
2024-01-22 20:10 ` Dan Williams
2024-01-22 21:58 ` Xing, Cedric
2024-01-22 22:32 ` Dan Williams
2024-01-23 18:48 ` Xing, Cedric
2024-01-23 19:14 ` Dan Williams
2024-01-23 20:59 ` Kuppuswamy Sathyanarayanan
2024-01-26 16:55 ` Dionna Amalie Glaze
2024-01-23 1:22 ` Yao, Jiewen
[not found] ` <90EDEF2B-DB43-413F-840E-3268977FDBD0@google.com>
2024-01-22 7:46 ` Samuel Ortiz
2024-01-22 15:04 ` Kuppuswamy Sathyanarayanan
2024-01-22 22:12 ` Kuppuswamy Sathyanarayanan
2024-01-14 22:35 ` [RFC PATCH v1 4/4] tsm: Allow for extending and reading configured RTMRs Samuel Ortiz
2024-01-16 20:44 ` [RFC PATCH v1 0/4] tsm: Runtime measurement registers ABI Dan Williams
2024-01-18 3:35 ` biao.lu
2024-01-18 17:42 ` Dionna Amalie Glaze
2024-01-18 19:20 ` Dan Williams
2024-01-21 18:11 ` Samuel Ortiz
2024-01-21 19:15 ` Dan Williams
2024-01-22 22:12 ` Xing, Cedric
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240114223532.290550-4-sameo@rivosinc.com \
--to=sameo@rivosinc.com \
--cc=dan.j.williams@intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).