From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2E013C48C for ; Sun, 28 Jan 2024 22:44:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706481847; cv=none; b=GPy2PPOMYuq3xAnYWGyITnNXaKGLbaM52h9CjU0TUwIvd1dmpOPacUZHbzjKlt91ilntfZ5LMgvrW+XuK7fnoPWnUNX6sRHyWtGZ2quQtyFdE09QivSxJI+t15xtjgieYFO8nju6yz2x2wmrK4HkOUWgQlsJm0pDXFgYZXJlXzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706481847; c=relaxed/simple; bh=ry3Pg0gR7A8dvWHi1I9jwv4x9sME26VfWKPl0cIii1M=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=orirXHZdhrhpamk39Rlf0ymxfMzcxZ3U/8DqZ1zlZ3jJrBZAQbzZVfGwU5YtG/7gvLtdJSbJlv7aLRBp0xPS7vEuS5Rf31dJFXaBLn0yv6VwdfEx8BiEkpFeSmP6crXij+gbmfRCOVW4OoU1q7NJIIz+wSVAbnfe3lgiYL4gFa4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=G5hl/gag; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="G5hl/gag" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706481844; x=1738017844; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ry3Pg0gR7A8dvWHi1I9jwv4x9sME26VfWKPl0cIii1M=; b=G5hl/gagf9u6dMzw3l+b7iLf6EJZ76NujkxRfUJSfcpdVSjcEwRzl8DU 2U3qnqTUcEBkCPF6MWEjj5sSojFSSRjs/IvI54n1UrolcFLvLBSxVjDTT tYtQ5xb6qrizYe/xlAhAaUfxpfvbQ0mc+AxtHD3101VD9zHBGJVQSB4Di 11sarT7+g3mkulYkHd7yY3xuOjgyihDp53FNt7X+211uuD8oq74KU4TW6 qB9dmROaO+ao6jqvkfF7BXts7iLPXSdEp5Ip9V+pN9tOWICyYjAw1jkrv /RnPm7qneg4Gq/lAzc4LtUloMrGndaGEmvMMopCvmnpiZQXJEpaR+nsF8 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10967"; a="2673822" X-IronPort-AV: E=Sophos;i="6.05,226,1701158400"; d="scan'208";a="2673822" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2024 14:44:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10967"; a="737202916" X-IronPort-AV: E=Sophos;i="6.05,226,1701158400"; d="scan'208";a="737202916" Received: from smyint-mobl1.amr.corp.intel.com (HELO [10.212.130.147]) ([10.212.130.147]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2024 14:44:03 -0800 Message-ID: <0c396883-6eb7-4ee9-955b-42e365a737cf@linux.intel.com> Date: Sun, 28 Jan 2024 14:44:03 -0800 Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v2 3/4] tsm: Map RTMRs to TCG TPM PCRs Content-Language: en-US To: Samuel Ortiz , Dan Williams Cc: Qinkun Bao , "Yao, Jiewen" , "Xing, Cedric" , Dionna Amalie Glaze , biao.lu@intel.com, linux-coco@lists.linux.dev, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240128212532.2754325-1-sameo@rivosinc.com> <20240128212532.2754325-4-sameo@rivosinc.com> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20240128212532.2754325-4-sameo@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/28/24 1:25 PM, Samuel Ortiz wrote: > 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. Why expose the mapping to user space? IMO, the goal should be to let user space application work without any changes. So we should try to hide this conversion in kernel and let userspace code to use PCR as usual. > > TPM PCR mappings are statically configured through the TSM provider > capabilities. A TSM backend defines its number of RTMRs, and for each > one of them can define a bitmask of TCG TPM PCR it maps to. As they are > TSM backend specific, those mappings are to some extend architecture > specific. Each architecture is free to decide and choose how it builds > it, e.g. by requesting an EFI firmware when it supports the EFI_CC > protocol. > > The tsm-configfs rtmrs/tcg_map describes these static mappings. > > Signed-off-by: Samuel Ortiz > --- > Documentation/ABI/testing/configfs-tsm | 14 +++++ > drivers/virt/coco/tsm.c | 74 ++++++++++++++++++++++++++ > 2 files changed, 88 insertions(+) > > diff --git a/Documentation/ABI/testing/configfs-tsm b/Documentation/ABI/testing/configfs-tsm > index 590e103a9bcd..5d20a872475e 100644 > --- a/Documentation/ABI/testing/configfs-tsm > +++ b/Documentation/ABI/testing/configfs-tsm > @@ -91,3 +91,17 @@ Description: > can be mapped to a hardware RTMR by writing into its index > attribute. The TSM provider will then map the configfs entry to > its corresponding hardware register. > + > +What: /sys/kernel/config/tsm/rtmrs/$name/tcg_map > +Date: January, 2024 > +KernelVersion: v6.8 > +Contact: linux-coco@lists.linux.dev > +Description: > + (RO) A representation of the architecturally defined mapping > + between this RTMR and one or more TCG TPM PCRs [1]. When using > + a TSM as Root of Trust for Storage (RTS), TCG TPM PCRs > + associated semantics and indexes can be used when RTMRs are > + logically mapped to TPM PCRs. > + > + [1]: TCG PC Client Specific Platform Firmware Profile Specification > + https://trustedcomputinggroup.org/resource/pc-client-specific-platform-firmware-profile-specification/ > diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c > index bb9ed2d2accc..d03cf5173bc9 100644 > --- a/drivers/virt/coco/tsm.c > +++ b/drivers/virt/coco/tsm.c > @@ -419,6 +419,46 @@ static const struct config_item_type tsm_reports_type = { > .ct_group_ops = &tsm_report_group_ops, > }; > > +static int tsm_rtmr_build_tcg_map(const struct tsm_provider *tsm, > + const struct tsm_rtmr_state *rtmr_state, > + u32 rtmr_idx) > +{ > + const struct tsm_ops *ops; > + unsigned long pcr_mask; > + int i; > + > + lockdep_assert_held_write(&tsm_rwsem); > + > + ops = tsm->ops; > + if (!ops) > + return -ENOTTY; > + > + if (!ops->capabilities.rtmrs) > + return -ENXIO; > + > + pcr_mask = ops->capabilities.rtmrs[rtmr_idx].tcg_pcr_mask; > + > + /* Check that the PCR mask is valid */ > + for (i = 0; i < TPM2_PLATFORM_PCR; i++) { > + if (!(pcr_mask & BIT(i))) > + continue; > + > + /* If another RTMR maps to this PCR, the mask is discarded */ > + if (tsm_rtmrs->tcg_map[i] && > + tsm_rtmrs->tcg_map[i] != rtmr_state) > + return -EBUSY; > + } > + > + for (i = 0; i < TPM2_PLATFORM_PCR; i++) { > + if (!(pcr_mask & BIT(i))) > + continue; > + > + tsm_rtmrs->tcg_map[i] = rtmr_state; > + } > + > + return 0; > +} > + > static ssize_t tsm_rtmr_index_store(struct config_item *cfg, > const char *buf, size_t len) > { > @@ -449,6 +489,10 @@ static ssize_t tsm_rtmr_index_store(struct config_item *cfg, > if (tsm_rtmrs->rtmrs[val]) > return -EINVAL; > > + rc = tsm_rtmr_build_tcg_map(&provider, rtmr_state, val); > + if (rc) > + return rc; > + > rtmr_state->index = val; > rtmr_state->alg = ops->capabilities.rtmrs[val].hash_alg; > > @@ -472,8 +516,38 @@ static ssize_t tsm_rtmr_index_show(struct config_item *cfg, > } > CONFIGFS_ATTR(tsm_rtmr_, index); > > +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_RO(tsm_rtmr_, tcg_map); > + > static struct configfs_attribute *tsm_rtmr_attrs[] = { > &tsm_rtmr_attr_index, > + &tsm_rtmr_attr_tcg_map, > NULL, > }; > -- Sathyanarayanan Kuppuswamy Linux Kernel Developer