From patchwork Mon Mar 6 09:20:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1752269 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=gbQNW9YJ; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PVY3q1hgXz246l for ; Mon, 6 Mar 2023 20:21:26 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pZ71y-0007my-EV; Mon, 06 Mar 2023 09:21:18 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pZ71p-0007gb-PR for kernel-team@lists.ubuntu.com; Mon, 06 Mar 2023 09:21:09 +0000 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 309643F125 for ; Mon, 6 Mar 2023 09:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1678094469; bh=3QUhESpsJG3/Q4t3sdpOc8qOvq8Wof0H1f4g0t510Q0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=gbQNW9YJYljQPBiOHS5+xSpZ4Ct2ggFI0LIbtdiyqgUje52FNBiBuWMXcQTPG/zrH jw81e4BTXSBusaVeT0HjBa9wKDmOduAHjACs809QRxDCO+aSIU2/A6RsFpp3nyWdkS Cb1WMbs0IcMqvJCawG2N5H0J1zUCGznqqgVzS98T0voyrX4mUNsQgLrBpAxt9UYMe9 TdeFya08sr3q9udEjnljik9920rQDKxDmVzssPaGJYPQzlTCz1i3xaEefqkxQHa0Ez uEIpIcoh1kRygum9bhGHJ+QipGDJpG6SC396JpCFSSbYbT0O3CS9KDFiiLEBe4b9yv /kfuLOXDE89lA== Received: by mail-ed1-f70.google.com with SMTP id y1-20020a056402358100b004ea439d57b7so635251edc.12 for ; Mon, 06 Mar 2023 01:21:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3QUhESpsJG3/Q4t3sdpOc8qOvq8Wof0H1f4g0t510Q0=; b=7ds4NKPTNIWnVu3uHBeufwXIVFXhTvj5AoP4Cab2IErnvkSWvmBTn+rPoKFeM7KH5X lVrovP8UTWASn/Ns7XIFz0YE8DlngZkA7CUpNsCzJATxYy9oR1YioTcS3OGdsKLuhAG7 0Xpq4/8luLXUB9l2RGX8RQDx325Am6+i1xLvIO77sP0f08GuOn/JMC4MdEW09keKxGCE /kd+t7Hdf02OzjABTrRoZyCCIluKrAKJIM5R9j9ukJz8HySouioZpy8efdGiBA9Z57qQ fkJ3ECeZ6TDAB7V4dphWprClK+vsUHNBLQ/LYw0mKWCPnhzbHJnJQJZ3dz5p9VTs3VJC LVSQ== X-Gm-Message-State: AO0yUKXCE/lMhbAooaQJEqsQeaHFdJRH06NSYAsEraBA8Inq3WIBmwdZ IBMEZmZSypQ/Zv63Rp0OQe7lsOTUWshdL2PywlCIZ120veBu9y+uWDG3XaDlEuv8gCJL7l9r8Hm TBQACSA71qVYOOHlZphGyBk1DQEe+ED5tUwj17Jv9XiAAWmeC0g== X-Received: by 2002:aa7:d7c3:0:b0:4af:5aa1:6e58 with SMTP id e3-20020aa7d7c3000000b004af5aa16e58mr9792603eds.21.1678094467722; Mon, 06 Mar 2023 01:21:07 -0800 (PST) X-Google-Smtp-Source: AK7set84JzSYmbNXXuFb8Kba11gWYufpoYDyXDnQ19jg6qI/Q304kSnsO++G4Lm2LCS59fLl4YvmwA== X-Received: by 2002:aa7:d7c3:0:b0:4af:5aa1:6e58 with SMTP id e3-20020aa7d7c3000000b004af5aa16e58mr9792588eds.21.1678094467423; Mon, 06 Mar 2023 01:21:07 -0800 (PST) Received: from localhost.localdomain (host-79-53-23-214.retail.telecomitalia.it. [79.53.23.214]) by smtp.gmail.com with ESMTPSA id n18-20020a50c212000000b004af515d2dd8sm4864293edf.74.2023.03.06.01.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 01:21:07 -0800 (PST) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][K][PATCH 1/6] Revert "UBUNTU: SAUCE: selftests: tdx: Test GetReport TDX attestation feature" Date: Mon, 6 Mar 2023 10:20:53 +0100 Message-Id: <20230306092058.26718-2-andrea.righi@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306092058.26718-1-andrea.righi@canonical.com> References: <20230306092058.26718-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2009437 This reverts commit the following commit, that will be replaced by a new TDX patch set: 0b78a71c7d76 ("UBUNTU: SAUCE: selftests: tdx: Test GetReport TDX attestation feature") Signed-off-by: Andrea Righi --- tools/arch/x86/include/uapi/asm/tdx.h | 51 ------ tools/testing/selftests/Makefile | 1 - tools/testing/selftests/tdx/Makefile | 11 -- tools/testing/selftests/tdx/config | 1 - tools/testing/selftests/tdx/tdx_attest_test.c | 156 ------------------ 5 files changed, 220 deletions(-) delete mode 100644 tools/arch/x86/include/uapi/asm/tdx.h delete mode 100644 tools/testing/selftests/tdx/Makefile delete mode 100644 tools/testing/selftests/tdx/config delete mode 100644 tools/testing/selftests/tdx/tdx_attest_test.c diff --git a/tools/arch/x86/include/uapi/asm/tdx.h b/tools/arch/x86/include/uapi/asm/tdx.h deleted file mode 100644 index c1667b20fe20..000000000000 --- a/tools/arch/x86/include/uapi/asm/tdx.h +++ /dev/null @@ -1,51 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _UAPI_ASM_X86_TDX_H -#define _UAPI_ASM_X86_TDX_H - -#include -#include - -/* Length of the REPORTDATA used in TDG.MR.REPORT TDCALL */ -#define TDX_REPORTDATA_LEN 64 - -/* Length of TDREPORT used in TDG.MR.REPORT TDCALL */ -#define TDX_REPORT_LEN 1024 - -/** - * struct tdx_report_req: Get TDREPORT using REPORTDATA as input. - * - * @subtype : Subtype of TDREPORT (fixed as 0 by TDX Module - * specification, but added a parameter to handle - * future extension). - * @reportdata : User-defined REPORTDATA to be included into - * TDREPORT. Typically it can be some nonce - * provided by attestation service, so the - * generated TDREPORT can be uniquely verified. - * @rpd_len : Length of the REPORTDATA (fixed as 64 bytes by - * the TDX Module specification, but parameter is - * added to handle future extension). - * @tdreport : TDREPORT output from TDCALL[TDG.MR.REPORT]. - * @tdr_len : Length of the TDREPORT (fixed as 1024 bytes by - * the TDX Module specification, but a parameter - * is added to accommodate future extension). - * - * Used in TDX_CMD_GET_REPORT IOCTL request. - */ -struct tdx_report_req { - __u8 subtype; - __u64 reportdata; - __u32 rpd_len; - __u64 tdreport; - __u32 tdr_len; -}; - -/* - * TDX_CMD_GET_REPORT - Get TDREPORT using TDCALL[TDG.MR.REPORT] - * - * Return 0 on success, -EIO on TDCALL execution failure, and - * standard errno on other general error cases. - * - */ -#define TDX_CMD_GET_REPORT _IOWR('T', 0x01, __u64) - -#endif /* _UAPI_ASM_X86_TDX_H */ diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 807a839d69c4..de11992dc577 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -69,7 +69,6 @@ TARGETS += sync TARGETS += syscall_user_dispatch TARGETS += sysctl TARGETS += tc-testing -TARGETS += tdx TARGETS += timens ifneq (1, $(quicktest)) TARGETS += timers diff --git a/tools/testing/selftests/tdx/Makefile b/tools/testing/selftests/tdx/Makefile deleted file mode 100644 index 014795420184..000000000000 --- a/tools/testing/selftests/tdx/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -top_srcdir = ../../../.. - -LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include - -CFLAGS += -O3 -Wl,-no-as-needed -Wall -static -I$(LINUX_TOOL_ARCH_INCLUDE) - -TEST_GEN_PROGS := tdx_attest_test - -include ../lib.mk diff --git a/tools/testing/selftests/tdx/config b/tools/testing/selftests/tdx/config deleted file mode 100644 index 1340073a4abf..000000000000 --- a/tools/testing/selftests/tdx/config +++ /dev/null @@ -1 +0,0 @@ -CONFIG_INTEL_TDX_GUEST=y diff --git a/tools/testing/selftests/tdx/tdx_attest_test.c b/tools/testing/selftests/tdx/tdx_attest_test.c deleted file mode 100644 index b8cef2707905..000000000000 --- a/tools/testing/selftests/tdx/tdx_attest_test.c +++ /dev/null @@ -1,156 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Test TDX attestation feature - * - * Copyright (C) 2022 Intel Corporation. All rights reserved. - * - * Author: Kuppuswamy Sathyanarayanan - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include "../kselftest_harness.h" - -#define devname "/dev/tdx-guest" -#define HEX_DUMP_SIZE 8 -#define __packed __attribute__((packed)) - -/* - * Trusted Execution Environment (TEE) report (TDREPORT_STRUCT) type, - * sub type and version. More details can be found in TDX v1.0 Module - * specification, sec titled "REPORTTYPE". - */ -struct tdreport_type { - /* 0 - SGX, 81 -TDX, rest are reserved */ - __u8 type; - /* Default value is 0 */ - __u8 sub_type; - /* Default value is 0 */ - __u8 version; - __u8 reserved; -} __packed; - -/* - * struct reportmac - First field in the TRDREPORT_STRUCT. It is common - * to Intel’s TEE's e.g., SGX and TDX. It is MAC-protected and contains - * hashes of the remainder of the report structure which includes the - * TEE’s measurements, and where applicable, the measurements of additional - * TCB elements not reflected in CPUSVN – e.g., a SEAM’s measurements. - * More details can be found in TDX v1.0 Module specification, sec titled - * "REPORTMACSTRUCT" - */ -struct reportmac { - struct tdreport_type type; - __u8 reserved1[12]; - /* CPU security version */ - __u8 cpu_svn[16]; - /* SHA384 hash of TEE TCB INFO */ - __u8 tee_tcb_info_hash[48]; - /* SHA384 hash of TDINFO_STRUCT */ - __u8 tee_td_info_hash[48]; - /* User defined unique data passed in TDG.MR.REPORT request */ - __u8 reportdata[64]; - __u8 reserved2[32]; - __u8 mac[32]; -} __packed; - -/* - * struct td_info - It contains the measurements and initial configuration - * of the TD that was locked at initialization and a set of measurement - * registers that are run-time extendable. These values are copied from - * the TDCS by the TDG.MR.REPORT function. More details can be found in - * TDX v1.0 Module specification, sec titled "TDINFO_STRUCT". - */ -struct td_info { - /* TD attributes (like debug, spet_disable, etc) */ - __u8 attr[8]; - __u64 xfam; - /* Measurement registers */ - __u64 mrtd[6]; - __u64 mrconfigid[6]; - __u64 mrowner[6]; - __u64 mrownerconfig[6]; - /* Runtime measurement registers */ - __u64 rtmr[24]; - __u64 reserved[14]; -} __packed; - -struct tdreport { - /* Common to TDX/SGX of size 256 bytes */ - struct reportmac reportmac; - __u8 tee_tcb_info[239]; - __u8 reserved[17]; - /* Measurements and configuration data of size 512 byes */ - struct td_info tdinfo; -} __packed; - -#ifdef DEBUG -static void print_array_hex(const char *title, const char *prefix_str, - const void *buf, int len) -{ - const __u8 *ptr = buf; - int i, rowsize = HEX_DUMP_SIZE; - - if (!len || !buf) - return; - - printf("\t\t%s", title); - - for (i = 0; i < len; i++) { - if (!(i % rowsize)) - printf("\n%s%.8x:", prefix_str, i); - printf(" %.2x", ptr[i]); - } - - printf("\n"); -} -#endif - -TEST(verify_report) -{ - __u8 reportdata[TDX_REPORTDATA_LEN]; - struct tdreport tdreport; - struct tdx_report_req req; - int devfd, i; - - devfd = open(devname, O_RDWR | O_SYNC); - - ASSERT_LT(0, devfd); - - /* Generate sample report data */ - for (i = 0; i < TDX_REPORTDATA_LEN; i++) - reportdata[i] = i; - - /* Initialize IOCTL request */ - req.subtype = 0; - req.reportdata = (__u64)reportdata; - req.rpd_len = TDX_REPORTDATA_LEN; - req.tdreport = (__u64)&tdreport; - req.tdr_len = sizeof(tdreport); - - /* Get TDREPORT */ - ASSERT_EQ(0, ioctl(devfd, TDX_CMD_GET_REPORT, &req)); - -#ifdef DEBUG - print_array_hex("\n\t\tTDX report data\n", "", - reportdata, sizeof(reportdata)); - - print_array_hex("\n\t\tTDX tdreport data\n", "", - &tdreport, sizeof(tdreport)); -#endif - - /* Make sure TDREPORT data includes the REPORTDATA passed */ - ASSERT_EQ(0, memcmp(&tdreport.reportmac.reportdata[0], - reportdata, sizeof(reportdata))); - - ASSERT_EQ(0, close(devfd)); -} - -TEST_HARNESS_MAIN From patchwork Mon Mar 6 09:20:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1752271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=d5O/Ygaj; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PVY3s2kw2z1yWw for ; Mon, 6 Mar 2023 20:21:29 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pZ722-0007rq-87; Mon, 06 Mar 2023 09:21:22 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pZ71q-0007gt-LK for kernel-team@lists.ubuntu.com; Mon, 06 Mar 2023 09:21:10 +0000 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id DAE373F599 for ; Mon, 6 Mar 2023 09:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1678094469; bh=IAYp1tFMxyOwxepd8ZsaQrnH7uKXMm/KQOoI7HGErXE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d5O/YgajQRGShlWNzm3/gMzi1HKkEsmNCV3dCx+0bL1TA9nuhsM8NycoHAUu9Z8kX hDH6L1YsWVNLfQtbilpnGxKHpfDo4TfFyximxzmgBvvH7R7DXzBc13oX08dQmbiWsH IYVygXZzKQ9/FCn8kkxVYkA9HTdb0otM0DE95fzf3uYh8j4FWEhvGf6zyJxtKmSOH1 lpZzs2Pkj2upOv3zPzGlWSW2+m8fmbcizISDgsv1Z8XJ2JdMhY2pt7QWHpVTC9dyKI /C6VRBTiD1nQBxTI3A2+mIaQssCQZJdd+R5FhXYVaED//NH27qUQVcrD5e8FuuYirX Pyn2vwyipZ37g== Received: by mail-ed1-f71.google.com with SMTP id b1-20020aa7dc01000000b004ad062fee5eso12708680edu.17 for ; Mon, 06 Mar 2023 01:21:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IAYp1tFMxyOwxepd8ZsaQrnH7uKXMm/KQOoI7HGErXE=; b=Yig76NA1AlS6ruaAaEfU9WUlY/9f5sUPeVzCZiUG8RTde5QfqmMPbh36OuusXGZwD5 6Cstibiyol2Sms2b97ECpAeNaJAi6hRXdAwITRHwanqP5xiZa0Xef2wulAsCh7Z3mRMj s/VWr2TwSr8//ofSyo3SvbGRX6xu6yIHPWucishBnAL//fwchb07IRnCgCnJ4nJ5E/nh pvcILca6mt/LHAoK4BEw6qXscuDC7kVoAWAcHMy1irnd8MXjJwoNx7mgfMoL05XLyv0S ulNElZj3DXaXILQAFgFR/Iz/N4074uyrWv6UdjoUX5ao/hHSt8zwEwpCAdg/ldGuF3f9 tVVg== X-Gm-Message-State: AO0yUKXDMdGpEV0QV8/aublI8wbxl1z/Q9JF5nreoLMZRDeLA1PLdoOM eUx44M/WKEUVk/BTS2DmVaUuJiBUnLWLDdqMBccGHOT/HwJ8GNBiyZZ+JQ7ebh+Ay7yxCO37/mB 7yMmBFpVf+23+ToTZfmP9iiWdze+y95MM0QeNS3ct8Sv0p6Czsw== X-Received: by 2002:aa7:cd55:0:b0:4c0:e156:7954 with SMTP id v21-20020aa7cd55000000b004c0e1567954mr7791587edw.34.1678094468132; Mon, 06 Mar 2023 01:21:08 -0800 (PST) X-Google-Smtp-Source: AK7set99wGtL1+V3VIbsIfMivRDbefpXs7H47udo28luccK9LrvbzgiMFpcjz/RLbI0YEMfL0+reeQ== X-Received: by 2002:aa7:cd55:0:b0:4c0:e156:7954 with SMTP id v21-20020aa7cd55000000b004c0e1567954mr7791568edw.34.1678094467813; Mon, 06 Mar 2023 01:21:07 -0800 (PST) Received: from localhost.localdomain (host-79-53-23-214.retail.telecomitalia.it. [79.53.23.214]) by smtp.gmail.com with ESMTPSA id n18-20020a50c212000000b004af515d2dd8sm4864293edf.74.2023.03.06.01.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 01:21:07 -0800 (PST) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][K][PATCH 2/6] Revert "UBUNTU: SAUCE: x86/tdx: Add TDX Guest attestation interface driver" Date: Mon, 6 Mar 2023 10:20:54 +0100 Message-Id: <20230306092058.26718-3-andrea.righi@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306092058.26718-1-andrea.righi@canonical.com> References: <20230306092058.26718-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2009437 This reverts commit the following commit, that will be replaced by a new TDX patch set: 285d6d8136eb ("UBUNTU: SAUCE: x86/tdx: Add TDX Guest attestation interface driver") Signed-off-by: Andrea Righi --- arch/x86/coco/tdx/tdx.c | 117 -------------------------------- arch/x86/include/uapi/asm/tdx.h | 51 -------------- 2 files changed, 168 deletions(-) delete mode 100644 arch/x86/include/uapi/asm/tdx.h diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index d8be693cb3a2..b8998cf0508a 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -5,21 +5,16 @@ #define pr_fmt(fmt) "tdx: " fmt #include -#include -#include -#include #include #include #include #include #include #include -#include /* TDX module Call Leaf IDs */ #define TDX_GET_INFO 1 #define TDX_GET_VEINFO 3 -#define TDX_GET_REPORT 4 #define TDX_ACCEPT_PAGE 6 /* TDX hypercall Leaf IDs */ @@ -39,10 +34,6 @@ #define VE_GET_PORT_NUM(e) ((e) >> 16) #define VE_IS_IO_STRING(e) ((e) & BIT(4)) -#define DRIVER_NAME "tdx-guest" - -static struct miscdevice tdx_misc_dev; - #define ATTR_SEPT_VE_DISABLE BIT(28) /* @@ -795,111 +786,3 @@ void __init tdx_early_init(void) pr_info("Guest detected\n"); } - -static long tdx_get_report(void __user *argp) -{ - u8 *reportdata = NULL, *tdreport = NULL; - struct tdx_report_req req; - long ret; - - /* Copy request struct from the user buffer */ - if (copy_from_user(&req, argp, sizeof(req))) - return -EFAULT; - - /* - * Per TDX Module 1.0 specification, section titled - * "TDG.MR.REPORT", REPORTDATA and TDREPORT length - * is fixed as TDX_REPORTDATA_LEN and TDX_REPORT_LEN. - */ - if (req.rpd_len != TDX_REPORTDATA_LEN || req.tdr_len != TDX_REPORT_LEN) - return -EINVAL; - - /* Allocate kernel buffers for REPORTDATA and TDREPORT */ - reportdata = kzalloc(req.rpd_len, GFP_KERNEL); - if (!reportdata) { - ret = -ENOMEM; - goto out; - } - - tdreport = kzalloc(req.tdr_len, GFP_KERNEL); - if (!tdreport) { - ret = -ENOMEM; - goto out; - } - - - /* Copy REPORTDATA from user to kernel buffer */ - if (copy_from_user(reportdata, (void *)req.reportdata, req.rpd_len)) { - ret = -EFAULT; - goto out; - } - - /* - * Generate TDREPORT using "TDG.MR.REPORT" TDCALL. - * - * Get the TDREPORT using REPORTDATA as input. Refer to - * section 22.3.3 TDG.MR.REPORT leaf in the TDX Module 1.0 - * Specification for detailed information. - */ - ret = __tdx_module_call(TDX_GET_REPORT, virt_to_phys(tdreport), - virt_to_phys(reportdata), req.subtype, - 0, NULL); - if (ret) { - ret = -EIO; - goto out; - } - - /* Copy TDREPORT data back to the user buffer */ - if (copy_to_user((void *)req.tdreport, tdreport, req.tdr_len)) - ret = -EFAULT; - -out: - kfree(reportdata); - kfree(tdreport); - return ret; -} -static long tdx_guest_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - void __user *argp = (void __user *)arg; - long ret = -EINVAL; - - switch (cmd) { - case TDX_CMD_GET_REPORT: - ret = tdx_get_report(argp); - break; - default: - pr_debug("cmd %d not supported\n", cmd); - break; - } - - return ret; -} - -static const struct file_operations tdx_guest_fops = { - .owner = THIS_MODULE, - .unlocked_ioctl = tdx_guest_ioctl, - .llseek = no_llseek, -}; - -static int __init tdx_guest_init(void) -{ - int ret; - - /* Make sure we are in a valid TDX platform */ - if (!cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) - return -EIO; - - tdx_misc_dev.name = DRIVER_NAME; - tdx_misc_dev.minor = MISC_DYNAMIC_MINOR; - tdx_misc_dev.fops = &tdx_guest_fops; - - ret = misc_register(&tdx_misc_dev); - if (ret) { - pr_err("misc device registration failed\n"); - return ret; - } - - return 0; -} -device_initcall(tdx_guest_init) diff --git a/arch/x86/include/uapi/asm/tdx.h b/arch/x86/include/uapi/asm/tdx.h deleted file mode 100644 index c1667b20fe20..000000000000 --- a/arch/x86/include/uapi/asm/tdx.h +++ /dev/null @@ -1,51 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _UAPI_ASM_X86_TDX_H -#define _UAPI_ASM_X86_TDX_H - -#include -#include - -/* Length of the REPORTDATA used in TDG.MR.REPORT TDCALL */ -#define TDX_REPORTDATA_LEN 64 - -/* Length of TDREPORT used in TDG.MR.REPORT TDCALL */ -#define TDX_REPORT_LEN 1024 - -/** - * struct tdx_report_req: Get TDREPORT using REPORTDATA as input. - * - * @subtype : Subtype of TDREPORT (fixed as 0 by TDX Module - * specification, but added a parameter to handle - * future extension). - * @reportdata : User-defined REPORTDATA to be included into - * TDREPORT. Typically it can be some nonce - * provided by attestation service, so the - * generated TDREPORT can be uniquely verified. - * @rpd_len : Length of the REPORTDATA (fixed as 64 bytes by - * the TDX Module specification, but parameter is - * added to handle future extension). - * @tdreport : TDREPORT output from TDCALL[TDG.MR.REPORT]. - * @tdr_len : Length of the TDREPORT (fixed as 1024 bytes by - * the TDX Module specification, but a parameter - * is added to accommodate future extension). - * - * Used in TDX_CMD_GET_REPORT IOCTL request. - */ -struct tdx_report_req { - __u8 subtype; - __u64 reportdata; - __u32 rpd_len; - __u64 tdreport; - __u32 tdr_len; -}; - -/* - * TDX_CMD_GET_REPORT - Get TDREPORT using TDCALL[TDG.MR.REPORT] - * - * Return 0 on success, -EIO on TDCALL execution failure, and - * standard errno on other general error cases. - * - */ -#define TDX_CMD_GET_REPORT _IOWR('T', 0x01, __u64) - -#endif /* _UAPI_ASM_X86_TDX_H */ From patchwork Mon Mar 6 09:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1752270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=wOxXSp9+; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PVY3r0ydzz246m for ; Mon, 6 Mar 2023 20:21:28 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pZ720-0007od-26; Mon, 06 Mar 2023 09:21:20 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pZ71q-0007gu-Iy for kernel-team@lists.ubuntu.com; Mon, 06 Mar 2023 09:21:10 +0000 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id DAC643F592 for ; Mon, 6 Mar 2023 09:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1678094469; bh=KAUb4gufqXFtAZDEeRUoworWxTwkI+ySLIH32QIDcYc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=wOxXSp9+cbva1CVs/eLd1CtEckofFycjN7h2eXWl7wzDfEyjwz3XuLiu6MxdkqlRj zhlhpFC8X/Zys7CZ+d7ZO9MvnvOQuLC5Rcwy/GSnoUO4Fxi31NtQxkZL5EzJOJxMkz KKiS+wf6t6z/x1ZJnX3/ZEgytqWOtHbuoQrz+paU2TPljkO+L97gorMGgymVM6J/HJ hjbU9L68kl4TCLgozJELy1BLJyqJd1K6vOd4kn9MQbRbEp/h6gv7wGqyZ0yNodn3Za yR5dztrOgP6mn9zSvdGBta1lU80fT71ZzHSBOroBtkPURvq0CpdXKbPntFsYEV/Yrr b1Akm1S86R2DA== Received: by mail-ed1-f72.google.com with SMTP id dn8-20020a05640222e800b004bd35dd76a9so12969428edb.13 for ; Mon, 06 Mar 2023 01:21:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KAUb4gufqXFtAZDEeRUoworWxTwkI+ySLIH32QIDcYc=; b=so2rTafmVbO94AX/fvZsi7O1kIyDJYVRMcIUMtJ42FRKjbQKXqG+qTb0G/MO/qmJGI 4b1UodCKthrlV7HHJzyOYVH+DdHMbXemyWS4puwsyyMl/+HyJ5bmRDswQ7ytHr57WUc5 FwDrM3SL8VEWkQDzK2ZNpth2vksjE0YQJICh0v+zCKlKJJkgVSxVkUo1kvBs+J5AKQkE twmkReYAstUaRDCT24RyOqf0ae6cmPXeuocO4ACP1usl8/94o2GSkT0lta1nq3py2+16 tMtv+p8Og5zbWDhGS1ifY5CNpEYQRuEmtn0np2e1PdGetrr+BoEXd/BIepU4+eETdWXv denA== X-Gm-Message-State: AO0yUKUaRQNGgPOKt9Rl+WjklsCNk8YaIusxW807cRikVTfJHyGKCI9l IwPKbITjWbpDLjI6+m8YJ5oWZ4o8e9giC1JVahweM9nFatAySNIH2I7GFvQBtNp3R0ixj7YJKfs nW4M66p3SzYlcDDt+zFmOinJiLrRQRKQFGaeUrc2BLyjoly1r8g== X-Received: by 2002:a17:906:4953:b0:877:a2d1:7560 with SMTP id f19-20020a170906495300b00877a2d17560mr10056841ejt.27.1678094468552; Mon, 06 Mar 2023 01:21:08 -0800 (PST) X-Google-Smtp-Source: AK7set+180waPCG5GXattevLf9by75b8htxhroslAPoeCLdpLmhQoAzH3o1fjlAUpPh27nn0VHjT4Q== X-Received: by 2002:a17:906:4953:b0:877:a2d1:7560 with SMTP id f19-20020a170906495300b00877a2d17560mr10056827ejt.27.1678094468228; Mon, 06 Mar 2023 01:21:08 -0800 (PST) Received: from localhost.localdomain (host-79-53-23-214.retail.telecomitalia.it. [79.53.23.214]) by smtp.gmail.com with ESMTPSA id n18-20020a50c212000000b004af515d2dd8sm4864293edf.74.2023.03.06.01.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 01:21:08 -0800 (PST) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][K][PATCH 3/6] UBUNTU: SAUCE: x86/tdx: Add a wrapper to get TDREPORT0 from the TDX Module Date: Mon, 6 Mar 2023 10:20:55 +0100 Message-Id: <20230306092058.26718-4-andrea.righi@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306092058.26718-1-andrea.righi@canonical.com> References: <20230306092058.26718-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Kuppuswamy Sathyanarayanan BugLink: https://bugs.launchpad.net/bugs/2009437 To support TDX attestation, the TDX guest driver exposes an IOCTL interface to allow userspace to get the TDREPORT0 (a.k.a. TDREPORT subtype 0) from the TDX module via TDG.MR.TDREPORT TDCALL. In order to get the TDREPORT0 in the TDX guest driver, instead of using a low level function like __tdx_module_call(), add a tdx_mcall_get_report0() wrapper function to handle it. This is a preparatory patch for adding attestation support. Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Dave Hansen Acked-by: Wander Lairson Costa Link: https://lore.kernel.org/all/20221116223820.819090-2-sathyanarayanan.kuppuswamy%40linux.intel.com Signed-off-by: Andrea Righi --- arch/x86/coco/tdx/tdx.c | 40 ++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/tdx.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index b8998cf0508a..cfd4c95b9f04 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -5,6 +5,8 @@ #define pr_fmt(fmt) "tdx: " fmt #include +#include +#include #include #include #include @@ -15,6 +17,7 @@ /* TDX module Call Leaf IDs */ #define TDX_GET_INFO 1 #define TDX_GET_VEINFO 3 +#define TDX_GET_REPORT 4 #define TDX_ACCEPT_PAGE 6 /* TDX hypercall Leaf IDs */ @@ -36,6 +39,12 @@ #define ATTR_SEPT_VE_DISABLE BIT(28) +/* TDX Module call error codes */ +#define TDCALL_RETURN_CODE(a) ((a) >> 32) +#define TDCALL_INVALID_OPERAND 0xc0000100 + +#define TDREPORT_SUBTYPE_0 0 + /* * Wrapper for standard use of __tdx_hypercall with no output aside from * return code. @@ -100,6 +109,37 @@ static inline void tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9, panic("TDCALL %lld failed (Buggy TDX module!)\n", fn); } +/** + * tdx_mcall_get_report0() - Wrapper to get TDREPORT0 (a.k.a. TDREPORT + * subtype 0) using TDG.MR.REPORT TDCALL. + * @reportdata: Address of the input buffer which contains user-defined + * REPORTDATA to be included into TDREPORT. + * @tdreport: Address of the output buffer to store TDREPORT. + * + * Refer to section titled "TDG.MR.REPORT leaf" in the TDX Module + * v1.0 specification for more information on TDG.MR.REPORT TDCALL. + * It is used in the TDX guest driver module to get the TDREPORT0. + * + * Return 0 on success, -EINVAL for invalid operands, or -EIO on + * other TDCALL failures. + */ +int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport) +{ + u64 ret; + + ret = __tdx_module_call(TDX_GET_REPORT, virt_to_phys(tdreport), + virt_to_phys(reportdata), TDREPORT_SUBTYPE_0, + 0, NULL); + if (ret) { + if (TDCALL_RETURN_CODE(ret) == TDCALL_INVALID_OPERAND) + return -EINVAL; + return -EIO; + } + + return 0; +} +EXPORT_SYMBOL_GPL(tdx_mcall_get_report0); + static void tdx_parse_tdinfo(u64 *cc_mask) { struct tdx_module_output out; diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 020c81a7c729..28d889c9aa16 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -67,6 +67,8 @@ void tdx_safe_halt(void); bool tdx_early_handle_ve(struct pt_regs *regs); +int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport); + #else static inline void tdx_early_init(void) { }; From patchwork Mon Mar 6 09:20:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1752268 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=GYv8DPsj; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PVY3m3s7dz246j for ; Mon, 6 Mar 2023 20:21:23 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pZ71s-0007hX-JM; Mon, 06 Mar 2023 09:21:12 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pZ71p-0007gc-SK for kernel-team@lists.ubuntu.com; Mon, 06 Mar 2023 09:21:09 +0000 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 70FCA3F206 for ; Mon, 6 Mar 2023 09:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1678094469; bh=fVuGIM62rEWHr0yeLdLJwSK76SaK8h4Q/YIZYIkC/bE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GYv8DPsjAuXqSv4qAs5bbMhk2ktmmljvg9YY2TuZa/8q/W3jBYnEqNsULl85ygoJZ uPJvbI8vYbN2TqKfCPJWcDgjLDDcCrDEe732wnHWnk/Hs6UXlb3pCAGI1BMu8akmU9 FbnxbXQZL8blUVK0cCWqLzJSwUBgStXrWrPrEPV4K6ipJzK2R8yRwne2K+mYmhaKND z+yIgjJ8z7HyxcJJMW6AJU1k37snO9VCyopnPZtsWcTfx4wwTVH95uz4dkPSkjPT9j xnpH5t6HiAnVLhK6r/deHW4zcF8a9O/6tCYtZy5vokNf74ibR44vnAe0F3LXtmix1M Qzdlq0DgVp1SA== Received: by mail-ed1-f72.google.com with SMTP id h15-20020a056402280f00b004bf9e193c23so13023263ede.11 for ; Mon, 06 Mar 2023 01:21:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fVuGIM62rEWHr0yeLdLJwSK76SaK8h4Q/YIZYIkC/bE=; b=gri6sX6f0gmuqOyvWRRb8VJSLSaQMEbcKcaEejHCO7UsiIVZzaDZGjgw6CoV3mt2T0 j2ReFTOUYNuua+x0MFshuww9mnd3cl4D3ktKQBuZeeUqKNs2MR0CGmS64ysHZokzGGLf V/7HXkMoQZklmyr5N9CVJVRXu9U0efDxXgEcBClaqICsdXGHm6fdZE4CyJefyZwY7jl/ ABwugQMWtYXVt8GCsAK9UbmOJSXJ1mStkbhQn4cd6A0adnfpwuLw1mVJidPq47F2/Ys7 1ANwwibEBckLd5pjr/SluxxifCo9lIUNrsC+c7VMyXKGXZe/4kVENKO4JJE3U7FEsL8C QH+Q== X-Gm-Message-State: AO0yUKWfG0EITqS1uNLDlDrp+1BFn7bBS6riJdq4qjxpiyIqX/f2ShUT p47KTjnAAOfVkREiofSkMB86/ULYrB5p5O5Ro+ohGNJKNs5l6tZUv2O0PayRHVsLH/mbL0mW2pl dDs5c5L/qXTHkVHza/jgJ0Up/tRApjiiyOEDb+cgtL76PXr3pFA== X-Received: by 2002:aa7:c153:0:b0:4ac:b309:3d76 with SMTP id r19-20020aa7c153000000b004acb3093d76mr12140212edp.31.1678094469085; Mon, 06 Mar 2023 01:21:09 -0800 (PST) X-Google-Smtp-Source: AK7set87y1iZaWMr7auhFC4AWNZy7KSd7wd8xjGBNQ9AX7PyC9LCU9CftMOn2/hxJ3L7qzKbe2HQ9w== X-Received: by 2002:aa7:c153:0:b0:4ac:b309:3d76 with SMTP id r19-20020aa7c153000000b004acb3093d76mr12140194edp.31.1678094468755; Mon, 06 Mar 2023 01:21:08 -0800 (PST) Received: from localhost.localdomain (host-79-53-23-214.retail.telecomitalia.it. [79.53.23.214]) by smtp.gmail.com with ESMTPSA id n18-20020a50c212000000b004af515d2dd8sm4864293edf.74.2023.03.06.01.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 01:21:08 -0800 (PST) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][K][PATCH 4/6] UBUNTU: SAUCE: virt: Add TDX guest driver Date: Mon, 6 Mar 2023 10:20:56 +0100 Message-Id: <20230306092058.26718-5-andrea.righi@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306092058.26718-1-andrea.righi@canonical.com> References: <20230306092058.26718-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Kuppuswamy Sathyanarayanan BugLink: https://bugs.launchpad.net/bugs/2009437 TDX guest driver exposes IOCTL interfaces to service TDX guest user-specific requests. Currently, it is only used to allow the user to get the TDREPORT to support TDX attestation. Details about the TDX attestation process are documented in Documentation/x86/tdx.rst, and the IOCTL details are documented in Documentation/virt/coco/tdx-guest.rst. Operations like getting TDREPORT involves sending a blob of data as input and getting another blob of data as output. It was considered to use a sysfs interface for this, but it doesn't fit well into the standard sysfs model for configuring values. It would be possible to do read/write on files, but it would need multiple file descriptors, which would be somewhat messy. IOCTLs seem to be the best fitting and simplest model for this use case. The AMD sev-guest driver also uses the IOCTL interface to support attestation. [Bagas Sanjaya: Ack is for documentation portion] Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Dave Hansen Reviewed-by: Bagas Sanjaya Reviewed-by: Tony Luck Reviewed-by: Mika Westerberg Acked-by: Kai Huang Acked-by: Kirill A. Shutemov Acked-by: Wander Lairson Costa Link: https://lore.kernel.org/all/20221116223820.819090-3-sathyanarayanan.kuppuswamy%40linux.intel.com Signed-off-by: Andrea Righi --- Documentation/virt/coco/tdx-guest.rst | 52 ++++++++++++ Documentation/virt/index.rst | 1 + Documentation/x86/tdx.rst | 43 ++++++++++ drivers/virt/Kconfig | 2 + drivers/virt/Makefile | 1 + drivers/virt/coco/tdx-guest/Kconfig | 10 +++ drivers/virt/coco/tdx-guest/Makefile | 2 + drivers/virt/coco/tdx-guest/tdx-guest.c | 102 ++++++++++++++++++++++++ include/uapi/linux/tdx-guest.h | 42 ++++++++++ 9 files changed, 255 insertions(+) create mode 100644 Documentation/virt/coco/tdx-guest.rst create mode 100644 drivers/virt/coco/tdx-guest/Kconfig create mode 100644 drivers/virt/coco/tdx-guest/Makefile create mode 100644 drivers/virt/coco/tdx-guest/tdx-guest.c create mode 100644 include/uapi/linux/tdx-guest.h diff --git a/Documentation/virt/coco/tdx-guest.rst b/Documentation/virt/coco/tdx-guest.rst new file mode 100644 index 000000000000..46e316db6bb4 --- /dev/null +++ b/Documentation/virt/coco/tdx-guest.rst @@ -0,0 +1,52 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================================================================== +TDX Guest API Documentation +=================================================================== + +1. General description +====================== + +The TDX guest driver exposes IOCTL interfaces via the /dev/tdx-guest misc +device to allow userspace to get certain TDX guest-specific details. + +2. API description +================== + +In this section, for each supported IOCTL, the following information is +provided along with a generic description. + +:Input parameters: Parameters passed to the IOCTL and related details. +:Output: Details about output data and return value (with details about + the non common error values). + +2.1 TDX_CMD_GET_REPORT0 +----------------------- + +:Input parameters: struct tdx_report_req +:Output: Upon successful execution, TDREPORT data is copied to + tdx_report_req.tdreport and return 0. Return -EINVAL for invalid + operands, -EIO on TDCALL failure or standard error number on other + common failures. + +The TDX_CMD_GET_REPORT0 IOCTL can be used by the attestation software to get +the TDREPORT0 (a.k.a. TDREPORT subtype 0) from the TDX module using +TDCALL[TDG.MR.REPORT]. + +A subtype index is added at the end of this IOCTL CMD to uniquely identify the +subtype-specific TDREPORT request. Although the subtype option is mentioned in +the TDX Module v1.0 specification, section titled "TDG.MR.REPORT", it is not +currently used, and it expects this value to be 0. So to keep the IOCTL +implementation simple, the subtype option was not included as part of the input +ABI. However, in the future, if the TDX Module supports more than one subtype, +a new IOCTL CMD will be created to handle it. To keep the IOCTL naming +consistent, a subtype index is added as part of the IOCTL CMD. + +Reference +--------- + +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. diff --git a/Documentation/virt/index.rst b/Documentation/virt/index.rst index 492f0920b988..9e3e72ab61f1 100644 --- a/Documentation/virt/index.rst +++ b/Documentation/virt/index.rst @@ -14,6 +14,7 @@ Linux Virtualization Support ne_overview acrn/index coco/sev-guest + coco/tdx-guest .. only:: html and subproject diff --git a/Documentation/x86/tdx.rst b/Documentation/x86/tdx.rst index b8fa4329e1a5..dc8d9fd2c3f7 100644 --- a/Documentation/x86/tdx.rst +++ b/Documentation/x86/tdx.rst @@ -210,6 +210,49 @@ converted to shared on boot. For coherent DMA allocation, the DMA buffer gets converted on the allocation. Check force_dma_unencrypted() for details. +Attestation +=========== + +Attestation is used to verify the TDX guest trustworthiness to other +entities before provisioning secrets to the guest. For example, a key +server may want to use attestation to verify that the guest is the +desired one before releasing the encryption keys to mount the encrypted +rootfs or a secondary drive. + +The TDX module records the state of the TDX guest in various stages of +the guest boot process using the build time measurement register (MRTD) +and runtime measurement registers (RTMR). Measurements related to the +guest initial configuration and firmware image are recorded in the MRTD +register. Measurements related to initial state, kernel image, firmware +image, command line options, initrd, ACPI tables, etc are recorded in +RTMR registers. For more details, as an example, please refer to TDX +Virtual Firmware design specification, section titled "TD Measurement". +At TDX guest runtime, the attestation process is used to attest to these +measurements. + +The attestation process consists of two steps: TDREPORT generation and +Quote generation. + +TDX guest uses TDCALL[TDG.MR.REPORT] to get the TDREPORT (TDREPORT_STRUCT) +from the TDX module. TDREPORT is a fixed-size data structure generated by +the TDX module which contains guest-specific information (such as build +and boot measurements), platform security version, and the MAC to protect +the integrity of the TDREPORT. A user-provided 64-Byte REPORTDATA is used +as input and included in the TDREPORT. Typically it can be some nonce +provided by attestation service so the TDREPORT can be verified uniquely. +More details about the TDREPORT can be found in Intel TDX Module +specification, section titled "TDG.MR.REPORT Leaf". + +After getting the TDREPORT, the second step of the attestation process +is to send it to the Quoting Enclave (QE) to generate the Quote. TDREPORT +by design can only be verified on the local platform as the MAC key is +bound to the platform. To support remote verification of the TDREPORT, +TDX leverages Intel SGX Quoting Enclave to verify the TDREPORT locally +and convert it to a remotely verifiable Quote. Method of sending TDREPORT +to QE is implementation specific. Attestation software can choose +whatever communication channel available (i.e. vsock or TCP/IP) to +send the TDREPORT to QE and receive the Quote. + References ========== diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig index 87ef258cec64..f79ab13a5c28 100644 --- a/drivers/virt/Kconfig +++ b/drivers/virt/Kconfig @@ -52,4 +52,6 @@ source "drivers/virt/coco/efi_secret/Kconfig" source "drivers/virt/coco/sev-guest/Kconfig" +source "drivers/virt/coco/tdx-guest/Kconfig" + endif diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile index 093674e05c40..e9aa6fc96fab 100644 --- a/drivers/virt/Makefile +++ b/drivers/virt/Makefile @@ -11,3 +11,4 @@ obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) += acrn/ obj-$(CONFIG_EFI_SECRET) += coco/efi_secret/ obj-$(CONFIG_SEV_GUEST) += coco/sev-guest/ +obj-$(CONFIG_INTEL_TDX_GUEST) += coco/tdx-guest/ diff --git a/drivers/virt/coco/tdx-guest/Kconfig b/drivers/virt/coco/tdx-guest/Kconfig new file mode 100644 index 000000000000..14246fc2fb02 --- /dev/null +++ b/drivers/virt/coco/tdx-guest/Kconfig @@ -0,0 +1,10 @@ +config TDX_GUEST_DRIVER + tristate "TDX Guest driver" + depends on INTEL_TDX_GUEST + help + The driver provides userspace interface to communicate with + the TDX module to request the TDX guest details like attestation + report. + + To compile this driver as module, choose M here. The module will + be called tdx-guest. diff --git a/drivers/virt/coco/tdx-guest/Makefile b/drivers/virt/coco/tdx-guest/Makefile new file mode 100644 index 000000000000..775cb463f9c8 --- /dev/null +++ b/drivers/virt/coco/tdx-guest/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_TDX_GUEST_DRIVER) += tdx-guest.o diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c new file mode 100644 index 000000000000..5e44a0fa69bd --- /dev/null +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * TDX guest user interface driver + * + * Copyright (C) 2022 Intel Corporation + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +static long tdx_get_report0(struct tdx_report_req __user *req) +{ + u8 *reportdata, *tdreport; + long ret; + + reportdata = kmalloc(TDX_REPORTDATA_LEN, GFP_KERNEL); + if (!reportdata) + return -ENOMEM; + + tdreport = kzalloc(TDX_REPORT_LEN, GFP_KERNEL); + if (!tdreport) { + ret = -ENOMEM; + goto out; + } + + if (copy_from_user(reportdata, req->reportdata, TDX_REPORTDATA_LEN)) { + ret = -EFAULT; + goto out; + } + + /* Generate TDREPORT0 using "TDG.MR.REPORT" TDCALL */ + ret = tdx_mcall_get_report0(reportdata, tdreport); + if (ret) + goto out; + + if (copy_to_user(req->tdreport, tdreport, TDX_REPORT_LEN)) + ret = -EFAULT; + +out: + kfree(reportdata); + kfree(tdreport); + + return ret; +} + +static long tdx_guest_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + switch (cmd) { + case TDX_CMD_GET_REPORT0: + return tdx_get_report0((struct tdx_report_req __user *)arg); + default: + return -ENOTTY; + } +} + +static const struct file_operations tdx_guest_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = tdx_guest_ioctl, + .llseek = no_llseek, +}; + +static struct miscdevice tdx_misc_dev = { + .name = KBUILD_MODNAME, + .minor = MISC_DYNAMIC_MINOR, + .fops = &tdx_guest_fops, +}; + +static const struct x86_cpu_id tdx_guest_ids[] = { + X86_MATCH_FEATURE(X86_FEATURE_TDX_GUEST, NULL), + {} +}; +MODULE_DEVICE_TABLE(x86cpu, tdx_guest_ids); + +static int __init tdx_guest_init(void) +{ + if (!x86_match_cpu(tdx_guest_ids)) + return -ENODEV; + + return misc_register(&tdx_misc_dev); +} +module_init(tdx_guest_init); + +static void __exit tdx_guest_exit(void) +{ + misc_deregister(&tdx_misc_dev); +} +module_exit(tdx_guest_exit); + +MODULE_AUTHOR("Kuppuswamy Sathyanarayanan "); +MODULE_DESCRIPTION("TDX Guest Driver"); +MODULE_LICENSE("GPL"); diff --git a/include/uapi/linux/tdx-guest.h b/include/uapi/linux/tdx-guest.h new file mode 100644 index 000000000000..a6a2098c08ff --- /dev/null +++ b/include/uapi/linux/tdx-guest.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Userspace interface for TDX guest driver + * + * Copyright (C) 2022 Intel Corporation + */ + +#ifndef _UAPI_LINUX_TDX_GUEST_H_ +#define _UAPI_LINUX_TDX_GUEST_H_ + +#include +#include + +/* Length of the REPORTDATA used in TDG.MR.REPORT TDCALL */ +#define TDX_REPORTDATA_LEN 64 + +/* Length of TDREPORT used in TDG.MR.REPORT TDCALL */ +#define TDX_REPORT_LEN 1024 + +/** + * struct tdx_report_req - Request struct for TDX_CMD_GET_REPORT0 IOCTL. + * + * @reportdata: User buffer with REPORTDATA to be included into TDREPORT. + * Typically it can be some nonce provided by attestation + * service, so the generated TDREPORT can be uniquely verified. + * @tdreport: User buffer to store TDREPORT output from TDCALL[TDG.MR.REPORT]. + */ +struct tdx_report_req { + __u8 reportdata[TDX_REPORTDATA_LEN]; + __u8 tdreport[TDX_REPORT_LEN]; +}; + +/* + * TDX_CMD_GET_REPORT0 - Get TDREPORT0 (a.k.a. TDREPORT subtype 0) using + * TDCALL[TDG.MR.REPORT] + * + * Return 0 on success, -EIO on TDCALL execution failure, and + * standard errno on other general error cases. + */ +#define TDX_CMD_GET_REPORT0 _IOWR('T', 1, struct tdx_report_req) + +#endif /* _UAPI_LINUX_TDX_GUEST_H_ */ From patchwork Mon Mar 6 09:20:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1752266 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=Ne7xZ6vS; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PVY3m3HJzz1yWw for ; Mon, 6 Mar 2023 20:21:23 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pZ71u-0007iL-0B; Mon, 06 Mar 2023 09:21:14 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pZ71q-0007hD-TX for kernel-team@lists.ubuntu.com; Mon, 06 Mar 2023 09:21:10 +0000 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id EE75B3F125 for ; Mon, 6 Mar 2023 09:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1678094470; bh=nfMKefxHUopuEW76IhtrOfE4YHJSDBH8X7qXrApq35k=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ne7xZ6vSFqRcTZF26e3qAvdT5U5st5yx9hgAYLbQMxIUx/UiqnETX2x0FxVV/bRzQ KLob1GI7Ymuoyv6DMlYEwsw0DegIowNk7SIfFeQYtGhPPo6RbuJryN8nIK8R902SIQ dP6v2/T9oW2IlqGWdIO+lIVN7a/mA9XltQM3K+/b3PartQVNJPUAIScKkJa3oX8B7V pHmOJ1d+PuL/c9WndV13/wOkNB32ULL4smMLVkYOpHR7hqYhjLfLTjGbNokPeHCFsm UATr64tChiE5bAGQ8owNoW8XnM5hOVSv1QJ8suEh4NtmGxyavT84K5v+0z12yQAa3l JMxqqZy/rUzeQ== Received: by mail-ed1-f69.google.com with SMTP id d35-20020a056402402300b004e37aed9832so3514075eda.18 for ; Mon, 06 Mar 2023 01:21:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nfMKefxHUopuEW76IhtrOfE4YHJSDBH8X7qXrApq35k=; b=rmyF5KUfmmj2I7Fxx7DKpezhxYW9UX06rLv1qT6uZe40ij3y+9ONA0PXRR+4sw9flC Yg+vPo1BkZjZ4qmF93IZRzMz7RXW3oP9qdpgICCcCfOR+wmz8TtaqLC1XeDXCUDb9JCh +ib8nhGIQaS95CObYh/fGY33BNRemn0ORnORUHF5vnzMHmD4fearQU8BY0eV893wQMiP WRjoQSQT95XqCW3yPBe2Bbch6huBqhp6RZ4Pz1gZQI+NCi2PPeebGaX0LzVkZZkniTu2 b7gH3fSFgdSpejLPwA2pHkG6Wi0r1g7MoyZNPSpJiYa/UhLvsTh4UhgFz83Hury1ryz3 KWTw== X-Gm-Message-State: AO0yUKX74/vzz0hZffIleP9NNuSYZFJiC6TtjHc0Mxu29J2hUZ5IzvOT WN78nZg1TaeAN7DfyyCwcYkKy3JkNWxM5+AMKMp/rxsAsPGqmgD++uWteJnesvJMfaISqUZZdzI ILAcNSDNwg9TXBr7dwS/7TiOISaLFiqrpc/cjj+cXmcM/u4DIgg== X-Received: by 2002:aa7:d6d8:0:b0:4a0:af87:b3ab with SMTP id x24-20020aa7d6d8000000b004a0af87b3abmr8064388edr.36.1678094469735; Mon, 06 Mar 2023 01:21:09 -0800 (PST) X-Google-Smtp-Source: AK7set9Avo5h2+oDAhspXvIFGcSJOtLfkFHBrOVlML3qZkhrB1f+MSrCeXTBRGSZ06X111I5GsRmdg== X-Received: by 2002:aa7:d6d8:0:b0:4a0:af87:b3ab with SMTP id x24-20020aa7d6d8000000b004a0af87b3abmr8064350edr.36.1678094469260; Mon, 06 Mar 2023 01:21:09 -0800 (PST) Received: from localhost.localdomain (host-79-53-23-214.retail.telecomitalia.it. [79.53.23.214]) by smtp.gmail.com with ESMTPSA id n18-20020a50c212000000b004af515d2dd8sm4864293edf.74.2023.03.06.01.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 01:21:09 -0800 (PST) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][K][PATCH 5/6] UBUNTU: SAUCE: selftests/tdx: Test TDX attestation GetReport support Date: Mon, 6 Mar 2023 10:20:57 +0100 Message-Id: <20230306092058.26718-6-andrea.righi@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306092058.26718-1-andrea.righi@canonical.com> References: <20230306092058.26718-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Kuppuswamy Sathyanarayanan BugLink: https://bugs.launchpad.net/bugs/2009437 Attestation is used to verify the trustworthiness of a TDX guest. During the guest bring-up, the Intel TDX module measures and records the initial contents and configuration of the guest, and at runtime, guest software uses runtime measurement registers (RMTRs) to measure and record details related to kernel image, command line params, ACPI tables, initrd, etc. At guest runtime, the attestation process is used to attest to these measurements. The first step in the TDX attestation process is to get the TDREPORT data. It is a fixed size data structure generated by the TDX module which includes the above mentioned measurements data, a MAC ID to protect the integrity of the TDREPORT, and a 64-Byte of user specified data passed during TDREPORT request which can uniquely identify the TDREPORT. Intel's TDX guest driver exposes TDX_CMD_GET_REPORT0 IOCTL interface to enable guest userspace to get the TDREPORT subtype 0. Add a kernel self test module to test this ABI and verify the validity of the generated TDREPORT. Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Dave Hansen Reviewed-by: Tony Luck Reviewed-by: Mika Westerberg Acked-by: Kai Huang Acked-by: Wander Lairson Costa Acked-by: Kirill A. Shutemov Link: https://lore.kernel.org/all/20221116223820.819090-4-sathyanarayanan.kuppuswamy%40linux.intel.com Signed-off-by: Andrea Righi --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/tdx/Makefile | 7 + tools/testing/selftests/tdx/config | 1 + tools/testing/selftests/tdx/tdx_guest_test.c | 163 +++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 tools/testing/selftests/tdx/Makefile create mode 100644 tools/testing/selftests/tdx/config create mode 100644 tools/testing/selftests/tdx/tdx_guest_test.c diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index de11992dc577..807a839d69c4 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -69,6 +69,7 @@ TARGETS += sync TARGETS += syscall_user_dispatch TARGETS += sysctl TARGETS += tc-testing +TARGETS += tdx TARGETS += timens ifneq (1, $(quicktest)) TARGETS += timers diff --git a/tools/testing/selftests/tdx/Makefile b/tools/testing/selftests/tdx/Makefile new file mode 100644 index 000000000000..8dd43517cd55 --- /dev/null +++ b/tools/testing/selftests/tdx/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -O3 -Wl,-no-as-needed -Wall -static + +TEST_GEN_PROGS := tdx_guest_test + +include ../lib.mk diff --git a/tools/testing/selftests/tdx/config b/tools/testing/selftests/tdx/config new file mode 100644 index 000000000000..aa1edc829ab6 --- /dev/null +++ b/tools/testing/selftests/tdx/config @@ -0,0 +1 @@ +CONFIG_TDX_GUEST_DRIVER=y diff --git a/tools/testing/selftests/tdx/tdx_guest_test.c b/tools/testing/selftests/tdx/tdx_guest_test.c new file mode 100644 index 000000000000..2a2afd856798 --- /dev/null +++ b/tools/testing/selftests/tdx/tdx_guest_test.c @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test TDX guest features + * + * Copyright (C) 2022 Intel Corporation. + * + * Author: Kuppuswamy Sathyanarayanan + */ + +#include + +#include +#include + +#include "../kselftest_harness.h" +#include "../../../../include/uapi/linux/tdx-guest.h" + +#define TDX_GUEST_DEVNAME "/dev/tdx_guest" +#define HEX_DUMP_SIZE 8 +#define DEBUG 0 + +/** + * struct tdreport_type - Type header of TDREPORT_STRUCT. + * @type: Type of the TDREPORT (0 - SGX, 81 - TDX, rest are reserved) + * @sub_type: Subtype of the TDREPORT (Default value is 0). + * @version: TDREPORT version (Default value is 0). + * @reserved: Added for future extension. + * + * More details can be found in TDX v1.0 module specification, sec + * titled "REPORTTYPE". + */ +struct tdreport_type { + __u8 type; + __u8 sub_type; + __u8 version; + __u8 reserved; +}; + +/** + * struct reportmac - TDX guest report data, MAC and TEE hashes. + * @type: TDREPORT type header. + * @reserved1: Reserved for future extension. + * @cpu_svn: CPU security version. + * @tee_tcb_info_hash: SHA384 hash of TEE TCB INFO. + * @tee_td_info_hash: SHA384 hash of TDINFO_STRUCT. + * @reportdata: User defined unique data passed in TDG.MR.REPORT request. + * @reserved2: Reserved for future extension. + * @mac: CPU MAC ID. + * + * It is MAC-protected and contains hashes of the remainder of the + * report structure along with user provided report data. More details can + * be found in TDX v1.0 Module specification, sec titled "REPORTMACSTRUCT" + */ +struct reportmac { + struct tdreport_type type; + __u8 reserved1[12]; + __u8 cpu_svn[16]; + __u8 tee_tcb_info_hash[48]; + __u8 tee_td_info_hash[48]; + __u8 reportdata[64]; + __u8 reserved2[32]; + __u8 mac[32]; +}; + +/** + * struct td_info - TDX guest measurements and configuration. + * @attr: TDX Guest attributes (like debug, spet_disable, etc). + * @xfam: Extended features allowed mask. + * @mrtd: Build time measurement register. + * @mrconfigid: Software-defined ID for non-owner-defined configuration + * of the guest - e.g., run-time or OS configuration. + * @mrowner: Software-defined ID for the guest owner. + * @mrownerconfig: Software-defined ID for owner-defined configuration of + * the guest - e.g., specific to the workload. + * @rtmr: Run time measurement registers. + * @reserved: Added for future extension. + * + * It contains the measurements and initial configuration of the TDX guest + * that was locked at initialization and a set of measurement registers + * that are run-time extendable. More details can be found in TDX v1.0 + * Module specification, sec titled "TDINFO_STRUCT". + */ +struct td_info { + __u8 attr[8]; + __u64 xfam; + __u64 mrtd[6]; + __u64 mrconfigid[6]; + __u64 mrowner[6]; + __u64 mrownerconfig[6]; + __u64 rtmr[24]; + __u64 reserved[14]; +}; + +/* + * struct tdreport - Output of TDCALL[TDG.MR.REPORT]. + * @reportmac: Mac protected header of size 256 bytes. + * @tee_tcb_info: Additional attestable elements in the TCB are not + * reflected in the reportmac. + * @reserved: Added for future extension. + * @tdinfo: Measurements and configuration data of size 512 bytes. + * + * More details can be found in TDX v1.0 Module specification, sec + * titled "TDREPORT_STRUCT". + */ +struct tdreport { + struct reportmac reportmac; + __u8 tee_tcb_info[239]; + __u8 reserved[17]; + struct td_info tdinfo; +}; + +static void print_array_hex(const char *title, const char *prefix_str, + const void *buf, int len) +{ + int i, j, line_len, rowsize = HEX_DUMP_SIZE; + const __u8 *ptr = buf; + + printf("\t\t%s", title); + + for (j = 0; j < len; j += rowsize) { + line_len = rowsize < (len - j) ? rowsize : (len - j); + printf("%s%.8x:", prefix_str, j); + for (i = 0; i < line_len; i++) + printf(" %.2x", ptr[j + i]); + printf("\n"); + } + + printf("\n"); +} + +TEST(verify_report) +{ + struct tdx_report_req req; + struct tdreport *tdreport; + int devfd, i; + + devfd = open(TDX_GUEST_DEVNAME, O_RDWR | O_SYNC); + ASSERT_LT(0, devfd); + + /* Generate sample report data */ + for (i = 0; i < TDX_REPORTDATA_LEN; i++) + req.reportdata[i] = i; + + /* Get TDREPORT */ + ASSERT_EQ(0, ioctl(devfd, TDX_CMD_GET_REPORT0, &req)); + + if (DEBUG) { + print_array_hex("\n\t\tTDX report data\n", "", + req.reportdata, sizeof(req.reportdata)); + + print_array_hex("\n\t\tTDX tdreport data\n", "", + req.tdreport, sizeof(req.tdreport)); + } + + /* Make sure TDREPORT data includes the REPORTDATA passed */ + tdreport = (struct tdreport *)req.tdreport; + ASSERT_EQ(0, memcmp(&tdreport->reportmac.reportdata[0], + req.reportdata, sizeof(req.reportdata))); + + ASSERT_EQ(0, close(devfd)); +} + +TEST_HARNESS_MAIN From patchwork Mon Mar 6 09:20:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1752265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=bomLch15; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PVY3m3Zqhz246g for ; Mon, 6 Mar 2023 20:21:23 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pZ71s-0007hi-P5; Mon, 06 Mar 2023 09:21:12 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pZ71q-0007h7-Qv for kernel-team@lists.ubuntu.com; Mon, 06 Mar 2023 09:21:10 +0000 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 7025E3F59A for ; Mon, 6 Mar 2023 09:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1678094470; bh=ftgdUzemgxPajriqAXCZ5KaMz39afQMaUmL2tCkzF0A=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bomLch15VT7CsxGknv0wvnLnfGnTKUTvinEr71S6onN7b+h7OqHmvh/G5v7uJCDmS 15F7wSD70TDrhn6DNOmoEFRnGEXseta/19w+pPlLMn5gJOqHvW6y3BQ35ZoUTOH8gM 1NTisl5EvsjSMPEo5hehdtxvfjoYgkx92vf/Aj7507guP483X5bfvS/ghh90ydvOWj Zv5TltPmhxkbyU8NlvrsV3viEPN6O9sZ8XqYrBdzCugkQTw3bKwsVUToQZVTsI0GEf iThOFwqS/w9npTSpS+sNcQmzwRTQZlpyoE/LDhbQ6n+1SwwK++EBt6txf6qxDSzyNv PWBisJcusGzKw== Received: by mail-ed1-f70.google.com with SMTP id w7-20020a056402268700b004bbcdf3751bso12764536edd.1 for ; Mon, 06 Mar 2023 01:21:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ftgdUzemgxPajriqAXCZ5KaMz39afQMaUmL2tCkzF0A=; b=PS6M//y0S5TtlkURIQQFHv79Qcw/NS4ulkjLYR811WCx2odAjN/+7UxN3Nhg6bWknp o9i5oC07iYY4BCOlK2/z5ysZgJ79QOCVF4qeMl9/4D0QiXS9DDvlVtieTniCgzRWFU3r JWm271gRwA8ZujKvHKLVHU6o2hKUZvrsUD0I+sqhlAgl4Xa04IIZW8lInyOMLFM4PRtW tnG1GlLwMTwz7JMXskLFe9BK1YvLU0MXPoxbrIfxMwsoV8WCyi3a4FWa0FojreVjDr9n +fndsYmojJLfKoWe3h11pIzOBfmyCPKhhNO6lEIgYVzC4TXJQVaaGN96dU+WPYMdQRYw mRFw== X-Gm-Message-State: AO0yUKULsrY+DrMN4N3DVDKFVC8AzqBpjihXLiYxesZ8+F9jLjqFnA+0 evTx3U4aGE535GiWSXBaHRaNYwuIvf6uFv1gmjEaxG3kIENGn9jFI5S7Ip1X0DSWUXQbfrzYdj2 LABZSzkJ/fciZutMEuDtQP2czJo4FO7f0jmRejdMT9NVsURNF3w== X-Received: by 2002:a05:6402:384:b0:4af:6aa6:12d3 with SMTP id o4-20020a056402038400b004af6aa612d3mr7689878edv.40.1678094470104; Mon, 06 Mar 2023 01:21:10 -0800 (PST) X-Google-Smtp-Source: AK7set8FyL55zRJry/X2QbDXnAAa2PdCaGqqgOX2usA441HoV7mkWPZlt4eyrVS5M8XYh6kpDGdZaw== X-Received: by 2002:a05:6402:384:b0:4af:6aa6:12d3 with SMTP id o4-20020a056402038400b004af6aa612d3mr7689868edv.40.1678094469864; Mon, 06 Mar 2023 01:21:09 -0800 (PST) Received: from localhost.localdomain (host-79-53-23-214.retail.telecomitalia.it. [79.53.23.214]) by smtp.gmail.com with ESMTPSA id n18-20020a50c212000000b004af515d2dd8sm4864293edf.74.2023.03.06.01.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 01:21:09 -0800 (PST) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][K][PATCH 6/6] UBUNTU: [Config] enable TDX attestation driver as module by default Date: Mon, 6 Mar 2023 10:20:58 +0100 Message-Id: <20230306092058.26718-7-andrea.righi@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306092058.26718-1-andrea.righi@canonical.com> References: <20230306092058.26718-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2009437 Signed-off-by: Andrea Righi --- debian.master/config/annotations | 3 +++ debian.master/config/config.common.ubuntu | 1 + 2 files changed, 4 insertions(+) diff --git a/debian.master/config/annotations b/debian.master/config/annotations index c0d51a759b94..21261d17b4a8 100644 --- a/debian.master/config/annotations +++ b/debian.master/config/annotations @@ -14401,6 +14401,9 @@ CONFIG_KVM_AMD policy<{'amd64': 'm'}> CONFIG_KVM_AMD_SEV policy<{'amd64': 'y'}> CONFIG_KVM_XEN policy<{'amd64': 'y'}> +CONFIG_TDX_GUEST_DRIVER policy<{'amd64': 'm'}> +CONFIG_TDX_GUEST_DRIVER note + # Menu: Virtualization >> Linux - VM Monitor Stream, base infrastructure >> Architecture: s390 CONFIG_APPLDATA_BASE policy<{'s390x': 'y'}> diff --git a/debian.master/config/config.common.ubuntu b/debian.master/config/config.common.ubuntu index 1284d6c7eba8..00079122932b 100644 --- a/debian.master/config/config.common.ubuntu +++ b/debian.master/config/config.common.ubuntu @@ -11485,6 +11485,7 @@ CONFIG_TCP_CONG_YEAH=m CONFIG_TCP_MD5SIG=y CONFIG_TCS3414=m CONFIG_TCS3472=m +CONFIG_TDX_GUEST_DRIVER=m CONFIG_TEE=m CONFIG_TEE_BNXT_FW=m CONFIG_TEGRA124_CLK_EMC=y