From nobody Fri Dec 19 16:11:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC626C83F14 for ; Wed, 30 Aug 2023 20:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240084AbjH3UBC (ORCPT ); Wed, 30 Aug 2023 16:01:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239845AbjH3UAT (ORCPT ); Wed, 30 Aug 2023 16:00:19 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88564793D8 for ; Wed, 30 Aug 2023 12:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693424101; x=1724960101; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1QNSa8PfJ6fHxxDbOfg/mWMGFnDXUsLlbGCHGWdkA9Q=; b=n/PU5MODV8YzgbFE2fcXQdhAZsukUVPQk9Z4l/IGmpQKZw5LiycAGLUH EQDwHCubB8s7a87MeZ0POS8p7TNQHFS+aaC3enQMbXJDs3I8CBiEhR7qT aOzrlhTwolk3lmxRbUZiXpwwpwxAomRyFeG8x786YgkSZPfpStUeHqtbe 35YQJ4W2bgmtf+PQz3Is0Cg0/OtrWe6QRcrLAgl4of9oj6wxPN3pyrd4c Nd9vKSg4hFwiIIdm9wgS6fDpPfl9jxzXN2+b7FXivm9bEzuIhgSUm8bcL ZpqE9QpC90luaGPf0kFHJolmGQZvGrZOK6Dg1FpMCP3qDxN+qyzRmx/FL A==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="360723612" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="360723612" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="853844784" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="853844784" Received: from nivakuma-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.212.238.163]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:19 -0700 Subject: [PATCH v3 1/5] virt: coco: Add a coco/Makefile and coco/Kconfig From: Dan Williams To: linux-coco@lists.linux.dev Cc: peterz@infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de Date: Wed, 30 Aug 2023 12:33:18 -0700 Message-ID: <169342399880.3934343.12969478676791150366.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> References: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for adding another coco build target, relieve drivers/virt/Makefile of the responsibility to track new compilation unit additions to drivers/virt/coco/, and do the same for drivers/virt/Kconfig. Signed-off-by: Dan Williams Reviewed-by's from v2. Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/virt/Kconfig | 6 +----- drivers/virt/Makefile | 4 +--- drivers/virt/coco/Kconfig | 9 +++++++++ drivers/virt/coco/Makefile | 7 +++++++ 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 drivers/virt/coco/Kconfig create mode 100644 drivers/virt/coco/Makefile diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index f79ab13a5c28..40129b6f0eca 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -48,10 +48,6 @@ source "drivers/virt/nitro_enclaves/Kconfig" =20 source "drivers/virt/acrn/Kconfig" =20 -source "drivers/virt/coco/efi_secret/Kconfig" - -source "drivers/virt/coco/sev-guest/Kconfig" - -source "drivers/virt/coco/tdx-guest/Kconfig" +source "drivers/virt/coco/Kconfig" =20 endif diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index e9aa6fc96fab..f29901bd7820 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -9,6 +9,4 @@ obj-y +=3D vboxguest/ =20 obj-$(CONFIG_NITRO_ENCLAVES) +=3D nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) +=3D acrn/ -obj-$(CONFIG_EFI_SECRET) +=3D coco/efi_secret/ -obj-$(CONFIG_SEV_GUEST) +=3D coco/sev-guest/ -obj-$(CONFIG_INTEL_TDX_GUEST) +=3D coco/tdx-guest/ +obj-y +=3D coco/ diff --git a/drivers/virt/coco/Kconfig b/drivers/virt/coco/Kconfig new file mode 100644 index 000000000000..fc5c64f04c4a --- /dev/null +++ b/drivers/virt/coco/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Confidential computing related collateral +# +source "drivers/virt/coco/efi_secret/Kconfig" + +source "drivers/virt/coco/sev-guest/Kconfig" + +source "drivers/virt/coco/tdx-guest/Kconfig" diff --git a/drivers/virt/coco/Makefile b/drivers/virt/coco/Makefile new file mode 100644 index 000000000000..55302ef719ad --- /dev/null +++ b/drivers/virt/coco/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Confidential computing related collateral +# +obj-$(CONFIG_EFI_SECRET) +=3D efi_secret/ +obj-$(CONFIG_SEV_GUEST) +=3D sev-guest/ +obj-$(CONFIG_INTEL_TDX_GUEST) +=3D tdx-guest/ From nobody Fri Dec 19 16:11:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 475C1C83F14 for ; Wed, 30 Aug 2023 20:21:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235867AbjH3UVD (ORCPT ); Wed, 30 Aug 2023 16:21:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240102AbjH3UAb (ORCPT ); Wed, 30 Aug 2023 16:00:31 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559C745B19 for ; Wed, 30 Aug 2023 12:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693424130; x=1724960130; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4UKbNpagiAq35d+VrOb37UzA4eObE0g/YZSbZ4ms0Dw=; b=gqoFDNszzBxHmodL7kzgX6AlPVDhvam+22ztBxDSRtZ3WTB+1LRgz2cV ZLaR5wgut6M9Rz9g/7OnlQirElqtjFEZdnNAXwHfgSquRG1QCRSHc2lwn nbsxAPdHRK8q+QE/N+T17ImNEm/2upIunDihWk+U/yJio8GAqwz9kJlGK ERgqc9anO0TAxDS063yCgu5/jUBOFm3AhEymvSKs92bfFulRxDVnF8Hmv qWMTgp6Rlc0QbK3nrMLjfahFLmiqUqjaw6hkr89zw4/4TLJEaa95vLcJn bDADCRLnQ8C/Yme331j9URnZrWKqvNRYcxP+vytLnXT4DoehlQDrYvnUK A==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="360723620" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="360723620" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="853844805" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="853844805" Received: from nivakuma-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.212.238.163]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:25 -0700 Subject: [PATCH v3 2/5] configfs-tsm: Introduce a shared ABI for attestation reports From: Dan Williams To: linux-coco@lists.linux.dev Cc: Kuppuswamy Sathyanarayanan , Dionna Amalie Glaze , James Bottomley , Peter Gonda , Greg Kroah-Hartman , Samuel Ortiz , peterz@infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de Date: Wed, 30 Aug 2023 12:33:24 -0700 Message-ID: <169342400469.3934343.12316161608372095860.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> References: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One of the common operations of a TSM (Trusted Security Module) is to provide a way for a TVM (confidential computing guest execution environment) to take a measurement of its launch state, sign it and submit it to a verifying party. Upon successful attestation that verifies the integrity of the TVM additional secrets may be deployed. The concept is common across TSMs, but the implementations are unfortunately vendor specific. While the industry grapples with a common definition of this attestation format [1], Linux need not make this problem worse by defining a new ABI per TSM that wants to perform a similar operation. The current momentum has been to invent new ioctl-ABI per TSM per function which at best is an abdication of the kernel's responsibility to make common infrastructure concepts share common ABI. The proposal, targeted to conceptually work with TDX, SEV-SNP, COVE if not more, is to define a configfs interface to retrieve the TSM-specific blob. report=3D/sys/kernel/config/tsm/report/report0 mkdir $report dd if=3Dbinary_userdata_plus_nonce > $report/inblob hexdump $report/outblob This approach later allows for the standardization of the attestation blob format without needing to invent a new ABI. Once standardization happens the standard format can be emitted by $report/outblob and indicated by $report/provider, or a new attribute like "$report/tcg_coco_report" can emit the standard format alongside the vendor format. Review of previous iterations of this interface identified that there is a need to scale report generation for multiple container environments [2]. Configfs enables a model where each container can bind mount one or more report generation item instances. Still, within a container only a single thread can be manipulating a given configuration instance at a time. A 'generation' count is provided to detect conflicts between multiple threads racing to configure a report instance. The SEV-SNP concepts of "extended reports" and "privilege levels" are optionally enabled by selecting 'tsm_report_ext_type' at register_tsm() time. The expectation is that those concepts are generic enough that they may be adopted by other TSM implementations. In other words, configfs-tsm aims to address a superset of TSM specific functionality with a common ABI where attributes may appear, or not appear, based on the = set of concepts the implementation supports. Link: http://lore.kernel.org/r/64961c3baf8ce_142af829436@dwillia2-xfh.jf.in= tel.com.notmuch [1] Link: http://lore.kernel.org/r/57f3a05e-8fcd-4656-beea-56bb8365ae64@linux.m= icrosoft.com [2] Cc: Kuppuswamy Sathyanarayanan Cc: Dionna Amalie Glaze Cc: James Bottomley Cc: Peter Gonda Cc: Greg Kroah-Hartman Cc: Samuel Ortiz Signed-off-by: Dan Williams Acked-by: Greg Kroah-Hartman Acked-by: Thomas Gleixner Reviewed-by's from v2. --- Documentation/ABI/testing/configfs-tsm | 68 ++++++ MAINTAINERS | 8 + drivers/virt/coco/Kconfig | 5=20 drivers/virt/coco/Makefile | 1=20 drivers/virt/coco/tdx-guest/Kconfig | 1=20 drivers/virt/coco/tsm.c | 391 ++++++++++++++++++++++++++++= ++++ include/linux/tsm.h | 54 ++++ 7 files changed, 528 insertions(+) create mode 100644 Documentation/ABI/testing/configfs-tsm create mode 100644 drivers/virt/coco/tsm.c create mode 100644 include/linux/tsm.h diff --git a/Documentation/ABI/testing/configfs-tsm b/Documentation/ABI/tes= ting/configfs-tsm new file mode 100644 index 000000000000..0f137039643b --- /dev/null +++ b/Documentation/ABI/testing/configfs-tsm @@ -0,0 +1,68 @@ +What: /sys/kernel/config/tsm/report/$name/inblob +Date: August, 2023 +KernelVersion: v6.7 +Contact: linux-coco@lists.linux.dev +Description: + (WO) Up to 64 bytes of user specified binary data. For replay + protection this should include a nonce, but the kernel does not + place any restrictions on the content. + +What: /sys/kernel/config/tsm/report/$name/outblob +Date: August, 2023 +KernelVersion: v6.7 +Contact: linux-coco@lists.linux.dev +Description: + (RO) Binary attestation report generated from @inblob and other + options The format of the report is implementation specific + (modulo options like @format and @privlevel) where the + implementation is conveyed via the @provider attribute. + +What: /sys/kernel/config/tsm/report/$name/provider +Date: August, 2023 +KernelVersion: v6.7 +Contact: linux-coco@lists.linux.dev +Description: + (RO) A name for the format-specification of @outblob like + "sev-snp" or "tdx" in the near term, or a common standard format + in the future. + +What: /sys/kernel/config/tsm/report/$name/generation +Date: August, 2023 +KernelVersion: v6.7 +Contact: linux-coco@lists.linux.dev +Description: + (RO) The value in this attribute increments each time @inblob or + any option is written. Userspace can detect conflicts by + checking generation before writing to any attribute and making + sure the number of writes matches expectations after reading + @outblob, or it can prevent conflicts by creating a report + instance per requesting context. + +What: /sys/kernel/config/tsm/report/$name/privlevel +Date: August, 2023 +KernelVersion: v6.7 +Contact: linux-coco@lists.linux.dev +Description: + (WO) If a TSM implementation supports the concept of attestation + reports for TVMs running at different privilege levels, like + SEV-SNP "VMPL", specify the privilege level via this attribute. + The minimum acceptable value is conveyed via @privlevel_floor + and the maximum acceptable value is TSM_PRIVLEVEL_MAX (3). + +What: /sys/kernel/config/tsm/report/$name/privlevel_floor +Date: August, 2023 +KernelVersion: v6.7 +Contact: linux-coco@lists.linux.dev +Description: + (RO) Indicates the minimum permissible value that can be written + to @privlevel. + +What: /sys/kernel/config/tsm/report/$name/format +Date: August, 2023 +KernelVersion: v6.7 +Contact: linux-coco@lists.linux.dev +Description: + (WO) If a TSM implementation supports the concept of attestation + reports with "extended" contents, like SEV-SNP extended reports + with certificate chains, specify "extended" vs "default" via + this attribute. diff --git a/MAINTAINERS b/MAINTAINERS index 4cc6bf79fdd8..996122ab62ab 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21671,6 +21671,14 @@ W: https://github.com/srcres258/linux-doc T: git git://github.com/srcres258/linux-doc.git doc-zh-tw F: Documentation/translations/zh_TW/ =20 +TRUSTED SECURITY MODULE (TSM) ATTESTATION REPORTS +M: Dan Williams +L: linux-coco@lists.linux.dev +S: Maintained +F: Documentation/ABI/testing/configfs-tsm +F: drivers/virt/coco/tsm.c +F: include/linux/tsm.h + TTY LAYER AND SERIAL DRIVERS M: Greg Kroah-Hartman M: Jiri Slaby diff --git a/drivers/virt/coco/Kconfig b/drivers/virt/coco/Kconfig index fc5c64f04c4a..87d142c1f932 100644 --- a/drivers/virt/coco/Kconfig +++ b/drivers/virt/coco/Kconfig @@ -2,6 +2,11 @@ # # Confidential computing related collateral # + +config TSM_REPORTS + select CONFIGFS_FS + tristate + source "drivers/virt/coco/efi_secret/Kconfig" =20 source "drivers/virt/coco/sev-guest/Kconfig" diff --git a/drivers/virt/coco/Makefile b/drivers/virt/coco/Makefile index 55302ef719ad..18c1aba5edb7 100644 --- a/drivers/virt/coco/Makefile +++ b/drivers/virt/coco/Makefile @@ -2,6 +2,7 @@ # # Confidential computing related collateral # +obj-$(CONFIG_TSM_REPORTS) +=3D tsm.o obj-$(CONFIG_EFI_SECRET) +=3D efi_secret/ obj-$(CONFIG_SEV_GUEST) +=3D sev-guest/ obj-$(CONFIG_INTEL_TDX_GUEST) +=3D tdx-guest/ diff --git a/drivers/virt/coco/tdx-guest/Kconfig b/drivers/virt/coco/tdx-gu= est/Kconfig index 14246fc2fb02..22dd59e19431 100644 --- a/drivers/virt/coco/tdx-guest/Kconfig +++ b/drivers/virt/coco/tdx-guest/Kconfig @@ -1,6 +1,7 @@ config TDX_GUEST_DRIVER tristate "TDX Guest driver" depends on INTEL_TDX_GUEST + select TSM_REPORTS help The driver provides userspace interface to communicate with the TDX module to request the TDX guest details like attestation diff --git a/drivers/virt/coco/tsm.c b/drivers/virt/coco/tsm.c new file mode 100644 index 000000000000..da19257797d7 --- /dev/null +++ b/drivers/virt/coco/tsm.c @@ -0,0 +1,391 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2023 Intel Corporation. All rights reserved. */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +static struct tsm_provider { + const struct tsm_ops *ops; + const struct config_item_type *type; + void *data; +} provider; +static DECLARE_RWSEM(tsm_rwsem); + +/** + * DOC: Trusted Security Module (TSM) Attestation Report Interface + * + * The TSM report interface is a common provider of blobs that facilitate + * attestation of a TVM (confidential computing guest) by an attestation + * service. A TSM report combines a user-defined blob (likely a public-key= with + * a nonce for a key-exchange protocol) with a signed attestation report. = That + * combined blob is then used to obtain secrets provided by an agent that = can + * validate the attestation report. The expectation is that this interface= is + * invoked infrequently, likely only once at TVM boot time. + * + * The attestation report format is TSM provider specific, when / if a sta= ndard + * materializes that can be published instead of the vendor layout. Until = then + * the 'provider' attribute indicates the format of 'outblob'. + */ + +/** + * struct tsm_report - track state of report generation relative to options + * @desc: report generation options / cached report state + * @outblob: generated evidence to provider to the attestation agent + * @outblob_len: sizeof(outblob) + * @write_generation: conflict detection, and report regeneration tracking + * @read_generation: cached report invalidation tracking + * @cfg: configfs interface + */ +struct tsm_report { + struct tsm_desc desc; + size_t outblob_len; + u8 *outblob; + unsigned long write_generation; + unsigned long read_generation; + struct config_item cfg; +}; + +static struct tsm_report *to_tsm_report(struct config_item *cfg) +{ + return container_of(cfg, struct tsm_report, cfg); +} + +static int try_advance_write_generation(struct tsm_report *report) +{ + lockdep_assert_held_write(&tsm_rwsem); + + /* + * malicious or broken userspace is attempting to wrap read_generation, + * stop accepting updates until current report configuration is read. + */ + if (report->write_generation =3D=3D report->read_generation - 1) + return -EBUSY; + report->write_generation++; + return 0; +} + +static ssize_t tsm_report_privlevel_store(struct config_item *cfg, + const char *buf, size_t len) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + unsigned int val; + int rc; + + rc =3D kstrtouint(buf, 0, &val); + if (rc) + return rc; + + /* + * The valid privilege levels that a TSM might accept, if it accepts a + * privilege level setting at all, are a max of TSM_PRIVLEVEL_MAX (see + * SEV-SNP GHCB) and a minimum of a TSM selected floor value no less + * than 0. + */ + if (provider.ops->privlevel_floor > val || val > TSM_PRIVLEVEL_MAX) + return -EINVAL; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + report->desc.privlevel =3D val; + + return len; +} +CONFIGFS_ATTR_WO(tsm_report_, privlevel); + +static ssize_t tsm_report_privlevel_floor_show(struct config_item *cfg, + char *buf) +{ + guard(rwsem_read)(&tsm_rwsem); + return sysfs_emit(buf, "%u\n", provider.ops->privlevel_floor); +} +CONFIGFS_ATTR_RO(tsm_report_, privlevel_floor); + +static ssize_t tsm_report_format_store(struct config_item *cfg, const char= *buf, + size_t len) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + enum tsm_format format; + int rc; + + if (sysfs_streq(buf, "default")) + format =3D TSM_FORMAT_DEFAULT; + else if (sysfs_streq(buf, "extended")) + format =3D TSM_FORMAT_EXTENDED; + else + return -EINVAL; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + report->desc.outblob_format =3D format; + + return len; +} +CONFIGFS_ATTR_WO(tsm_report_, format); + +static ssize_t tsm_report_inblob_write(struct config_item *cfg, + const void *buf, size_t count) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + int rc; + + guard(rwsem_write)(&tsm_rwsem); + rc =3D try_advance_write_generation(report); + if (rc) + return rc; + + report->desc.inblob_len =3D count; + memcpy(report->desc.inblob, buf, count); + return count; +} +CONFIGFS_BIN_ATTR_WO(tsm_report_, inblob, NULL, TSM_INBLOB_MAX); + +static ssize_t tsm_report_generation_show(struct config_item *cfg, char *b= uf) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + + guard(rwsem_read)(&tsm_rwsem); + return sysfs_emit(buf, "%lu\n", report->write_generation); +} +CONFIGFS_ATTR_RO(tsm_report_, generation); + +static ssize_t tsm_report_provider_show(struct config_item *cfg, char *buf) +{ + guard(rwsem_read)(&tsm_rwsem); + return sysfs_emit(buf, "%s\n", provider.ops->name); +} +CONFIGFS_ATTR_RO(tsm_report_, provider); + +static ssize_t read_cached_report(struct tsm_report *report, void *buf, si= ze_t count) +{ + loff_t offset =3D 0; + + guard(rwsem_read)(&tsm_rwsem); + if (!report->desc.inblob_len) + return -EINVAL; + + if (!report->outblob || + report->read_generation !=3D report->write_generation) + return -EWOULDBLOCK; + + if (!buf) + return report->outblob_len; + return memory_read_from_buffer(buf, count, &offset, report->outblob, + report->outblob_len); +} + +static ssize_t tsm_report_outblob_read(struct config_item *cfg, void *buf, + size_t count) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + const struct tsm_ops *ops; + size_t outblob_len; + loff_t offset =3D 0; + u8 *outblob; + ssize_t rc; + + /* try to read from the existing report if present and valid... */ + rc =3D read_cached_report(report, buf, count); + if (rc >=3D 0 || rc !=3D -EWOULDBLOCK) + return rc; + + /* slow path, report may need to be regenerated... */ + guard(rwsem_write)(&tsm_rwsem); + ops =3D provider.ops; + if (!report->desc.inblob_len) + return -EINVAL; + + /* did another thread already generate this report? */ + if (report->outblob && + report->read_generation =3D=3D report->write_generation) + goto out; + + kvfree(report->outblob); + report->outblob =3D NULL; + outblob =3D ops->report_new(&report->desc, provider.data, &outblob_len); + if (IS_ERR(outblob)) + return PTR_ERR(outblob); + report->outblob_len =3D outblob_len; + report->outblob =3D outblob; + report->read_generation =3D report->write_generation; + +out: + if (!buf) + return report->outblob_len; + return memory_read_from_buffer(buf, count, &offset, report->outblob, + report->outblob_len); +} +CONFIGFS_BIN_ATTR_RO(tsm_report_, outblob, NULL, TSM_OUTBLOB_MAX); + +#define TSM_DEFAULT_ATTRS() \ + &tsm_report_attr_generation, \ + &tsm_report_attr_provider + +static struct configfs_attribute *tsm_report_attrs[] =3D { + TSM_DEFAULT_ATTRS(), + NULL, +}; + +static struct configfs_bin_attribute *tsm_report_bin_attrs[] =3D { + &tsm_report_attr_inblob, + &tsm_report_attr_outblob, + NULL, +}; + +static struct configfs_attribute *tsm_report_extra_attrs[] =3D { + TSM_DEFAULT_ATTRS(), + &tsm_report_attr_format, + &tsm_report_attr_privlevel, + &tsm_report_attr_privlevel_floor, + NULL, +}; + +static void tsm_report_item_release(struct config_item *cfg) +{ + struct tsm_report *report =3D to_tsm_report(cfg); + + kvfree(report->outblob); + kfree(report); +} + +static struct configfs_item_operations tsm_report_item_ops =3D { + .release =3D tsm_report_item_release, +}; + +const struct config_item_type tsm_report_default_type =3D { + .ct_owner =3D THIS_MODULE, + .ct_bin_attrs =3D tsm_report_bin_attrs, + .ct_attrs =3D tsm_report_attrs, + .ct_item_ops =3D &tsm_report_item_ops, +}; +EXPORT_SYMBOL_GPL(tsm_report_default_type); + +const struct config_item_type tsm_report_ext_type =3D { + .ct_owner =3D THIS_MODULE, + .ct_bin_attrs =3D tsm_report_bin_attrs, + .ct_attrs =3D tsm_report_extra_attrs, + .ct_item_ops =3D &tsm_report_item_ops, +}; +EXPORT_SYMBOL_GPL(tsm_report_ext_type); + +static struct config_item *tsm_report_make_item(struct config_group *group, + const char *name) +{ + struct tsm_report *report; + + guard(rwsem_read)(&tsm_rwsem); + if (!provider.ops) + return ERR_PTR(-ENXIO); + + report =3D kzalloc(sizeof(*report), GFP_KERNEL); + if (!report) + return ERR_PTR(-ENOMEM); + + config_item_init_type_name(&report->cfg, name, provider.type); + return &report->cfg; +} + +static struct configfs_group_operations tsm_report_group_ops =3D { + .make_item =3D tsm_report_make_item, +}; + +static const struct config_item_type tsm_reports_type =3D { + .ct_owner =3D THIS_MODULE, + .ct_group_ops =3D &tsm_report_group_ops, +}; + +static const struct config_item_type tsm_root_group_type =3D { + .ct_owner =3D THIS_MODULE, +}; + +static struct configfs_subsystem tsm_configfs =3D { + .su_group =3D { + .cg_item =3D { + .ci_namebuf =3D "tsm", + .ci_type =3D &tsm_root_group_type, + }, + }, + .su_mutex =3D __MUTEX_INITIALIZER(tsm_configfs.su_mutex), +}; + +static struct config_group *tsm_report_group; + +int register_tsm(const struct tsm_ops *ops, void *priv, + const struct config_item_type *type) +{ + const struct tsm_ops *conflict; + + if (!type) + type =3D &tsm_report_default_type; + if (!(type =3D=3D &tsm_report_default_type || type =3D=3D &tsm_report_ext= _type)) + return -EINVAL; + + guard(rwsem_write)(&tsm_rwsem); + conflict =3D provider.ops; + if (conflict) { + pr_err("\"%s\" ops already registered\n", conflict->name); + return -EBUSY; + } + + provider.ops =3D ops; + provider.data =3D priv; + provider.type =3D type; + return 0; +} +EXPORT_SYMBOL_GPL(register_tsm); + +int unregister_tsm(const struct tsm_ops *ops) +{ + guard(rwsem_write)(&tsm_rwsem); + if (ops !=3D provider.ops) + return -EBUSY; + provider.ops =3D NULL; + provider.data =3D NULL; + provider.type =3D NULL; + return 0; +} +EXPORT_SYMBOL_GPL(unregister_tsm); + +static int __init tsm_init(void) +{ + struct config_group *root =3D &tsm_configfs.su_group; + struct config_group *tsm; + int rc; + + config_group_init(root); + rc =3D configfs_register_subsystem(&tsm_configfs); + if (rc) + return rc; + + tsm =3D configfs_register_default_group(root, "report", + &tsm_reports_type); + if (IS_ERR(tsm)) { + configfs_unregister_subsystem(&tsm_configfs); + return PTR_ERR(tsm); + } + tsm_report_group =3D tsm; + + return 0; +} +module_init(tsm_init); + +static void __exit tsm_exit(void) +{ + configfs_unregister_default_group(tsm_report_group); + configfs_unregister_subsystem(&tsm_configfs); +} +module_exit(tsm_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Provide Trusted Security Module attestation reports vi= a configfs"); diff --git a/include/linux/tsm.h b/include/linux/tsm.h new file mode 100644 index 000000000000..4b110b69a330 --- /dev/null +++ b/include/linux/tsm.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __TSM_H +#define __TSM_H + +#include +#include +#include + +#define TSM_INBLOB_MAX 64 +#define TSM_OUTBLOB_MAX SZ_32K + +/* + * Privilege level is a nested permission concept to allow confidential + * guests to partition address space, 4-levels are supported. + */ +#define TSM_PRIVLEVEL_MAX 3 + +enum tsm_format { + TSM_FORMAT_DEFAULT, + TSM_FORMAT_EXTENDED, +}; + +/** + * struct tsm_desc - option descriptor for generating tsm report blobs + * @privlevel: optional privilege level to associate with @outblob + * @inblob_len: sizeof @inblob + * @inblob: arbitrary input data + * @outblob_format: for TSMs with an "extended" format + */ +struct tsm_desc { + unsigned int privlevel; + size_t inblob_len; + u8 inblob[TSM_INBLOB_MAX]; + enum tsm_format outblob_format; +}; + +/* + * arch specific ops, only one is expected to be registered at a time + * i.e. only one of SEV, TDX, COVE, etc. + */ +struct tsm_ops { + const char *name; + const int privlevel_floor; + u8 *(*report_new)(const struct tsm_desc *desc, void *data, + size_t *outblob_len); +}; + +extern const struct config_item_type tsm_report_ext_type; +extern const struct config_item_type tsm_report_default_type; + +int register_tsm(const struct tsm_ops *ops, void *priv, + const struct config_item_type *type); +int unregister_tsm(const struct tsm_ops *ops); +#endif /* __TSM_H */ From nobody Fri Dec 19 16:11:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC948C6FA8F for ; Wed, 30 Aug 2023 21:32:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241543AbjH3Vco (ORCPT ); Wed, 30 Aug 2023 17:32:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241577AbjH3Vck (ORCPT ); Wed, 30 Aug 2023 17:32:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD708465DC for ; Wed, 30 Aug 2023 12:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693424161; x=1724960161; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yHkxxHhfcS/p1Zj4sNJBN+HXPs+0Ubf8u2ycubsIO3g=; b=kRRDhxO1xfa5WXeHxjBP+Skoj9EAnfmjwKjetZp/sYsENECWPc65yBeI ITPNCnTtkGoSrNMCdHetHxSYzR1wMfQrcwkUDDnnJN1SCH4I4a7umnhNn TxPCmECT2DY7qToPfB6PStGQTOBaZxFaiUb2GtvStDJRuxNbtTdy1OE+5 Il1raEaK9UI67hYBG0kiYMCY7cxwi9c5xtwI8rrlj9DzeEe0ns1Zp0p30 TUs2rOUIyKOec69dMdVhOdtqEmkY+jfX5iy1tEz8+oYok+OgZuZ7XcytB OIZD+Ma4ssSkL90PvEabddwfgzGwuaSkHl4CYThtrt5VO1VmgyL5EfzTM g==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="360723643" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="360723643" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="853844831" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="853844831" Received: from nivakuma-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.212.238.163]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:31 -0700 Subject: [PATCH v3 3/5] virt: sevguest: Prep for kernel internal {get, get_ext}_report() From: Dan Williams To: linux-coco@lists.linux.dev Cc: Borislav Petkov , Tom Lendacky , Dionna Glaze , Brijesh Singh , peterz@infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de Date: Wed, 30 Aug 2023 12:33:30 -0700 Message-ID: <169342401062.3934343.10039181536465702635.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> References: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for using the configs-tsm facility to convey attestation blobs to userspace, switch to using the 'sockptr' api for copying payloads to provided buffers where 'sockptr' handles user vs kernel buffers. While configfs-tsm is meant to replace existing confidential computing ioctl() implementations for attestation report retrieval the old ioctl() path needs to stick around for a deprecation period. No behavior change intended. Cc: Borislav Petkov Cc: Tom Lendacky Cc: Dionna Glaze Cc: Brijesh Singh Signed-off-by: Dan Williams Reviewed-by's from v2. --- drivers/virt/coco/sev-guest/sev-guest.c | 50 ++++++++++++++++++++-------= ---- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index 97dbe715e96a..c3c9e9ea691f 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include =20 @@ -470,7 +471,13 @@ static int handle_guest_request(struct snp_guest_dev *= snp_dev, u64 exit_code, return 0; } =20 -static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_requ= est_ioctl *arg) +struct snp_req_resp { + sockptr_t req_data; + sockptr_t resp_data; +}; + +static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_requ= est_ioctl *arg, + struct snp_req_resp *io) { struct snp_guest_crypto *crypto =3D snp_dev->crypto; struct snp_report_resp *resp; @@ -479,10 +486,10 @@ static int get_report(struct snp_guest_dev *snp_dev, = struct snp_guest_request_io =20 lockdep_assert_held(&snp_cmd_mutex); =20 - if (!arg->req_data || !arg->resp_data) + if (sockptr_is_null(io->req_data) || sockptr_is_null(io->resp_data)) return -EINVAL; =20 - if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req))) + if (copy_from_sockptr(&req, io->req_data, sizeof(req))) return -EFAULT; =20 /* @@ -501,7 +508,7 @@ static int get_report(struct snp_guest_dev *snp_dev, st= ruct snp_guest_request_io if (rc) goto e_free; =20 - if (copy_to_user((void __user *)arg->resp_data, resp, sizeof(*resp))) + if (copy_to_sockptr(io->resp_data, resp, sizeof(*resp))) rc =3D -EFAULT; =20 e_free: @@ -550,22 +557,25 @@ static int get_derived_key(struct snp_guest_dev *snp_= dev, struct snp_guest_reque return rc; } =20 -static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_= request_ioctl *arg) +static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_= request_ioctl *arg, + struct snp_req_resp *io) + { struct snp_guest_crypto *crypto =3D snp_dev->crypto; struct snp_ext_report_req req; struct snp_report_resp *resp; int ret, npages =3D 0, resp_len; + sockptr_t certs_address; =20 lockdep_assert_held(&snp_cmd_mutex); =20 - if (!arg->req_data || !arg->resp_data) + if (sockptr_is_null(io->req_data) || sockptr_is_null(io->resp_data)) return -EINVAL; =20 - if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req))) + if (copy_from_sockptr(&req, io->req_data, sizeof(req))) return -EFAULT; =20 - /* userspace does not want certificate data */ + /* caller does not want certificate data */ if (!req.certs_len || !req.certs_address) goto cmd; =20 @@ -573,8 +583,13 @@ static int get_ext_report(struct snp_guest_dev *snp_de= v, struct snp_guest_reques !IS_ALIGNED(req.certs_len, PAGE_SIZE)) return -EINVAL; =20 - if (!access_ok((const void __user *)req.certs_address, req.certs_len)) - return -EFAULT; + if (sockptr_is_kernel(io->resp_data)) { + certs_address =3D KERNEL_SOCKPTR((void *)req.certs_address); + } else { + certs_address =3D USER_SOCKPTR((void __user *)req.certs_address); + if (!access_ok(certs_address.user, req.certs_len)) + return -EFAULT; + } =20 /* * Initialize the intermediate buffer with all zeros. This buffer @@ -604,21 +619,19 @@ static int get_ext_report(struct snp_guest_dev *snp_d= ev, struct snp_guest_reques if (arg->vmm_error =3D=3D SNP_GUEST_VMM_ERR_INVALID_LEN) { req.certs_len =3D snp_dev->input.data_npages << PAGE_SHIFT; =20 - if (copy_to_user((void __user *)arg->req_data, &req, sizeof(req))) + if (copy_to_sockptr(io->req_data, &req, sizeof(req))) ret =3D -EFAULT; } =20 if (ret) goto e_free; =20 - if (npages && - copy_to_user((void __user *)req.certs_address, snp_dev->certs_data, - req.certs_len)) { + if (npages && copy_to_sockptr(certs_address, snp_dev->certs_data, req.cer= ts_len)) { ret =3D -EFAULT; goto e_free; } =20 - if (copy_to_user((void __user *)arg->resp_data, resp, sizeof(*resp))) + if (copy_to_sockptr(io->resp_data, resp, sizeof(*resp))) ret =3D -EFAULT; =20 e_free: @@ -631,6 +644,7 @@ static long snp_guest_ioctl(struct file *file, unsigned= int ioctl, unsigned long struct snp_guest_dev *snp_dev =3D to_snp_dev(file); void __user *argp =3D (void __user *)arg; struct snp_guest_request_ioctl input; + struct snp_req_resp io; int ret =3D -ENOTTY; =20 if (copy_from_user(&input, argp, sizeof(input))) @@ -651,15 +665,17 @@ static long snp_guest_ioctl(struct file *file, unsign= ed int ioctl, unsigned long return -ENOTTY; } =20 + io.req_data =3D USER_SOCKPTR((void __user *)input.req_data); + io.resp_data =3D USER_SOCKPTR((void __user *)input.resp_data); switch (ioctl) { case SNP_GET_REPORT: - ret =3D get_report(snp_dev, &input); + ret =3D get_report(snp_dev, &input, &io); break; case SNP_GET_DERIVED_KEY: ret =3D get_derived_key(snp_dev, &input); break; case SNP_GET_EXT_REPORT: - ret =3D get_ext_report(snp_dev, &input); + ret =3D get_ext_report(snp_dev, &input, &io); break; default: break; From nobody Fri Dec 19 16:11:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CCC8C6FA8F for ; Wed, 30 Aug 2023 20:01:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240226AbjH3UBF (ORCPT ); Wed, 30 Aug 2023 16:01:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240399AbjH3UAj (ORCPT ); Wed, 30 Aug 2023 16:00:39 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 648257D263 for ; Wed, 30 Aug 2023 12:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693424193; x=1724960193; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=igrcA3q8KN5WrWYA/jTLGNsZx4aaW/jLTGUAudQ8oU0=; b=DtqfTekGxhkqsTmhtppYugPo1njhTMnGpmleVlTB5dJx3KWfmTv4vQXX VfWM0lNiwRbikeYguENReYVcIYsSKbhDCK4WVkMZbAR83XgnpsfNLFMKb R6qxJ2Me5g4duqGOg+1XPBzl855u18T0jpO4yIpumFDa70a4O9DifJ/Po hHxSgWYSvjMtE7yMOZ0zOUuw/cVIhl/Y/lsrpx2q+W640OACGd1CKhTpE 7VvKLto/akGMtw7/QwW4PjTFSRnnOp+ig8TX63FXjXTO6P5cbN7S22CiM 05tTQ690btCrB52QpoGv+WhDPi8dP8bKEzMIhc+lCL3v/Y1Mpvyyw0KkK Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="360723668" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="360723668" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="853844876" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="853844876" Received: from nivakuma-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.212.238.163]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:37 -0700 Subject: [PATCH v3 4/5] mm/slab: Add __free() support for kvfree From: Dan Williams To: linux-coco@lists.linux.dev Cc: Andrew Morton , Peter Zijlstra , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, tglx@linutronix.de Date: Wed, 30 Aug 2023 12:33:36 -0700 Message-ID: <169342401666.3934343.5520453508283712955.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> References: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow for the declaration of variables that trigger kvfree() when they go out of scope. The check for NULL and call to kvfree() can be elided by the compiler in most cases, otherwise without the NULL check an unnecessary call to kvfree() may be emitted. Peter proposed a comment for this detail [1]. Link: http://lore.kernel.org/r/20230816103102.GF980931@hirez.programming.ki= cks-ass.net [1] Cc: Andrew Morton Cc: Peter Zijlstra Cc: Greg Kroah-Hartman Signed-off-by: Dan Williams Acked-by: Greg Kroah-Hartman Acked-by: Pankaj Gupta Reviewed-by's from v2. --- include/linux/slab.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/slab.h b/include/linux/slab.h index 848c7c82ad5a..241025367943 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -746,6 +746,8 @@ static inline __alloc_size(1, 2) void *kvcalloc(size_t = n, size_t size, gfp_t fla extern void *kvrealloc(const void *p, size_t oldsize, size_t newsize, gfp_= t flags) __realloc_size(3); extern void kvfree(const void *addr); +DEFINE_FREE(kvfree, void *, if (_T) kvfree(_T)) + extern void kvfree_sensitive(const void *addr, size_t len); =20 unsigned int kmem_cache_size(struct kmem_cache *s); From nobody Fri Dec 19 16:11:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6251C83F14 for ; Wed, 30 Aug 2023 20:01:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239470AbjH3UBN (ORCPT ); Wed, 30 Aug 2023 16:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238293AbjH3UAt (ORCPT ); Wed, 30 Aug 2023 16:00:49 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBFAA4EE3 for ; Wed, 30 Aug 2023 12:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693424222; x=1724960222; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c+jEDPqTHm9uescgnXUEsEv+dnWGPwPiDy6A7HSsyBA=; b=bRxOJuPHzQMsBFrFvRi0n4OV0PVxmaxz1+7BUY1unwTFfF5FJsdQTuY+ u2QsbRAnHcqgph/1zwST8lT4xNcrDnJbVe8fxNp3kYzCmzW/M5k8y6PUw yaPp8atkOwI0iFvbwkArNV7KDQmsV0LglZjzCI20plDhY35/LuMUoggan ulOwjTIO4Bb+XIDY1CbVY0bFpi4ICbFlAR+FMLWdgxk9OgReZ/AmRQDMv ayPHzrklOQL/3a036t7r+MvJz4mC2AVzFH14FDX5b5Rct0qKLYMeDvt26 LZ1OEp1iC5eEd9JkHJKGl8aHiKtAL28eNTo21Gfi7KjbVzQmTw8TgLivF g==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="360723672" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="360723672" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="853844918" X-IronPort-AV: E=Sophos;i="6.02,214,1688454000"; d="scan'208";a="853844918" Received: from nivakuma-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.212.238.163]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 12:33:43 -0700 Subject: [PATCH v3 5/5] virt: sevguest: Add TSM_REPORTS support for SNP_{GET, GET_EXT}_REPORT From: Dan Williams To: linux-coco@lists.linux.dev Cc: Borislav Petkov , Tom Lendacky , Dionna Glaze , Brijesh Singh , peterz@infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de Date: Wed, 30 Aug 2023 12:33:42 -0700 Message-ID: <169342402274.3934343.11704206926819634506.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> References: <169342399185.3934343.3035845348326944519.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sevguest driver was a first mover in the confidential computing space. As a first mover that afforded some leeway to build the driver without concern for common infrastructure. Now that sevguest is no longer a singleton [1] the common operation of building and transmitting attestation report blobs can / should be made common. In this model the so called "TSM-provider" implementations can share a common envelope ABI even if the contents of that envelope remain vendor-specific. When / if the industry agrees on an attestation record format, that definition can also fit in the same ABI. In the meantime the kernel's maintenance burden is reduced and collaboration on the commons is increased. Convert sevguest to use CONFIG_TSM_REPORTS to retrieve the blobs that the SNP_{GET,GET_EXT}_REPORT ioctls produce. An example flow follows for retrieving the SNP_GET_REPORT blob via the TSM interface utility, assuming no nonce and VMPL=3D=3D2: report=3D/sys/kernel/config/tsm/report/report0 mkdir $report echo 2 > $report/privlevel dd if=3D/dev/urandom bs=3D64 count=3D1 > $report/inblob hexdump -C $report/outblob rmdir $report ...while the SNP_GET_EXT_REPORT flow needs to additionally set the format to "extended": report=3D/sys/kernel/config/tsm/report/report1 mkdir $report echo extended > $report/format dd if=3D/dev/urandom bs=3D64 count=3D1 > $report/inblob hexdump -C $report/outblob rmdir $report The old ioctls can be lazily deprecated, the main motivation of this effort is to stop the proliferation of new ioctls, and to increase cross-vendor collaboration. Note, only compile-tested. Link: http://lore.kernel.org/r/64961c3baf8ce_142af829436@dwillia2-xfh.jf.in= tel.com.notmuch [1] Cc: Borislav Petkov Cc: Tom Lendacky Cc: Dionna Glaze Cc: Brijesh Singh Signed-off-by: Dan Williams Reviewed-by's from v2. --- drivers/virt/coco/sev-guest/Kconfig | 1=20 drivers/virt/coco/sev-guest/sev-guest.c | 83 +++++++++++++++++++++++++++= ++++ 2 files changed, 84 insertions(+) diff --git a/drivers/virt/coco/sev-guest/Kconfig b/drivers/virt/coco/sev-gu= est/Kconfig index da2d7ca531f0..1cffc72c41cb 100644 --- a/drivers/virt/coco/sev-guest/Kconfig +++ b/drivers/virt/coco/sev-guest/Kconfig @@ -5,6 +5,7 @@ config SEV_GUEST select CRYPTO select CRYPTO_AEAD2 select CRYPTO_GCM + select TSM_REPORTS help SEV-SNP firmware provides the guest a mechanism to communicate with the PSP without risk from a malicious hypervisor who wishes to read, diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index c3c9e9ea691f..c7bbb8f372a3 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -16,10 +16,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include =20 @@ -759,6 +761,79 @@ static u8 *get_vmpck(int id, struct snp_secrets_page_l= ayout *layout, u32 **seqno return key; } =20 +static u8 *sev_report_new(const struct tsm_desc *desc, void *data, size_t = *outblob_len) +{ + struct snp_guest_dev *snp_dev =3D data; + const int report_size =3D SZ_4K; + const int ext_size =3D SZ_16K; + int ret, size; + + if (desc->inblob_len !=3D 64) + return ERR_PTR(-EINVAL); + + if (desc->outblob_format =3D=3D TSM_FORMAT_EXTENDED) + size =3D report_size + ext_size; + else + size =3D report_size; + + u8 *buf __free(kvfree) =3D kvzalloc(size, GFP_KERNEL); + + guard(mutex)(&snp_cmd_mutex); + if (desc->outblob_format =3D=3D TSM_FORMAT_EXTENDED) { + struct snp_ext_report_req ext_req =3D { + .data =3D { .vmpl =3D desc->privlevel }, + .certs_address =3D (__u64)buf + report_size, + .certs_len =3D ext_size, + }; + memcpy(&ext_req.data.user_data, desc->inblob, desc->inblob_len); + + struct snp_guest_request_ioctl input =3D { + .msg_version =3D 1, + .req_data =3D (__u64)&ext_req, + .resp_data =3D (__u64)buf, + }; + struct snp_req_resp io =3D { + .req_data =3D KERNEL_SOCKPTR(&ext_req), + .resp_data =3D KERNEL_SOCKPTR(buf), + }; + + ret =3D get_ext_report(snp_dev, &input, &io); + } else { + struct snp_report_req req =3D { + .vmpl =3D desc->privlevel, + }; + memcpy(&req.user_data, desc->inblob, desc->inblob_len); + + struct snp_guest_request_ioctl input =3D { + .msg_version =3D 1, + .req_data =3D (__u64)&req, + .resp_data =3D (__u64)buf, + }; + struct snp_req_resp io =3D { + .req_data =3D KERNEL_SOCKPTR(&req), + .resp_data =3D KERNEL_SOCKPTR(buf), + }; + + ret =3D get_report(snp_dev, &input, &io); + } + + if (ret) + return ERR_PTR(ret); + + *outblob_len =3D size; + return_ptr(buf); +} + +static const struct tsm_ops sev_tsm_ops =3D { + .name =3D KBUILD_MODNAME, + .report_new =3D sev_report_new, +}; + +static void unregister_sev_tsm(void *data) +{ + unregister_tsm(&sev_tsm_ops); +} + static int __init sev_guest_probe(struct platform_device *pdev) { struct snp_secrets_page_layout *layout; @@ -832,6 +907,14 @@ static int __init sev_guest_probe(struct platform_devi= ce *pdev) snp_dev->input.resp_gpa =3D __pa(snp_dev->response); snp_dev->input.data_gpa =3D __pa(snp_dev->certs_data); =20 + ret =3D register_tsm(&sev_tsm_ops, snp_dev, &tsm_report_ext_type); + if (ret) + goto e_free_cert_data; + + ret =3D devm_add_action_or_reset(&pdev->dev, unregister_sev_tsm, NULL); + if (ret) + goto e_free_cert_data; + ret =3D misc_register(misc); if (ret) goto e_free_cert_data;