From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9147D3ECBDA for ; Fri, 15 May 2026 21:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879658; cv=none; b=H1y3dGZ3WaccGLNxFKTf+EE+VHJ0KN/jSFZgbVdcDzMeXPL4VQMvct6/AMhU+NM8+BxyUo1qdTkB6N8Ef6n0+mwXIW848B9nX9dr2R+DZ/3ceXOzIraskspCRYJO4IYpYwbln0FF8rG71Ip+H5+ypX5pzcC4CANKpgv5kh1QLVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879658; c=relaxed/simple; bh=JgJyVLfDqMQljVqRU1MTHdSlUCVaSc0hfEkcczuhqcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H8Edk09MuIPk7hhybGwpfBhEyMEP92yp0Gjp0W/VIxuhToZsv26Gp63XAPs74N30IzTB0kBM6xpsuK9ktiQ47DqFX9HdWDh5cPno4MFO2wtv6ioZ1fJarQHxtu97IwN89w0IrKCIrdqIodLuhSw5zuakIpfVaSOB0PFZHsAi3mY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VtfgL7d7; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VtfgL7d7" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-2c156c4a9efso373784eec.1 for ; Fri, 15 May 2026 14:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879655; x=1779484455; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Rg1O72SYx+Mww3ZjC2LhL3IwBU8aOcEM6iuwyJssfKc=; b=VtfgL7d7KSiuzNG5iroeCd6PGRFsxK0zNEtY8VbbevY++FbZegbne6D+xeV/Yg8VPu 0YkrmF92wtCJFFViCyPILayp3jMOl2/0IB8Qmo5NRMZKIWOw+5qQa5+J3TKDpHh24F+N +BmMea9opbRfHaopvH/yYiOnULGA1qpdso2BgEhyZ5tngPmmQL7NuKuBp7U+FrAb4UCZ UV2p3OqvzcW/dtwIgEWg2mnMizv71blKbRo8N2n/w+VkhNLiyxGDLZyMes3DnIZskMXK 5uFoPzGhxR9XjbFxeImU3YCkrV8DkV/9OqBXQhSEkAydAnCDQA6vBEanT1VLiENLB1AR GkAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879655; x=1779484455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Rg1O72SYx+Mww3ZjC2LhL3IwBU8aOcEM6iuwyJssfKc=; b=bE8B0npP5hXy03fek2mva1hlLViAqalHANllfNoKQmfeeq0Gd3A6yO5jiduNr6D9Wg 5b4gdRKi2ekd63HkXxTX6Cn2ZgQdX/8KTBCYx3ffi7Pty+BnnAfpVDWUA+a9OAGE0Z6T kpZxcGeFKq81IEYimuzDdXkwvuUYP8ydJ3I3dKnziQT1/Ot/ycGpM2RFsjywRfumxkx0 5OktewTdoJ9TuuOiRw8JsLWhx5MeMpFjh1M0fs5ZlPok1x+TMRSS3HVoyRHZRbgiWK8T 6LcOXbSIYnIfVyIAnuVHI/XEjDl9il4KTpQ9GUtnsb+XGO0j5zlgIWKKfaijLlc3QjTo zBlg== X-Gm-Message-State: AOJu0YxHSANveWL+R5PsHr+1+I9yug16dGxhXrBK3oUoj/4ELJBWt9IG 7prDPcS2ZKR6wgacTPqBfA8YJrtFZCQ7K+vw+QdsGmci7amwm4bb3XDuP12SGb5p X-Gm-Gg: Acq92OGD7RQ8qomcVrfIg47UhPKNIBo06zGDlur4V+Cx4FgTwcobovzYS1DswZ7OTe/ FRxlnmGezAREtoMhYdApfPB7PabPx+KCsZrb7VSnfi9waQqsZZOHJp3uglXshTe0+/VR7Zjxa09 bu28ImjmucKZPxqtkrq2yTQ/zfddtuQGpB8+enheqUqUw3Ph5jay0zT7m0Kti/M1baKE9o0hMbO v0wL8O8YeOAhdhkW+L3pEk9L4xuAn3t/L72kg7I6P/YXxRc0kn97Y3mpSrL/kgPqL3juwcZzQgn elDzbJDnbeKW62cGXgsYYDpIW4va486/U2bWEQWbTrL8GOIrp0XfkSeJyv9IniGZ1zMmpNoxB6m scPgg80e7Si0cz+de/c5UjhEAReGMWPo3/B1PSk8MnDoqSRLBMY/jqNTE40ll8Dd3zhHgeL+buI /mvI5y0ngCCBnltkbKPcuqGo1Azk2QRNQ= X-Received: by 2002:a05:7300:6c05:b0:2d8:df01:d9f6 with SMTP id 5a478bee46e88-3039864d5c1mr2737865eec.23.1778879655311; Fri, 15 May 2026 14:14:15 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302947e917dsm8003313eec.12.2026.05.15.14.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:14 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 01/38] tpm: Initial step to reorganize TPM public headers Date: Fri, 15 May 2026 14:13:33 -0700 Message-ID: <20260515211410.31440-2-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Consolidate TPM1 constants in tpm_command.h and remove duplicate constants from tpm1-cmd.c. Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Co-developed-by: Alec Brown Signed-off-by: Alec Brown Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm-buf.c | 1 - drivers/char/tpm/tpm1-cmd.c | 14 +------- include/keys/trusted_tpm.h | 1 - include/linux/tpm.h | 2 ++ include/linux/tpm_command.h | 41 ++++++++++++++++------- security/keys/trusted-keys/trusted_tpm1.c | 1 - security/keys/trusted-keys/trusted_tpm2.c | 1 - 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index dc882fc9fa9e..4c4f450630df 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -3,7 +3,6 @@ * Handling of TPM command and other buffers. */ =20 -#include #include #include =20 diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c index b49a790f1bd5..664ca1fff2e8 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -22,8 +22,6 @@ =20 #include "tpm.h" =20 -#define TPM_MAX_ORDINAL 243 - /* * Array with one entry per ordinal defining the maximum amount * of time the chip could take to return the result. The ordinal @@ -308,9 +306,6 @@ unsigned long tpm1_calc_ordinal_duration(struct tpm_chi= p *chip, u32 ordinal) return duration; } =20 -#define TPM_ORD_STARTUP 153 -#define TPM_ST_CLEAR 1 - /** * tpm1_startup() - turn on the TPM * @chip: TPM chip to use @@ -459,7 +454,6 @@ int tpm1_get_timeouts(struct tpm_chip *chip) return 0; } =20 -#define TPM_ORD_PCR_EXTEND 20 int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash, const char *log_msg) { @@ -478,7 +472,6 @@ int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,= const u8 *hash, return rc; } =20 -#define TPM_ORD_GET_CAP 101 ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, const char *desc, size_t min_cap_length) { @@ -511,7 +504,6 @@ ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_i= d, cap_t *cap, } EXPORT_SYMBOL_GPL(tpm1_getcap); =20 -#define TPM_ORD_GET_RANDOM 70 struct tpm1_get_random_out { __be32 rng_data_len; u8 rng_data[TPM_MAX_RNG_DATA]; @@ -580,13 +572,12 @@ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, = size_t max) return rc; } =20 -#define TPM_ORD_PCRREAD 21 int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf) { struct tpm_buf buf; int rc; =20 - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCRREAD); + rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_READ); if (rc) return rc; =20 @@ -609,7 +600,6 @@ int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u= 8 *res_buf) return rc; } =20 -#define TPM_ORD_CONTINUE_SELFTEST 83 /** * tpm1_continue_selftest() - run TPM's selftest * @chip: TPM chip to use @@ -726,8 +716,6 @@ int tpm1_auto_startup(struct tpm_chip *chip) return rc; } =20 -#define TPM_ORD_SAVESTATE 152 - /** * tpm1_pm_suspend() - pm suspend handler * @chip: TPM chip to use. diff --git a/include/keys/trusted_tpm.h b/include/keys/trusted_tpm.h index 0fadc6a4f166..3a0fa3bc8454 100644 --- a/include/keys/trusted_tpm.h +++ b/include/keys/trusted_tpm.h @@ -3,7 +3,6 @@ #define __TRUSTED_TPM_H =20 #include -#include =20 extern struct trusted_key_ops trusted_key_tpm_ops; =20 diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 202da079d500..1846d5485a2c 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -25,6 +25,8 @@ #include #include =20 +#include + #define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */ =20 #define TPM2_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h index f5c03e9c3913..174b043d8bbc 100644 --- a/include/linux/tpm_command.h +++ b/include/linux/tpm_command.h @@ -3,27 +3,42 @@ #define __LINUX_TPM_COMMAND_H__ =20 /* - * TPM Command constants from specifications at - * http://www.trustedcomputinggroup.org + * =3D=3D TPM 1 Family Chips =3D=3D + * + * TPM 1.2 Main Specification: + * https://trustedcomputinggroup.org/resource/tpm-main-specification/ */ =20 +#define TPM_MAX_ORDINAL 243 + /* Command TAGS */ -#define TPM_TAG_RQU_COMMAND 193 -#define TPM_TAG_RQU_AUTH1_COMMAND 194 -#define TPM_TAG_RQU_AUTH2_COMMAND 195 -#define TPM_TAG_RSP_COMMAND 196 -#define TPM_TAG_RSP_AUTH1_COMMAND 197 -#define TPM_TAG_RSP_AUTH2_COMMAND 198 +enum tpm_command_tags { + TPM_TAG_RQU_COMMAND =3D 193, + TPM_TAG_RQU_AUTH1_COMMAND =3D 194, + TPM_TAG_RQU_AUTH2_COMMAND =3D 195, + TPM_TAG_RSP_COMMAND =3D 196, + TPM_TAG_RSP_AUTH1_COMMAND =3D 197, + TPM_TAG_RSP_AUTH2_COMMAND =3D 198, +}; =20 /* Command Ordinals */ -#define TPM_ORD_GETRANDOM 70 -#define TPM_ORD_OSAP 11 -#define TPM_ORD_OIAP 10 -#define TPM_ORD_SEAL 23 -#define TPM_ORD_UNSEAL 24 +enum tpm_command_ordinals { + TPM_ORD_CONTINUE_SELFTEST =3D 83, + TPM_ORD_GET_CAP =3D 101, + TPM_ORD_GET_RANDOM =3D 70, + TPM_ORD_PCR_EXTEND =3D 20, + TPM_ORD_PCR_READ =3D 21, + TPM_ORD_OSAP =3D 11, + TPM_ORD_OIAP =3D 10, + TPM_ORD_SAVESTATE =3D 152, + TPM_ORD_SEAL =3D 23, + TPM_ORD_STARTUP =3D 153, + TPM_ORD_UNSEAL =3D 24, +}; =20 /* Other constants */ #define SRKHANDLE 0x40000000 #define TPM_NONCE_SIZE 20 +#define TPM_ST_CLEAR 1 =20 #endif diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trus= ted-keys/trusted_tpm1.c index 6ea728f1eae6..0d3244af8de3 100644 --- a/security/keys/trusted-keys/trusted_tpm1.c +++ b/security/keys/trusted-keys/trusted_tpm1.c @@ -18,7 +18,6 @@ #include #include #include -#include =20 #include =20 diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trus= ted-keys/trusted_tpm2.c index 6340823f8b53..29d79c05ed6b 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -9,7 +9,6 @@ #include #include #include -#include =20 #include #include --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BF7B3ED11F for ; Fri, 15 May 2026 21:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879661; cv=none; b=SrSgLhBSIQEUOIIbmfJDJW0GqhZJ0NxP2/gEC2If8G70FZ8tfqnKqeMivR4dDbuizVWo0YIt9cBuzvFSl9ZF3Ze1seZDt3sx+Kf0p5dE/NIO8bicyJeJ04iCv+fUG3ANavWtQBZrhsNhgaFSKk1AUEyllpY6zBoQ243C6thalgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879661; c=relaxed/simple; bh=SggoenfzsCsY+pb4Ek78lCUJ5LNnpYbdU37TQ8AdKSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cf2V9OgsM5SeWBMebVABto58btcqT4+X1TDGYjiSLO0oL5O2k05ExSTymV3mfSk9KV/nJUK+d3bXjSdgV8r1L1iQGiXe1/mXdq85x6LPkuCj+vcjL//AfZuXLgAJksEktMg47ROZl/g95AIOtBaC9Ra/kaWoLGR5pp4SakObisY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ru0WDDcL; arc=none smtp.client-ip=74.125.82.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ru0WDDcL" Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-30246cfd41aso1507620eec.1 for ; Fri, 15 May 2026 14:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879658; x=1779484458; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nv+Nw7PPpS+EKWG0VbfKgMCfu5HHf7cWkQjqPeveVJA=; b=ru0WDDcLWSL1Gi2iGhC0i4R5j++PKiDQbs2a5p44PBgkduWP1zGlxPLEsi5Nbu/tuk yUnsKoeQynrMvWXQ74RWCpe9JPvSHppDZ/EYjRzcAYql7GYi43ht5lnq4LjwNOzBr5dU dw4+QG5xXd3xsXtM5kz+iOwyY7AmLVAinI7k/8kmCYhy0H+Kj8deBo8Z780myQuGG7A4 a4wgQdm1FEHEIC9nMSEWBGSzU79/w+8g/4GdwKo89A25vzEIR3CvuQSYmmOjoAQDO3X6 /NT8sGr6QWUtbEUMdiVKzI2rEChXXMgoVV1WRMovs+HecQXTmfdVTcMO0Uuo0qsPjrCa JCFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879658; x=1779484458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nv+Nw7PPpS+EKWG0VbfKgMCfu5HHf7cWkQjqPeveVJA=; b=ljv2vvSoxk5OOBoaCVdVSy3CwLy9ztoPo4YUoA7rUWSM9k7MLlo5cqYPqB8G3ostfM J4vOBTppXzF8MWXHayrqi1KHRuSIMFoxOiweVYuyxbOAPWqjKx/PXU3eWdAruWYk+mM9 6y0qbLyM09Ah2nuew3Xygr3TpXbUd3BkLss5dJycu9aVLGw/waJs9A8Mt5L3ahJE8Y5w NGgriC+eU8Ds/Uv0hac6r10jW5PE6dIMW/mI5v4R8eeEJv1EagAdKXKsdTOCHeM1duVl mEYL491NpKhgsoTeeEGypAHbaupU+65x+VXU1f4fwDG97pnpWT8ELzjkwhUHx1e0KP4j AIjQ== X-Gm-Message-State: AOJu0Yyf1xhnUo6NK/4ywUrLxFpLixPmuOb0Gl17cTB3x+Or9gcTZv+X SF5kIhSsVPVpTRmJv3cSwTmacIFSfKby1a/R4UpvbTQPUYVNZkHW7TGMWWGeohPM X-Gm-Gg: Acq92OERzYylTlP/6GHy7RTSkNKEPv2/5H8XQWhJQiPngEl/VV43iGBEUxjDYQM1ahz USn89wYjQx4IlLZKphvbOCVRWA8ppCM4DX7edXtwKg9tPCs6bq4UKPjFZaaD75u8VKMrAU8Tn0z cyn1RwEXxHZOA9xfii+/egLuSKJNSHYjb3CUGflTeLIIt/HB7Uvcb//Oh2rWYQGTaeMxv7jW38P vyXPuk8uHFpUs9wn4PxU4rLPyLXgVm3yO2mXyBmOw7Isuve64LLrt3W2uq3cGBeafJxsvRq1rrI ndLpniuiwe+hR4J+GelGYfwfCJMiAgi/waO3hhSPLTCWaiz2QDPfPViF3ThtmH+K+5uBSS8Dt2H CpGAYA68jEMIG4E3igDz5YzQu0wn/Oxeb4417fU1qnLSV+L4z0Wx/jZh/62StTjhfMtOiof6M/T 4RemEzundiJ57d+57w71sxMq9iYZ9ZC2SDofe3uafZ4w== X-Received: by 2002:a05:7300:e6c6:b0:2dd:c066:bf7 with SMTP id 5a478bee46e88-303982b11bbmr2831503eec.11.1778879658197; Fri, 15 May 2026 14:14:18 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302977a9474sm8153511eec.25.2026.05.15.14.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:17 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 02/38] tpm: Move TPM1 specific definitions to the command header Date: Fri, 15 May 2026 14:13:34 -0700 Message-ID: <20260515211410.31440-3-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Gather all the TPM1 definitions and structures in the internal header file drivers/char/tpm/tpm.h into the command header. In addition, bring in the single RNG structure from tpm-interface.c. The definitions moved to these files correspond to the TCG specification for TPM 1 family: TPM 1.2 Main Specification - https://trustedcomputinggroup.org/resource/tpm-main-specification/ Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Co-developed-by: Alec Brown Signed-off-by: Alec Brown Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm.h | 102 -------------------------------- drivers/char/tpm/tpm1-cmd.c | 5 -- include/linux/tpm_command.h | 115 ++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 107 deletions(-) diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 87d68ddf270a..043d78a9617a 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -52,105 +52,9 @@ enum tpm_addr { TPM_ADDR =3D 0x4E, }; =20 -#define TPM_WARN_RETRY 0x800 -#define TPM_WARN_DOING_SELFTEST 0x802 -#define TPM_ERR_DEACTIVATED 0x6 -#define TPM_ERR_DISABLED 0x7 -#define TPM_ERR_FAILEDSELFTEST 0x1C -#define TPM_ERR_INVALID_POSTINIT 38 - -#define TPM_TAG_RQU_COMMAND 193 - /* TPM2 specific constants. */ #define TPM2_SPACE_BUFFER_SIZE 16384 /* 16 kB */ =20 -struct stclear_flags_t { - __be16 tag; - u8 deactivated; - u8 disableForceClear; - u8 physicalPresence; - u8 physicalPresenceLock; - u8 bGlobalLock; -} __packed; - -struct tpm1_version { - u8 major; - u8 minor; - u8 rev_major; - u8 rev_minor; -} __packed; - -struct tpm1_version2 { - __be16 tag; - struct tpm1_version version; -} __packed; - -struct timeout_t { - __be32 a; - __be32 b; - __be32 c; - __be32 d; -} __packed; - -struct duration_t { - __be32 tpm_short; - __be32 tpm_medium; - __be32 tpm_long; -} __packed; - -struct permanent_flags_t { - __be16 tag; - u8 disable; - u8 ownership; - u8 deactivated; - u8 readPubek; - u8 disableOwnerClear; - u8 allowMaintenance; - u8 physicalPresenceLifetimeLock; - u8 physicalPresenceHWEnable; - u8 physicalPresenceCMDEnable; - u8 CEKPUsed; - u8 TPMpost; - u8 TPMpostLock; - u8 FIPS; - u8 operator; - u8 enableRevokeEK; - u8 nvLocked; - u8 readSRKPub; - u8 tpmEstablished; - u8 maintenanceDone; - u8 disableFullDALogicInfo; -} __packed; - -typedef union { - struct permanent_flags_t perm_flags; - struct stclear_flags_t stclear_flags; - __u8 owned; - __be32 num_pcrs; - struct tpm1_version version1; - struct tpm1_version2 version2; - __be32 manufacturer_id; - struct timeout_t timeout; - struct duration_t duration; -} cap_t; - -enum tpm_capabilities { - TPM_CAP_FLAG =3D 4, - TPM_CAP_PROP =3D 5, - TPM_CAP_VERSION_1_1 =3D 0x06, - TPM_CAP_VERSION_1_2 =3D 0x1A, -}; - -enum tpm_sub_capabilities { - TPM_CAP_PROP_PCR =3D 0x101, - TPM_CAP_PROP_MANUFACTURER =3D 0x103, - TPM_CAP_FLAG_PERM =3D 0x108, - TPM_CAP_FLAG_VOL =3D 0x109, - TPM_CAP_PROP_OWNER =3D 0x111, - TPM_CAP_PROP_TIS_TIMEOUT =3D 0x115, - TPM_CAP_PROP_TIS_DURATION =3D 0x120, -}; - enum tpm2_pt_props { TPM2_PT_NONE =3D 0x00000000, TPM2_PT_GROUP =3D 0x00000100, @@ -225,12 +129,6 @@ enum tpm2_pt_props { TPM2_PT_AUDIT_COUNTER_1 =3D TPM2_PT_VAR + 20, }; =20 -/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - = 18 - * bytes, but 128 is still a relatively large number of random bytes and - * anything much bigger causes users of struct tpm_cmd_t to start getting - * compiler warnings about stack frame size. */ -#define TPM_MAX_RNG_DATA 128 - extern const struct class tpm_class; extern const struct class tpmrm_class; extern dev_t tpm_devt; diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c index 664ca1fff2e8..96f189b5fd6f 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -504,11 +504,6 @@ ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_= id, cap_t *cap, } EXPORT_SYMBOL_GPL(tpm1_getcap); =20 -struct tpm1_get_random_out { - __be32 rng_data_len; - u8 rng_data[TPM_MAX_RNG_DATA]; -} __packed; - /** * tpm1_get_random() - get random bytes from the TPM's RNG * @chip: a &struct tpm_chip instance diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h index 174b043d8bbc..30d01953a6f8 100644 --- a/include/linux/tpm_command.h +++ b/include/linux/tpm_command.h @@ -36,6 +36,121 @@ enum tpm_command_ordinals { TPM_ORD_UNSEAL =3D 24, }; =20 +enum tpm_capabilities { + TPM_CAP_FLAG =3D 4, + TPM_CAP_PROP =3D 5, + TPM_CAP_VERSION_1_1 =3D 0x06, + TPM_CAP_VERSION_1_2 =3D 0x1A, +}; + +enum tpm_sub_capabilities { + TPM_CAP_PROP_PCR =3D 0x101, + TPM_CAP_PROP_MANUFACTURER =3D 0x103, + TPM_CAP_FLAG_PERM =3D 0x108, + TPM_CAP_FLAG_VOL =3D 0x109, + TPM_CAP_PROP_OWNER =3D 0x111, + TPM_CAP_PROP_TIS_TIMEOUT =3D 0x115, + TPM_CAP_PROP_TIS_DURATION =3D 0x120, +}; + +/* Return Codes */ +enum tpm_return_codes { + TPM_BASE_MASK =3D 0, + TPM_NON_FATAL_MASK =3D 0x00000800, + TPM_SUCCESS =3D TPM_BASE_MASK + 0, + TPM_ERR_DEACTIVATED =3D TPM_BASE_MASK + 6, + TPM_ERR_DISABLED =3D TPM_BASE_MASK + 7, + TPM_ERR_FAIL =3D TPM_BASE_MASK + 9, + TPM_ERR_FAILEDSELFTEST =3D TPM_BASE_MASK + 28, + TPM_ERR_INVALID_POSTINIT =3D TPM_BASE_MASK + 38, + TPM_ERR_INVALID_FAMILY =3D TPM_BASE_MASK + 55, + TPM_WARN_RETRY =3D TPM_BASE_MASK + TPM_NON_FATAL_MASK + 0, + TPM_WARN_DOING_SELFTEST =3D TPM_BASE_MASK + TPM_NON_FATAL_MASK + 2, +}; + +struct stclear_flags_t { + __be16 tag; + u8 deactivated; + u8 disableForceClear; + u8 physicalPresence; + u8 physicalPresenceLock; + u8 bGlobalLock; +} __packed; + +struct tpm1_version { + u8 major; + u8 minor; + u8 rev_major; + u8 rev_minor; +} __packed; + +struct tpm1_version2 { + __be16 tag; + struct tpm1_version version; +} __packed; + +struct timeout_t { + __be32 a; + __be32 b; + __be32 c; + __be32 d; +} __packed; + +struct duration_t { + __be32 tpm_short; + __be32 tpm_medium; + __be32 tpm_long; +} __packed; + +struct permanent_flags_t { + __be16 tag; + u8 disable; + u8 ownership; + u8 deactivated; + u8 readPubek; + u8 disableOwnerClear; + u8 allowMaintenance; + u8 physicalPresenceLifetimeLock; + u8 physicalPresenceHWEnable; + u8 physicalPresenceCMDEnable; + u8 CEKPUsed; + u8 TPMpost; + u8 TPMpostLock; + u8 FIPS; + u8 operator; + u8 enableRevokeEK; + u8 nvLocked; + u8 readSRKPub; + u8 tpmEstablished; + u8 maintenanceDone; + u8 disableFullDALogicInfo; +} __packed; + +typedef union { + struct permanent_flags_t perm_flags; + struct stclear_flags_t stclear_flags; + __u8 owned; + __be32 num_pcrs; + struct tpm1_version version1; + struct tpm1_version2 version2; + __be32 manufacturer_id; + struct timeout_t timeout; + struct duration_t duration; +} cap_t; + +/* + * 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - = 18 + * bytes, but 128 is still a relatively large number of random bytes and + * anything much bigger causes users of struct tpm_cmd_t to start getting + * compiler warnings about stack frame size. + */ +#define TPM_MAX_RNG_DATA 128 + +struct tpm1_get_random_out { + __be32 rng_data_len; + u8 rng_data[TPM_MAX_RNG_DATA]; +} __packed; + /* Other constants */ #define SRKHANDLE 0x40000000 #define TPM_NONCE_SIZE 20 --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A1ED3ED100 for ; Fri, 15 May 2026 21:14:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879667; cv=none; b=AxDTYh3W9mOVMbeMmuAUT6fH6Qsze9NhjjWrhUxJfs99pNeNJyxmqiJ6o4kQXQdTsAO+X9ioldAdv15LlQaE74iWDTvs9W6Mv0ym9bD6vLNvcv5T+e50RfuEXb8g9Dlwk3/J2vIjqDiMMKsM0lwWBntXAhd62pVA+jS7Vbesv5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879667; c=relaxed/simple; bh=xFdieBqUqN/M8WrAKk61/d5q8AXUROY3V7K0ANiVKIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iXLFizkskZae4XP8e1AALnpoFmWiQY6HYUnJFGDuifoz8GMtqF1ANAbgX82+pvSw3DYJ+XfJQa6hhi3ZArszFidz/hTs2ZdZjtZ9C49VhsuylL5kPmXvqx/EQiu4H7/NkrlYTyrSHe9PhibXjY+Y4kV8T1h74ZpCU8a//g5uMCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b1F1Y9xD; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b1F1Y9xD" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2f3c623322bso1041316eec.0 for ; Fri, 15 May 2026 14:14:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879661; x=1779484461; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/ArL4NEl7kvaG8IsOXiHUmX/R5DnmrcPFIeRPtVMEkM=; b=b1F1Y9xDMYi+ytYhjdUZDZ3FqMV3pVxGKjRv2Y3hemzL8wqAKhOYvD1AzZ0Ef1CA1Q r55eNYcqHZfo0EERA7qVLpVEOrrCm07BmdB+pGTUyp5Oi6WGUdtrmm0LCdqH3tO9HPuZ mWnivW6pje2Ehzgc//ixqq4omJFZBY0Nq+9j0UPsLc21Sg/GctLuFD+WuAwonX5Rczb5 y9YRLu80Ln/hmStw61DHliMBrUaWDNUnx9ATLibZZCYXvvoVXyZZFrbccUjT1qs1QqLn Lg3GeaiwKCC7gsMYZGo/cSdwAWZyS+fO9KS3Vwqr3ky2wcruUvSCiZxDkpl1llsrTNPu 8y8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879661; x=1779484461; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/ArL4NEl7kvaG8IsOXiHUmX/R5DnmrcPFIeRPtVMEkM=; b=Jut1R2/WErHZgeO02xfWT2e/i4psaMTSA7vPtjorBmrvW2xqX1mA+tpLQ5THx3T17/ viqO1A3QOGF+b92no1FeIhTyTzLZMKJzGfuOS7E7qmeNHgU9f8h/7O6iQzgBNk0kcDwp XUtdE/CuBoXXYy5X8G4hqmyfPeZFKTlrcwrF80fUfszqnADP5d+iAK9cGB3rUvQpA+Nh C96GBtlEfidhmekLBY1XsGHMXMYbHPHjyslS5LSddMmKCNsb9tubp4MSryJsrxD6vqO2 YXoEPO6SJ35VbaMrNgnV1B5tw31mzlfVT1YiMAkXDFsKWqhoUEyzx/+zBKTPM1FBRHoP ldzw== X-Gm-Message-State: AOJu0YzO0mNl+GbgZnoa9AacqA6l2Y1abzKoSDNw79oPPvvJwNOVbBAm 5+bljhAWmPBhdo4HWlz3ihTAb2d8Wo3igpEMdgD6unwiOAuY98pwgs09Q99Rh8Gz X-Gm-Gg: Acq92OENr54lC6JonWaYovFMbgGxdk+5znOkmSBvpjxqgCpcvll1asjprii1Mivd4Xb ex8rLIby0v5iQY56wMs4I9ZEfZ6fiBDvhkw6WVt8DtZ6aL+A/jLyUQELAMgM8tzk/q25u/2hJdN +jFx3FPMj2zR+2nz+ZxkjHCVgEohfb49EUuKgrSgiXXvkF38EOs04QS3GQwX6sOJJ+g3jOiXbna IqwHoY2R0d7h9QDogH8gnuTHsxcwj7rPjxxr2Q6jHGgWVYYpozeVrDFzpwl+hvV1VHuCkjBszmz fWuPsvtPqUsj5tfeKFrnLuj5sBOOHLbaHVRsV2zOwcu/jVeMqs64h3Ttl16oEfXcW2pqbEom3G3 hd1XyLBhD40240vCq7Rr6XsADPfaefqo2lFkRR2UJ215ZiTDmzr83l9v3dY6/44fcY2bQ5a/FnN AG6LnVnXUteuWo3oe4thjuxOQ/8kb6twA= X-Received: by 2002:a05:693c:3282:b0:2ed:e12:3771 with SMTP id 5a478bee46e88-303986b1633mr2898164eec.33.1778879661136; Fri, 15 May 2026 14:14:21 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302978ad18asm8001602eec.26.2026.05.15.14.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:20 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 03/38] tpm: Move TPM2 specific definitions to the command header Date: Fri, 15 May 2026 14:13:35 -0700 Message-ID: <20260515211410.31440-4-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Gather all the TPM2 definitions and structures in the internal header file drivers/char/tpm/tpm.h into the command header, including: - Command codes, return codes and definitions from the public and internal tpm.h files. - Structures defined in numerous TPM driver C modules. The definitions moved to these files correspond to the TCG specification for TPM 2 family: TPM 2.0 Library - https://trustedcomputinggroup.org/resource/tpm-library-specification/ Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Co-developed-by: Alec Brown Signed-off-by: Alec Brown Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm.h | 77 ---------- drivers/char/tpm/tpm2-cmd.c | 30 ---- drivers/char/tpm/tpm2-space.c | 13 -- include/linux/tpm.h | 145 ------------------ include/linux/tpm_command.h | 271 ++++++++++++++++++++++++++++++++++ 5 files changed, 271 insertions(+), 265 deletions(-) diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 043d78a9617a..680f89d9c9f9 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -52,83 +52,6 @@ enum tpm_addr { TPM_ADDR =3D 0x4E, }; =20 -/* TPM2 specific constants. */ -#define TPM2_SPACE_BUFFER_SIZE 16384 /* 16 kB */ - -enum tpm2_pt_props { - TPM2_PT_NONE =3D 0x00000000, - TPM2_PT_GROUP =3D 0x00000100, - TPM2_PT_FIXED =3D TPM2_PT_GROUP * 1, - TPM2_PT_FAMILY_INDICATOR =3D TPM2_PT_FIXED + 0, - TPM2_PT_LEVEL =3D TPM2_PT_FIXED + 1, - TPM2_PT_REVISION =3D TPM2_PT_FIXED + 2, - TPM2_PT_DAY_OF_YEAR =3D TPM2_PT_FIXED + 3, - TPM2_PT_YEAR =3D TPM2_PT_FIXED + 4, - TPM2_PT_MANUFACTURER =3D TPM2_PT_FIXED + 5, - TPM2_PT_VENDOR_STRING_1 =3D TPM2_PT_FIXED + 6, - TPM2_PT_VENDOR_STRING_2 =3D TPM2_PT_FIXED + 7, - TPM2_PT_VENDOR_STRING_3 =3D TPM2_PT_FIXED + 8, - TPM2_PT_VENDOR_STRING_4 =3D TPM2_PT_FIXED + 9, - TPM2_PT_VENDOR_TPM_TYPE =3D TPM2_PT_FIXED + 10, - TPM2_PT_FIRMWARE_VERSION_1 =3D TPM2_PT_FIXED + 11, - TPM2_PT_FIRMWARE_VERSION_2 =3D TPM2_PT_FIXED + 12, - TPM2_PT_INPUT_BUFFER =3D TPM2_PT_FIXED + 13, - TPM2_PT_HR_TRANSIENT_MIN =3D TPM2_PT_FIXED + 14, - TPM2_PT_HR_PERSISTENT_MIN =3D TPM2_PT_FIXED + 15, - TPM2_PT_HR_LOADED_MIN =3D TPM2_PT_FIXED + 16, - TPM2_PT_ACTIVE_SESSIONS_MAX =3D TPM2_PT_FIXED + 17, - TPM2_PT_PCR_COUNT =3D TPM2_PT_FIXED + 18, - TPM2_PT_PCR_SELECT_MIN =3D TPM2_PT_FIXED + 19, - TPM2_PT_CONTEXT_GAP_MAX =3D TPM2_PT_FIXED + 20, - TPM2_PT_NV_COUNTERS_MAX =3D TPM2_PT_FIXED + 22, - TPM2_PT_NV_INDEX_MAX =3D TPM2_PT_FIXED + 23, - TPM2_PT_MEMORY =3D TPM2_PT_FIXED + 24, - TPM2_PT_CLOCK_UPDATE =3D TPM2_PT_FIXED + 25, - TPM2_PT_CONTEXT_HASH =3D TPM2_PT_FIXED + 26, - TPM2_PT_CONTEXT_SYM =3D TPM2_PT_FIXED + 27, - TPM2_PT_CONTEXT_SYM_SIZE =3D TPM2_PT_FIXED + 28, - TPM2_PT_ORDERLY_COUNT =3D TPM2_PT_FIXED + 29, - TPM2_PT_MAX_COMMAND_SIZE =3D TPM2_PT_FIXED + 30, - TPM2_PT_MAX_RESPONSE_SIZE =3D TPM2_PT_FIXED + 31, - TPM2_PT_MAX_DIGEST =3D TPM2_PT_FIXED + 32, - TPM2_PT_MAX_OBJECT_CONTEXT =3D TPM2_PT_FIXED + 33, - TPM2_PT_MAX_SESSION_CONTEXT =3D TPM2_PT_FIXED + 34, - TPM2_PT_PS_FAMILY_INDICATOR =3D TPM2_PT_FIXED + 35, - TPM2_PT_PS_LEVEL =3D TPM2_PT_FIXED + 36, - TPM2_PT_PS_REVISION =3D TPM2_PT_FIXED + 37, - TPM2_PT_PS_DAY_OF_YEAR =3D TPM2_PT_FIXED + 38, - TPM2_PT_PS_YEAR =3D TPM2_PT_FIXED + 39, - TPM2_PT_SPLIT_MAX =3D TPM2_PT_FIXED + 40, - TPM2_PT_TOTAL_COMMANDS =3D TPM2_PT_FIXED + 41, - TPM2_PT_LIBRARY_COMMANDS =3D TPM2_PT_FIXED + 42, - TPM2_PT_VENDOR_COMMANDS =3D TPM2_PT_FIXED + 43, - TPM2_PT_NV_BUFFER_MAX =3D TPM2_PT_FIXED + 44, - TPM2_PT_MODES =3D TPM2_PT_FIXED + 45, - TPM2_PT_MAX_CAP_BUFFER =3D TPM2_PT_FIXED + 46, - TPM2_PT_VAR =3D TPM2_PT_GROUP * 2, - TPM2_PT_PERMANENT =3D TPM2_PT_VAR + 0, - TPM2_PT_STARTUP_CLEAR =3D TPM2_PT_VAR + 1, - TPM2_PT_HR_NV_INDEX =3D TPM2_PT_VAR + 2, - TPM2_PT_HR_LOADED =3D TPM2_PT_VAR + 3, - TPM2_PT_HR_LOADED_AVAIL =3D TPM2_PT_VAR + 4, - TPM2_PT_HR_ACTIVE =3D TPM2_PT_VAR + 5, - TPM2_PT_HR_ACTIVE_AVAIL =3D TPM2_PT_VAR + 6, - TPM2_PT_HR_TRANSIENT_AVAIL =3D TPM2_PT_VAR + 7, - TPM2_PT_HR_PERSISTENT =3D TPM2_PT_VAR + 8, - TPM2_PT_HR_PERSISTENT_AVAIL =3D TPM2_PT_VAR + 9, - TPM2_PT_NV_COUNTERS =3D TPM2_PT_VAR + 10, - TPM2_PT_NV_COUNTERS_AVAIL =3D TPM2_PT_VAR + 11, - TPM2_PT_ALGORITHM_SET =3D TPM2_PT_VAR + 12, - TPM2_PT_LOADED_CURVES =3D TPM2_PT_VAR + 13, - TPM2_PT_LOCKOUT_COUNTER =3D TPM2_PT_VAR + 14, - TPM2_PT_MAX_AUTH_FAIL =3D TPM2_PT_VAR + 15, - TPM2_PT_LOCKOUT_INTERVAL =3D TPM2_PT_VAR + 16, - TPM2_PT_LOCKOUT_RECOVERY =3D TPM2_PT_VAR + 17, - TPM2_PT_NV_WRITE_RECOVERY =3D TPM2_PT_VAR + 18, - TPM2_PT_AUDIT_COUNTER_0 =3D TPM2_PT_VAR + 19, - TPM2_PT_AUDIT_COUNTER_1 =3D TPM2_PT_VAR + 20, -}; - extern const struct class tpm_class; extern const struct class tpmrm_class; extern dev_t tpm_devt; diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 3a77be7ebf4a..1fa3e8a43c79 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -94,17 +94,6 @@ unsigned long tpm2_calc_ordinal_duration(u32 ordinal) return msecs_to_jiffies(TPM2_DURATION_DEFAULT); } =20 -struct tpm2_pcr_read_out { - __be32 update_cnt; - __be32 pcr_selects_cnt; - __be16 hash_alg; - u8 pcr_select_size; - u8 pcr_select[TPM2_PCR_SELECT_MIN]; - __be32 digests_cnt; - __be16 digest_size; - u8 digest[]; -} __packed; - /** * tpm2_pcr_read() - read a PCR value * @chip: TPM chip to use. @@ -238,11 +227,6 @@ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, return rc; } =20 -struct tpm2_get_random_out { - __be16 size; - u8 buffer[TPM_MAX_RNG_DATA]; -} __packed; - /** * tpm2_get_random() - get random bytes from the TPM RNG * @@ -366,14 +350,6 @@ void tpm2_flush_context(struct tpm_chip *chip, u32 han= dle) } EXPORT_SYMBOL_GPL(tpm2_flush_context); =20 -struct tpm2_get_cap_out { - u8 more_data; - __be32 subcap_id; - __be32 property_cnt; - __be32 property_id; - __be32 value; -} __packed; - /** * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property * @chip: a &tpm_chip instance @@ -541,12 +517,6 @@ static int tpm2_init_bank_info(struct tpm_chip *chip, = u32 bank_index) return tpm2_pcr_read(chip, 0, &digest, &bank->digest_size); } =20 -struct tpm2_pcr_selection { - __be16 hash_alg; - u8 size_of_select; - u8 pcr_select[3]; -} __packed; - ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) { struct tpm2_pcr_selection pcr_selection; diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index 60354cd53b5c..7c1c0a174a2b 100644 --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -15,19 +15,6 @@ #include #include "tpm.h" =20 -enum tpm2_handle_types { - TPM2_HT_HMAC_SESSION =3D 0x02000000, - TPM2_HT_POLICY_SESSION =3D 0x03000000, - TPM2_HT_TRANSIENT =3D 0x80000000, -}; - -struct tpm2_context { - __be64 sequence; - __be32 saved_handle; - __be32 hierarchy; - __be16 blob_size; -} __packed; - static void tpm2_flush_sessions(struct tpm_chip *chip, struct tpm_space *s= pace) { int i; diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 1846d5485a2c..8551b24c2bff 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -38,12 +38,6 @@ struct trusted_key_options; /* opaque structure, holds auth session parameters like the session key */ struct tpm2_auth; =20 -enum tpm2_session_types { - TPM2_SE_HMAC =3D 0x00, - TPM2_SE_POLICY =3D 0x01, - TPM2_SE_TRIAL =3D 0x02, -}; - /* if you add a new hash to this, increment TPM_MAX_HASHES below */ enum tpm_algorithms { TPM_ALG_ERROR =3D 0x0000, @@ -65,11 +59,6 @@ enum tpm_algorithms { */ #define TPM_MAX_HASHES 5 =20 -enum tpm2_curves { - TPM2_ECC_NONE =3D 0x0000, - TPM2_ECC_NIST_P256 =3D 0x0003, -}; - struct tpm_digest { u16 alg_id; u8 digest[TPM2_MAX_DIGEST_SIZE]; @@ -222,122 +211,11 @@ struct tpm_chip { =20 #define TPM_HEADER_SIZE 10 =20 -enum tpm2_const { - TPM2_PLATFORM_PCR =3D 24, - TPM2_PCR_SELECT_MIN =3D ((TPM2_PLATFORM_PCR + 7) / 8), -}; - -enum tpm2_timeouts { - TPM2_TIMEOUT_A =3D 750, - TPM2_TIMEOUT_B =3D 4000, - TPM2_TIMEOUT_C =3D 200, - TPM2_TIMEOUT_D =3D 30, -}; - -enum tpm2_durations { - TPM2_DURATION_SHORT =3D 20, - TPM2_DURATION_LONG =3D 2000, - TPM2_DURATION_DEFAULT =3D 120000, -}; - -enum tpm2_structures { - TPM2_ST_NO_SESSIONS =3D 0x8001, - TPM2_ST_SESSIONS =3D 0x8002, - TPM2_ST_CREATION =3D 0x8021, -}; - -/* Indicates from what layer of the software stack the error comes from */ -#define TSS2_RC_LAYER_SHIFT 16 -#define TSS2_RESMGR_TPM_RC_LAYER (11 << TSS2_RC_LAYER_SHIFT) - -enum tpm2_return_codes { - TPM2_RC_SUCCESS =3D 0x0000, - TPM2_RC_HASH =3D 0x0083, /* RC_FMT1 */ - TPM2_RC_HANDLE =3D 0x008B, - TPM2_RC_INTEGRITY =3D 0x009F, - TPM2_RC_INITIALIZE =3D 0x0100, /* RC_VER1 */ - TPM2_RC_FAILURE =3D 0x0101, - TPM2_RC_DISABLED =3D 0x0120, - TPM2_RC_UPGRADE =3D 0x012D, - TPM2_RC_COMMAND_CODE =3D 0x0143, - TPM2_RC_TESTING =3D 0x090A, /* RC_WARN */ - TPM2_RC_REFERENCE_H0 =3D 0x0910, - TPM2_RC_RETRY =3D 0x0922, - TPM2_RC_SESSION_MEMORY =3D 0x0903, -}; - -enum tpm2_command_codes { - TPM2_CC_FIRST =3D 0x011F, - TPM2_CC_HIERARCHY_CONTROL =3D 0x0121, - TPM2_CC_HIERARCHY_CHANGE_AUTH =3D 0x0129, - TPM2_CC_CREATE_PRIMARY =3D 0x0131, - TPM2_CC_SEQUENCE_COMPLETE =3D 0x013E, - TPM2_CC_SELF_TEST =3D 0x0143, - TPM2_CC_STARTUP =3D 0x0144, - TPM2_CC_SHUTDOWN =3D 0x0145, - TPM2_CC_NV_READ =3D 0x014E, - TPM2_CC_CREATE =3D 0x0153, - TPM2_CC_LOAD =3D 0x0157, - TPM2_CC_SEQUENCE_UPDATE =3D 0x015C, - TPM2_CC_UNSEAL =3D 0x015E, - TPM2_CC_CONTEXT_LOAD =3D 0x0161, - TPM2_CC_CONTEXT_SAVE =3D 0x0162, - TPM2_CC_FLUSH_CONTEXT =3D 0x0165, - TPM2_CC_READ_PUBLIC =3D 0x0173, - TPM2_CC_START_AUTH_SESS =3D 0x0176, - TPM2_CC_VERIFY_SIGNATURE =3D 0x0177, - TPM2_CC_GET_CAPABILITY =3D 0x017A, - TPM2_CC_GET_RANDOM =3D 0x017B, - TPM2_CC_PCR_READ =3D 0x017E, - TPM2_CC_PCR_EXTEND =3D 0x0182, - TPM2_CC_EVENT_SEQUENCE_COMPLETE =3D 0x0185, - TPM2_CC_HASH_SEQUENCE_START =3D 0x0186, - TPM2_CC_CREATE_LOADED =3D 0x0191, - TPM2_CC_LAST =3D 0x0193, /* Spec 1.36 */ -}; - -enum tpm2_permanent_handles { - TPM2_RH_NULL =3D 0x40000007, - TPM2_RS_PW =3D 0x40000009, -}; - -/* Most Significant Octet for key types */ -enum tpm2_mso_type { - TPM2_MSO_NVRAM =3D 0x01, - TPM2_MSO_SESSION =3D 0x02, - TPM2_MSO_POLICY =3D 0x03, - TPM2_MSO_PERMANENT =3D 0x40, - TPM2_MSO_VOLATILE =3D 0x80, - TPM2_MSO_PERSISTENT =3D 0x81, -}; - static inline enum tpm2_mso_type tpm2_handle_mso(u32 handle) { return handle >> 24; } =20 -enum tpm2_capabilities { - TPM2_CAP_HANDLES =3D 1, - TPM2_CAP_COMMANDS =3D 2, - TPM2_CAP_PCRS =3D 5, - TPM2_CAP_TPM_PROPERTIES =3D 6, -}; - -enum tpm2_properties { - TPM_PT_TOTAL_COMMANDS =3D 0x0129, -}; - -enum tpm2_startup_types { - TPM2_SU_CLEAR =3D 0x0000, - TPM2_SU_STATE =3D 0x0001, -}; - -enum tpm2_cc_attrs { - TPM2_CC_ATTR_CHANDLES =3D 25, - TPM2_CC_ATTR_RHANDLE =3D 28, - TPM2_CC_ATTR_VENDOR =3D 29, -}; - #define TPM_VID_INTEL 0x8086 #define TPM_VID_WINBOND 0x1050 #define TPM_VID_STM 0x104A @@ -389,29 +267,6 @@ struct tpm_buf { u8 handles; }; =20 -enum tpm2_object_attributes { - TPM2_OA_FIXED_TPM =3D BIT(1), - TPM2_OA_ST_CLEAR =3D BIT(2), - TPM2_OA_FIXED_PARENT =3D BIT(4), - TPM2_OA_SENSITIVE_DATA_ORIGIN =3D BIT(5), - TPM2_OA_USER_WITH_AUTH =3D BIT(6), - TPM2_OA_ADMIN_WITH_POLICY =3D BIT(7), - TPM2_OA_NO_DA =3D BIT(10), - TPM2_OA_ENCRYPTED_DUPLICATION =3D BIT(11), - TPM2_OA_RESTRICTED =3D BIT(16), - TPM2_OA_DECRYPT =3D BIT(17), - TPM2_OA_SIGN =3D BIT(18), -}; - -enum tpm2_session_attributes { - TPM2_SA_CONTINUE_SESSION =3D BIT(0), - TPM2_SA_AUDIT_EXCLUSIVE =3D BIT(1), - TPM2_SA_AUDIT_RESET =3D BIT(3), - TPM2_SA_DECRYPT =3D BIT(5), - TPM2_SA_ENCRYPT =3D BIT(6), - TPM2_SA_AUDIT =3D BIT(7), -}; - struct tpm2_hash { unsigned int crypto_id; unsigned int tpm_id; diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h index 30d01953a6f8..9dd903dd6b5c 100644 --- a/include/linux/tpm_command.h +++ b/include/linux/tpm_command.h @@ -156,4 +156,275 @@ struct tpm1_get_random_out { #define TPM_NONCE_SIZE 20 #define TPM_ST_CLEAR 1 =20 +/* + * =3D=3D TPM 2 Family Chips =3D=3D + * + * TPM 2.0 Library + * https://trustedcomputinggroup.org/resource/tpm-library-specification/ + */ + +/* TPM2 specific constants. */ +#define TPM2_SPACE_BUFFER_SIZE 16384 /* 16 kB */ + +enum tpm2_session_types { + TPM2_SE_HMAC =3D 0x00, + TPM2_SE_POLICY =3D 0x01, + TPM2_SE_TRIAL =3D 0x02, +}; + +enum tpm2_timeouts { + TPM2_TIMEOUT_A =3D 750, + TPM2_TIMEOUT_B =3D 4000, + TPM2_TIMEOUT_C =3D 200, + TPM2_TIMEOUT_D =3D 30, + TPM2_DURATION_SHORT =3D 20, + TPM2_DURATION_MEDIUM =3D 750, + TPM2_DURATION_LONG =3D 2000, + TPM2_DURATION_LONG_LONG =3D 300000, + TPM2_DURATION_DEFAULT =3D 120000, +}; + +enum tpm2_structures { + TPM2_ST_NO_SESSIONS =3D 0x8001, + TPM2_ST_SESSIONS =3D 0x8002, + TPM2_ST_CREATION =3D 0x8021, +}; + +/* Indicates from what layer of the software stack the error comes from */ +#define TSS2_RC_LAYER_SHIFT 16 +#define TSS2_RESMGR_TPM_RC_LAYER (11 << TSS2_RC_LAYER_SHIFT) + +enum tpm2_return_codes { + TPM2_RC_SUCCESS =3D 0x0000, + TPM2_RC_HASH =3D 0x0083, /* RC_FMT1 */ + TPM2_RC_HANDLE =3D 0x008B, + TPM2_RC_INTEGRITY =3D 0x009F, + TPM2_RC_INITIALIZE =3D 0x0100, /* RC_VER1 */ + TPM2_RC_FAILURE =3D 0x0101, + TPM2_RC_DISABLED =3D 0x0120, + TPM2_RC_UPGRADE =3D 0x012D, + TPM2_RC_COMMAND_CODE =3D 0x0143, + TPM2_RC_TESTING =3D 0x090A, /* RC_WARN */ + TPM2_RC_REFERENCE_H0 =3D 0x0910, + TPM2_RC_RETRY =3D 0x0922, + TPM2_RC_SESSION_MEMORY =3D 0x0903, +}; + +enum tpm2_command_codes { + TPM2_CC_FIRST =3D 0x011F, + TPM2_CC_HIERARCHY_CONTROL =3D 0x0121, + TPM2_CC_HIERARCHY_CHANGE_AUTH =3D 0x0129, + TPM2_CC_CREATE_PRIMARY =3D 0x0131, + TPM2_CC_SEQUENCE_COMPLETE =3D 0x013E, + TPM2_CC_SELF_TEST =3D 0x0143, + TPM2_CC_STARTUP =3D 0x0144, + TPM2_CC_SHUTDOWN =3D 0x0145, + TPM2_CC_NV_READ =3D 0x014E, + TPM2_CC_CREATE =3D 0x0153, + TPM2_CC_LOAD =3D 0x0157, + TPM2_CC_SEQUENCE_UPDATE =3D 0x015C, + TPM2_CC_UNSEAL =3D 0x015E, + TPM2_CC_CONTEXT_LOAD =3D 0x0161, + TPM2_CC_CONTEXT_SAVE =3D 0x0162, + TPM2_CC_FLUSH_CONTEXT =3D 0x0165, + TPM2_CC_READ_PUBLIC =3D 0x0173, + TPM2_CC_START_AUTH_SESS =3D 0x0176, + TPM2_CC_VERIFY_SIGNATURE =3D 0x0177, + TPM2_CC_GET_CAPABILITY =3D 0x017A, + TPM2_CC_GET_RANDOM =3D 0x017B, + TPM2_CC_PCR_READ =3D 0x017E, + TPM2_CC_PCR_EXTEND =3D 0x0182, + TPM2_CC_EVENT_SEQUENCE_COMPLETE =3D 0x0185, + TPM2_CC_HASH_SEQUENCE_START =3D 0x0186, + TPM2_CC_CREATE_LOADED =3D 0x0191, + TPM2_CC_LAST =3D 0x0193, /* Spec 1.36 */ +}; + +enum tpm2_capabilities { + TPM2_CAP_HANDLES =3D 1, + TPM2_CAP_COMMANDS =3D 2, + TPM2_CAP_PCRS =3D 5, + TPM2_CAP_TPM_PROPERTIES =3D 6, +}; + +enum tpm2_properties { + TPM_PT_TOTAL_COMMANDS =3D 0x0129, +}; + +enum tpm2_startup_types { + TPM2_SU_CLEAR =3D 0x0000, + TPM2_SU_STATE =3D 0x0001, +}; + +enum tpm2_cc_attrs { + TPM2_CC_ATTR_CHANDLES =3D 25, + TPM2_CC_ATTR_RHANDLE =3D 28, + TPM2_CC_ATTR_VENDOR =3D 29, +}; + +enum tpm2_permanent_handles { + TPM2_RH_NULL =3D 0x40000007, + TPM2_RS_PW =3D 0x40000009, +}; + +/* Most Significant Octet for key types */ +enum tpm2_mso_type { + TPM2_MSO_NVRAM =3D 0x01, + TPM2_MSO_SESSION =3D 0x02, + TPM2_MSO_POLICY =3D 0x03, + TPM2_MSO_PERMANENT =3D 0x40, + TPM2_MSO_VOLATILE =3D 0x80, + TPM2_MSO_PERSISTENT =3D 0x81, +}; + +enum tpm2_curves { + TPM2_ECC_NONE =3D 0x0000, + TPM2_ECC_NIST_P256 =3D 0x0003, +}; + +enum tpm2_object_attributes { + TPM2_OA_FIXED_TPM =3D BIT(1), + TPM2_OA_ST_CLEAR =3D BIT(2), + TPM2_OA_FIXED_PARENT =3D BIT(4), + TPM2_OA_SENSITIVE_DATA_ORIGIN =3D BIT(5), + TPM2_OA_USER_WITH_AUTH =3D BIT(6), + TPM2_OA_ADMIN_WITH_POLICY =3D BIT(7), + TPM2_OA_NO_DA =3D BIT(10), + TPM2_OA_ENCRYPTED_DUPLICATION =3D BIT(11), + TPM2_OA_RESTRICTED =3D BIT(16), + TPM2_OA_DECRYPT =3D BIT(17), + TPM2_OA_SIGN =3D BIT(18), +}; + +enum tpm2_session_attributes { + TPM2_SA_CONTINUE_SESSION =3D BIT(0), + TPM2_SA_AUDIT_EXCLUSIVE =3D BIT(1), + TPM2_SA_AUDIT_RESET =3D BIT(3), + TPM2_SA_DECRYPT =3D BIT(5), + TPM2_SA_ENCRYPT =3D BIT(6), + TPM2_SA_AUDIT =3D BIT(7), +}; + +enum tpm2_pcr_select { + TPM2_PLATFORM_PCR =3D 24, + TPM2_PCR_SELECT_MIN =3D ((TPM2_PLATFORM_PCR + 7) / 8), +}; + +enum tpm2_handle_types { + TPM2_HT_HMAC_SESSION =3D 0x02000000, + TPM2_HT_POLICY_SESSION =3D 0x03000000, + TPM2_HT_TRANSIENT =3D 0x80000000, +}; + +enum tpm2_pt_props { + TPM2_PT_NONE =3D 0x00000000, + TPM2_PT_GROUP =3D 0x00000100, + TPM2_PT_FIXED =3D TPM2_PT_GROUP * 1, + TPM2_PT_FAMILY_INDICATOR =3D TPM2_PT_FIXED + 0, + TPM2_PT_LEVEL =3D TPM2_PT_FIXED + 1, + TPM2_PT_REVISION =3D TPM2_PT_FIXED + 2, + TPM2_PT_DAY_OF_YEAR =3D TPM2_PT_FIXED + 3, + TPM2_PT_YEAR =3D TPM2_PT_FIXED + 4, + TPM2_PT_MANUFACTURER =3D TPM2_PT_FIXED + 5, + TPM2_PT_VENDOR_STRING_1 =3D TPM2_PT_FIXED + 6, + TPM2_PT_VENDOR_STRING_2 =3D TPM2_PT_FIXED + 7, + TPM2_PT_VENDOR_STRING_3 =3D TPM2_PT_FIXED + 8, + TPM2_PT_VENDOR_STRING_4 =3D TPM2_PT_FIXED + 9, + TPM2_PT_VENDOR_TPM_TYPE =3D TPM2_PT_FIXED + 10, + TPM2_PT_FIRMWARE_VERSION_1 =3D TPM2_PT_FIXED + 11, + TPM2_PT_FIRMWARE_VERSION_2 =3D TPM2_PT_FIXED + 12, + TPM2_PT_INPUT_BUFFER =3D TPM2_PT_FIXED + 13, + TPM2_PT_HR_TRANSIENT_MIN =3D TPM2_PT_FIXED + 14, + TPM2_PT_HR_PERSISTENT_MIN =3D TPM2_PT_FIXED + 15, + TPM2_PT_HR_LOADED_MIN =3D TPM2_PT_FIXED + 16, + TPM2_PT_ACTIVE_SESSIONS_MAX =3D TPM2_PT_FIXED + 17, + TPM2_PT_PCR_COUNT =3D TPM2_PT_FIXED + 18, + TPM2_PT_PCR_SELECT_MIN =3D TPM2_PT_FIXED + 19, + TPM2_PT_CONTEXT_GAP_MAX =3D TPM2_PT_FIXED + 20, + TPM2_PT_NV_COUNTERS_MAX =3D TPM2_PT_FIXED + 22, + TPM2_PT_NV_INDEX_MAX =3D TPM2_PT_FIXED + 23, + TPM2_PT_MEMORY =3D TPM2_PT_FIXED + 24, + TPM2_PT_CLOCK_UPDATE =3D TPM2_PT_FIXED + 25, + TPM2_PT_CONTEXT_HASH =3D TPM2_PT_FIXED + 26, + TPM2_PT_CONTEXT_SYM =3D TPM2_PT_FIXED + 27, + TPM2_PT_CONTEXT_SYM_SIZE =3D TPM2_PT_FIXED + 28, + TPM2_PT_ORDERLY_COUNT =3D TPM2_PT_FIXED + 29, + TPM2_PT_MAX_COMMAND_SIZE =3D TPM2_PT_FIXED + 30, + TPM2_PT_MAX_RESPONSE_SIZE =3D TPM2_PT_FIXED + 31, + TPM2_PT_MAX_DIGEST =3D TPM2_PT_FIXED + 32, + TPM2_PT_MAX_OBJECT_CONTEXT =3D TPM2_PT_FIXED + 33, + TPM2_PT_MAX_SESSION_CONTEXT =3D TPM2_PT_FIXED + 34, + TPM2_PT_PS_FAMILY_INDICATOR =3D TPM2_PT_FIXED + 35, + TPM2_PT_PS_LEVEL =3D TPM2_PT_FIXED + 36, + TPM2_PT_PS_REVISION =3D TPM2_PT_FIXED + 37, + TPM2_PT_PS_DAY_OF_YEAR =3D TPM2_PT_FIXED + 38, + TPM2_PT_PS_YEAR =3D TPM2_PT_FIXED + 39, + TPM2_PT_SPLIT_MAX =3D TPM2_PT_FIXED + 40, + TPM2_PT_TOTAL_COMMANDS =3D TPM2_PT_FIXED + 41, + TPM2_PT_LIBRARY_COMMANDS =3D TPM2_PT_FIXED + 42, + TPM2_PT_VENDOR_COMMANDS =3D TPM2_PT_FIXED + 43, + TPM2_PT_NV_BUFFER_MAX =3D TPM2_PT_FIXED + 44, + TPM2_PT_MODES =3D TPM2_PT_FIXED + 45, + TPM2_PT_MAX_CAP_BUFFER =3D TPM2_PT_FIXED + 46, + TPM2_PT_VAR =3D TPM2_PT_GROUP * 2, + TPM2_PT_PERMANENT =3D TPM2_PT_VAR + 0, + TPM2_PT_STARTUP_CLEAR =3D TPM2_PT_VAR + 1, + TPM2_PT_HR_NV_INDEX =3D TPM2_PT_VAR + 2, + TPM2_PT_HR_LOADED =3D TPM2_PT_VAR + 3, + TPM2_PT_HR_LOADED_AVAIL =3D TPM2_PT_VAR + 4, + TPM2_PT_HR_ACTIVE =3D TPM2_PT_VAR + 5, + TPM2_PT_HR_ACTIVE_AVAIL =3D TPM2_PT_VAR + 6, + TPM2_PT_HR_TRANSIENT_AVAIL =3D TPM2_PT_VAR + 7, + TPM2_PT_HR_PERSISTENT =3D TPM2_PT_VAR + 8, + TPM2_PT_HR_PERSISTENT_AVAIL =3D TPM2_PT_VAR + 9, + TPM2_PT_NV_COUNTERS =3D TPM2_PT_VAR + 10, + TPM2_PT_NV_COUNTERS_AVAIL =3D TPM2_PT_VAR + 11, + TPM2_PT_ALGORITHM_SET =3D TPM2_PT_VAR + 12, + TPM2_PT_LOADED_CURVES =3D TPM2_PT_VAR + 13, + TPM2_PT_LOCKOUT_COUNTER =3D TPM2_PT_VAR + 14, + TPM2_PT_MAX_AUTH_FAIL =3D TPM2_PT_VAR + 15, + TPM2_PT_LOCKOUT_INTERVAL =3D TPM2_PT_VAR + 16, + TPM2_PT_LOCKOUT_RECOVERY =3D TPM2_PT_VAR + 17, + TPM2_PT_NV_WRITE_RECOVERY =3D TPM2_PT_VAR + 18, + TPM2_PT_AUDIT_COUNTER_0 =3D TPM2_PT_VAR + 19, + TPM2_PT_AUDIT_COUNTER_1 =3D TPM2_PT_VAR + 20, +}; + +struct tpm2_pcr_read_out { + __be32 update_cnt; + __be32 pcr_selects_cnt; + __be16 hash_alg; + u8 pcr_select_size; + u8 pcr_select[TPM2_PCR_SELECT_MIN]; + __be32 digests_cnt; + __be16 digest_size; + u8 digest[]; +} __packed; + +struct tpm2_get_random_out { + __be16 size; + u8 buffer[TPM_MAX_RNG_DATA]; +} __packed; + +struct tpm2_get_cap_out { + u8 more_data; + __be32 subcap_id; + __be32 property_cnt; + __be32 property_id; + __be32 value; +} __packed; + +struct tpm2_pcr_selection { + __be16 hash_alg; + u8 size_of_select; + u8 pcr_select[3]; +} __packed; + +struct tpm2_context { + __be64 sequence; + __be32 saved_handle; + __be32 hierarchy; + __be16 blob_size; +} __packed; + #endif --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f42.google.com (mail-dl1-f42.google.com [74.125.82.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7874F3EC2D1 for ; Fri, 15 May 2026 21:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879668; cv=none; b=ooihmrBPhionpUPeVSNOMb3WoQvB0Wx8dkXPHotJ5eS4WB38iPwGyr7bGxVbRg0x5Wvf3vSd6ly4lSwL9EmfbF5jCLUOBL5u94wLQOGC9SeUWbxpNihmx+ltK322RhcsiH6yVglDSrXjm6rSGl+IerNDC00USZvjhHIx/9JjZ2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879668; c=relaxed/simple; bh=msNEhWQcSwNE6T7QnFoUfFfSSSD/YmuJUa2h6PeyfBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lUZQs3SjJ0lk5LvzJHJmR3KSHtHNcEk/Yh9iOqeSqDSvtUCjUpBuvHEQE0x6ozI7Mw2TBfrx1vZgve1qK/HkBx9AOlmK4yx+s9AeR8ezbimVRx3cwWeteIP9wCrMP5tlvgo8rQrzSp7C6j3qa70hkspSUftDxJtq7AKUOzLYtGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=sfgckZEp; arc=none smtp.client-ip=74.125.82.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sfgckZEp" Received: by mail-dl1-f42.google.com with SMTP id a92af1059eb24-134ac81c445so953080c88.1 for ; Fri, 15 May 2026 14:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879664; x=1779484464; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kFmz/IKFkr+yHkTTECqlvzt5xXCg9R4f8VRlkTmPQhI=; b=sfgckZEp9aJp4JjltgjE93ZFVO+j1jS7bj/eaC1RBry7Gd1fqUmOyXDwPUoXx8R3CV jxm0Og4GpEZpu1+EMu2wx20HE+JJVSUoqQu4gQTuuR6/0yuZlv26OEsBZQZYUejXpW0Q PC1Zhci8mDGxF04u+hDdynx/cwtfYbJEP3pSpnRSIgJ4yn+t/84TWWaapxJKhKfG+dAH 8Z1m97XKRayC+iXJabSBQtZpEWZzD/cVT6Y1A2T4zt4z+VQ3QqnEmsmzLRt1PTszwr1i 4A8sc133sozwg2rNHyNmDaH1ORUjkbSa9eXzcgS5fQJYj9kPY1Cy+K1DWYCoWra/Adqj JFSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879664; x=1779484464; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kFmz/IKFkr+yHkTTECqlvzt5xXCg9R4f8VRlkTmPQhI=; b=Gczpp6+1vEucHWLWHadq0Wy2azsbiuEG6H38xZGz7qHJwsFLpCmf+cS5fHyziPijsI HSqeHZvotAx+uZoR0uDYwcHGc3zI8L7gclYz70oPDggbWrukXqCmHdqLxCHx3ovFEyMG j6D/1CnNvFrgFbYF7s/mk1Hz9f8oapttk8OnFMB0FqYF7Gvw8HNxTxwDrNDg5pHQNeZr c6M6KcS33F8oawdKpazt3lNX6zAYRXW7SCpDdRGiWZJ4qPQaA/iSqzi8dV0PV7yt6zCE kz+JiiWKH2HsjU8tqaTeVeQT2srFLucsAwdxjx39whwtoU+L0laCWdGGYEUU8BrMft9U 54NQ== X-Gm-Message-State: AOJu0YzgR86xSZMz56rsYE6iJA4dCXYtslnvVdwbAGCpnfnqTbCEdBBM 3VTfkVhAvuwrQ/nsYEDU/HhjHes4OXkSWOQ1nUQOitcZ+xZ0PHGH7FPFIDPf3RFp X-Gm-Gg: Acq92OGlsiod567lIIO8IT/m5oy9nYXuuSOxOH0M2B+JW8JB/f7o62FooE+UE6wP0CJ QIMLCpIXJfVpC5l7BGhmk6/VoBXlp2wXLqoiWK81LdFkqgJZcof31j4tgt22TOYOK/NKD/6O1af B22mOVGi92jcalvxETXkb53StJ9LKH6gWJQu1GrLPBaErEtei+6DLHLiHo7ZMiFf3/nHO2PmlPG EaZ9YXMN7/T7L/YLwnEHERzJuGBsT6qdPPwppag8O13u5lfej3D3yg+HiT1dx8OE/kYXebJYpzU 9ri0CrHvNpiXfu/7F8M8bLftz4qozhLf1hik66isUmKUMVv400k8s6IYpUZ2nYwvomKKGPccY5v 9HUJxOga8nNYFKV73zD+XOk6J7uTVRiACbZN7uiTdvGXczt/lZ8KMlQyQ7lrahP+D/gxx1xU0Q4 Ge2rRTwZfDOsQodAj7PqTM8JS+x3Uj2Bo= X-Received: by 2002:a05:7022:4582:b0:132:5db9:27af with SMTP id a92af1059eb24-13504a49ademr2695477c88.35.1778879663897; Fri, 15 May 2026 14:14:23 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cbcb93f3sm11145075c88.3.2026.05.15.14.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:23 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 04/38] tpm: Move TPM common base definitions to the command header Date: Fri, 15 May 2026 14:13:36 -0700 Message-ID: <20260515211410.31440-5-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These are top level definitions shared by both TPM 1 and 2 family chips. This includes core definitions like TPM localities, common crypto algorithm IDs, and the base TPM command header. Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Co-developed-by: Alec Brown Signed-off-by: Alec Brown Signed-off-by: Ross Philipson --- include/linux/tpm.h | 50 +-------------------- include/linux/tpm_command.h | 89 +++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 49 deletions(-) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 8551b24c2bff..3630b2ea6aef 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -27,49 +27,12 @@ =20 #include =20 -#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */ - -#define TPM2_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE -#define TPM2_MAX_PCR_BANKS 8 - struct tpm_chip; struct trusted_key_payload; struct trusted_key_options; /* opaque structure, holds auth session parameters like the session key */ struct tpm2_auth; =20 -/* if you add a new hash to this, increment TPM_MAX_HASHES below */ -enum tpm_algorithms { - TPM_ALG_ERROR =3D 0x0000, - TPM_ALG_SHA1 =3D 0x0004, - TPM_ALG_AES =3D 0x0006, - TPM_ALG_KEYEDHASH =3D 0x0008, - TPM_ALG_SHA256 =3D 0x000B, - TPM_ALG_SHA384 =3D 0x000C, - TPM_ALG_SHA512 =3D 0x000D, - TPM_ALG_NULL =3D 0x0010, - TPM_ALG_SM3_256 =3D 0x0012, - TPM_ALG_ECC =3D 0x0023, - TPM_ALG_CFB =3D 0x0043, -}; - -/* - * maximum number of hashing algorithms a TPM can have. This is - * basically a count of every hash in tpm_algorithms above - */ -#define TPM_MAX_HASHES 5 - -struct tpm_digest { - u16 alg_id; - u8 digest[TPM2_MAX_DIGEST_SIZE]; -} __packed; - -struct tpm_bank_info { - u16 alg_id; - u16 digest_size; - u16 crypto_id; -}; - enum TPM_OPS_FLAGS { TPM_OPS_AUTO_STARTUP =3D BIT(0), }; @@ -127,7 +90,7 @@ struct tpm_chip_seqops { const struct seq_operations *seqops; }; =20 -/* fixed define for the curve we use which is NIST_P256 */ +/* Fixed define for the curve we use which is NIST_P256 */ #define EC_PT_SZ 32 =20 /* @@ -209,8 +172,6 @@ struct tpm_chip { #endif }; =20 -#define TPM_HEADER_SIZE 10 - static inline enum tpm2_mso_type tpm2_handle_mso(u32 handle) { return handle >> 24; @@ -239,15 +200,6 @@ enum tpm_chip_flags { =20 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) =20 -struct tpm_header { - __be16 tag; - __be32 length; - union { - __be32 ordinal; - __be32 return_code; - }; -} __packed; - enum tpm_buf_flags { /* the capacity exceeded: */ TPM_BUF_OVERFLOW =3D BIT(0), diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h index 9dd903dd6b5c..96edebd9610f 100644 --- a/include/linux/tpm_command.h +++ b/include/linux/tpm_command.h @@ -427,4 +427,93 @@ struct tpm2_context { __be16 blob_size; } __packed; =20 +/* + * =3D=3D TPM Common Defs =3D=3D + */ + +#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */ +#define TPM_BUFSIZE 4096 + +/* + * SHA-512 is, as of today, the largest digest in the TCG algorithm reposi= tory. + */ +#define TPM2_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE + +/* + * A TPM name digest i.e., TPMT_HA, is a concatenation of TPM_ALG_ID of the + * name algorithm and hash of TPMT_PUBLIC. + */ +#define TPM2_MAX_NAME_SIZE (TPM2_MAX_DIGEST_SIZE + 2) + +/* + * Fixed define for the size of a name. This is actually HASHALG size + * plus 2, so 32 for SHA256 + */ +#define TPM2_NULL_NAME_SIZE 34 + +/* + * The maximum number of PCR banks. + */ +#define TPM2_MAX_PCR_BANKS 8 + +/* If you add a new hash to this, increment TPM_MAX_HASHES below */ +enum tpm_algorithms { + TPM_ALG_ERROR =3D 0x0000, + TPM_ALG_SHA1 =3D 0x0004, + TPM_ALG_AES =3D 0x0006, + TPM_ALG_KEYEDHASH =3D 0x0008, + TPM_ALG_SHA256 =3D 0x000B, + TPM_ALG_SHA384 =3D 0x000C, + TPM_ALG_SHA512 =3D 0x000D, + TPM_ALG_NULL =3D 0x0010, + TPM_ALG_SM3_256 =3D 0x0012, + TPM_ALG_ECC =3D 0x0023, + TPM_ALG_CFB =3D 0x0043, +}; + +/* + * The locality (0 - 4) for a TPM, as defined in section 3.2 of the + * Client Platform Profile Specification. + */ +enum tpm_localities { + TPM_LOCALITY_0 =3D 0, /* Static RTM */ + TPM_LOCALITY_1 =3D 1, /* Dynamic OS */ + TPM_LOCALITY_2 =3D 2, /* DRTM Environment */ + TPM_LOCALITY_3 =3D 3, /* Aux Components */ + TPM_LOCALITY_4 =3D 4, /* CPU DRTM Establishment */ + TPM_MAX_LOCALITY =3D TPM_LOCALITY_4 +}; + +/* + * Structure to represent active PCR algorithm banks usable by the + * TPM chip. + */ +struct tpm_bank_info { + u16 alg_id; + u16 digest_size; + u16 crypto_id; +}; + +/* + * Maximum number of hashing algorithms a TPM can have. This is + * basically a count of every hash in tpm_algorithms above + */ +#define TPM_MAX_HASHES 5 + +struct tpm_digest { + u16 alg_id; + u8 digest[TPM2_MAX_DIGEST_SIZE]; +} __packed; + +#define TPM_HEADER_SIZE 10 + +struct tpm_header { + __be16 tag; + __be32 length; + union { + __be32 ordinal; + __be32 return_code; + }; +} __packed; + #endif --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1774A3E1D0F for ; Fri, 15 May 2026 21:14:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879670; cv=none; b=pUjj87b02eXZY50H9LRuoZC8wVLAsD39FqB5qLyxS/dSorRw+rIxyetmwmVJObvGujUwPZCsy46vKEmUSggx3J3ff/zU6l6y75yX+vKcrgftCjxFV/NKOj7YvxfaJM7+lNsNkwu40z0lLLEtA7vHt4aU3WZOmb3RUJH8AkmKAuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879670; c=relaxed/simple; bh=iZx+Ma9ZLO27Qd1OSFPbIPI91crZcyGUmYYOTAyaGV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WFuevLwwOV9EBkwVBpI1Femh7/npHrOmiK5W/nj+aYpELCE0wXyK+C/6vuZ1hEmpk/LZrGnSQ2rxmS9K6gTBrunwrrupBp13NS4g+NIvR06Omp0YXq0UOlvK/lhh3LlsgMfJ+jft3zQr3MoKI7qrI3x0r0ZbqWuIMrNMYglEzwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V+aYs+sS; arc=none smtp.client-ip=74.125.82.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V+aYs+sS" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-132c338a537so1026467c88.0 for ; Fri, 15 May 2026 14:14:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879667; x=1779484467; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zvhJ+ydmVFUO/FtDIG83CBk7wY0hq1hCXhxrxXZ6CzE=; b=V+aYs+sS8kXrENeJEYszeay1jLDUpy8kXTjVEGtORS5QflQnwyXwrVZZf6AWM3KSrH p3loYQh1cSwdAH/ClG38n2IltMK+e+QOktZ38/7Y61DNR3BjE4PCfA70fYeMWoObIYQK /p9MxXRFQJNWOpsVpYiTDEpWiImZO33lHIadpJUJZByA8Z99pwIYnt7mHy0EyH59Kk7x fgijEtE5LZNrecyVn1qopbBriufmCDUELfAUlJycyuOY9klZvELHtlqwnqr5gPv2clmN XbwhCSWJxy5i6rnS69hSWFvNrp6n+ExzeVaF9t6zyjEBan8Q0DvbKV98dDCXMuGLjW6j xVfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879667; x=1779484467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zvhJ+ydmVFUO/FtDIG83CBk7wY0hq1hCXhxrxXZ6CzE=; b=FhOVyroCJ507IZgqtab8URRSCwKxuGfI5ZSmYsTZMh7BC/p2W6z+r/D0PZPWhMef25 eAaz7miHMJvaJwDakLcZRdC+u5qKUA765/k1UTcOzENzkPqN+1A/OG6+SYPqoJHLV9MN tU1YNI/g+tO+U+Knj2hvtzkuRtpBp1dvHbvvGviBMeibCQdPpt8dtLmBSz03h5ttr5eR TPRFur4JJ1UkW1W+9tnB2J20VK7c2ho74IRxBQ0BSD9iJWoyi5lci+IaM7JVh8AVO8mA dGFzBNxv8tO8NcJSi/lLmyiFakrNQb42b7/A1sueWaY6YU0BB5wknGLhL1vBQVazT7ZF xR7Q== X-Gm-Message-State: AOJu0Yws5eRz+oIBB1WuMpWYHAPcLxfMYDO0ISgf5a6BiURMpuU+lssw DKIJ+GxT+FrOHodCARMkIDE1s3TnCWxaBvjWeLf+5h6Sm6VMjFG8M6vMgNmdi6lh X-Gm-Gg: Acq92OG4VZ2TGNBgs7RK9voAmpxpfsljnMWdfuziKRPLmm1Kgwjk/tbn5tZEMOZm0Sz gEGvL1ccj4FZLUlEBsugFaywhR9Wq2lxBU1CgETir23bD31tzgzU1g53UWJnH3FD6GWjVgkSt2R G4TFLj1BiM6UPtxI/qIVf7Fd1diKgIbI/s4OnbRqCV96bI6t4AetPdR3YP9OcwX45Y9rjguyzoc sK1ekY3BZU2t+YLpFBt2vw3ufS4PMyzdFF/LNzZD87Ckr0fJGVJsFxfI9jOYpd0A4FOnb09y9og chrrchBX4oUQSRj75uomQS0ghdvKCz9WBN9YhnRuakPQ0KHlK6R2JpuTLvkda9ef9iY8Xg/cmaR d7BA4Y0RmljksnQQefMb3q3ubSpS+nqQjRTatjd3+H0GBg5cFJvX+ZCWxlvHO6FeMp7vR2eIek6 Y64qMu1NvwZYqduuRmavfnLWZOo92D8iL7VOyxTxvhiQ== X-Received: by 2002:a05:7301:2a02:b0:2c1:67e1:61a9 with SMTP id 5a478bee46e88-303979af82emr2367379eec.13.1778879666828; Fri, 15 May 2026 14:14:26 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30296dcb6f6sm9726668eec.17.2026.05.15.14.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:26 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 05/38] tpm: Move platform specific definitions to the new PTP header Date: Fri, 15 May 2026 14:13:37 -0700 Message-ID: <20260515211410.31440-6-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These are definitions for TPM 2.0 interface and interactions with the platform as defined in the TCG specification: These definitions are located here in a separate file to avoid conflicts with vendor specific TIS/FIFO definition (e.g. STMicroelectronics, Infineon Technologies, etc). This allows the TCG defined TIS/FIFO interface to be in a public header while the former chip specific implementations contain their own definitions. TPM 1.x family chips that adhere to the TCG specifications use the TIS/FIFO interface as defined here. TCG PC Client Platform TPM Profile (PTP) Specification - https://trustedcomputinggroup.org/resource/pc-client-platform-tpm-profil= e-ptp-specification/ Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Co-developed-by: Alec Brown Signed-off-by: Alec Brown Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm_tis_core.h | 64 +------------- include/linux/tpm_ptp.h | 151 ++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 63 deletions(-) create mode 100644 include/linux/tpm_ptp.h diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_cor= e.h index 6c3aa480396b..be68883ed399 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -19,71 +19,9 @@ #ifndef __TPM_TIS_CORE_H__ #define __TPM_TIS_CORE_H__ =20 +#include #include "tpm.h" =20 -enum tis_access { - TPM_ACCESS_VALID =3D 0x80, - TPM_ACCESS_ACTIVE_LOCALITY =3D 0x20, - TPM_ACCESS_REQUEST_PENDING =3D 0x04, - TPM_ACCESS_REQUEST_USE =3D 0x02, -}; - -enum tis_status { - TPM_STS_VALID =3D 0x80, - TPM_STS_COMMAND_READY =3D 0x40, - TPM_STS_GO =3D 0x20, - TPM_STS_DATA_AVAIL =3D 0x10, - TPM_STS_DATA_EXPECT =3D 0x08, - TPM_STS_RESPONSE_RETRY =3D 0x02, - TPM_STS_READ_ZERO =3D 0x23, /* bits that must be zero on read */ -}; - -enum tis_int_flags { - TPM_GLOBAL_INT_ENABLE =3D 0x80000000, - TPM_INTF_BURST_COUNT_STATIC =3D 0x100, - TPM_INTF_CMD_READY_INT =3D 0x080, - TPM_INTF_INT_EDGE_FALLING =3D 0x040, - TPM_INTF_INT_EDGE_RISING =3D 0x020, - TPM_INTF_INT_LEVEL_LOW =3D 0x010, - TPM_INTF_INT_LEVEL_HIGH =3D 0x008, - TPM_INTF_LOCALITY_CHANGE_INT =3D 0x004, - TPM_INTF_STS_VALID_INT =3D 0x002, - TPM_INTF_DATA_AVAIL_INT =3D 0x001, -}; - -enum tis_defaults { - TIS_MEM_LEN =3D 0x5000, - TIS_SHORT_TIMEOUT =3D 750, /* ms */ - TIS_LONG_TIMEOUT =3D 4000, /* 4 secs */ - TIS_TIMEOUT_MIN_ATML =3D 14700, /* usecs */ - TIS_TIMEOUT_MAX_ATML =3D 15000, /* usecs */ -}; - -/* Some timeout values are needed before it is known whether the chip is - * TPM 1.0 or TPM 2.0. - */ -#define TIS_TIMEOUT_A_MAX max_t(int, TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_A) -#define TIS_TIMEOUT_B_MAX max_t(int, TIS_LONG_TIMEOUT, TPM2_TIMEOUT_B) -#define TIS_TIMEOUT_C_MAX max_t(int, TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_C) -#define TIS_TIMEOUT_D_MAX max_t(int, TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_D) - -#define TPM_ACCESS(l) (0x0000 | ((l) << 12)) -#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12)) -#define TPM_INT_VECTOR(l) (0x000C | ((l) << 12)) -#define TPM_INT_STATUS(l) (0x0010 | ((l) << 12)) -#define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12)) -#define TPM_STS(l) (0x0018 | ((l) << 12)) -#define TPM_STS3(l) (0x001b | ((l) << 12)) -#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12)) - -#define TPM_DID_VID(l) (0x0F00 | ((l) << 12)) -#define TPM_RID(l) (0x0F04 | ((l) << 12)) - -#define LPC_CNTRL_OFFSET 0x84 -#define LPC_CLKRUN_EN (1 << 2) -#define INTEL_LEGACY_BLK_BASE_ADDR 0xFED08000 -#define ILB_REMAP_SIZE 0x100 - enum tpm_tis_flags { TPM_TIS_ITPM_WORKAROUND =3D 0, TPM_TIS_INVALID_STATUS =3D 1, diff --git a/include/linux/tpm_ptp.h b/include/linux/tpm_ptp.h new file mode 100644 index 000000000000..143e887599bb --- /dev/null +++ b/include/linux/tpm_ptp.h @@ -0,0 +1,151 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Following copyright information was take from the original file + * where the definitions were moved + * from: + * + * Copyright (C) 2005, 2006 IBM Corporation + * Copyright (C) 2014, 2015 Intel Corporation + * + * Authors: + * Leendert van Doorn + * Kylene Hall + * + * Maintained by: + * + * Device driver for TCG/TCPA TPM (trusted platform module). + * Specifications at www.trustedcomputinggroup.org + * + * This device driver implements the TPM interface as defined in + * the TCG TPM Interface Spec version 1.2, revision 1.0. + */ + +#ifndef __LINUX_TPM_PTP_H__ +#define __LINUX_TPM_PTP_H__ + +/* + * TCG PC Client Platform TPM Profile (PTP) Specification + * https://trustedcomputinggroup.org/resource/pc-client-platform-tpm-profi= le-ptp-specification/ + */ + +/* TIS/FIFO macros and definitions */ + +enum tis_access { + TPM_ACCESS_VALID =3D 0x80, + TPM_ACCESS_ACTIVE_LOCALITY =3D 0x20, /* (R) */ + TPM_ACCESS_RELINQUISH_LOCALITY =3D 0x20, /* (W) */ + TPM_ACCESS_REQUEST_PENDING =3D 0x04, /* (W) */ + TPM_ACCESS_REQUEST_USE =3D 0x02, /* (W) */ +}; + +enum tis_status { + TPM_STS_VALID =3D 0x80, /* (R) */ + TPM_STS_COMMAND_READY =3D 0x40, /* (R) */ + TPM_STS_DATA_AVAIL =3D 0x10, /* (R) */ + TPM_STS_DATA_EXPECT =3D 0x08, /* (R) */ + TPM_STS_GO =3D 0x20, /* (W) */ + TPM_STS_RESPONSE_RETRY =3D 0x02, /* (R) */ + TPM_STS_READ_ZERO =3D 0x23, /* bits that must be zero on read */ +}; + +enum tis_int_flags { + TPM_GLOBAL_INT_ENABLE =3D 0x80000000, + TPM_INTF_BURST_COUNT_STATIC =3D 0x100, + TPM_INTF_CMD_READY_INT =3D 0x080, + TPM_INTF_INT_EDGE_FALLING =3D 0x040, + TPM_INTF_INT_EDGE_RISING =3D 0x020, + TPM_INTF_INT_LEVEL_LOW =3D 0x010, + TPM_INTF_INT_LEVEL_HIGH =3D 0x008, + TPM_INTF_LOCALITY_CHANGE_INT =3D 0x004, + TPM_INTF_STS_VALID_INT =3D 0x002, + TPM_INTF_DATA_AVAIL_INT =3D 0x001, +}; + +enum tis_defaults { + TIS_MEM_LEN =3D 0x5000, + TIS_SHORT_TIMEOUT =3D 750, /* ms */ + TIS_LONG_TIMEOUT =3D 4000, /* 4 secs */ + TIS_TIMEOUT_MIN_ATML =3D 14700, /* usecs */ + TIS_TIMEOUT_MAX_ATML =3D 15000, /* usecs */ +}; + +enum tis_x86_defaults { + TIS_MEM_X86_LPC_BASE =3D 0xFED40000, + TIS_MEM_X86_LEN =3D 0x5000, + INTEL_LEGACY_BLK_BASE_ADDR =3D 0xFED08000, + ILB_REMAP_SIZE =3D 0x100, + LPC_CNTRL_OFFSET =3D 0x84, + LPC_CLKRUN_EN =3D (1 << 2), +}; + +/* + * Some timeout values are needed before it is known whether the chip is + * TPM 1.0 or TPM 2.0. + */ +#define TIS_TIMEOUT_A_MAX max_t(int, TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_A) +#define TIS_TIMEOUT_B_MAX max_t(int, TIS_LONG_TIMEOUT, TPM2_TIMEOUT_B) +#define TIS_TIMEOUT_C_MAX max_t(int, TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_C) +#define TIS_TIMEOUT_D_MAX max_t(int, TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_D) + +#define TPM_ACCESS(l) (0x0000 | ((l) << 12)) +#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12)) +#define TPM_INT_VECTOR(l) (0x000C | ((l) << 12)) +#define TPM_INT_STATUS(l) (0x0010 | ((l) << 12)) +#define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12)) +#define TPM_STS(l) (0x0018 | ((l) << 12)) +#define TPM_STS3(l) (0x001b | ((l) << 12)) +#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12)) +#define TPM_INTF_ID(l) (0x0030 | ((l) << 12)) + +#define TPM_DID_VID(l) (0x0F00 | ((l) << 12)) +#define TPM_RID(l) (0x0F04 | ((l) << 12)) + +/* TPM HW Interface and Capabilities */ +#define TPM_TIS_INTF_ACTIVE 0x00 +#define TPM_CRB_INTF_ACTIVE 0x01 + +struct tpm_interface_id { + union { + u32 val; + struct { + u32 interface_type:4; + u32 interface_version:4; + u32 cap_locality:1; + u32 reserved1:4; + u32 cap_tis:1; + u32 cap_crb:1; + u32 cap_if_res:2; + u32 interface_selector:2; + u32 intf_sel_lock:1; + u32 reserved2:4; + u32 reserved3:8; + }; + }; +} __packed; + +#define TPM_TIS_INTF_12 0x00 +#define TPM_TIS_INTF_13 0x02 +#define TPM2_TIS_INTF_13 0x03 + +struct tpm_intf_capability { + union { + u32 val; + struct { + u32 data_avail_int_support:1; + u32 sts_valid_int_support:1; + u32 locality_change_int_support:1; + u32 interrupt_level_high:1; + u32 interrupt_level_low:1; + u32 interrupt_edge_rising:1; + u32 interrupt_edge_falling:1; + u32 command_ready_int_support:1; + u32 burst_count_static:1; + u32 data_transfer_size_support:2; + u32 reserved1:17; + u32 interface_version:3; + u32 reserved2:1; + }; + }; +} __packed; + +#endif --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA2623ED109 for ; Fri, 15 May 2026 21:14:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879674; cv=none; b=t+mpJKhGMGDXarSB/RYyfsLgwP6N3pEewzFvVzvgljRcmWepAuH1niHKjjJ11kDdsf9BlJKCYLln4vmKTy+jeg9Ear9JLcPLTw52TOIwiwfCwxXQ2foztQlIXJV6tLxQBWLHvD3XrySMnAl0ovfyaD/tIuBFuftpTCP8MPIQIec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879674; c=relaxed/simple; bh=tgSnXEl/4HoRNelt6PM6wKCfW7tff83XdCqIyzj9aek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jm/Au3SdixwbcVLU94bnZsPm41LFtdxQgd7gV6TpZ/QyOzOqALGILDBZ9Aq313QPxPXr6Dd3J5nzR1jeykABDltstWUMe5qM7Xh++/IW6CHYX/GWSoZLLtLX87DhGZAsE7Axh1wxHf2XIXUTlbsUEnTnRbq0pPpvQc//wKaNSA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ObM+UCfj; arc=none smtp.client-ip=74.125.82.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ObM+UCfj" Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-3025d725a05so923717eec.1 for ; Fri, 15 May 2026 14:14:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879670; x=1779484470; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vsy43cKdjjquhJVv3pJ2fPEZtWZ9VhRxjDQaQqinW+s=; b=ObM+UCfjlsSeq0ZhH2iSw6wylKUn+YVk5t13OqFDfdGfbbozLB7YQAsohbocEPamxg M666walSMK+bu4f9T2c4JE6zuA0wm5Y0MWQOtYn31jq13dsxCJ/7NExqYnPmw9UFYFXQ 2jco6BxXkT3ocPurrRUjIjfmO7d89AGKLRV8X+sqGZKOUFMmy/yBJb9OomC8c/MAGGnk X8ynJploJbAVYG+Xn47zvRjtY8LTzBd1R4jxcs/PqocpOqwbu9iB++n3gkB/tQL5OmWN 1UE8UNEZ/yHl5DMhrOWCIFuJnOO2hJR7uO7iBYQfjIo8Mj3biG8SazcBNV75QEM79d/o r96A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879670; x=1779484470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vsy43cKdjjquhJVv3pJ2fPEZtWZ9VhRxjDQaQqinW+s=; b=lDZ0g/gik1ubHbX7Vut3jLtI05N0oD7DfK3u6wo1HgfvpqfBUIvno53SGuU3DvFVVD 4K4bn7u8MTiz0hyM/unzLho1ZkFLioQ7kl9dYwsJIwnOgU+vSMC46jtrxFZ1Ajl1wLSs d1JAcLYdiEflJj4zh2rlnB81ZkGgEO3mUX9Wy10X5VEFrR9ZYx8PP8zo8KeuBzQnjkEa IlMwTXwK9ik5qJvQn4PO2plbF7UuipUdjfMRjwwKFa8Z5/clf0I73N7wQkBCgUUZMSEN eIxp+NYZWJ2IZuIel64li72nuksxJpuutaYDvPGTavoTrpguGU34Gu63HAvKjVapRVtT vlEw== X-Gm-Message-State: AOJu0YyWFwjmNth7qoe92yHHQnRl8pcLptdbj3ZbGhWDLva1Nfg1kBGl BH6RoYDifjHWYq0aaarMEB5qsNKirtOJhdR4yit5XDlRR8jQvsz57vIKQrEwZvHU X-Gm-Gg: Acq92OEvuHZy5qPDCdAG2P2hU6zKQS61WO2Mzv0d9ivxjVtDi+NjUqrTTkPwrGibGrB Bz04GEbWuBYj8mUCSD2854+FhvF09KAeDYgThGcLTUaLKPQ6y1J8d+PBe3275i50YGRLauBdVrf vPwByEtg8x/PJqDVTA4x59hc36IqjL0f/o8KxcS/jIw5Nho/kTAAghO4K/BbH9MzIR8mO22hM9V TNm4GoU+5jswqxwrFI3ktqsZOtwqLnEOFXu6Z1/JnlvZ2BpMnFGQsuSWeJq3IIbrzDmthxLQy0f mtf7PJmYkFnqcaNBxc0srvj7+xy6apNIXLUQRKykoRGmvVVRyOzI7yPX4ecX0JT80RwWsVnjIpp PGbhxk+VtiDBFVSkwLECE+tytp72m3icPE2saUbOJv7JfC/buZIpTCNOT6ZLGQvWQ2VioqlB/fR 1yGXsu6OUqkjzNPH99u88KykmcdM31eSY= X-Received: by 2002:a05:7300:e6c4:b0:2ff:c84d:44d2 with SMTP id 5a478bee46e88-3039815cae2mr2917959eec.12.1778879669685; Fri, 15 May 2026 14:14:29 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302978b3cb2sm10323215eec.30.2026.05.15.14.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:29 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 06/38] tpm: Remove main TPM header from TPM event log header Date: Fri, 15 May 2026 14:13:38 -0700 Message-ID: <20260515211410.31440-7-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alec Brown Allow the TPM event log functionality to be used without including the main TPM driver definitions. Signed-off-by: Alec Brown Signed-off-by: Ross Philipson --- include/linux/tpm_eventlog.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h index 891368e82558..367b70ecc4b1 100644 --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -3,7 +3,9 @@ #ifndef __LINUX_TPM_EVENTLOG_H__ #define __LINUX_TPM_EVENTLOG_H__ =20 -#include +#include +#include +#include =20 #define TCG_EVENT_NAME_LEN_MAX 255 #define MAX_TEXT_EVENT 1000 /* Max event string length */ --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97E423EBF3A for ; Fri, 15 May 2026 21:14:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879680; cv=none; b=iVtSM647zl9F1foJOkYd4ulMjZSYmh2RRzRZS/TsNodRoDsAyN8y+KCe6GOF29TzpF88N2yPGM0NX/TvphRKROe0CDQGFvA2jqhPnQK68AoheraMOuwL/+6VokTLDk6HbQJxug2ZzNK2/XMOjh8nJxKA8Ly5YfLkZJMdRHCb3jM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879680; c=relaxed/simple; bh=WimTnPb5ErtUQ91diuLvqjTS3pHvP1bJ9GtZuSv1Bf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hDX9DJb6eq2LuO3n6ROLd4cTK93MkkBds6T8begrUzrVu46Zaqkvk0TApSNqwnBWZseFmzJN6bOIV52bUzUfllbXye/fgLQAgZW8BN/1fM+koXy6eALblupbVNsRnLkd1H9IAQSxxsow1R59MBHbMAfv/Is1ZMXHBFShtV3HLSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E2hoNZqg; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E2hoNZqg" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2f68f3b075fso1100970eec.0 for ; Fri, 15 May 2026 14:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879673; x=1779484473; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q5U2oXqABMo/EXd3140iU8ar3y05m7m/a9rRtZzhgJM=; b=E2hoNZqgN5GeQniAK6QAmAIDiaAQH2EJOxOHeRaH/grCpZD4lI/gu2odWffRqbYJYZ 1sIxrkPPh+Cnfhx872TUjUmDUxpUkhomW9fyAJ+UJyA+RpKuTXPGEpjA2zSiaF5LExjM L9QD5ZvK2t9AykShyNDdayeKU0x/q0ZFgcQJLXjs9nR5IfMq2ZOa6LRR3MmqlG9zoNQy 1yMhV+f07d+NBwC/0L76ic4bVZ5dMiSgJzi5V6opIBYUhZtKmd0UaMvsOBA3yjyljZp8 WAixMF0vVZZIOtan39WrvH2P2hKysqizEDojDDAWydGq1X2yeBI2f71KMD8Xsbl1X7tw ijuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879673; x=1779484473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=q5U2oXqABMo/EXd3140iU8ar3y05m7m/a9rRtZzhgJM=; b=Z7z25lwYOXihnMmJdY/cYAsLpbHPZS9EUgGps1bxINr9pAVt044dWLurzpQVvoGynx 8rU+BeGkhx1DFwOnhQ/J6x3uGMDNDH4K4SMw4vKRtUVBJTxIMZD1S5XZvscg+FhQndKD hM1uyoJbQHFmGTTTnsKcP2v52QuaTVDNnB8acMAHG3rqSC8lQEfHvbjLPgD3Fo5p+Dow wEnxC75l4O9lcywH1ri1efNtMhsZFbaPECoStCAqnL5RTGyhhIL+8j54oZcVui22sUhL 2k0+7CJ9d2y8ZQG2wDMm5NVn0PyMQCG9GRkv3X/kwQiwJSrAc6gV32QT4GDhZF+g8UBr e+1w== X-Gm-Message-State: AOJu0YwCp8Dp4rBodDD92nLbZ1i8OPiQuv5CmLK5RcHX3YpjALzNxur/ 9ZJJGAnNhWsKm3iOHMBX9s4i8FWWDhoj6iUc/D6zcoL60q/H3XAWhJjycyTdZxHC X-Gm-Gg: Acq92OG6DeIeL9+cE47YQySWzIDjScQgtvDArd5nvmPb1LJH5p4Ofl0+uPMmE+XiBWA 19ZOXzZLBdh0i4XhPkFPHm2cCuYRMqnHc+3XHV1ZE8SuJKdzZWTnpOZSSaGdRKRPCISQ5dFBGo3 iF3eBk15ZnWFy7kQGB8JmLoIh3czxd4InRcS4lxhLpfr4+MrKxTcqb9+iYdytUheHdTiVz3j73y yjHwLLVWDAqX/t6ZBcVtQcsGItT7WcZc2S7WMn+pGbYn5kNbu3YtcqyAYlKCj30fbN0bsb4tAjJ +Hrv4CEi3KavZp2WuLP1zblGIC1CJ0kRKBodhTV028SlRN5XHO3kLq1FlpZx6oIWknIB5JoDMAJ jCHigtRuCV00v3LjX6Z7D/Zx4Eiw5QxrhGEB70FGJazJEDfD1CoKhaZ4pTSQr652pFWz2jgdY5d qrnpyeIL1Z/02sTYHAAxIMOkhZQRMpeU8= X-Received: by 2002:a05:7300:b913:b0:2f4:3a9c:8193 with SMTP id 5a478bee46e88-3039862655amr2733579eec.16.1778879672589; Fri, 15 May 2026 14:14:32 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302973bc8ddsm7829907eec.21.2026.05.15.14.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:32 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 07/38] tpm-buf: Merge TPM_BUF_BOUNDARY_ERROR and TPM_BUF_OVERFLOW Date: Fri, 15 May 2026 14:13:39 -0700 Message-ID: <20260515211410.31440-8-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jarkko Sakkinen Merge TPM_BUF_BOUNDARY_ERROR and TPM_BUF_OVERFLOW into TPM_BUF_INVALID, given that they are identical (the only difference being the associated log messages). In addition, add a missing TPM_BUF_INVALID check to tpm_buf_append_handle() following the pattern from other functions in tpm-buf.c. Message-ID: <20260125192526.782202-11-jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen Reviewed-by: Jonathan McDowell Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm-buf.c | 10 ++++------ include/linux/tpm.h | 8 +++----- security/keys/trusted-keys/trusted_tpm2.c | 6 +++--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index 4c4f450630df..61833b4d81f0 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -103,13 +103,12 @@ EXPORT_SYMBOL_GPL(tpm_buf_length); */ void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_lengt= h) { - /* Return silently if overflow has already happened. */ - if (buf->flags & TPM_BUF_OVERFLOW) + if (buf->flags & TPM_BUF_INVALID) return; =20 if ((buf->length + new_length) > PAGE_SIZE) { WARN(1, "tpm_buf: write overflow\n"); - buf->flags |=3D TPM_BUF_OVERFLOW; + buf->flags |=3D TPM_BUF_INVALID; return; } =20 @@ -176,14 +175,13 @@ static void tpm_buf_read(struct tpm_buf *buf, off_t *= offset, size_t count, void { off_t next_offset; =20 - /* Return silently if overflow has already happened. */ - if (buf->flags & TPM_BUF_BOUNDARY_ERROR) + if (buf->flags & TPM_BUF_INVALID) return; =20 next_offset =3D *offset + count; if (next_offset > buf->length) { WARN(1, "tpm_buf: read out of boundary\n"); - buf->flags |=3D TPM_BUF_BOUNDARY_ERROR; + buf->flags |=3D TPM_BUF_INVALID; return; } =20 diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 3630b2ea6aef..3c6a5bcc138a 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -201,12 +201,10 @@ enum tpm_chip_flags { #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) =20 enum tpm_buf_flags { - /* the capacity exceeded: */ - TPM_BUF_OVERFLOW =3D BIT(0), /* TPM2B format: */ - TPM_BUF_TPM2B =3D BIT(1), - /* read out of boundary: */ - TPM_BUF_BOUNDARY_ERROR =3D BIT(2), + TPM_BUF_TPM2B =3D BIT(0), + /* The buffer is in invalid and unusable state: */ + TPM_BUF_INVALID =3D BIT(1), }; =20 /* diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trus= ted-keys/trusted_tpm2.c index 29d79c05ed6b..779a2e66ac20 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -312,7 +312,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip, /* creation PCR */ tpm_buf_append_u32(&buf, 0); =20 - if (buf.flags & TPM_BUF_OVERFLOW) { + if (buf.flags & TPM_BUF_INVALID) { rc =3D -E2BIG; tpm2_end_auth_session(chip); goto out; @@ -328,7 +328,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip, goto out; =20 blob_len =3D tpm_buf_read_u32(&buf, &offset); - if (blob_len > MAX_BLOB_SIZE || buf.flags & TPM_BUF_BOUNDARY_ERROR) { + if (blob_len > MAX_BLOB_SIZE || buf.flags & TPM_BUF_INVALID) { rc =3D -E2BIG; goto out; } @@ -441,7 +441,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip, =20 tpm_buf_append(&buf, blob, blob_len); =20 - if (buf.flags & TPM_BUF_OVERFLOW) { + if (buf.flags & TPM_BUF_INVALID) { rc =3D -E2BIG; tpm2_end_auth_session(chip); goto out; --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02DCF3EBF3B for ; Fri, 15 May 2026 21:14:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879678; cv=none; b=oNRtzjEJLzdRKR8KDJxoz3WPfe8ogF1LNjJByl53TWctLG0rk+1Qq0gFrNVgjjGi8gORrBGuSEQ5lGAx+OHnZ1/CdUmSWayujTXsVt+Wcb4Q9gT2K7aRyed2K2lsp2EpE9Q+z6a0K48iwbujDA4uELxOtVQO+/mQjgAe3ZLfY/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879678; c=relaxed/simple; bh=53lrliy0YE81pqMpILWMlkkyv1qPCSWN//0gQcdAdOI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bqn8wYsXwOn0FuE+BG3DWWNEYcSN2aQhmAgiYXnzuK90QwfzxyomDL/ham4JFsqj/pg8EfaDlQ5/qb9xSqovmNVsF4Fv0LiRnzNpDm+cOEFntb+vF5Jv9Lcyma+xymvXMvc00Q1QvIKDihzPLi5vXksmaOoDFNrW8/39GksFBVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=coZxNLUV; arc=none smtp.client-ip=74.125.82.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="coZxNLUV" Received: by mail-dl1-f48.google.com with SMTP id a92af1059eb24-1354403c610so388952c88.0 for ; Fri, 15 May 2026 14:14:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879676; x=1779484476; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zaLNJCVWymRzHzAosL0l4Cb63oV8tVc7xKx597eZEkQ=; b=coZxNLUVyrcW4+qDpIm9h5KsdOEZWCz2mv/nyyNz6xPun9i04yI7IEbuqeCcEA0Qvo CgivbygcWx0y7mhjfCmX18Xhzn5RGGCZG5QjQIefM2kR6VCGk53vZyK+JaK0zwk7Gx1d chHzp7T1pf3t+s/JLVCigdlmd1eGo8/R3hfUzaSHyYJZRe2droz6Mi23YqCkEtxhCJfQ PINrqjyV0NTayQbZmjsA83XgxsDWW8qAyI3BP3aBYfb6/nnQnY4uOxlSs9Nllt9hD8tF d65Lj6T5vP8vOXD9/vzC8mh30K9mShaK4LbuVvMpojiNuar0rgHSi7GT1nIGWUpwBUDM jK8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879676; x=1779484476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zaLNJCVWymRzHzAosL0l4Cb63oV8tVc7xKx597eZEkQ=; b=JT9h3RxXITcZZWxlnB7jDpBwQ0dFYG8jnJG7XeOCQM8OmUvtiPa+0RTtzJbJGM+TcU gds+cI4sfQPnCma4p54lIriRSePfvaC1BJRDYMD8GpXewnz1nzH2LCODB4z8xaZ78L5B NskTS4AMfsjibgssPNFVUT5ehJy3lc0a+egvbKiv+RAy1ej3wD1+15E9zoallFa6N+pM LiCF4zVD72m8HIZQhCDl7DVG3XaKRbmJst5zjizfor3jYp6/aW+6B+ORCv8UJYkA3xeT fRjr7h8JGSHt6T/opUWE9JCjVDe1Nld07hgiCwzw1MTlLEMkokuh5HJ/mu4m6/gQnUZg nR6Q== X-Gm-Message-State: AOJu0YwaBcmrKIOeLr4vTyPicQjCXxMIbOPNZ5WyzIq+xSsi2N2q0vRN n8HSUqhY3cEWrzeQarId0ZEelBX0pVXWggHOb2ETbN9FK9yogRNQKOMrmfSPEkZI X-Gm-Gg: Acq92OEaa6tt8Vmpg+ld5RSG0+gphbntWWFRqGR6EzlqgXi6ZYoWypbkm/pAZSzBSk+ f2fwzzWDXmyCW8BiMjTQbAstQnDDl/uJ/tvUl8AHL9olbL1CSH/hM+cBTdlg/tqfemBCoDpIEaX 4SHA7BYKeQZFWYRzSXz1a6a0/Rt08E4xbvn7IKhql7ar2yFZ9j6w8XHv3nIXaOxcrj1Xwesbyyw LRryffL+jkaoiLJJ2LsP29NR86TfGRWxRpGwntuxm7lBFMr7JJLnGVZaHH9AmSnAwR1PD8YKyBC Mh+yMfyzIgHRcCvewnbIbb7nKP129kNsnBVlmkKz6Yyl4N2Ip7+EXwiwmbrZPVen2xnyFQP5clV rKdgu4SLKTYHKMm3UBn+VDIA2MdF0BzT2Bc98VwTpvgu04ZgUclhQmBONHSB2WT0Yo0sQoC9hMR 7oZY+6Z0/V/e6B4FiIBDDJK4Zzv3zMrTE= X-Received: by 2002:a05:7022:6b9a:b0:12d:de3e:86aa with SMTP id a92af1059eb24-13505642857mr2505039c88.40.1778879675567; Fri, 15 May 2026 14:14:35 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cc33a618sm11242540c88.12.2026.05.15.14.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:35 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 08/38] tpm-buf: Remove chip parameter from tpm_buf_append_handle() Date: Fri, 15 May 2026 14:13:40 -0700 Message-ID: <20260515211410.31440-9-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jarkko Sakkinen Remove the TPM driver chip parameter from the function tpm_buf_append_handle(). The chip parameter is only for error logging which can be done with other facilities like WARN(). Message-ID: <20260125192526.782202-11-jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm-buf.c | 9 ++++++--- drivers/char/tpm/tpm2-cmd.c | 2 +- drivers/char/tpm/tpm2-sessions.c | 2 +- include/linux/tpm.h | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index 61833b4d81f0..99811809a72a 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -146,17 +146,20 @@ EXPORT_SYMBOL_GPL(tpm_buf_append_u32); =20 /** * tpm_buf_append_handle() - Add a handle - * @chip: &tpm_chip instance * @buf: &tpm_buf instance * @handle: a TPM object handle * * Add a handle to the buffer, and increase the count tracking the number = of * handles in the command buffer. Works only for command buffers. */ -void tpm_buf_append_handle(struct tpm_chip *chip, struct tpm_buf *buf, u32= handle) +void tpm_buf_append_handle(struct tpm_buf *buf, u32 handle) { + if (buf->flags & TPM_BUF_INVALID) + return; + if (buf->flags & TPM_BUF_TPM2B) { - dev_err(&chip->dev, "Invalid buffer type (TPM2B)\n"); + WARN(1, "tpm-buf: invalid type: TPM2B\n"); + buf->flags |=3D TPM_BUF_INVALID; return; } =20 diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 1fa3e8a43c79..c9dc35b57687 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -198,7 +198,7 @@ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, } tpm_buf_append_hmac_session(chip, &buf, 0, NULL, 0); } else { - tpm_buf_append_handle(chip, &buf, pcr_idx); + tpm_buf_append_handle(&buf, pcr_idx); tpm_buf_append_auth(chip, &buf, NULL, 0); } =20 diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessi= ons.c index 3b1cf1ca0420..eb67ae14ad73 100644 --- a/drivers/char/tpm/tpm2-sessions.c +++ b/drivers/char/tpm/tpm2-sessions.c @@ -257,7 +257,7 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct t= pm_buf *buf, #endif =20 if (!tpm2_chip_auth(chip)) { - tpm_buf_append_handle(chip, buf, handle); + tpm_buf_append_handle(buf, handle); return 0; } =20 diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 3c6a5bcc138a..b357f8971d03 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -235,7 +235,7 @@ void tpm_buf_append_u32(struct tpm_buf *buf, const u32 = value); u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset); u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset); u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset); -void tpm_buf_append_handle(struct tpm_chip *chip, struct tpm_buf *buf, u32= handle); +void tpm_buf_append_handle(struct tpm_buf *buf, u32 handle); =20 /* * Check if TPM device is in the firmware upgrade mode. --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2ABB3ED5B9 for ; Fri, 15 May 2026 21:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879684; cv=none; b=Z195bGcZIYxLI8bDYCBwX6m0Bln7zvICK73GVH71O+J73HbMR4AcL3q3DKc7GGt07hhMB42h9oRXtcgCF1MsUiGI5AEpT7FTC7lgSQC5+Wns1+A2lP0LVkEZop7eCle3RIizzeXveSPTxKAIw1XaPi7jKUSqqpesm3SEEpnfUOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879684; c=relaxed/simple; bh=KmMuFaZ47SktGkwlkyAAHZ+8pIrSgOx69g0xNUTeidE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b3gRX56p+7idrrP23rOXhE87WMJbIi0XTBYQiUMw3SEnwy0Nu94dUan286jIlS5rTp9A29ChDfUk4u9A+zzp5g9afh5wjmRCitk4wtzA9ZKJQ5U6diAXlvdGtc3HczrVf3sidk5s4jAmLxQhOVOh8UIVaJRHgTo8mbOpHZM9fSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XVk3x7/3; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XVk3x7/3" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-2c15849aa2cso364933eec.0 for ; Fri, 15 May 2026 14:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879679; x=1779484479; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OlxyTJHK1qXe4zH9KCCXFkLyu/Bt9I2QGkqATJMamdk=; b=XVk3x7/3EjUHX3sV9Z/aNEPZTU6yQ+na5JmfJTpod1y22Y7EfK+GbZTzMpWNFqXzjL imSMwFb0pwlnbl7lfgKQ3QxvWAIGF9mBYCcKmaD4DMwC/+zfjyRumLH7B9cwFcwjDS5i T+m+3mLud8QFL+WhZYG52fa9zHt5E64AZdSQwYUJMjgfBJ6NdPnPns1ETnJmoYAYwcDP fwGajAASGo9YGArvOJQhpOvNHFemf6Q1BqPOi1aNd9HnnR/Ky3cS1wNh+WSdW1uF8oTw k3wPmxGlErg2ug8p+ulhnu7WnEgBX/ngLn6GM8ZlpbEMGgf6Pql8Eni1rIYYZP8s8hOm vWAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879679; x=1779484479; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OlxyTJHK1qXe4zH9KCCXFkLyu/Bt9I2QGkqATJMamdk=; b=a0zWdQu6stUK5PRgFdFqRVdJ70lEdXlg8UJU2TpjQrCRYevn8xthNK0eqfTGyAyui3 mXaf/wQDHcDSbZCR4aoHYvuogmjj7Z4R+PfS5CnAfXuW1sT/TZIB9PK+2zqChiqDeYUB 8E8sOgybTU7fk70SEk40NqER119czs0E5AUBvV5tQp4ZtX94mCFuSMncpYRxyeLO3u/6 rKyQzpRAoOLX1vY8XQvOM8kgVwya/Zx45/Yvk9iNRBvki77JitlI6S5K6Pu90Ap8Oc4n zxBvoydSisjzt2go9VB2NxbLm3Nnf9WiPus3371ssHIOgAbzuAuf1U9G5E1YzDdTkukr glNQ== X-Gm-Message-State: AOJu0YxCfM/EM/9T4cQckXa+ulAV2EcPgMKtG8NqWiVLwhDyKsSGPCzh tpzZW6/aKDNMBuFh3q0Rqbjj+XAPXO/EqRMLq+DQBuRrK3e4tq6dToeTamjlVIvp X-Gm-Gg: Acq92OG9VEA4rAI/kot6tj9CjM/oUn7M59SNNANyvB3AG9LDgqJgup0FzmnF1oMU3Ik vUHebsW9I72NT6NzEb8OddL+6z1rdP4N8KHSmgl9HTyZa8yHI7EIiOoLFcxQCtSU3jSd8IXQG8c gv0uXdVk9COoLQHM0q389AE0QKqbs6wAJo5C9Bez6ZO72/T+FCGsO3rCbnEQYyKazIfyVTAKzL4 Grn3eoQltiZisXfz9zNRmptPYj4lAQKtHqedEBmpRalVSkO1ajJZxBQCmBvAvX4oXLKQg5Gwvn5 17oFspI7sZozAgf882/Va2EbOctqRBsWkACxLXj7y0GawUVM9r0OBtkEuFad7pmY/dTT5/zTXPC v9JyScZ+elyKv5i+8UKBPsW8e9/H9rj4yk+GOQupl5DyKBM4Fq7NTLIWoSuIIsJdU7JH4COdtdU 1Itl3MoLMnjyNmQ292pLerj7s/q3t+qQ0arK8WrnOAuA== X-Received: by 2002:a05:7300:e9db:20b0:2ed:6f94:9d9e with SMTP id 5a478bee46e88-303982bbb8cmr2045425eec.10.1778879678587; Fri, 15 May 2026 14:14:38 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30296dcb6adsm9085792eec.15.2026.05.15.14.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:38 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 09/38] tpm-buf: Implement managed allocations Date: Fri, 15 May 2026 14:13:41 -0700 Message-ID: <20260515211410.31440-10-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jarkko Sakkinen Decouple kzalloc from buffer creation, so that a managed allocation can be used: struct tpm_buf *buf __free(kfree) buf =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); if (!buf) return -ENOMEM; tpm_buf_init(buf, TPM_BUFSIZE); Alternatively, stack allocations are also possible: u8 buf_data[512]; struct tpm_buf *buf =3D (struct tpm_buf *)buf_data; tpm_buf_init(buf, sizeof(buf_data)); This is achieved by embedding buffer's header inside the allocated blob, instead of having an outer wrapper. Message-ID: <20260125192526.782202-12-jarkko@kernel.org> Co-developed-by: Ross Philipson Signed-off-by: Jarkko Sakkinen Signed-off-by: Ross Philipson Reviewed-by: Stefan Berger --- Original version was reviewed but significant changes were made during port= ing: Reviewed-by: Stefan Berger --- drivers/char/tpm/tpm-buf.c | 124 +++++---- drivers/char/tpm/tpm-sysfs.c | 21 +- drivers/char/tpm/tpm.h | 1 - drivers/char/tpm/tpm1-cmd.c | 176 ++++++------- drivers/char/tpm/tpm2-cmd.c | 308 ++++++++++------------ drivers/char/tpm/tpm2-sessions.c | 142 +++++----- drivers/char/tpm/tpm2-space.c | 44 ++-- drivers/char/tpm/tpm_vtpm_proxy.c | 30 +-- include/linux/tpm.h | 17 +- security/keys/trusted-keys/trusted_tpm1.c | 36 +-- security/keys/trusted-keys/trusted_tpm2.c | 170 ++++++------ 11 files changed, 513 insertions(+), 556 deletions(-) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index 99811809a72a..e79a8071c9ee 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -6,82 +6,109 @@ #include #include =20 -/** - * tpm_buf_init() - Allocate and initialize a TPM command - * @buf: A &tpm_buf - * @tag: TPM_TAG_RQU_COMMAND, TPM2_ST_NO_SESSIONS or TPM2_ST_SESSIONS - * @ordinal: A command ordinal - * - * Return: 0 or -ENOMEM - */ -int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal) +static void __tpm_buf_size_invariant(struct tpm_buf *buf, u16 buf_size) { - buf->data =3D (u8 *)__get_free_page(GFP_KERNEL); - if (!buf->data) - return -ENOMEM; - - tpm_buf_reset(buf, tag, ordinal); - return 0; + u32 buf_size_2 =3D (u32)buf->capacity + (u32)sizeof(*buf); + + if (!buf->capacity) { + if (buf_size > TPM_BUFSIZE) { + WARN(1, "%s: size overflow: %u\n", __func__, buf_size); + buf->flags |=3D TPM_BUF_INVALID; + } + } else { + if (buf_size !=3D buf_size_2) { + WARN(1, "%s: size mismatch: %u !=3D %u\n", __func__, buf_size, + buf_size_2); + buf->flags |=3D TPM_BUF_INVALID; + } + } } -EXPORT_SYMBOL_GPL(tpm_buf_init); =20 -/** - * tpm_buf_reset() - Initialize a TPM command - * @buf: A &tpm_buf - * @tag: TPM_TAG_RQU_COMMAND, TPM2_ST_NO_SESSIONS or TPM2_ST_SESSIONS - * @ordinal: A command ordinal - */ -void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal) +static void __tpm_buf_reset(struct tpm_buf *buf, u16 buf_size, u16 tag, u3= 2 ordinal) { struct tpm_header *head =3D (struct tpm_header *)buf->data; =20 + __tpm_buf_size_invariant(buf, buf_size); + + if (buf->flags & TPM_BUF_INVALID) + return; + WARN_ON(tag !=3D TPM_TAG_RQU_COMMAND && tag !=3D TPM2_ST_NO_SESSIONS && tag !=3D TPM2_ST_SESSIONS && tag !=3D 0); =20 buf->flags =3D 0; buf->length =3D sizeof(*head); + buf->capacity =3D buf_size - sizeof(*buf); + buf->handles =3D 0; head->tag =3D cpu_to_be16(tag); head->length =3D cpu_to_be32(sizeof(*head)); head->ordinal =3D cpu_to_be32(ordinal); +} + +static void __tpm_buf_reset_sized(struct tpm_buf *buf, u16 buf_size) +{ + __tpm_buf_size_invariant(buf, buf_size); + + if (buf->flags & TPM_BUF_INVALID) + return; + + buf->flags =3D TPM_BUF_TPM2B; + buf->length =3D 2; + buf->capacity =3D buf_size - sizeof(*buf); buf->handles =3D 0; + buf->data[0] =3D 0; + buf->data[1] =3D 0; } -EXPORT_SYMBOL_GPL(tpm_buf_reset); =20 /** - * tpm_buf_init_sized() - Allocate and initialize a sized (TPM2B) buffer - * @buf: A @tpm_buf - * - * Return: 0 or -ENOMEM + * tpm_buf_init() - Initialize a TPM command + * @buf: A &tpm_buf + * @buf_size: Size of the buffer. */ -int tpm_buf_init_sized(struct tpm_buf *buf) +void tpm_buf_init(struct tpm_buf *buf, u16 buf_size) { - buf->data =3D (u8 *)__get_free_page(GFP_KERNEL); - if (!buf->data) - return -ENOMEM; + memset(buf, 0, buf_size); + __tpm_buf_reset(buf, buf_size, TPM_TAG_RQU_COMMAND, 0); +} +EXPORT_SYMBOL_GPL(tpm_buf_init); =20 - tpm_buf_reset_sized(buf); - return 0; +/** + * tpm_buf_init_sized() - Initialize a sized buffer + * @buf: A &tpm_buf + * @buf_size: Size of the buffer. + */ +void tpm_buf_init_sized(struct tpm_buf *buf, u16 buf_size) +{ + memset(buf, 0, buf_size); + __tpm_buf_reset_sized(buf, buf_size); } EXPORT_SYMBOL_GPL(tpm_buf_init_sized); =20 /** - * tpm_buf_reset_sized() - Initialize a sized buffer + * tpm_buf_reset() - Re-initialize a TPM command * @buf: A &tpm_buf + * @tag: TPM_TAG_RQU_COMMAND, TPM2_ST_NO_SESSIONS or TPM2_ST_SESSIONS + * @ordinal: A command ordinal */ -void tpm_buf_reset_sized(struct tpm_buf *buf) +void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal) { - buf->flags =3D TPM_BUF_TPM2B; - buf->length =3D 2; - buf->data[0] =3D 0; - buf->data[1] =3D 0; + u16 buf_size =3D buf->capacity + sizeof(*buf); + + __tpm_buf_reset(buf, buf_size, tag, ordinal); } -EXPORT_SYMBOL_GPL(tpm_buf_reset_sized); +EXPORT_SYMBOL_GPL(tpm_buf_reset); =20 -void tpm_buf_destroy(struct tpm_buf *buf) +/** + * tpm_buf_reset_sized() - Re-initialize a sized buffer + * @buf: A &tpm_buf + */ +void tpm_buf_reset_sized(struct tpm_buf *buf) { - free_page((unsigned long)buf->data); + u16 buf_size =3D buf->capacity + sizeof(*buf); + + __tpm_buf_reset_sized(buf, buf_size); } -EXPORT_SYMBOL_GPL(tpm_buf_destroy); +EXPORT_SYMBOL_GPL(tpm_buf_reset_sized); =20 /** * tpm_buf_length() - Return the number of bytes consumed by the data @@ -89,8 +116,11 @@ EXPORT_SYMBOL_GPL(tpm_buf_destroy); * * Return: The number of bytes consumed by the buffer */ -u32 tpm_buf_length(struct tpm_buf *buf) +u16 tpm_buf_length(struct tpm_buf *buf) { + if (buf->flags & TPM_BUF_INVALID) + return 0; + return buf->length; } EXPORT_SYMBOL_GPL(tpm_buf_length); @@ -103,10 +133,12 @@ EXPORT_SYMBOL_GPL(tpm_buf_length); */ void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_lengt= h) { + u32 total_length =3D (u32)buf->length + (u32)new_length; + if (buf->flags & TPM_BUF_INVALID) return; =20 - if ((buf->length + new_length) > PAGE_SIZE) { + if (total_length > (u32)buf->capacity) { WARN(1, "tpm_buf: write overflow\n"); buf->flags |=3D TPM_BUF_INVALID; return; diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index 94231f052ea7..f5dcadb1ab3c 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -32,28 +32,29 @@ struct tpm_readpubek_out { static ssize_t pubek_show(struct device *dev, struct device_attribute *att= r, char *buf) { - struct tpm_buf tpm_buf; struct tpm_readpubek_out *out; int i; char *str =3D buf; struct tpm_chip *chip =3D to_tpm_chip(dev); char anti_replay[20]; =20 + struct tpm_buf *tpm_buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL= ); + if (!tpm_buf) + return -ENOMEM; + memset(&anti_replay, 0, sizeof(anti_replay)); =20 if (tpm_try_get_ops(chip)) return 0; =20 - if (tpm_buf_init(&tpm_buf, TPM_TAG_RQU_COMMAND, TPM_ORD_READPUBEK)) - goto out_ops; - - tpm_buf_append(&tpm_buf, anti_replay, sizeof(anti_replay)); + tpm_buf_init(tpm_buf, TPM_BUFSIZE); + tpm_buf_reset(tpm_buf, TPM_TAG_RQU_COMMAND, TPM_ORD_READPUBEK); + tpm_buf_append(tpm_buf, anti_replay, sizeof(anti_replay)); =20 - if (tpm_transmit_cmd(chip, &tpm_buf, READ_PUBEK_RESULT_MIN_BODY_SIZE, - "attempting to read the PUBEK")) - goto out_buf; + if (tpm_transmit_cmd(chip, tpm_buf, READ_PUBEK_RESULT_MIN_BODY_SIZE, "TPM= _ReadPubek")) + goto out_ops; =20 - out =3D (struct tpm_readpubek_out *)&tpm_buf.data[10]; + out =3D (struct tpm_readpubek_out *)&tpm_buf->data[10]; str +=3D sprintf(str, "Algorithm: %4ph\n" @@ -71,8 +72,6 @@ static ssize_t pubek_show(struct device *dev, struct devi= ce_attribute *attr, for (i =3D 0; i < 256; i +=3D 16) str +=3D sprintf(str, "%16ph\n", &out->modulus[i]); =20 -out_buf: - tpm_buf_destroy(&tpm_buf); out_ops: tpm_put_ops(chip); return str - buf; diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 680f89d9c9f9..fa554c5ad80b 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -33,7 +33,6 @@ #endif =20 #define TPM_MINOR 224 /* officially assigned */ -#define TPM_BUFSIZE 4096 #define TPM_NUM_DEVICES 65536 #define TPM_RETRY 50 =20 diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c index 96f189b5fd6f..ee420d73927d 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -318,20 +318,14 @@ unsigned long tpm1_calc_ordinal_duration(struct tpm_c= hip *chip, u32 ordinal) */ static int tpm1_startup(struct tpm_chip *chip) { - struct tpm_buf buf; - int rc; - - dev_info(&chip->dev, "starting up the TPM manually\n"); - - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_STARTUP); - if (rc < 0) - return rc; - - tpm_buf_append_u16(&buf, TPM_ST_CLEAR); - - rc =3D tpm_transmit_cmd(chip, &buf, 0, "attempting to start the TPM"); - tpm_buf_destroy(&buf); - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_STARTUP); + tpm_buf_append_u16(buf, TPM_ST_CLEAR); + return tpm_transmit_cmd(chip, buf, 0, "attempting to start the TPM"); } =20 int tpm1_get_timeouts(struct tpm_chip *chip) @@ -457,49 +451,46 @@ int tpm1_get_timeouts(struct tpm_chip *chip) int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash, const char *log_msg) { - struct tpm_buf buf; - int rc; - - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_EXTEND); - if (rc) - return rc; - - tpm_buf_append_u32(&buf, pcr_idx); - tpm_buf_append(&buf, hash, TPM_DIGEST_SIZE); - - rc =3D tpm_transmit_cmd(chip, &buf, TPM_DIGEST_SIZE, log_msg); - tpm_buf_destroy(&buf); - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_EXTEND); + tpm_buf_append_u32(buf, pcr_idx); + tpm_buf_append(buf, hash, TPM_DIGEST_SIZE); + return tpm_transmit_cmd(chip, buf, TPM_DIGEST_SIZE, log_msg); } =20 ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, const char *desc, size_t min_cap_length) { - struct tpm_buf buf; int rc; =20 - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_CAP); - if (rc) - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_CAP); =20 if (subcap_id =3D=3D TPM_CAP_VERSION_1_1 || subcap_id =3D=3D TPM_CAP_VERSION_1_2) { - tpm_buf_append_u32(&buf, subcap_id); - tpm_buf_append_u32(&buf, 0); + tpm_buf_append_u32(buf, subcap_id); + tpm_buf_append_u32(buf, 0); } else { if (subcap_id =3D=3D TPM_CAP_FLAG_PERM || subcap_id =3D=3D TPM_CAP_FLAG_VOL) - tpm_buf_append_u32(&buf, TPM_CAP_FLAG); + tpm_buf_append_u32(buf, TPM_CAP_FLAG); else - tpm_buf_append_u32(&buf, TPM_CAP_PROP); + tpm_buf_append_u32(buf, TPM_CAP_PROP); =20 - tpm_buf_append_u32(&buf, 4); - tpm_buf_append_u32(&buf, subcap_id); + tpm_buf_append_u32(buf, 4); + tpm_buf_append_u32(buf, subcap_id); } - rc =3D tpm_transmit_cmd(chip, &buf, min_cap_length, desc); + rc =3D tpm_transmit_cmd(chip, buf, min_cap_length, desc); if (!rc) - *cap =3D *(cap_t *)&buf.data[TPM_HEADER_SIZE + 4]; - tpm_buf_destroy(&buf); + *cap =3D *(cap_t *)&buf->data[TPM_HEADER_SIZE + 4]; return rc; } EXPORT_SYMBOL_GPL(tpm1_getcap); @@ -518,80 +509,74 @@ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, = size_t max) { struct tpm1_get_random_out *out; u32 num_bytes =3D min_t(u32, max, TPM_MAX_RNG_DATA); - struct tpm_buf buf; u32 total =3D 0; int retries =3D 5; u32 recd; int rc; =20 - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_RANDOM); - if (rc) - return rc; + if (!dest || !max || max > TPM_MAX_RNG_DATA) + return -EINVAL; + + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); =20 do { - tpm_buf_append_u32(&buf, num_bytes); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_RANDOM); + tpm_buf_append_u32(buf, num_bytes); =20 - rc =3D tpm_transmit_cmd(chip, &buf, sizeof(out->rng_data_len), + rc =3D tpm_transmit_cmd(chip, buf, sizeof(out->rng_data_len), "attempting get random"); if (rc) { if (rc > 0) rc =3D -EIO; - goto out; + return rc; } =20 - out =3D (struct tpm1_get_random_out *)&buf.data[TPM_HEADER_SIZE]; + out =3D (struct tpm1_get_random_out *)&buf->data[TPM_HEADER_SIZE]; =20 recd =3D be32_to_cpu(out->rng_data_len); - if (recd > num_bytes) { - rc =3D -EFAULT; - goto out; - } + if (recd > num_bytes) + return -EFAULT; + + if (tpm_buf_length(buf) < + TPM_HEADER_SIZE + sizeof(out->rng_data_len) + recd) + return -EFAULT; =20 - if (tpm_buf_length(&buf) < TPM_HEADER_SIZE + - sizeof(out->rng_data_len) + recd) { - rc =3D -EFAULT; - goto out; - } memcpy(dest, out->rng_data, recd); =20 dest +=3D recd; total +=3D recd; num_bytes -=3D recd; - - tpm_buf_reset(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_RANDOM); } while (retries-- && total < max); =20 - rc =3D total ? (int)total : -EIO; -out: - tpm_buf_destroy(&buf); - return rc; + return total ? (int)total : -EIO; } =20 int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf) { - struct tpm_buf buf; int rc; =20 - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_READ); - if (rc) - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; =20 - tpm_buf_append_u32(&buf, pcr_idx); + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_READ); + tpm_buf_append_u32(buf, pcr_idx); =20 - rc =3D tpm_transmit_cmd(chip, &buf, TPM_DIGEST_SIZE, - "attempting to read a pcr value"); + rc =3D tpm_transmit_cmd(chip, buf, TPM_DIGEST_SIZE, + "attempting to read a PCR value"); if (rc) - goto out; + return rc; =20 - if (tpm_buf_length(&buf) < TPM_DIGEST_SIZE) { - rc =3D -EFAULT; - goto out; - } + if (tpm_buf_length(buf) < TPM_DIGEST_SIZE) + return -EFAULT; =20 - memcpy(res_buf, &buf.data[TPM_HEADER_SIZE], TPM_DIGEST_SIZE); + memcpy(res_buf, &buf->data[TPM_HEADER_SIZE], TPM_DIGEST_SIZE); =20 -out: - tpm_buf_destroy(&buf); return rc; } =20 @@ -604,16 +589,13 @@ int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx,= u8 *res_buf) */ static int tpm1_continue_selftest(struct tpm_chip *chip) { - struct tpm_buf buf; - int rc; - - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_CONTINUE_SELFTEST); - if (rc) - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; =20 - rc =3D tpm_transmit_cmd(chip, &buf, 0, "continue selftest"); - tpm_buf_destroy(&buf); - return rc; + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_CONTINUE_SELFTEST); + return tpm_transmit_cmd(chip, buf, 0, "continue selftest"); } =20 /** @@ -725,22 +707,24 @@ int tpm1_auto_startup(struct tpm_chip *chip) int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr) { u8 dummy_hash[TPM_DIGEST_SIZE] =3D { 0 }; - struct tpm_buf buf; unsigned int try; int rc; =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; =20 - /* for buggy tpm, flush pcrs with extend to selected dummy */ + /* for buggy tpm, flush PCRs with extend to selected dummy */ if (tpm_suspend_pcr) rc =3D tpm1_pcr_extend(chip, tpm_suspend_pcr, dummy_hash, - "extending dummy pcr before suspend"); + "extending dummy PCR before suspend"); + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_SAVESTATE); =20 - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_SAVESTATE); - if (rc) - return rc; /* now do the actual savestate */ for (try =3D 0; try < TPM_RETRY; try++) { - rc =3D tpm_transmit_cmd(chip, &buf, 0, NULL); + rc =3D tpm_transmit_cmd(chip, buf, 0, NULL); /* * If the TPM indicates that it is too busy to respond to * this command then retry before giving up. It can take @@ -755,7 +739,7 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_susp= end_pcr) break; tpm_msleep(TPM_TIMEOUT_RETRY); =20 - tpm_buf_reset(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_SAVESTATE); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_SAVESTATE); } =20 if (rc) @@ -765,8 +749,6 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_susp= end_pcr) dev_warn(&chip->dev, "TPM savestate took %dms\n", try * TPM_TIMEOUT_RETRY); =20 - tpm_buf_destroy(&buf); - return rc; } =20 diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index c9dc35b57687..95c1b57d5096 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -108,12 +108,15 @@ int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, { int i; int rc; - struct tpm_buf buf; struct tpm2_pcr_read_out *out; u8 pcr_select[TPM2_PCR_SELECT_MIN] =3D {0}; u16 digest_size; u16 expected_digest_size =3D 0; =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + if (pcr_idx >=3D TPM2_PLATFORM_PCR) return -EINVAL; =20 @@ -128,36 +131,32 @@ int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, expected_digest_size =3D chip->allocated_banks[i].digest_size; } =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_PCR_READ); - if (rc) - return rc; + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_PCR_READ); =20 pcr_select[pcr_idx >> 3] =3D 1 << (pcr_idx & 0x7); =20 - tpm_buf_append_u32(&buf, 1); - tpm_buf_append_u16(&buf, digest->alg_id); - tpm_buf_append_u8(&buf, TPM2_PCR_SELECT_MIN); - tpm_buf_append(&buf, (const unsigned char *)pcr_select, + tpm_buf_append_u32(buf, 1); + tpm_buf_append_u16(buf, digest->alg_id); + tpm_buf_append_u8(buf, TPM2_PCR_SELECT_MIN); + tpm_buf_append(buf, (const unsigned char *)pcr_select, sizeof(pcr_select)); =20 - rc =3D tpm_transmit_cmd(chip, &buf, 0, "attempting to read a pcr value"); + rc =3D tpm_transmit_cmd(chip, buf, 0, "attempting to read a pcr value"); if (rc) - goto out; + return rc; =20 - out =3D (struct tpm2_pcr_read_out *)&buf.data[TPM_HEADER_SIZE]; + out =3D (struct tpm2_pcr_read_out *)&buf->data[TPM_HEADER_SIZE]; digest_size =3D be16_to_cpu(out->digest_size); if (digest_size > sizeof(digest->digest) || - (!digest_size_ptr && digest_size !=3D expected_digest_size)) { - rc =3D -EINVAL; - goto out; - } + (!digest_size_ptr && digest_size !=3D expected_digest_size)) + return -EINVAL; =20 if (digest_size_ptr) *digest_size_ptr =3D digest_size; =20 memcpy(digest->digest, out->digest, digest_size); -out: - tpm_buf_destroy(&buf); + return rc; } =20 @@ -173,56 +172,53 @@ int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, struct tpm_digest *digests) { - struct tpm_buf buf; int rc; int i; =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + if (!disable_pcr_integrity) { rc =3D tpm2_start_auth_session(chip); if (rc) return rc; } =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_PCR_EXTEND); - if (rc) { - if (!disable_pcr_integrity) - tpm2_end_auth_session(chip); - return rc; - } + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_PCR_EXTEND); =20 if (!disable_pcr_integrity) { - rc =3D tpm_buf_append_name(chip, &buf, pcr_idx, NULL); - if (rc) { - tpm_buf_destroy(&buf); + rc =3D tpm_buf_append_name(chip, buf, pcr_idx, NULL); + if (rc) return rc; - } - tpm_buf_append_hmac_session(chip, &buf, 0, NULL, 0); + + tpm_buf_append_hmac_session(chip, buf, 0, NULL, 0); } else { - tpm_buf_append_handle(&buf, pcr_idx); - tpm_buf_append_auth(chip, &buf, NULL, 0); + tpm_buf_append_handle(buf, pcr_idx); + tpm_buf_append_auth(chip, buf, NULL, 0); } =20 - tpm_buf_append_u32(&buf, chip->nr_allocated_banks); + tpm_buf_append_u32(buf, chip->nr_allocated_banks); =20 for (i =3D 0; i < chip->nr_allocated_banks; i++) { - tpm_buf_append_u16(&buf, digests[i].alg_id); - tpm_buf_append(&buf, (const unsigned char *)&digests[i].digest, + tpm_buf_append_u16(buf, digests[i].alg_id); + tpm_buf_append(buf, (const unsigned char *)&digests[i].digest, chip->allocated_banks[i].digest_size); } =20 + if (buf->flags & TPM_BUF_INVALID) + return -EINVAL; + if (!disable_pcr_integrity) { - rc =3D tpm_buf_fill_hmac_session(chip, &buf); - if (rc) { - tpm_buf_destroy(&buf); + rc =3D tpm_buf_fill_hmac_session(chip, buf); + if (rc) return rc; - } } =20 - rc =3D tpm_transmit_cmd(chip, &buf, 0, "attempting extend a PCR value"); + rc =3D tpm_transmit_cmd(chip, buf, 0, "attempting extend a PCR value"); if (!disable_pcr_integrity) - rc =3D tpm_buf_check_hmac_response(chip, &buf, rc); - - tpm_buf_destroy(&buf); + rc =3D tpm_buf_check_hmac_response(chip, buf, rc); =20 return rc; } @@ -242,7 +238,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, si= ze_t max) { struct tpm2_get_random_out *out; struct tpm_header *head; - struct tpm_buf buf; u32 recd; u32 num_bytes =3D max; int err; @@ -258,52 +253,53 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, = size_t max) if (err) return err; =20 - err =3D tpm_buf_init(&buf, 0, 0); - if (err) { + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) { tpm2_end_auth_session(chip); - return err; + return -ENOMEM; } =20 + tpm_buf_init(buf, TPM_BUFSIZE); + do { - tpm_buf_reset(&buf, TPM2_ST_SESSIONS, TPM2_CC_GET_RANDOM); + tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_GET_RANDOM); if (tpm2_chip_auth(chip)) { - tpm_buf_append_hmac_session(chip, &buf, + tpm_buf_append_hmac_session(chip, buf, TPM2_SA_ENCRYPT | TPM2_SA_CONTINUE_SESSION, NULL, 0); } else { - offset =3D buf.handles * 4 + TPM_HEADER_SIZE; - head =3D (struct tpm_header *)buf.data; - if (tpm_buf_length(&buf) =3D=3D offset) + offset =3D buf->handles * 4 + TPM_HEADER_SIZE; + head =3D (struct tpm_header *)buf->data; + if (tpm_buf_length(buf) =3D=3D offset) head->tag =3D cpu_to_be16(TPM2_ST_NO_SESSIONS); } - tpm_buf_append_u16(&buf, num_bytes); - err =3D tpm_buf_fill_hmac_session(chip, &buf); - if (err) { - tpm_buf_destroy(&buf); + tpm_buf_append_u16(buf, num_bytes); + err =3D tpm_buf_fill_hmac_session(chip, buf); + if (err) return err; - } =20 - err =3D tpm_transmit_cmd(chip, &buf, + err =3D tpm_transmit_cmd(chip, buf, offsetof(struct tpm2_get_random_out, buffer), "attempting get random"); - err =3D tpm_buf_check_hmac_response(chip, &buf, err); + err =3D tpm_buf_check_hmac_response(chip, buf, err); if (err) { if (err > 0) err =3D -EIO; goto out; } =20 - head =3D (struct tpm_header *)buf.data; + head =3D (struct tpm_header *)buf->data; offset =3D TPM_HEADER_SIZE; + /* Skip the parameter size field: */ if (be16_to_cpu(head->tag) =3D=3D TPM2_ST_SESSIONS) offset +=3D 4; =20 - out =3D (struct tpm2_get_random_out *)&buf.data[offset]; + out =3D (struct tpm2_get_random_out *)&buf->data[offset]; recd =3D min_t(u32, be16_to_cpu(out->size), num_bytes); - if (tpm_buf_length(&buf) < + if (tpm_buf_length(buf) < TPM_HEADER_SIZE + offsetof(struct tpm2_get_random_out, buffer) + recd) { @@ -317,11 +313,9 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, s= ize_t max) num_bytes -=3D recd; } while (retries-- && total < max); =20 - tpm_buf_destroy(&buf); - return total ? total : -EIO; + out: - tpm_buf_destroy(&buf); tpm2_end_auth_session(chip); return err; } @@ -333,20 +327,18 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, = size_t max) */ void tpm2_flush_context(struct tpm_chip *chip, u32 handle) { - struct tpm_buf buf; - int rc; - - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_FLUSH_CONTEXT); - if (rc) { + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) { dev_warn(&chip->dev, "0x%08x was not flushed, out of memory\n", handle); return; } =20 - tpm_buf_append_u32(&buf, handle); + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_FLUSH_CONTEXT); + tpm_buf_append_u32(buf, handle); =20 - tpm_transmit_cmd(chip, &buf, 0, "flushing context"); - tpm_buf_destroy(&buf); + tpm_transmit_cmd(chip, buf, 0, "flushing context"); } EXPORT_SYMBOL_GPL(tpm2_flush_context); =20 @@ -365,19 +357,22 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 pr= operty_id, u32 *value, const char *desc) { struct tpm2_get_cap_out *out; - struct tpm_buf buf; int rc; =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); - if (rc) - return rc; - tpm_buf_append_u32(&buf, TPM2_CAP_TPM_PROPERTIES); - tpm_buf_append_u32(&buf, property_id); - tpm_buf_append_u32(&buf, 1); - rc =3D tpm_transmit_cmd(chip, &buf, 0, NULL); + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); + tpm_buf_append_u32(buf, TPM2_CAP_TPM_PROPERTIES); + tpm_buf_append_u32(buf, property_id); + tpm_buf_append_u32(buf, 1); + + rc =3D tpm_transmit_cmd(chip, buf, 0, NULL); if (!rc) { out =3D (struct tpm2_get_cap_out *) - &buf.data[TPM_HEADER_SIZE]; + &buf->data[TPM_HEADER_SIZE]; /* * To prevent failing boot up of some systems, Infineon TPM2.0 * returns SUCCESS on TPM2_Startup in field upgrade mode. Also @@ -389,7 +384,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 prop= erty_id, u32 *value, else rc =3D -ENODATA; } - tpm_buf_destroy(&buf); + return rc; } EXPORT_SYMBOL_GPL(tpm2_get_tpm_pt); @@ -406,15 +401,14 @@ EXPORT_SYMBOL_GPL(tpm2_get_tpm_pt); */ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type) { - struct tpm_buf buf; - int rc; - - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_SHUTDOWN); - if (rc) + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) return; - tpm_buf_append_u16(&buf, shutdown_type); - tpm_transmit_cmd(chip, &buf, 0, "stopping the TPM"); - tpm_buf_destroy(&buf); + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_SHUTDOWN); + tpm_buf_append_u16(buf, shutdown_type); + tpm_transmit_cmd(chip, buf, 0, "stopping the TPM"); } =20 /** @@ -432,20 +426,21 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdow= n_type) */ static int tpm2_do_selftest(struct tpm_chip *chip) { - struct tpm_buf buf; int full; int rc; =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); + for (full =3D 0; full < 2; full++) { - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_SELF_TEST); - if (rc) - return rc; + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_SELF_TEST); + tpm_buf_append_u8(buf, full); =20 - tpm_buf_append_u8(&buf, full); - rc =3D tpm_transmit_cmd(chip, &buf, 0, + rc =3D tpm_transmit_cmd(chip, buf, 0, "attempting the self test"); - tpm_buf_destroy(&buf); - if (rc =3D=3D TPM2_RC_TESTING) rc =3D TPM2_RC_SUCCESS; if (rc =3D=3D TPM2_RC_INITIALIZE || rc =3D=3D TPM2_RC_SUCCESS) @@ -470,23 +465,26 @@ static int tpm2_do_selftest(struct tpm_chip *chip) int tpm2_probe(struct tpm_chip *chip) { struct tpm_header *out; - struct tpm_buf buf; int rc; =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); - if (rc) - return rc; - tpm_buf_append_u32(&buf, TPM2_CAP_TPM_PROPERTIES); - tpm_buf_append_u32(&buf, TPM_PT_TOTAL_COMMANDS); - tpm_buf_append_u32(&buf, 1); - rc =3D tpm_transmit_cmd(chip, &buf, 0, NULL); + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); + tpm_buf_append_u32(buf, TPM2_CAP_TPM_PROPERTIES); + tpm_buf_append_u32(buf, TPM_PT_TOTAL_COMMANDS); + tpm_buf_append_u32(buf, 1); + + rc =3D tpm_transmit_cmd(chip, buf, 0, NULL); /* We ignore TPM return codes on purpose. */ if (rc >=3D 0) { - out =3D (struct tpm_header *)buf.data; + out =3D (struct tpm_header *)buf->data; if (be16_to_cpu(out->tag) =3D=3D TPM2_ST_NO_SESSIONS) chip->flags |=3D TPM_CHIP_FLAG_TPM2; } - tpm_buf_destroy(&buf); + return 0; } EXPORT_SYMBOL_GPL(tpm2_probe); @@ -520,7 +518,6 @@ static int tpm2_init_bank_info(struct tpm_chip *chip, u= 32 bank_index) ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) { struct tpm2_pcr_selection pcr_selection; - struct tpm_buf buf; void *marker; void *end; void *pcr_select_offset; @@ -532,39 +529,38 @@ ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) int rc; int i =3D 0; =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); - if (rc) - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; =20 - tpm_buf_append_u32(&buf, TPM2_CAP_PCRS); - tpm_buf_append_u32(&buf, 0); - tpm_buf_append_u32(&buf, 1); + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); + tpm_buf_append_u32(buf, TPM2_CAP_PCRS); + tpm_buf_append_u32(buf, 0); + tpm_buf_append_u32(buf, 1); =20 - rc =3D tpm_transmit_cmd(chip, &buf, 9, "get tpm pcr allocation"); + rc =3D tpm_transmit_cmd(chip, buf, 9, "get TPM PCR allocation"); if (rc) - goto out; + return rc; =20 nr_possible_banks =3D be32_to_cpup( - (__be32 *)&buf.data[TPM_HEADER_SIZE + 5]); + (__be32 *)&buf->data[TPM_HEADER_SIZE + 5]); if (nr_possible_banks > TPM2_MAX_PCR_BANKS) { pr_err("tpm: out of bank capacity: %u > %u\n", nr_possible_banks, TPM2_MAX_PCR_BANKS); - rc =3D -ENOMEM; - goto out; + return -ENOMEM; } =20 - marker =3D &buf.data[TPM_HEADER_SIZE + 9]; + marker =3D &buf->data[TPM_HEADER_SIZE + 9]; =20 - rsp_len =3D be32_to_cpup((__be32 *)&buf.data[2]); - end =3D &buf.data[rsp_len]; + rsp_len =3D be32_to_cpup((__be32 *)&buf->data[2]); + end =3D &buf->data[rsp_len]; =20 for (i =3D 0; i < nr_possible_banks; i++) { pcr_select_offset =3D marker + offsetof(struct tpm2_pcr_selection, size_of_select); - if (pcr_select_offset >=3D end) { - rc =3D -EFAULT; - break; - } + if (pcr_select_offset >=3D end) + return -EFAULT; =20 memcpy(&pcr_selection, marker, sizeof(pcr_selection)); hash_alg =3D be16_to_cpu(pcr_selection.hash_alg); @@ -576,7 +572,7 @@ ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) =20 rc =3D tpm2_init_bank_info(chip, nr_alloc_banks); if (rc < 0) - break; + return rc; =20 nr_alloc_banks++; } @@ -588,21 +584,22 @@ ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) } =20 chip->nr_allocated_banks =3D nr_alloc_banks; -out: - tpm_buf_destroy(&buf); =20 - return rc; + return 0; } =20 int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip) { - struct tpm_buf buf; u32 nr_commands; __be32 *attrs; u32 cc; int i; int rc; =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + rc =3D tpm2_get_tpm_pt(chip, TPM_PT_TOTAL_COMMANDS, &nr_commands, NULL); if (rc) goto out; @@ -619,30 +616,25 @@ int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip) goto out; } =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); - if (rc) - goto out; + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); + tpm_buf_append_u32(buf, TPM2_CAP_COMMANDS); + tpm_buf_append_u32(buf, TPM2_CC_FIRST); + tpm_buf_append_u32(buf, nr_commands); =20 - tpm_buf_append_u32(&buf, TPM2_CAP_COMMANDS); - tpm_buf_append_u32(&buf, TPM2_CC_FIRST); - tpm_buf_append_u32(&buf, nr_commands); - - rc =3D tpm_transmit_cmd(chip, &buf, 9 + 4 * nr_commands, NULL); - if (rc) { - tpm_buf_destroy(&buf); + rc =3D tpm_transmit_cmd(chip, buf, 9 + 4 * nr_commands, NULL); + if (rc) goto out; - } =20 if (nr_commands !=3D - be32_to_cpup((__be32 *)&buf.data[TPM_HEADER_SIZE + 5])) { + be32_to_cpup((__be32 *)&buf->data[TPM_HEADER_SIZE + 5])) { rc =3D -EFAULT; - tpm_buf_destroy(&buf); goto out; } =20 chip->nr_commands =3D nr_commands; =20 - attrs =3D (__be32 *)&buf.data[TPM_HEADER_SIZE + 9]; + attrs =3D (__be32 *)&buf->data[TPM_HEADER_SIZE + 9]; for (i =3D 0; i < nr_commands; i++, attrs++) { chip->cc_attrs_tbl[i] =3D be32_to_cpup(attrs); cc =3D chip->cc_attrs_tbl[i] & 0xFFFF; @@ -654,8 +646,6 @@ int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip) } } =20 - tpm_buf_destroy(&buf); - out: if (rc > 0) rc =3D -ENODEV; @@ -676,20 +666,14 @@ EXPORT_SYMBOL_GPL(tpm2_get_cc_attrs_tbl); =20 static int tpm2_startup(struct tpm_chip *chip) { - struct tpm_buf buf; - int rc; - - dev_info(&chip->dev, "starting up the TPM manually\n"); - - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_STARTUP); - if (rc < 0) - return rc; - - tpm_buf_append_u16(&buf, TPM2_SU_CLEAR); - rc =3D tpm_transmit_cmd(chip, &buf, 0, "attempting to start the TPM"); - tpm_buf_destroy(&buf); - - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_STARTUP); + tpm_buf_append_u16(buf, TPM2_SU_CLEAR); + return tpm_transmit_cmd(chip, buf, 0, "attempting to start the TPM"); } =20 /** diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessi= ons.c index eb67ae14ad73..b50844740f90 100644 --- a/drivers/char/tpm/tpm2-sessions.c +++ b/drivers/char/tpm/tpm2-sessions.c @@ -168,7 +168,6 @@ static int tpm2_read_public(struct tpm_chip *chip, u32 = handle, void *name) u32 mso =3D tpm2_handle_mso(handle); off_t offset =3D TPM_HEADER_SIZE; int rc, name_size_alg; - struct tpm_buf buf; =20 if (mso !=3D TPM2_MSO_PERSISTENT && mso !=3D TPM2_MSO_VOLATILE && mso !=3D TPM2_MSO_NVRAM) { @@ -176,47 +175,42 @@ static int tpm2_read_public(struct tpm_chip *chip, u3= 2 handle, void *name) return sizeof(u32); } =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_READ_PUBLIC); - if (rc) - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; =20 - tpm_buf_append_u32(&buf, handle); + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_READ_PUBLIC); + tpm_buf_append_u32(buf, handle); =20 - rc =3D tpm_transmit_cmd(chip, &buf, 0, "TPM2_ReadPublic"); - if (rc) { - tpm_buf_destroy(&buf); + rc =3D tpm_transmit_cmd(chip, buf, 0, "TPM2_ReadPublic"); + if (rc) return tpm_ret_to_err(rc); - } =20 /* Skip TPMT_PUBLIC: */ - offset +=3D tpm_buf_read_u16(&buf, &offset); + offset +=3D tpm_buf_read_u16(buf, &offset); =20 /* * Ensure space for the length field of TPM2B_NAME and hashAlg field of * TPMT_HA (the extra four bytes). */ - if (offset + 4 > tpm_buf_length(&buf)) { - tpm_buf_destroy(&buf); + if (offset + 4 > tpm_buf_length(buf)) return -EIO; - } =20 - rc =3D tpm_buf_read_u16(&buf, &offset); - name_size_alg =3D name_size(&buf.data[offset]); + rc =3D tpm_buf_read_u16(buf, &offset); + name_size_alg =3D name_size(&buf->data[offset]); =20 if (name_size_alg < 0) return name_size_alg; =20 - if (rc !=3D name_size_alg) { - tpm_buf_destroy(&buf); + if (rc !=3D name_size_alg) return -EIO; - } =20 - if (offset + rc > tpm_buf_length(&buf)) { - tpm_buf_destroy(&buf); + if (offset + rc > tpm_buf_length(buf)) return -EIO; - } =20 - memcpy(name, &buf.data[offset], rc); + memcpy(name, &buf->data[offset], rc); + return name_size_alg; } #endif /* CONFIG_TCG_TPM2_HMAC */ @@ -982,7 +976,6 @@ static int tpm2_load_null(struct tpm_chip *chip, u32 *n= ull_key) int tpm2_start_auth_session(struct tpm_chip *chip) { struct tpm2_auth *auth; - struct tpm_buf buf; u32 null_key; int rc; =20 @@ -991,6 +984,10 @@ int tpm2_start_auth_session(struct tpm_chip *chip) return 0; } =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + auth =3D kzalloc_obj(*auth); if (!auth) return -ENOMEM; @@ -1001,41 +998,37 @@ int tpm2_start_auth_session(struct tpm_chip *chip) =20 auth->session =3D TPM_HEADER_SIZE; =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_START_AUTH_SESS); - if (rc) - goto out; - + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_NO_SESSIONS, TPM2_CC_START_AUTH_SESS); /* salt key handle */ - tpm_buf_append_u32(&buf, null_key); + tpm_buf_append_u32(buf, null_key); /* bind key handle */ - tpm_buf_append_u32(&buf, TPM2_RH_NULL); + tpm_buf_append_u32(buf, TPM2_RH_NULL); /* nonce caller */ get_random_bytes(auth->our_nonce, sizeof(auth->our_nonce)); - tpm_buf_append_u16(&buf, sizeof(auth->our_nonce)); - tpm_buf_append(&buf, auth->our_nonce, sizeof(auth->our_nonce)); + tpm_buf_append_u16(buf, sizeof(auth->our_nonce)); + tpm_buf_append(buf, auth->our_nonce, sizeof(auth->our_nonce)); =20 /* append encrypted salt and squirrel away unencrypted in auth */ - tpm_buf_append_salt(&buf, chip, auth); + tpm_buf_append_salt(buf, chip, auth); /* session type (HMAC, audit or policy) */ - tpm_buf_append_u8(&buf, TPM2_SE_HMAC); + tpm_buf_append_u8(buf, TPM2_SE_HMAC); =20 /* symmetric encryption parameters */ /* symmetric algorithm */ - tpm_buf_append_u16(&buf, TPM_ALG_AES); + tpm_buf_append_u16(buf, TPM_ALG_AES); /* bits for symmetric algorithm */ - tpm_buf_append_u16(&buf, AES_KEY_BITS); + tpm_buf_append_u16(buf, AES_KEY_BITS); /* symmetric algorithm mode (must be CFB) */ - tpm_buf_append_u16(&buf, TPM_ALG_CFB); + tpm_buf_append_u16(buf, TPM_ALG_CFB); /* hash algorithm for session */ - tpm_buf_append_u16(&buf, TPM_ALG_SHA256); + tpm_buf_append_u16(buf, TPM_ALG_SHA256); =20 - rc =3D tpm_ret_to_err(tpm_transmit_cmd(chip, &buf, 0, "StartAuthSession")= ); + rc =3D tpm_ret_to_err(tpm_transmit_cmd(chip, buf, 0, "StartAuthSession")); tpm2_flush_context(chip, null_key); =20 if (rc =3D=3D TPM2_RC_SUCCESS) - rc =3D tpm2_parse_start_auth_session(auth, &buf); - - tpm_buf_destroy(&buf); + rc =3D tpm2_parse_start_auth_session(auth, buf); =20 if (rc =3D=3D TPM2_RC_SUCCESS) { chip->auth =3D auth; @@ -1257,18 +1250,18 @@ static int tpm2_create_primary(struct tpm_chip *chi= p, u32 hierarchy, u32 *handle, u8 *name) { int rc; - struct tpm_buf buf; - struct tpm_buf template; =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE_PRIMARY); - if (rc) - return rc; + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; =20 - rc =3D tpm_buf_init_sized(&template); - if (rc) { - tpm_buf_destroy(&buf); - return rc; - } + struct tpm_buf *template __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNE= L); + if (!template) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE_PRIMARY); + tpm_buf_init_sized(template, TPM_BUFSIZE); =20 /* * create the template. Note: in order for userspace to @@ -1280,75 +1273,72 @@ static int tpm2_create_primary(struct tpm_chip *chi= p, u32 hierarchy, */ =20 /* key type */ - tpm_buf_append_u16(&template, TPM_ALG_ECC); + tpm_buf_append_u16(template, TPM_ALG_ECC); =20 /* name algorithm */ - tpm_buf_append_u16(&template, TPM_ALG_SHA256); + tpm_buf_append_u16(template, TPM_ALG_SHA256); =20 /* object properties */ - tpm_buf_append_u32(&template, TPM2_OA_NULL_KEY); + tpm_buf_append_u32(template, TPM2_OA_NULL_KEY); =20 /* sauth policy (empty) */ - tpm_buf_append_u16(&template, 0); + tpm_buf_append_u16(template, 0); =20 /* BEGIN parameters: key specific; for ECC*/ =20 /* symmetric algorithm */ - tpm_buf_append_u16(&template, TPM_ALG_AES); + tpm_buf_append_u16(template, TPM_ALG_AES); =20 /* bits for symmetric algorithm */ - tpm_buf_append_u16(&template, AES_KEY_BITS); + tpm_buf_append_u16(template, AES_KEY_BITS); =20 /* algorithm mode (must be CFB) */ - tpm_buf_append_u16(&template, TPM_ALG_CFB); + tpm_buf_append_u16(template, TPM_ALG_CFB); =20 /* scheme (NULL means any scheme) */ - tpm_buf_append_u16(&template, TPM_ALG_NULL); + tpm_buf_append_u16(template, TPM_ALG_NULL); =20 /* ECC Curve ID */ - tpm_buf_append_u16(&template, TPM2_ECC_NIST_P256); + tpm_buf_append_u16(template, TPM2_ECC_NIST_P256); =20 /* KDF Scheme */ - tpm_buf_append_u16(&template, TPM_ALG_NULL); + tpm_buf_append_u16(template, TPM_ALG_NULL); =20 /* unique: key specific; for ECC it is two zero size points */ - tpm_buf_append_u16(&template, 0); - tpm_buf_append_u16(&template, 0); + tpm_buf_append_u16(template, 0); + tpm_buf_append_u16(template, 0); =20 /* END parameters */ =20 /* primary handle */ - tpm_buf_append_u32(&buf, hierarchy); - tpm_buf_append_empty_auth(&buf, TPM2_RS_PW); + tpm_buf_append_u32(buf, hierarchy); + tpm_buf_append_empty_auth(buf, TPM2_RS_PW); =20 /* sensitive create size is 4 for two empty buffers */ - tpm_buf_append_u16(&buf, 4); + tpm_buf_append_u16(buf, 4); =20 /* sensitive create auth data (empty) */ - tpm_buf_append_u16(&buf, 0); + tpm_buf_append_u16(buf, 0); =20 /* sensitive create sensitive data (empty) */ - tpm_buf_append_u16(&buf, 0); + tpm_buf_append_u16(buf, 0); =20 /* the public template */ - tpm_buf_append(&buf, template.data, template.length); - tpm_buf_destroy(&template); + tpm_buf_append(buf, template->data, template->length); =20 /* outside info (empty) */ - tpm_buf_append_u16(&buf, 0); + tpm_buf_append_u16(buf, 0); =20 /* creation PCR (none) */ - tpm_buf_append_u32(&buf, 0); + tpm_buf_append_u32(buf, 0); =20 - rc =3D tpm_transmit_cmd(chip, &buf, 0, + rc =3D tpm_transmit_cmd(chip, buf, 0, "attempting to create NULL primary"); =20 if (rc =3D=3D TPM2_RC_SUCCESS) - rc =3D tpm2_parse_create_primary(chip, &buf, handle, hierarchy, + rc =3D tpm2_parse_create_primary(chip, buf, handle, hierarchy, name); =20 - tpm_buf_destroy(&buf); - return rc; } =20 diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index 7c1c0a174a2b..5b0f233db898 100644 --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -58,24 +58,25 @@ void tpm2_del_space(struct tpm_chip *chip, struct tpm_s= pace *space) int tpm2_load_context(struct tpm_chip *chip, u8 *buf, unsigned int *offset, u32 *handle) { - struct tpm_buf tbuf; struct tpm2_context *ctx; unsigned int body_size; int rc; =20 - rc =3D tpm_buf_init(&tbuf, TPM2_ST_NO_SESSIONS, TPM2_CC_CONTEXT_LOAD); - if (rc) - return rc; + struct tpm_buf *tbuf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!tbuf) + return -ENOMEM; + + tpm_buf_init(tbuf, TPM_BUFSIZE); + tpm_buf_reset(tbuf, TPM2_ST_NO_SESSIONS, TPM2_CC_CONTEXT_LOAD); =20 ctx =3D (struct tpm2_context *)&buf[*offset]; body_size =3D sizeof(*ctx) + be16_to_cpu(ctx->blob_size); - tpm_buf_append(&tbuf, &buf[*offset], body_size); + tpm_buf_append(tbuf, &buf[*offset], body_size); =20 - rc =3D tpm_transmit_cmd(chip, &tbuf, 4, NULL); + rc =3D tpm_transmit_cmd(chip, tbuf, 4, NULL); if (rc < 0) { dev_warn(&chip->dev, "%s: failed with a system error %d\n", __func__, rc); - tpm_buf_destroy(&tbuf); return -EFAULT; } else if (tpm2_rc_value(rc) =3D=3D TPM2_RC_HANDLE || rc =3D=3D TPM2_RC_REFERENCE_H0) { @@ -90,64 +91,55 @@ int tpm2_load_context(struct tpm_chip *chip, u8 *buf, * flushed outside the space */ *handle =3D 0; - tpm_buf_destroy(&tbuf); return -ENOENT; } else if (tpm2_rc_value(rc) =3D=3D TPM2_RC_INTEGRITY) { - tpm_buf_destroy(&tbuf); return -EINVAL; } else if (rc > 0) { dev_warn(&chip->dev, "%s: failed with a TPM error 0x%04X\n", __func__, rc); - tpm_buf_destroy(&tbuf); return -EFAULT; } =20 - *handle =3D be32_to_cpup((__be32 *)&tbuf.data[TPM_HEADER_SIZE]); + *handle =3D be32_to_cpup((__be32 *)&tbuf->data[TPM_HEADER_SIZE]); *offset +=3D body_size; - - tpm_buf_destroy(&tbuf); return 0; } =20 int tpm2_save_context(struct tpm_chip *chip, u32 handle, u8 *buf, unsigned int buf_size, unsigned int *offset) { - struct tpm_buf tbuf; unsigned int body_size; int rc; =20 - rc =3D tpm_buf_init(&tbuf, TPM2_ST_NO_SESSIONS, TPM2_CC_CONTEXT_SAVE); - if (rc) - return rc; + struct tpm_buf *tbuf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!tbuf) + return -ENOMEM; =20 - tpm_buf_append_u32(&tbuf, handle); + tpm_buf_init(tbuf, TPM_BUFSIZE); + tpm_buf_reset(tbuf, TPM2_ST_NO_SESSIONS, TPM2_CC_CONTEXT_SAVE); + tpm_buf_append_u32(tbuf, handle); =20 - rc =3D tpm_transmit_cmd(chip, &tbuf, 0, NULL); + rc =3D tpm_transmit_cmd(chip, tbuf, 0, NULL); if (rc < 0) { dev_warn(&chip->dev, "%s: failed with a system error %d\n", __func__, rc); - tpm_buf_destroy(&tbuf); return -EFAULT; } else if (tpm2_rc_value(rc) =3D=3D TPM2_RC_REFERENCE_H0) { - tpm_buf_destroy(&tbuf); return -ENOENT; } else if (rc) { dev_warn(&chip->dev, "%s: failed with a TPM error 0x%04X\n", __func__, rc); - tpm_buf_destroy(&tbuf); return -EFAULT; } =20 - body_size =3D tpm_buf_length(&tbuf) - TPM_HEADER_SIZE; + body_size =3D tpm_buf_length(tbuf) - TPM_HEADER_SIZE; if ((*offset + body_size) > buf_size) { dev_warn(&chip->dev, "%s: out of backing storage\n", __func__); - tpm_buf_destroy(&tbuf); return -ENOMEM; } =20 - memcpy(&buf[*offset], &tbuf.data[TPM_HEADER_SIZE], body_size); + memcpy(&buf[*offset], &tbuf->data[TPM_HEADER_SIZE], body_size); *offset +=3D body_size; - tpm_buf_destroy(&tbuf); return 0; } =20 diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_= proxy.c index 7bb0f4d4a2ed..b81fd2a537df 100644 --- a/drivers/char/tpm/tpm_vtpm_proxy.c +++ b/drivers/char/tpm/tpm_vtpm_proxy.c @@ -395,40 +395,36 @@ static bool vtpm_proxy_tpm_req_canceled(struct tpm_ch= ip *chip, u8 status) =20 static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality) { - struct tpm_buf buf; int rc; const struct tpm_header *header; struct proxy_dev *proxy_dev =3D dev_get_drvdata(&chip->dev); =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tpm_buf_init(buf, TPM_BUFSIZE); if (chip->flags & TPM_CHIP_FLAG_TPM2) - rc =3D tpm_buf_init(&buf, TPM2_ST_SESSIONS, - TPM2_CC_SET_LOCALITY); + tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_SET_LOCALITY); else - rc =3D tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, - TPM_ORD_SET_LOCALITY); - if (rc) - return rc; - tpm_buf_append_u8(&buf, locality); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_SET_LOCALITY); + + tpm_buf_append_u8(buf, locality); =20 proxy_dev->state |=3D STATE_DRIVER_COMMAND; =20 - rc =3D tpm_transmit_cmd(chip, &buf, 0, "attempting to set locality"); + rc =3D tpm_transmit_cmd(chip, buf, 0, "attempting to set locality"); =20 proxy_dev->state &=3D ~STATE_DRIVER_COMMAND; =20 - if (rc < 0) { - locality =3D rc; - goto out; - } + if (rc < 0) + return rc; =20 - header =3D (const struct tpm_header *)buf.data; + header =3D (const struct tpm_header *)buf->data; rc =3D be32_to_cpu(header->return_code); if (rc) locality =3D -1; =20 -out: - tpm_buf_destroy(&buf); - return locality; } =20 diff --git a/include/linux/tpm.h b/include/linux/tpm.h index b357f8971d03..0a56f6c1ea98 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -208,13 +208,15 @@ enum tpm_buf_flags { }; =20 /* - * A string buffer type for constructing TPM commands. + * A buffer for constructing and parsing TPM commands, responses and sized + * (TPM2B) buffers. */ struct tpm_buf { - u32 flags; - u32 length; - u8 *data; + u8 flags; u8 handles; + u16 length; + u16 capacity; + u8 data[]; }; =20 struct tpm2_hash { @@ -222,12 +224,11 @@ struct tpm2_hash { unsigned int tpm_id; }; =20 -int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal); +void tpm_buf_init(struct tpm_buf *buf, u16 buf_size); +void tpm_buf_init_sized(struct tpm_buf *buf, u16 buf_size); void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal); -int tpm_buf_init_sized(struct tpm_buf *buf); void tpm_buf_reset_sized(struct tpm_buf *buf); -void tpm_buf_destroy(struct tpm_buf *buf); -u32 tpm_buf_length(struct tpm_buf *buf); +u16 tpm_buf_length(struct tpm_buf *buf); void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_lengt= h); void tpm_buf_append_u8(struct tpm_buf *buf, const u8 value); void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value); diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trus= ted-keys/trusted_tpm1.c index 0d3244af8de3..592366572641 100644 --- a/security/keys/trusted-keys/trusted_tpm1.c +++ b/security/keys/trusted-keys/trusted_tpm1.c @@ -310,9 +310,10 @@ static int TSS_checkhmac2(unsigned char *buffer, * For key specific tpm requests, we will generate and send our * own TPM command packets using the drivers send function. */ -static int trusted_tpm_send(unsigned char *cmd, size_t buflen) +static int trusted_tpm_send(void *cmd, size_t cmd_len) { - struct tpm_buf buf; + u8 buf_data[512]; + struct tpm_buf *buf =3D (struct tpm_buf *)buf_data; int rc; =20 if (!chip) @@ -322,11 +323,10 @@ static int trusted_tpm_send(unsigned char *cmd, size_= t buflen) if (rc) return rc; =20 - buf.flags =3D 0; - buf.length =3D buflen; - buf.data =3D cmd; + tpm_buf_init(buf, sizeof(buf_data)); + tpm_buf_append(buf, cmd, cmd_len); dump_tpm_buf(cmd); - rc =3D tpm_transmit_cmd(chip, &buf, 4, "sending data"); + rc =3D tpm_transmit_cmd(chip, buf, 4, "sending data"); dump_tpm_buf(cmd); =20 if (rc > 0) @@ -624,23 +624,23 @@ static int tpm_unseal(struct tpm_buf *tb, static int key_seal(struct trusted_key_payload *p, struct trusted_key_options *o) { - struct tpm_buf tb; int ret; =20 - ret =3D tpm_buf_init(&tb, 0, 0); - if (ret) - return ret; + struct tpm_buf *tb __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!tb) + return -ENOMEM; + + tpm_buf_init(tb, TPM_BUFSIZE); =20 /* include migratable flag at end of sealed key */ p->key[p->key_len] =3D p->migratable; =20 - ret =3D tpm_seal(&tb, o->keytype, o->keyhandle, o->keyauth, + ret =3D tpm_seal(tb, o->keytype, o->keyhandle, o->keyauth, p->key, p->key_len + 1, p->blob, &p->blob_len, o->blobauth, o->pcrinfo, o->pcrinfo_len); if (ret < 0) pr_info("srkseal failed (%d)\n", ret); =20 - tpm_buf_destroy(&tb); return ret; } =20 @@ -650,14 +650,15 @@ static int key_seal(struct trusted_key_payload *p, static int key_unseal(struct trusted_key_payload *p, struct trusted_key_options *o) { - struct tpm_buf tb; int ret; =20 - ret =3D tpm_buf_init(&tb, 0, 0); - if (ret) - return ret; + struct tpm_buf *tb __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!tb) + return -ENOMEM; + + tpm_buf_init(tb, TPM_BUFSIZE); =20 - ret =3D tpm_unseal(&tb, o->keyhandle, o->keyauth, p->blob, p->blob_len, + ret =3D tpm_unseal(tb, o->keyhandle, o->keyauth, p->blob, p->blob_len, o->blobauth, p->key, &p->key_len); if (ret < 0) pr_info("srkunseal failed (%d)\n", ret); @@ -665,7 +666,6 @@ static int key_unseal(struct trusted_key_payload *p, /* pull migratable flag out of sealed key */ p->migratable =3D p->key[--p->key_len]; =20 - tpm_buf_destroy(&tb); return ret; } =20 diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trus= ted-keys/trusted_tpm2.c index 779a2e66ac20..8e77afbb50d9 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -233,12 +233,16 @@ int tpm2_seal_trusted(struct tpm_chip *chip, struct trusted_key_options *options) { off_t offset =3D TPM_HEADER_SIZE; - struct tpm_buf buf, sized; int blob_len =3D 0; int hash; u32 flags; int rc; =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + struct tpm_buf *sized __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf || !sized) + return -ENOMEM; + hash =3D tpm2_find_hash_alg(options->hash); if (hash < 0) return hash; @@ -254,97 +258,85 @@ int tpm2_seal_trusted(struct tpm_chip *chip, if (rc) goto out_put; =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE); - if (rc) { - tpm2_end_auth_session(chip); - goto out_put; - } - - rc =3D tpm_buf_init_sized(&sized); - if (rc) { - tpm_buf_destroy(&buf); - tpm2_end_auth_session(chip); - goto out_put; - } + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE); =20 - rc =3D tpm_buf_append_name(chip, &buf, options->keyhandle, NULL); + rc =3D tpm_buf_append_name(chip, buf, options->keyhandle, NULL); if (rc) - goto out; + goto out_put; =20 - tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_DECRYPT, + tpm_buf_append_hmac_session(chip, buf, TPM2_SA_DECRYPT, options->keyauth, TPM_DIGEST_SIZE); =20 /* sensitive */ - tpm_buf_append_u16(&sized, options->blobauth_len); + tpm_buf_init_sized(sized, TPM_BUFSIZE); + tpm_buf_append_u16(sized, options->blobauth_len); =20 if (options->blobauth_len) - tpm_buf_append(&sized, options->blobauth, options->blobauth_len); + tpm_buf_append(sized, options->blobauth, options->blobauth_len); =20 - tpm_buf_append_u16(&sized, payload->key_len); - tpm_buf_append(&sized, payload->key, payload->key_len); - tpm_buf_append(&buf, sized.data, sized.length); + tpm_buf_append_u16(sized, payload->key_len); + tpm_buf_append(sized, payload->key, payload->key_len); + tpm_buf_append(buf, sized->data, sized->length); =20 /* public */ - tpm_buf_reset_sized(&sized); - tpm_buf_append_u16(&sized, TPM_ALG_KEYEDHASH); - tpm_buf_append_u16(&sized, hash); + tpm_buf_init_sized(sized, TPM_BUFSIZE); + tpm_buf_append_u16(sized, TPM_ALG_KEYEDHASH); + tpm_buf_append_u16(sized, hash); =20 /* key properties */ flags =3D 0; flags |=3D options->policydigest_len ? 0 : TPM2_OA_USER_WITH_AUTH; flags |=3D payload->migratable ? 0 : (TPM2_OA_FIXED_TPM | TPM2_OA_FIXED_P= ARENT); - tpm_buf_append_u32(&sized, flags); + tpm_buf_append_u32(sized, flags); =20 /* policy */ - tpm_buf_append_u16(&sized, options->policydigest_len); + tpm_buf_append_u16(sized, options->policydigest_len); if (options->policydigest_len) - tpm_buf_append(&sized, options->policydigest, options->policydigest_len); + tpm_buf_append(sized, options->policydigest, options->policydigest_len); =20 /* public parameters */ - tpm_buf_append_u16(&sized, TPM_ALG_NULL); - tpm_buf_append_u16(&sized, 0); + tpm_buf_append_u16(sized, TPM_ALG_NULL); + tpm_buf_append_u16(sized, 0); =20 - tpm_buf_append(&buf, sized.data, sized.length); + tpm_buf_append(buf, sized->data, sized->length); =20 /* outside info */ - tpm_buf_append_u16(&buf, 0); + tpm_buf_append_u16(buf, 0); =20 /* creation PCR */ - tpm_buf_append_u32(&buf, 0); + tpm_buf_append_u32(buf, 0); =20 - if (buf.flags & TPM_BUF_INVALID) { + if (buf->flags & TPM_BUF_INVALID) { rc =3D -E2BIG; tpm2_end_auth_session(chip); goto out; } =20 - rc =3D tpm_buf_fill_hmac_session(chip, &buf); + rc =3D tpm_buf_fill_hmac_session(chip, buf); if (rc) goto out; =20 - rc =3D tpm_transmit_cmd(chip, &buf, 4, "sealing data"); - rc =3D tpm_buf_check_hmac_response(chip, &buf, rc); + rc =3D tpm_transmit_cmd(chip, buf, 4, "sealing data"); + rc =3D tpm_buf_check_hmac_response(chip, buf, rc); if (rc) goto out; =20 - blob_len =3D tpm_buf_read_u32(&buf, &offset); - if (blob_len > MAX_BLOB_SIZE || buf.flags & TPM_BUF_INVALID) { + blob_len =3D tpm_buf_read_u32(buf, &offset); + if (blob_len > MAX_BLOB_SIZE || buf->flags & TPM_BUF_INVALID) { rc =3D -E2BIG; goto out; } - if (buf.length - offset < blob_len) { + if (buf->length - offset < blob_len) { rc =3D -EFAULT; goto out; } =20 - blob_len =3D tpm2_key_encode(payload, options, &buf.data[offset], blob_le= n); + blob_len =3D tpm2_key_encode(payload, options, &buf->data[offset], blob_l= en); if (blob_len < 0) rc =3D blob_len; =20 out: - tpm_buf_destroy(&sized); - tpm_buf_destroy(&buf); - if (!rc) payload->blob_len =3D blob_len; =20 @@ -372,7 +364,6 @@ static int tpm2_load_cmd(struct tpm_chip *chip, u32 *blob_handle) { u8 *blob_ref __free(kfree) =3D NULL; - struct tpm_buf buf; unsigned int private_len; unsigned int public_len; unsigned int blob_len; @@ -380,6 +371,10 @@ static int tpm2_load_cmd(struct tpm_chip *chip, int rc; u32 attrs; =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + rc =3D tpm2_key_decode(payload, options, &blob); if (rc) { /* old form */ @@ -426,39 +421,32 @@ static int tpm2_load_cmd(struct tpm_chip *chip, if (rc) return rc; =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_LOAD); - if (rc) { - tpm2_end_auth_session(chip); - return rc; - } + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_LOAD); =20 - rc =3D tpm_buf_append_name(chip, &buf, options->keyhandle, NULL); + rc =3D tpm_buf_append_name(chip, buf, options->keyhandle, NULL); if (rc) - goto out; + return rc; =20 - tpm_buf_append_hmac_session(chip, &buf, 0, options->keyauth, + tpm_buf_append_hmac_session(chip, buf, 0, options->keyauth, TPM_DIGEST_SIZE); =20 - tpm_buf_append(&buf, blob, blob_len); + tpm_buf_append(buf, blob, blob_len); =20 - if (buf.flags & TPM_BUF_INVALID) { - rc =3D -E2BIG; + if (buf->flags & TPM_BUF_INVALID) { tpm2_end_auth_session(chip); - goto out; + return -E2BIG; } =20 - rc =3D tpm_buf_fill_hmac_session(chip, &buf); + rc =3D tpm_buf_fill_hmac_session(chip, buf); if (rc) - goto out; + return -EFAULT; =20 - rc =3D tpm_transmit_cmd(chip, &buf, 4, "loading blob"); - rc =3D tpm_buf_check_hmac_response(chip, &buf, rc); + rc =3D tpm_transmit_cmd(chip, buf, 4, "loading blob"); + rc =3D tpm_buf_check_hmac_response(chip, buf, rc); if (!rc) *blob_handle =3D be32_to_cpup( - (__be32 *) &buf.data[TPM_HEADER_SIZE]); - -out: - tpm_buf_destroy(&buf); + (__be32 *) &buf->data[TPM_HEADER_SIZE]); =20 return tpm_ret_to_err(rc); } @@ -481,28 +469,28 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, u32 blob_handle) { struct tpm_header *head; - struct tpm_buf buf; u16 data_len; int offset; u8 *data; int rc; =20 + struct tpm_buf *buf __free(kfree) =3D kzalloc(TPM_BUFSIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + rc =3D tpm2_start_auth_session(chip); if (rc) return rc; =20 - rc =3D tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_UNSEAL); - if (rc) { - tpm2_end_auth_session(chip); - return rc; - } + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_UNSEAL); =20 - rc =3D tpm_buf_append_name(chip, &buf, blob_handle, NULL); + rc =3D tpm_buf_append_name(chip, buf, blob_handle, NULL); if (rc) - goto out; + return rc; =20 if (!options->policyhandle) { - tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_ENCRYPT, + tpm_buf_append_hmac_session(chip, buf, TPM2_SA_ENCRYPT, options->blobauth, options->blobauth_len); } else { @@ -517,39 +505,35 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, * could repeat our actions with the exfiltrated * password. */ - tpm2_buf_append_auth(&buf, options->policyhandle, + tpm2_buf_append_auth(buf, options->policyhandle, NULL /* nonce */, 0, 0, options->blobauth, options->blobauth_len); if (tpm2_chip_auth(chip)) { - tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_ENCRYPT, NULL, 0); + tpm_buf_append_hmac_session(chip, buf, TPM2_SA_ENCRYPT, NULL, 0); } else { - offset =3D buf.handles * 4 + TPM_HEADER_SIZE; - head =3D (struct tpm_header *)buf.data; - if (tpm_buf_length(&buf) =3D=3D offset) + offset =3D buf->handles * 4 + TPM_HEADER_SIZE; + head =3D (struct tpm_header *)buf->data; + if (tpm_buf_length(buf) =3D=3D offset) head->tag =3D cpu_to_be16(TPM2_ST_NO_SESSIONS); } } =20 - rc =3D tpm_buf_fill_hmac_session(chip, &buf); + rc =3D tpm_buf_fill_hmac_session(chip, buf); if (rc) - goto out; + return rc; =20 - rc =3D tpm_transmit_cmd(chip, &buf, 6, "unsealing"); - rc =3D tpm_buf_check_hmac_response(chip, &buf, rc); + rc =3D tpm_transmit_cmd(chip, buf, 6, "unsealing"); + rc =3D tpm_buf_check_hmac_response(chip, buf, rc); =20 if (!rc) { data_len =3D be16_to_cpup( - (__be16 *) &buf.data[TPM_HEADER_SIZE + 4]); - if (data_len < MIN_KEY_SIZE || data_len > MAX_KEY_SIZE) { - rc =3D -EFAULT; - goto out; - } + (__be16 *) &buf->data[TPM_HEADER_SIZE + 4]); + if (data_len < MIN_KEY_SIZE || data_len > MAX_KEY_SIZE) + return -EFAULT; =20 - if (tpm_buf_length(&buf) < TPM_HEADER_SIZE + 6 + data_len) { - rc =3D -EFAULT; - goto out; - } - data =3D &buf.data[TPM_HEADER_SIZE + 6]; + if (tpm_buf_length(buf) < TPM_HEADER_SIZE + 6 + data_len) + return -EFAULT; + data =3D &buf->data[TPM_HEADER_SIZE + 6]; =20 if (payload->old_format) { /* migratable flag is at the end of the key */ @@ -566,8 +550,6 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, } } =20 -out: - tpm_buf_destroy(&buf); return tpm_ret_to_err(rc); } =20 --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f42.google.com (mail-dl1-f42.google.com [74.125.82.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D508A3ECBEE for ; Fri, 15 May 2026 21:14:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879685; cv=none; b=J83FQyQKuUkZ4VyLjIYo3EBXO6LcdRFIwOMAAjadfaASLVGR/R2dMtZmb2awONxf3c/eAfPA2UwH4LEyq2oRZlKa0/N0HLX/A7OaBvoIEyegLpseQUKXUmoo40h8GbOZLBGP4kzKpnHC0AxtABFyr7dXigr7rqL26A47T4biQ/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879685; c=relaxed/simple; bh=nAjY4qir7F1ZCb9sP0iaASf/Q4ek1ELKrjEEDlH4RuU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FQoACya7WnqQmLX9r1Fes0cCprsnbuyhSHj1J4AQXHiRnsBH+nKWF6fJF0z4S1WVohUePQEPDXHbyda5YCUsXuUHMkJVaXoce/fVMH1mWJacSbev+Npklk+FeZvHhOFttMFISoLLt8GXrOfzNz61LWC/hxBM7EQ2o8ET+LTX3cU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kMt1JGv/; arc=none smtp.client-ip=74.125.82.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kMt1JGv/" Received: by mail-dl1-f42.google.com with SMTP id a92af1059eb24-135200bc7d2so448119c88.0 for ; Fri, 15 May 2026 14:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879681; x=1779484481; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n6vamoagHMf4GbheCVmViNC3dNcySHzOx3Jk2wuZ+G0=; b=kMt1JGv/t/PApi4zH2l6JC0oM4q8sbVYdiieItDRPnWX+QyHj4LKYKASLJvT3cmuF2 nM+4V2UwPx9QF6/jXnpo+pcpbNaXLlnKXK6mwGMGkr8iMr1662J4oytEX28j7ExSNnM/ 8pCnPslcCOEzkKQ8YPxxhpb4pz7/QVB4Uim61/HpKLM3ae2WHDGjAXzLR4u+U1N/hNn6 nDmqqE0+yhabh4vtuMGgDF9iZmjkG0rieF0FUHMPowWyVr75Zxzvq5twUKlRkpBcxXNl ahg5tSd+BFQ5TkUfsOumYV+j4jKdfOOLWNBHc4A/yJ0XzQ93kDOv0S00WbN0DvK7pMb0 3wsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879681; x=1779484481; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=n6vamoagHMf4GbheCVmViNC3dNcySHzOx3Jk2wuZ+G0=; b=glXSy/O/EVyOKRbvZ7nJMumEQ0k4Kp249VmGC56uzEWP8o4De1SOg+Z2yhSBkM66zv X8QB9zbUApoAZc3EVFLfd0lGDwxlCb96sVyijx7LonASgsY6C44Lcxe23RLkm8kF5lCM EQEr2dDJ/7jsQ026B6igL87UJBiTXgEDOWEXY7GzbWSe/s+QSW6q/TMLYB7JtKyZEtQR 9DXZlwTgPSYS6FNHJr0lQruKZNNTTion8+dFQweozc9YcmZUMABT+QrKEfBwWOICwgq6 FRBS+MopgYQTk5VOPFWWAtzCzzWX8Re2xKXmOfyyYC/UvuU5Ks88blSHEL1fLEmSpniv /Uog== X-Gm-Message-State: AOJu0YwP0zttEs42A2G4hqNK4DE9nJltFOehOIYvrdfRFKlmdx+kQF/V 3fqVR/Dvayy00rT/IPraL+5iUmmYHGTAAlLtUl5/kp4ry1VYAal7Ogb+dEUgQjQW X-Gm-Gg: Acq92OHB7prepCpoVHQnKoswj72CDQgWN+oXtFoPdf39AXMBA/FLOD/4jwSCLTql4Ep OUtRIcKcl8kZfJeUgb3ElVkRhdFJH38f5nbvqxVmPCB6nC4/945lEZyDZylVqXWJs0oxmEhindZ 2FmgTomporjnWP5+PmbFgQ4squP2et9cHIAQWGqoVRx1ZKZZSU7jX0uq0FxZITn55H7cg/ViaxG VoQjucZ+hjAdqZ9YYw0gVhKnLXCl1dLB1i2QsGW0wF/DLY1EOdbVgxOXjURUfJgtDjpGwC13es0 SB80815xjj5yXiXVIjxvG3c4lrPmASKkEx3lYiBKfFyexVBhpQUmWoNgXCup0V8JKYHVyp/HIbo kElemuCSoHulHUHx+wRBIQC2rKVH+V2CsR58KVu2uRUpQqhhBlhG6q71e5WV/jFj7/97xE/cI/m L1TLKbC7f2KqIxNYunw+EEPJm3EA9VK5A= X-Received: by 2002:a05:7022:f10e:b0:12d:ed19:e6aa with SMTP id a92af1059eb24-1350494e78fmr2605508c88.33.1778879681459; Fri, 15 May 2026 14:14:41 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cbcb9ed3sm11076036c88.1.2026.05.15.14.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:41 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 10/38] tpm-buf: Add TPM buffer support header for standalone reuse Date: Fri, 15 May 2026 14:13:42 -0700 Message-ID: <20260515211410.31440-11-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extract all the functions and definitions for TPM buffer handling and separate them into their own header. Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm-buf.c | 4 ++- include/linux/tpm.h | 34 +---------------------- include/linux/tpm_buf.h | 57 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 include/linux/tpm_buf.h diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index e79a8071c9ee..e81ce7215b1a 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -4,7 +4,9 @@ */ =20 #include -#include +#include +#include +#include =20 static void __tpm_buf_size_invariant(struct tpm_buf *buf, u16 buf_size) { diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 0a56f6c1ea98..0db277af45c3 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -26,6 +26,7 @@ #include =20 #include +#include =20 struct tpm_chip; struct trusted_key_payload; @@ -200,44 +201,11 @@ enum tpm_chip_flags { =20 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) =20 -enum tpm_buf_flags { - /* TPM2B format: */ - TPM_BUF_TPM2B =3D BIT(0), - /* The buffer is in invalid and unusable state: */ - TPM_BUF_INVALID =3D BIT(1), -}; - -/* - * A buffer for constructing and parsing TPM commands, responses and sized - * (TPM2B) buffers. - */ -struct tpm_buf { - u8 flags; - u8 handles; - u16 length; - u16 capacity; - u8 data[]; -}; - struct tpm2_hash { unsigned int crypto_id; unsigned int tpm_id; }; =20 -void tpm_buf_init(struct tpm_buf *buf, u16 buf_size); -void tpm_buf_init_sized(struct tpm_buf *buf, u16 buf_size); -void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal); -void tpm_buf_reset_sized(struct tpm_buf *buf); -u16 tpm_buf_length(struct tpm_buf *buf); -void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_lengt= h); -void tpm_buf_append_u8(struct tpm_buf *buf, const u8 value); -void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value); -void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value); -u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset); -u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset); -u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset); -void tpm_buf_append_handle(struct tpm_buf *buf, u32 handle); - /* * Check if TPM device is in the firmware upgrade mode. */ diff --git a/include/linux/tpm_buf.h b/include/linux/tpm_buf.h new file mode 100644 index 000000000000..7f8abb59de24 --- /dev/null +++ b/include/linux/tpm_buf.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Following copyright information was take from the original file + * where the definitions were moved from: + * + * Copyright (C) 2004,2007,2008 IBM Corporation + * + * Authors: + * Leendert van Doorn + * Dave Safford + * Reiner Sailer + * Kylene Hall + * Debora Velarde + * + * Maintained by: + * + * Device driver for TCG/TCPA TPM (trusted platform module). + * Specifications at www.trustedcomputinggroup.org + */ + +#ifndef __LINUX_TPM_BUF_H__ +#define __LINUX_TPM_BUF_H__ + +enum tpm_buf_flags { + /* TPM2B format: */ + TPM_BUF_TPM2B =3D BIT(0), + /* The buffer is in invalid and unusable state: */ + TPM_BUF_INVALID =3D BIT(1), +}; + +/* + * A buffer for constructing and parsing TPM commands, responses and sized + * (TPM2B) buffers. + */ +struct tpm_buf { + u8 flags; + u8 handles; + u16 length; + u16 capacity; + u8 data[]; +}; + +void tpm_buf_init(struct tpm_buf *buf, u16 buf_size); +void tpm_buf_init_sized(struct tpm_buf *buf, u16 buf_size); +void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal); +void tpm_buf_reset_sized(struct tpm_buf *buf); +u16 tpm_buf_length(struct tpm_buf *buf); +void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_lengt= h); +void tpm_buf_append_u8(struct tpm_buf *buf, const u8 value); +void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value); +void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value); +u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset); +u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset); +u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset); +void tpm_buf_append_handle(struct tpm_buf *buf, u32 handle); + +#endif --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80DEB3ED126 for ; Fri, 15 May 2026 21:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879687; cv=none; b=iErVzAQLVyqk+Oo45RAA4Psgqv9sx6ml0QTM7P1tS+WkvnaBkButLmkgGUnTbUmLujJHZ1FQlVO8WN/EBWUJSp/pjqh1lAUVAdtySfgA9l3Tqlx+og54D49nSbz6+eokOmSNFRY011MnIWOL+EmWgiV5Y6IvBjNJMzwn1U8wOWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879687; c=relaxed/simple; bh=Ty5sURnTFWVnfbnIBPkCCksC+Y0itcL3NCDAmhozFyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=inLPefpyQDsIkIbgGsvbqa6GjxlQVoXNhdSXOOWKQQkksNb6gr/PwNzh8AhPeDI4MExrmdQG98S33v2t/wdMbpQVwkerDlDrE/VJhfFRosWz0Na5nMgSWmvKTlxwd8tPC5ZfaCvNfTGdFre6w8TjIDB5RV34bGboWDa+rrpPzkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KLVei2OK; arc=none smtp.client-ip=74.125.82.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KLVei2OK" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-135200bc7d2so448298c88.0 for ; Fri, 15 May 2026 14:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879684; x=1779484484; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MWgkYkzNwtEfRsNqnMWcy72BtOHvVyAwK+VJB1q1fiM=; b=KLVei2OKgLlVbyE5IdOmusvNTPkfJwn3fij9b7ObCFleGFkdpcXRFdMUq/VyKNaknc SycDyYTf5pW+1obDdaJCDNorLVWlM/gWhFNomolW60ut0gTEtjt7d88Ok7bK1KPJc2pk OcHWM9tF7izGnrarj96Bm0zFPjqszojR+nShHoiUw/R71rO1+tlz4EwBCz29nX+9g2Iy 07TE0jykFzYdtS7a/8cjPTimcxOYYFoL1CoIKQTaVgz0ALK9BkAH5lpIRaHgkqCtj9Qj MDcy53FNoSF0UP1EEQKKbMel7vzhhXIG/sftDh9E2lIlvznng+81oqD1Xz719k5aZmQy CrbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879684; x=1779484484; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MWgkYkzNwtEfRsNqnMWcy72BtOHvVyAwK+VJB1q1fiM=; b=VLHPs5RhzLv6eI57lwEW8KPZtEje7fAbikkLAvUTpa5WxeoWWWLc3kmtWDPNNyeHlD T/LKaJ8ofuku5D1hcgnXDKUOlKRpPKUqcl607m7cHxde7NOEEWuTv8gj9IOlbe8s3+9/ 7fScxs0Pnt0+EfzDWd1iFvYBOlt4NFjeeBtBoZ/4XV0wpGFD96033P4ChiV/b6uaM0v/ kgMWi4PuflMhEyMXzkwca3Xa/KtjvBmHi/ZcOeS7arGr7ouA5HQfEZUCBXqA/queyH8w TFOEuk55emiNSBLeJalKSQotPRXqIo9gZWHiqUTYjk3J62ys8N45M6ODL+a/AyfJU4oD iNxw== X-Gm-Message-State: AOJu0Yw42Nt2tG8E2lONpK7YMXR9FibCTrD9efKI6a19wgbP5RNzWUo2 Duh/e2iLUMUmAkity1ZDoCjRnYlSPITJEL0NHUENK+vQKytL6jItnM96WL4qtWFF X-Gm-Gg: Acq92OFxyTtyWNGR03ri3snsi53He0rFdMWc7Juj708ZGwjb9gJHVFatvAdkZtCOoCy wvE1KFSoSfIgyqxer7UUcFFDwfJpPmdQsshI+Ew/Y5R7O4Ho8koiwWd6i3TMg0+DtIdl7G2DG3g 7UeJ8b9MqH+xXxrj7R3JjKolTBCtQhLdDNcVVN7SvaQsKlFd1J3IJ4rWRsJ1xThrUDG1c/M9fnl /HRPCG3i5l/U8JJD7iE1YeLOrUcRAhd9H/aTfRzo1cXcMF/iPwAOWGgtoemjnd4H4meXk9cF31k B7/HXHirfqv3JgSTXdp00Xio6a9d087kxItwbc5liKNX/ttElxpJ3qk+jCeC87ZwqocYzaIGSdA lbwMKDqmUhDu0MD768SArymO2jNih5qypOKrD73wPuq0QP1MDOF8fMfMcDKKDKXV5tW8+f20+4n AZNwjh1OJUxYGEVqm387YbQVFF5xUTd+Nz9ijIBCyS6Q== X-Received: by 2002:a05:7022:928:b0:130:ca3d:fa74 with SMTP id a92af1059eb24-13504a545d4mr2603120c88.42.1778879684210; Fri, 15 May 2026 14:14:44 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cbdcf140sm11364153c88.5.2026.05.15.14.14.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:43 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 11/38] tpm/tpm_tis: Close all localities Date: Fri, 15 May 2026 14:13:43 -0700 Message-ID: <20260515211410.31440-12-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" Close all the localities while initializing the TPM driver. The addition of TCG DRTM support requires this. Co-developed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_cor= e.c index e2a1769081b1..1fbb74a565f4 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1111,7 +1111,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_= tis_data *priv, int irq, u32 intmask; u32 clkrun_val; u8 rid; - int rc, probe; + int rc, probe, i; struct tpm_chip *chip; =20 chip =3D tpmm_chip_alloc(dev, &tpm_tis); @@ -1176,6 +1176,15 @@ int tpm_tis_core_init(struct device *dev, struct tpm= _tis_data *priv, int irq, goto out_err; } =20 + /* + * In order to comply with the TCG DRTM specification, relinquish all + * the localities. + */ + for (i =3D 0; i <=3D TPM_MAX_LOCALITY; i++) { + if (check_locality(chip, i)) + tpm_tis_relinquish_locality(chip, i); + } + /* Take control of the TPM's interrupt hardware and shut it off */ rc =3D tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); if (rc < 0) --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D3C63EE1EE for ; Fri, 15 May 2026 21:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879689; cv=none; b=bBcaQCZCEYptIQtYqFJGRlCMBlLoZVk3RS2LT2M8T43Qt+XT40te3Po89Kh13fGF/v5EPFcjdN2456aBCRYPArTz/bIDm8GPnRG3tmF+WbiZbb9U3vSa1dkKRT0AYz/Ue0+UzCYuKWTc1tkIYLCmIKcYFYszzXqMwhJyiI7n4X0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879689; c=relaxed/simple; bh=YM/w2wtPzdX3RmdPxAtDTeVwrQxqc/8DXfB4OKpz4wQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IqhAX5wKgJZMKB98MGSbKZYVw+nbLk7HpyQgLodr7kdCSZeazNagjVWZyQthe6cjt2RArHY6Nq0EXYb3+KfEsy/dIFVdvlqt9zXlgaUkOvQJDWrMBNhUScI5Yvr91/F1GGgX8ucn873/2vT82upmkkZlxYzwX+7ZKK0op/lMHT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=os1ZZCh1; arc=none smtp.client-ip=74.125.82.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="os1ZZCh1" Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-2ee990e8597so744870eec.1 for ; Fri, 15 May 2026 14:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879687; x=1779484487; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4LfQsLm4zjgCBkokqW/LNO8kguAx5+WYTFTmZDrk46E=; b=os1ZZCh1Md5gOjiBCwlPZ8Xc0AtQRHNjZE2TTlYHhwXTWbiGH1LZ28DRDrwvDjkTCh RF2iReOYGP8hfSbbsgWHpDOgJMDFZrrqDRHbWAZVz6+qRHDE5VimMybaJqXfo7iwu/Vu bL2pEabGzP2Py4vEGE+SnI+eS7oK2Z6USfzb6tHMs7uFzrK/5kqdxByPrvaKakbqzah3 utLW/Fz+u7uCZeaSZr9GkdYoovYiDGMfK3prCTQc0Vk9DwkaxIRZct14h5X+5fvWjZd9 4rLtBS9EMiO8Y0RlqNuQ+ckh4OomzPGg1JQ99NjlNsWLLm/r9IqF/T7RCt3ZzIRU71QN Y0uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879687; x=1779484487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4LfQsLm4zjgCBkokqW/LNO8kguAx5+WYTFTmZDrk46E=; b=re98F3FrlUQM2q+YmN58KuLDnw+dP2RpqkqltF6i/POxwJR8Iwggo6e8Fkp3WtKMZ/ 2zlTNYgY8ZJyvfcLN435EiUlpQ6dOyLxghghsQvRNGjTeMuqIGlVWmVSf0jEVXxBs3Iu BlSIeVLMFQuQC0nsyN4bnU+fQTgESMi0IHVkTh9w6y8W5YbkZ/d0/d+R5hZdFQHi7S0E tG1ozLXurfEUb82JJRd7yb2arxeeO3fufsQp0gNDbpQQ31jTiMWOmffYSabLRFIX6iEo 7WoEiUQbNxNWZOXwuG0bj1c0vgqD2DpjzWu8opARJHautMcX612YQkC+kjVrt5Bg7LO/ vguA== X-Gm-Message-State: AOJu0YxNQDuGzVUmhilOH3q/Vo8Mc5s4PZfbf0lBdkXPguaYHxLPpW7S cvd4NXFFeMyv5qcgy5TAkJhphb3Z1Q2PQh+n65FVl6HlYn4unmMFNOYbx/9JBfHZ X-Gm-Gg: Acq92OHZXdUWNPPV4YdUlis/176UFib42wj8qnhy5PwSQ4YXMe8Wy9iDhGjrsPD8iXF nT1hWrzZSSaSll1pR2PrAH4S3OIkppeoViddjhWIA8MEKVGmjabMZrWJ1qyt111CkOy5Hc4VThL N0dG969jiGFQXHPsQMT/W3qDzb8yKYrKB3nSVmcEAr9/YevENGmEcVNtjtOLbt/dgs+341u/nu7 0k4VYLuzjn4mwGgKPuxG2OC3cckfW+xJEYhWD8X6DadgvxalGkDKBnAa4pwcU6nmhkWA6g7ektf FGB+7a7OXS9iG3jnLG++gOfgiHzc1qr/PizVqgJET/eiknRKnI9I7ITS1OaC6V04SCS9M/huKmR ToRyNQL3j6I84s4frPQ7F2Km8Yp4eAn6YB8MlSeYKgQIVIIKfAhGQSpGHE4JSoCjZoZqQ09+3ti 0aOcSS7zSciGhF+Z1vAFExJowpkywedtQ= X-Received: by 2002:a05:7300:a907:b0:2f0:c8b5:3dc7 with SMTP id 5a478bee46e88-30398680c36mr2863934eec.22.1778879686973; Fri, 15 May 2026 14:14:46 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30296dcb6c3sm9740068eec.19.2026.05.15.14.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:46 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 12/38] tpm/tpm_tis: Address positive localities in tpm_tis_request_locality() Date: Fri, 15 May 2026 14:13:44 -0700 Message-ID: <20260515211410.31440-13-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" Validate that the input locality is within the correct range, as specified by TCG standards, and increase the locality count also for the positive localities. Co-developed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm_tis_core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_cor= e.c index 1fbb74a565f4..70aba05f4ee1 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -179,7 +179,8 @@ static int tpm_tis_relinquish_locality(struct tpm_chip = *chip, int l) struct tpm_tis_data *priv =3D dev_get_drvdata(&chip->dev); =20 mutex_lock(&priv->locality_count_mutex); - priv->locality_count--; + if (priv->locality_count > 0) + priv->locality_count--; if (priv->locality_count =3D=3D 0) __tpm_tis_relinquish_locality(priv, l); mutex_unlock(&priv->locality_count_mutex); @@ -233,10 +234,16 @@ static int tpm_tis_request_locality(struct tpm_chip *= chip, int l) struct tpm_tis_data *priv =3D dev_get_drvdata(&chip->dev); int ret =3D 0; =20 + if (l < 0 || l > TPM_MAX_LOCALITY) { + dev_warn(&chip->dev, "%s: failed to request unknown locality: %d\n", + __func__, l); + return -EINVAL; + } + mutex_lock(&priv->locality_count_mutex); if (priv->locality_count =3D=3D 0) ret =3D __tpm_tis_request_locality(chip, l); - if (!ret) + if (ret >=3D 0) priv->locality_count++; mutex_unlock(&priv->locality_count_mutex); return ret; --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EC503EFFD5 for ; Fri, 15 May 2026 21:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879693; cv=none; b=qkf0taPEP6f/HQqQzSCkZKXopyMl36L5Qy+LvSo9QZX9+zX+Lpyn0/Ke4jjNW5G9DQsNLPipy69PxgWGeqAYKUmEhGb1pp0PiNZsNQ7BCTM0Agt+85EcoazVJbYpcS9o88Hr4lAmS3zDQvGJQMGdM7F9h+UCrhYpVMmKzLk/rOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879693; c=relaxed/simple; bh=AEsIZBvhIg+ptwqhrgMw5/o+SifZBkqY2LGhfABVAgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BsniWQpm8alGgR7bjVR/lQMhhHvp1pA/+O4TYQrNYHvk5Tipm0HF+aXHelsQpKTIpQhE3IjfGhBID6nHF+u8EyAqhsLkwA12kQvZv0aG9s5S/57nGfDPMafhevrSV2ceBQYKu5u36HYKd1SSbONfYYwEWTNcg7WqTZJGGw2d+7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=coBeEVvs; arc=none smtp.client-ip=74.125.82.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="coBeEVvs" Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-2f0ad52830cso402598eec.1 for ; Fri, 15 May 2026 14:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879690; x=1779484490; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JUJQNdeVMNwfKTOPs21LgA+X7O3xhgiTOeD6RQEitLA=; b=coBeEVvsyKMe+/GM59nTqRYYeTG/lbe6vF3i6caGpAAMgihF00MSEWu2XJ9Ny6jiAV m2O0yfD6B/RfRNMbB66uXqWrHopQsmWEwHWx/7/JFN/BpLWdDXDlnskqQSzdC1TMXDoL qNFJ0U7zX5STDkUASmgJZz8OM7L4az784r4w5ECU/JPafOUXY5BYTMWf39OwV/qmNtad SLSWqznff0nD6CJyrzCpNMrEooGH1nnuwhwIg5T4pyDwRQmb3f9V2jek6ebW8aQF9BUO 7075k5g8Ejy0Ihhy6rSwzmudgJyJfdCoAvIe0xieBbc+Kt3FX08LITXTSmOnbAsD60yb xjVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879690; x=1779484490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JUJQNdeVMNwfKTOPs21LgA+X7O3xhgiTOeD6RQEitLA=; b=rgFCbZ/UiA9qZFnavP55VhTfhBOESl7k/XDyS7XGHf6EtXEU921pJMJEni5+FjNtJd gIbkNORAE8IbJHxrr8IXhd5GJ2wkbLI0umNWiLXXHHk/8a9a6S9GNyPpmj2DuUjscJpK vHN+31Nf2r4KDPiE4PwH+VL1Jj6KyQiUorEuayKIikwu9ksobVAlopxbU8LPEV/4xvY2 UPyjmBaRtVEFU/XLrBr+NFq34jaow8LOyps9+NEdArq1C+c5N28FSlF4xo034/aubV7I 8GPBy7v0KQWXgsUVDdkyrlsEsB3M6dthQdajUFNO47Kh3MY99C65ISlErMCbDF57Aao6 Ho2Q== X-Gm-Message-State: AOJu0YwOYUllsTxWkM6bPusHUxzydCR0PXUvzuVMP6cqvPhdJ+K61DkW 0lU2mfaMwy0O0FtW/D9DZwesxfzk8ehFdPmQ8oVUaC3xxKTr/TyK78dokPgB+lJB X-Gm-Gg: Acq92OFGE2FKUitClXBDI5Z05j2ZMvE1Rocz7ZfdnVYeVoYIwQTalLTTr4FrNlHSsAx jRE0UtvX8Twl3icnbzcv+5JykTWao6WVaa9/AxFCRQ4y900Il/aaLBfOkUiEQWMuAc5iB1i9fqI OVAs73gz0/JikURLr8pilks4UU3RknLdX9qrnXQgUK+LfR5XNaPUwgQrqN571RjrTbm2oASW4tF jLc5LeY8DYMrd6XgFY4830snlRyPl4BqUhB2WWljKIDDUuCNPj9/nUA7u2IZQatkkeNzw6rcB0K 3lbf6l9R10LXJW7vksEZQZcNJwERt7loKrLXd8sPfFaSu9z0VXoMeVFRZ96HvR0ZumYPS2/fY2i 2rBgsHtZjDhkZonclBaC6AzamphyDcuTu2tL5zbq4iwCUyLJldpeQdXygsAo9X0VCEJdcVH7mtx Hv0n4RSHLRhWbiz+M+1zQuHWJU1rBk3Ls= X-Received: by 2002:a05:7300:4307:b0:2ea:5057:a331 with SMTP id 5a478bee46e88-30398655963mr2890920eec.21.1778879689799; Fri, 15 May 2026 14:14:49 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30294adddaasm8120311eec.13.2026.05.15.14.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:49 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 13/38] tpm/tpm_tis: Allow locality to be set to a different value Date: Fri, 15 May 2026 14:13:45 -0700 Message-ID: <20260515211410.31440-14-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" Provide a one-time function tpm_chip_set_locality() for setting the correct locality needed by DRTM launches. Co-developed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm-chip.c | 35 ++++++++++++++++++++++++++++++++- drivers/char/tpm/tpm_tis_core.c | 2 ++ include/linux/tpm.h | 4 ++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 0719577e584d..a9620b27b63d 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -44,7 +44,7 @@ static int tpm_request_locality(struct tpm_chip *chip) if (!chip->ops->request_locality) return 0; =20 - rc =3D chip->ops->request_locality(chip, 0); + rc =3D chip->ops->request_locality(chip, chip->kernel_locality); if (rc < 0) return rc; =20 @@ -343,6 +343,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, } =20 chip->locality =3D -1; + chip->kernel_locality =3D 0; return chip; =20 out: @@ -658,3 +659,35 @@ void tpm_chip_unregister(struct tpm_chip *chip) tpm_del_char_device(chip); } EXPORT_SYMBOL_GPL(tpm_chip_unregister); + +/** + * tpm_chip_set_locality() - Set the TPM locality the kernel uses + * @chip: &tpm_chip instance + * @locality: new locality + * + * This a one time function to set the locality the kernel driver + * uses. Returns zero or POSIX error on failure. + */ +int tpm_chip_set_locality(struct tpm_chip *chip, u8 locality) +{ + int ret; + + if (locality >=3D TPM_MAX_LOCALITY) + return -EINVAL; + + ret =3D tpm_try_get_ops(chip); + if (ret) + return ret; + + if (!(chip->flags & TPM_CHIP_FLAG_SET_LOCALITY_ENABLED)) { + tpm_put_ops(chip); + return -EPERM; + } + + chip->kernel_locality =3D locality; + chip->flags &=3D ~TPM_CHIP_FLAG_SET_LOCALITY_ENABLED; + tpm_put_ops(chip); + + return 0; +} +EXPORT_SYMBOL_GPL(tpm_chip_set_locality); diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_cor= e.c index 70aba05f4ee1..cf6d929ce5aa 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1125,6 +1125,8 @@ int tpm_tis_core_init(struct device *dev, struct tpm_= tis_data *priv, int irq, if (IS_ERR(chip)) return PTR_ERR(chip); =20 + chip->flags |=3D TPM_CHIP_FLAG_SET_LOCALITY_ENABLED; + #ifdef CONFIG_ACPI chip->acpi_dev_handle =3D acpi_dev_handle; #endif diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 0db277af45c3..4a26a49040b9 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -159,6 +159,8 @@ struct tpm_chip { =20 /* active locality */ int locality; + /* the locality used by kernel */ + u8 kernel_locality; =20 #ifdef CONFIG_TCG_TPM2_HMAC /* details for communication security via sessions */ @@ -197,6 +199,7 @@ enum tpm_chip_flags { TPM_CHIP_FLAG_HWRNG_DISABLED =3D BIT(9), TPM_CHIP_FLAG_DISABLE =3D BIT(10), TPM_CHIP_FLAG_SYNC =3D BIT(11), + TPM_CHIP_FLAG_SET_LOCALITY_ENABLED =3D BIT(12), }; =20 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) @@ -244,6 +247,7 @@ static inline ssize_t tpm_ret_to_err(ssize_t ret) extern int tpm_is_tpm2(struct tpm_chip *chip); extern __must_check int tpm_try_get_ops(struct tpm_chip *chip); extern void tpm_put_ops(struct tpm_chip *chip); +int tpm_chip_set_locality(struct tpm_chip *chip, u8 locality); extern ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf, size_t min_rsp_body_length, const char *desc); extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4B173ED121 for ; Fri, 15 May 2026 21:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879695; cv=none; b=eyZnd3RJQQE/yPRY0emgot/v+P2mJYc74hSmBd68V/gJSLqnDJuD4aiqMygSPs7S+JiEgJpAasHNu3KU9e2XLg33wp4lRWPnkgPatU+vh1SgXPU68CdrvYBajN0b7Zyk1SYdfvVoyde9JMlgWvtOL7gyxCG6fdEKKtYVrgJxEx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879695; c=relaxed/simple; bh=1PNKH8ntc5kC54kp2fuFbfDzJKv8jvUIR3tksHCBOAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BXAca/5ewln0nKi/7ReYRYCRMiuN7IZ3Ea8oFimgiN+veXpB+i55NoQaiJfaxzPl5y3i6qoi3GsAZy8XP5GEG9Qy2ARdNG7uSTmnspkNDKWfrigDdZCraRrg4XGECUlCM930gq8yG8Mjx2hY0qR50ChNZ231X0bh3BAu4aJoNfY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=n4B9AeC9; arc=none smtp.client-ip=74.125.82.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n4B9AeC9" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-132c338a537so1026654c88.0 for ; Fri, 15 May 2026 14:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879693; x=1779484493; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0Web2s5uVg47aYyCtELeKAMQeYbkPbYPk/ttB5U3wMg=; b=n4B9AeC9zDx0FEy61vxCAx34bh29XmU3Z5BLbMHLAWE6O/wVfLEQ7FP3ZxbJ1AoO+3 Q4IHV3iLrro6B9OWZyJ0ySCAfr2ANN3nJAxGRaz1CK03Eoyc8cXXyFDi1p4zrIbByLoF G/cWmmNLtCXFwLtotFmS8RwPOGBQ8Im+/5o1GAj6F/uWiCeG+pViN8+NaZVMMiMIq38q cMdvzU+l67iNywwvtRHAUcUPuYfZ6kAu9H14D7UOnAwYg1752Zphkw9oNYZwOz3VTv+A VXOCI69Ejr5PPmdrz6GB/RqJEsB8H1kWK3SuoRQfFy01STwODufsTeKZq0c9so5S+Zxy guMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879693; x=1779484493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0Web2s5uVg47aYyCtELeKAMQeYbkPbYPk/ttB5U3wMg=; b=nazBxs+KVupMyg9GSlifKeE49q3cohkzNyDdCrWVadqNT9E37DGsKJ0rwAcabQ3lXa SIE9QiyOxfh5QLWKXZJkdyljNlI/IlNaDcGnl5eRPo5IKOVfTBCj/11MLIVe/Fo2bRS8 Od+Jn6bqnvWgGewQbOQJ6cqcOYKlXp+Iip6RxNDdBWBqckE9u4RbMgmNujjezbD8o6dr F11lOXUIkwU/fvoBXaT8MZkcgqitU2cMSBtWWNHzxIym+Nqs7n8jZA/jGkGm8aLIAc7u GJlfXpFF9YaJ6MNwCgJVkDZfMX9kJRtblfDw0pKgjmls3yWV2XfNg9KlkqWyyDznSgsn LQ2Q== X-Gm-Message-State: AOJu0YxK2wiu3w9NWVF6xt64rUukTisPeAPhctJ2nWhXytEOMhQSzaXI oa+7hKcHPCUic/unVaMgY70Nk6W92FYbxWUdcRmkN9zJs3QXn4+XUEOoMWRrtL8G X-Gm-Gg: Acq92OGnLJqnCLIsEdhxMVROCkJup99r6psRZfth2xAbDfugvXemUNmZWUDlOub84/Q qCKJ/lksOktrP+sLOPzNd+AVQNDqf2zi+GW9vMMhvKAqPN0Aqnf44yTeTZameaIjpYlXEavA/lW BBDajx+QeHIb//1siK3AYdLUgtp7jOTPEZ+GL8WPXqJ0YFBjehoU7DaS+wznorsWsJbBnXQ2KKj sTm5zoxz2aFbfwh1LpUVFWyVyk6hxBfRPgCS0eEtwlJ93CZKArJQcEUWK1BjC3we9t0jUOSJdYo lFjgGPsQm/0pd89Vmf7Q5zvXe4uVi9st/yfeTdVSheAAoR3XWp1nnr1PzGXLjFz5aD+noRFOwP6 eFc7+4aSaXp3whHF9qm33t7PvmDBfUL8QENIjVbz3DCImu/ZrCzSXkc6PsdUeHfEmS0HEXHWCiX 8ZZsSReGB9qxI2IhQ1sg39gOwgVWbFyFQ= X-Received: by 2002:a05:7022:79d:b0:12a:6abf:ab1c with SMTP id a92af1059eb24-134ffe943c0mr2448441c88.11.1778879692592; Fri, 15 May 2026 14:14:52 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cc3490bcsm9740184c88.15.2026.05.15.14.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:52 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 14/38] tpm/sysfs: Show locality used by kernel Date: Fri, 15 May 2026 14:13:46 -0700 Message-ID: <20260515211410.31440-15-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" Expose the current locality used by the kernel TPM driver via the sysfs interface. Co-developed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm-sysfs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index f5dcadb1ab3c..772c4ae67957 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -308,6 +308,14 @@ static ssize_t tpm_version_major_show(struct device *d= ev, } static DEVICE_ATTR_RO(tpm_version_major); =20 +static ssize_t locality_show(struct device *dev, struct device_attribute *= attr, char *buf) +{ + struct tpm_chip *chip =3D to_tpm_chip(dev); + + return sprintf(buf, "%u\n", chip->kernel_locality); +} +static DEVICE_ATTR_RO(locality); + #ifdef CONFIG_TCG_TPM2_HMAC static ssize_t null_name_show(struct device *dev, struct device_attribute = *attr, char *buf) @@ -335,6 +343,7 @@ static struct attribute *tpm1_dev_attrs[] =3D { &dev_attr_durations.attr, &dev_attr_timeouts.attr, &dev_attr_tpm_version_major.attr, + &dev_attr_locality.attr, NULL, }; =20 @@ -343,6 +352,7 @@ static struct attribute *tpm2_dev_attrs[] =3D { #ifdef CONFIG_TCG_TPM2_HMAC &dev_attr_null_name.attr, #endif + &dev_attr_locality.attr, NULL }; =20 --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f50.google.com (mail-dl1-f50.google.com [74.125.82.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E7C53F788A for ; Fri, 15 May 2026 21:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879700; cv=none; b=Nni8I9u69eJQs9pp8yQ2aIS7OQQkU3A5z6KhR3ifg8PE7p6EwwEMvBcMyyt29PoIFGcLPaGVtLar2RNl3ixCIaYhGCeSK8Xiix5fygrOhw5myZ1K6hyn5+7do1uqY3oG5sLhKMBfVVgLXNPQJvqI+23lBDTh1u8FOL31rHW9e8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879700; c=relaxed/simple; bh=9YS4BuHjnfo+1IReQ3Kb+NmIPLFdp9Qh7Ox7isDv3NQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PLBfavyC/UpZdHfNwujrAyLsI93FO4wd+tVKeDm5OrrWtOkRYVoSbxn7Pky+ZvK3wmOEh6YhXasVGkM5RnFVe8L696O4iLJVKXjob4qg33lYQFfHTGqY8hgXd1FNdYz2tPNsplqeGpR9tkZlbaZOcZ7ZxHKYiZjYY7udVxd1g68= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=qCrdw4Ik; arc=none smtp.client-ip=74.125.82.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qCrdw4Ik" Received: by mail-dl1-f50.google.com with SMTP id a92af1059eb24-12c88e5f4aeso129686c88.0 for ; Fri, 15 May 2026 14:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879696; x=1779484496; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yYV487dim1u7McKHcszztZC/VNez+ruEau/ZSoQzK6U=; b=qCrdw4IkzM+j5ub2ZAZRhtcI5ZeBerH/N3TylpfGqhdbGlvZSp/9i1BoGDwUulwzo9 ih/aJUNsCDMS6I+Q7FeWj6PxXeX4IvoICuH44XRwqTRZlnv175fpVOcQsPHELZ1J/TPA xGhllREnLYSEjsHuTXm9/loijMK3zFRrFxkKc87as44299Fkzfm7SJvFBznYMdUehXPd svCpwIkr40vc9bhvSwLk5GbbZ3xWupFtjA6HGqwoU1XkeATVDX3AFNx1so1Vkcuv7PyU 4jgw9BxWdIWwX8st9gJM5b1CaIlqwwkW3IlY+i/O7Zhtqc5JY5QNsHue9JR4N3xcJkWV PfrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879696; x=1779484496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yYV487dim1u7McKHcszztZC/VNez+ruEau/ZSoQzK6U=; b=rIipR5Hba//M4WUTc98akYy4rcr5Un0g0h28X9spdu/tQBp+ehy6BXzZQo7Tllf+es ZGn4Vx7+Hg8Fy91mhjErOR8/73ZzQEKcUZ8g0ixo3PYqe2WYoKV2p8AmtmCwL9YIlnch MBEGQtJi5JI1JenVSBwKYFRlj36DUXfGQTV5gdutwWkiFW70iVe1RkXz5+cfYWttD670 zZH05RvGRYdNWS5aLUK+mSt0EBCSyCIM0by0ABcyZ5p++CUnY3tEHL1YjvL9i6ucdEXc VGAd9nq9hqqqZZP361cJTsEvoTnUKrFwlWasDr98Tjiug/2pUKdBdnFoFb98j3exCAV5 7IIA== X-Gm-Message-State: AOJu0YwqvQqc771zoI6S7fKYWchuV0UAM7H5oT89sJA1YJDQd546mIEU y0cTbvkmRCeR9Eb1m2M3FOd5Nolli1F1xaG2jAiW8gHjSXgW7iSB1W4hoV4X5H+s X-Gm-Gg: Acq92OGmnyWDNmJH5MuhjFHKfXhBczl+CUSdyqImODMzDl3Ui/zzVLZZcn1SHvp3kwT r9qbStttVMm1JswFM11PbncKB/utTdpXzxRGuN2ow1IeU+Fai3fSMJJhttB7HGpdWrF159dUV+N N6jxj5bU+JI0SpCL3eVdVvQA2L4qpF0YnbFovAmk0MXKrXym62VO4rh6OkLpObQQLk8idPtwH6v 2qA1cCTDY2l9zodyLMJ0R5HPz6pW8UE7D3yo9DUvbGnt7u3THKMVyxgMdrlv5NHTIyaQAI+UsQy vQVcwj/7TMmnykGJaP2PdvAkX8kLMjm+YsoBEY++TwHALbJQaVDnsaditFaqwXW0/YfpAVOKtK7 hBeF2EPCnDNS3gIHmC7XKp1huhEf/RvSOhx8etget3XgONbPDMshzqaZayx2Li0TSK3rb5XvnQR vnqOZQmM7l+OPtBMKhnC1wxtOOlDwPZYk= X-Received: by 2002:a05:7022:301:b0:12a:6d05:3938 with SMTP id a92af1059eb24-134ffc6a83fmr2842716c88.7.1778879695574; Fri, 15 May 2026 14:14:55 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cb5b3c20sm11525407c88.0.2026.05.15.14.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:55 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 15/38] Documentation/security: Secure Launch kernel documentation Date: Fri, 15 May 2026 14:13:47 -0700 Message-ID: <20260515211410.31440-16-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" Introduce documentation for the Linux Secure Launch feature. Co-developed-by: Ross Philipson Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- Documentation/arch/x86/boot.rst | 8 + Documentation/security/index.rst | 1 + .../security/launch-integrity/index.rst | 9 + .../launch-integrity/secure_launch.rst | 681 ++++++++++++++++++ 4 files changed, 699 insertions(+) create mode 100644 Documentation/security/launch-integrity/index.rst create mode 100644 Documentation/security/launch-integrity/secure_launch.r= st diff --git a/Documentation/arch/x86/boot.rst b/Documentation/arch/x86/boot.= rst index dca3875a2435..eb53da9dcbbf 100644 --- a/Documentation/arch/x86/boot.rst +++ b/Documentation/arch/x86/boot.rst @@ -482,6 +482,14 @@ Protocol: 2.00+ - If 1, KASLR enabled. - If 0, KASLR disabled. =20 + Bit 2 (kernel internal): SLAUNCH_FLAG + + - Used internally by the setup kernel to communicate + Secure Launch status to the kernel proper. + + - If 1, Secure Launch enabled. + - If 0, Secure Launch disabled. + Bit 5 (write): QUIET_FLAG =20 - If 0, print early messages. diff --git a/Documentation/security/index.rst b/Documentation/security/inde= x.rst index 3e0a7114a862..f89741271ed0 100644 --- a/Documentation/security/index.rst +++ b/Documentation/security/index.rst @@ -20,3 +20,4 @@ Security Documentation landlock secrets/index ipe + launch-integrity/index diff --git a/Documentation/security/launch-integrity/index.rst b/Documentat= ion/security/launch-integrity/index.rst new file mode 100644 index 000000000000..fb9f63f01056 --- /dev/null +++ b/Documentation/security/launch-integrity/index.rst @@ -0,0 +1,9 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +System Launch Integrity documentation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. toctree:: + :maxdepth: 3 + + secure_launch + diff --git a/Documentation/security/launch-integrity/secure_launch.rst b/Do= cumentation/security/launch-integrity/secure_launch.rst new file mode 100644 index 000000000000..b4c61fdceaf0 --- /dev/null +++ b/Documentation/security/launch-integrity/secure_launch.rst @@ -0,0 +1,681 @@ +.. SPDX-License-Identifier: GPL-2.0 +.. Copyright (c) 2019-2026 Daniel P. Smith + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Secure Launch Overview +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +:Author: Daniel P. Smith +:Date: February 2026 + +Overview +=3D=3D=3D=3D=3D=3D=3D=3D + +The TrenchBoot project initiated development of the Secure Launch kernel +feature to establish a generalized framework for dynamic root-of-trust +measurement (DRTM). The effort addresses two core objectives: (1) exposing= the +platform-specific launch protocols (e.g., Intel TXT, AMD SKINIT, Arm DRTM,= and +potentially OpenPOWER) directly to the Linux kernel, and (2) enabling the +kernel to act as the dynamic launch initiator. This design provides the +necessary foundation for the Linux kernel to support a broad range of dyna= mic +launch use cases without platform-specific user-space intermediaries. + +.. note:: + A quick note on terminology. The larger open source project itself is + called TrenchBoot, which is hosted on GitHub (links below). The kernel + feature enabling the use of the x86 technology is referred to as "Secu= re + Launch" within the kernel code. + +Goals +=3D=3D=3D=3D=3D + +The primary use case initially targeted by the TrenchBoot project is the +ability for the Linux kernel to be launched via a dynamic launch during the +early boot sequence. In this scenario, the dynamic launch is initiated by a +bootloader that has been extended with Secure Launch support. The first +bootloader targeted was GRUB2. + +An essential part of establishing measurement-based launch integrity is +ensuring that all components intended for execution (kernel image, initrd, +etc.) and all configuration data that will affect kernel execution (command +line, boot parameters, etc.) are measured prior to execution. These +measurements are then stored securely using the Trusted Platform Module (T= PM). + +Both Intel TXT and AMD dynamic launch implementations use the TPM for this +purpose. The architecture is designed so that a dynamic launch unlocks a +specific set of Platform Configuration Registers (PCRs) reserved for DRTM +(Dynamic Root of Trust for Measurement) measurements. These registers are = known +as the **DRTM PCRs** (PCRs 17-22). + +Further details on the hardware mechanisms are documented in Intel's Trust= ed +Execution Technology specification for the ``GETSEC`` instruction and AMD's +documentation for the ``SKINIT`` instruction. See the `Resources` section = for +references. + +.. note:: + Currently, only Intel TXT is supported in this first release of the Se= cure + Launch feature. AMD/Hygon SKINIT and Arm support will be added in a + subsequent release. + +To enable the Linux kernel to be launched via the Intel ``GETSEC`` instruc= tion, +a Secure Launch entry point is built into the mainline kernel. This entry = point +is responsible for handling the specific processor state that the dynamic +launch process leaves the Bootstrap Processor (BSP) in. + +The Secure Launch entry point performs the earliest possible measurements = of +all components and data that the kernel will consume (kernel image, initrd, +command line, boot parameters, etc.). Both this entry point code and subse= quent +kernel initialization code must also correctly handle the specific state t= hat +the dynamic launch leaves the Application Processors (APs) in. + +Design Decisions +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Several design decisions were made during the development of the Secure La= unch +feature. The primary guiding principle was to minimize the modifications t= o the +existing boot path of the kernel as little as possible. + +The following illustrate how the implementation followed these principle: + + - All the entry point code necessary to properly configure the system post + launch is found in sl_stub.S in the kernel image. This code + validates the state of the system, restores necessary system operating + configurations and properly handles post launch CPU states. + - Support is introduced in the SMP boot code to properly wake the APs. Th= is + is required due to the unique state the dynamic launch leaves the APs in + (i.e. they cannot be woken with the standard INIT-SIPI sequence). + - Final setup for the Secure Launch kernel is done in a separate Secure L= aunch + module that is loaded via a late initcall. This code is responsible for + setting up the securityfs interface to allow access to the TPM event lo= g and + public TXT registers. + - On the reboot and kexec paths, calls are made to a function to finalize= the + state of the Secure Launch kernel. + +Basic Boot Flow +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Outlined here is a summary of the boot flow for Secure Launch. A more deta= iled +review of the Secure Launch process can be found in the Secure Launch +Specification (a link is in the `Resources`_ section). + +Pre-launch: *Phase where the environment is prepared and configured to ini= tiate +the secure launch by the boot chain.* + + - The SLRT is initialized, and dl_stub is placed in memory. + - Load the kernel, initrd and ACM [4]_ into memory. + - Set up the TXT heap and page tables describing the MLE [1]_ per the + specification. + - If non-UEFI platform, SLRT is registered in boot params and dl_stub is + called from the legacy setup kernel. + - If UEFI platform, SLRT registered with UEFI and kernel efi-stub support= calls + dl_stub after executing EBS. + - The dl_stub will prepare the CPU and the TPM for the launch. + - The secure launch is then initiated with the GETSET[SENTER] instruction. + +Post-launch: *Phase where control is passed from the ACM to the MLE and th= e secure +kernel begins execution.* + + - Entry from the dynamic launch jumps to the SL stub. + - SL stub fixes up the world on the BSP. + - For TXT, + - SL stub wakes the APs, fixes up their worlds. + - APs are left in an optimized (MONITOR/MWAIT) wait state. + - SL main does validation of buffers and memory locations. It sets + the boot parameter loadflag value SLAUNCH_FLAG to inform the main + kernel that a Secure Launch was done. + - SL main locates the TPM event log and writes the measurements of + configuration and module information into it. + - The SMP bring up code is modified to wake the waiting APs via the monit= or + address. + - SL platform module is registered as a late initcall module. + - SL platform module initializes the securityfs interface to allow + access to the TPM event log and TXT public registers. + - Kernel boot finishes booting normally. + - SEXIT support to leave SMX mode is present on the kexec path and + the various reboot paths (poweroff, reset, halt). + +PCR Usage +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The TCG DRTM architecture defines three PCRs for dynamic root of trust +measurement: + +- PCR.Details (PCR 17) +- PCR.Authorities (PCR 18) +- PCR.DLME_Authority (PCR 19) + +Further details on the semantics of the Details and Authorities PCRs are +available in the TCG DRTM Architecture specification. + +The Linux kernel's Secure Launch implementation adheres to the TrenchBoot +Secure Launch Specification. It utilizes a measurement policy stored in the +`Secure Launch Resource Table` (``SLRT``) to determine both what to measur= e and +into which PCR each measurement should be extended. + +This policy makes it possible for the kernel to store its own DRTM measure= ments +(such as an external initrd image) into **PCR.DLME_Detail** (PCR 20). When +combined with storing user authority information into **PCR.DLME_Authority= ** +(PCR 19), it enables sealing and attestation across different combinations= of +platform and user details/authorities. + +An example of this approach was presented in the FOSDEM 2021 talk titled +"Secure Upgrades with DRTM". + +Configuration +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The settings to enable Secure Launch using Kconfig are under:: + + "Processor type and features" --> "Secure Launch support" + +A kernel with this option enabled can still be booted using other supported +methods. + +To reduce the Trusted Computing Base (TCB) of the MLE [1]_, the build +configuration should be pared down as narrowly as one's use case allows. +Fewer drivers (less active hardware) and features reduce the attack surfac= e. +As an example in the extreme, the MLE could only have local disk access wi= th no +other hardware supports except optional network access for remote attestat= ion. + +It is also desirable, if possible, to embed the initrd used with the MLE k= ernel +image to reduce complexity. + +The following are important configuration necessities to always consider: + +IOMMU Configuration +------------------- + +When doing a Secure Launch, the IOMMU should always be enabled and the dri= vers +loaded. However, IOMMU passthrough mode should never be used. This leaves = the +MLE completely exposed to DMA after the PMRs [2]_ are disabled. The current +default mode is to use IOMMU in lazy translated mode, but strict translated +mode, is the preferred IOMMU mode and this should be selected in the build +configuration:: + + "Device Drivers" --> + "IOMMU Hardware Support" --> + "IOMMU default domain type" --> + "(X) Translated - Strict" + +In addition, the Intel IOMMU should be on by default. The following sets t= his as the +default in the build configuration:: + + "Device Drivers" --> + "IOMMU Hardware Support" --> + "Support for Intel IOMMU using DMA Remapping Devices [*]" + +and:: + + "Device Drivers" --> + "IOMMU Hardware Support" --> + "Support for Intel IOMMU using DMA Remapping Devices [*]" --> + "Enable Intel DMA Remapping Devices by default [*]" + +It is recommended that no other command line options should be set to over= ride +the defaults above. If there is a desire to run an alternate configuration, +then that configuration should be evaluated for what benefits might +be gained against the risks for DMA attacks to which the kernel is likely +going to be exposed. + +Secure Launch Resource Table +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +The Secure Launch Resource Table (SLRT) is a platform-agnostic, standard f= ormat +for providing information for the pre-launch environment and to pass +information to the post-launch environment. The table is populated by one = or +more bootloaders in the boot chain and used by Secure Launch on how to set= up +the environment during post-launch. The details for the SLRT are documented +in the TrenchBoot Secure Launch Specification [3]_. + +Intel TXT Interface +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The primary interfaces between the various components in TXT are the TXT M= MIO +registers and the TXT heap. The MMIO register banks are described in Appen= dix B +of the TXT MLE [1]_ Development Guide. + +The TXT heap is described in Appendix C of the TXT MLE [1]_ Development +Guide. Most of the TXT heap is predefined in the specification. The heap is +initialized by firmware and the pre-launch environment and is subsequently= used +by the SINIT ACM. One section, called the OS to MLE Data Table, is reserve= d for +software to define. This table is set up per the recommendation detailed in +Appendix B of the TrenchBoot Secure Launch Specification:: + + /* + * Secure Launch defined OS/MLE TXT Heap table + */ + struct txt_os_mle_data { + u32 version; + u32 reserved; + u64 slrt; + u64 txt_info; + u32 ap_wake_block; + u32 ap_wake_block_size; + u8 mle_scratch[64]; + } __packed; + +Description of structure: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Field Use +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +version Structure version, current value 1 +slrt Physical address of the Secure Launch Resource Table +txt_info Pointer into the SLRT for easily locating TXT speci= fic table +ap_wake_block Physical address of the block of memory for parking= APs after a launch +ap_wake_block_size Size of the AP wake block +mle_scratch Scratch area used post-launch by the MLE kernel. Fi= elds: +=20 + - SL_SCRATCH_AP_EBX area to share %ebx base pointe= r among CPUs + - SL_SCRATCH_AP_JMP_OFFSET offset to abs. ljmp fix= up location for APs + - SL_SCRATCH_AP_STACKS_OFFSET offset to AP startup= stacks in wake block +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Error Codes +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The TXT specification defines the layout for TXT 32 bit error code values. +The bit encodings indicate where the error originated (e.g. with the CPU, +in the SINIT ACM, in software). The error is written to a sticky TXT +register that persists across resets called TXT.ERRORCODE (see the TXT +MLE Development Guide). The errors defined by the Secure Launch feature are +those generated in the MLE software. They have the format:: + + 0xc0008XXX + +The low 12 bits are free for defining the following Secure Launch specific +error codes. + +0xc0008001: SL_ERROR_GENERIC +---------------------------- + +Description: + +Generic catch all error. Currently unused. + +0xc0008002: SL_ERROR_TPM_INIT +----------------------------- + +Description: + +The Secure Launch code failed to get access to the TPM hardware interface. +This is most likely due to misconfigured hardware or kernel. Ensure the TPM +chip is enabled, and the kernel TPM support is built in (it should not be = built +as a module). + +0xc0008003: SL_ERROR_TPM_INVALID_LOG20 +-------------------------------------- + +Description: + +Either the Secure Launch code failed to find a valid event log descriptor = for a +version 2.0 TPM, or the event log descriptor is malformed. Usually this +indicates incompatible versions of the pre-launch environment and the +MLE kernel. The pre-launch environment and the kernel share a structure in= the +TXT heap and if this structure (the OS-MLE table) is mismatched, this erro= r is +common. This TXT heap area is set up by the pre-launch environment, so the +issue may originate there. It could also be the sign of an attempted attac= k. + +0xc0008004: SL_ERROR_TPM_LOGGING_FAILED +--------------------------------------- + +Description: + +There was a failed attempt to write a TPM event to the event log early in = the +Secure Launch process. This is likely the result of a malformed TPM event = log +buffer. Formatting of the event log buffer information is done by the +pre-launch environment, so the issue most likely originates there. + +0xc0008005: SL_ERROR_REGION_STRADDLE_4GB +---------------------------------------- + +Description: + +During early validation, a buffer or region was found to straddle the 4Gb +boundary. Because of the way TXT provides DMA memory protection, this is a= n unsafe +configuration and is flagged as an error. This is most likely a configurat= ion +issue in the pre-launch environment. It could also be the sign of an attem= pted +attack. + +0xc0008006: SL_ERROR_TPM_EXTEND +------------------------------- + +Description: + +There was a failed attempt to extend a TPM PCR in the Secure Launch platfo= rm +module. This is most likely to due to misconfigured hardware or kernel. En= sure +the TPM chip is enabled, and the kernel TPM support is built in (it should= not +be built as a module). + +0xc0008007: SL_ERROR_MTRR_INV_VCNT +---------------------------------- + +Description: + +During early Secure Launch validation, an invalid variable MTRR count was +found. The pre-launch environment passes several MSR values to the MLE to +restore including the MTRRs. The values are restored by the Secure Launch = early +entry point code. After measuring the values supplied by the pre-launch +environment, a discrepancy was found, validating the values. It could be t= he +sign of an attempted attack. + +0xc0008008: SL_ERROR_MTRR_INV_DEF_TYPE +-------------------------------------- + +Description: + +During early Secure Launch validation, an invalid default MTRR type was fo= und. +See SL_ERROR_MTRR_INV_VCNT for more details. + +0xc0008009: SL_ERROR_MTRR_INV_BASE +---------------------------------- + +Description: + +During early Secure Launch validation, an invalid variable MTRR base value= was +found. See SL_ERROR_MTRR_INV_VCNT for more details. + +0xc000800a: SL_ERROR_MTRR_INV_MASK +---------------------------------- + +Description: + +During early Secure Launch validation, an invalid variable MTRR mask value= was +found. See SL_ERROR_MTRR_INV_VCNT for more details. + +0xc000800b: SL_ERROR_MSR_INV_MISC_EN +------------------------------------ + +Description: + +During early Secure Launch validation, an invalid miscellaneous enable MSR +value was found. See SL_ERROR_MTRR_INV_VCNT for more details. + +0xc000800c: SL_ERROR_INV_AP_INTERRUPT +------------------------------------- + +Description: + +The application processors (APs) wait to be woken up by the SMP initializa= tion +code. The only interrupt that they expect is an NMI; all other interrupts +should be masked. If an AP gets an interrupt other than an NMI, it will +cause this error. This error is very unlikely to occur. + +0xc000800d: SL_ERROR_INTEGER_OVERFLOW +------------------------------------- + +Description: + +A buffer base and size passed to the MLE caused an integer overflow when +added together. This is most likely a configuration issue in the pre-launch +environment. It could also be the sign of an attempted attack. + +0xc000800e: SL_ERROR_HEAP_WALK +------------------------------ + +Description: + +An error occurred in TXT heap walking code. The underlying issue is a fail= ure to +early_memremap() portions of the heap, most likely due to a resource short= age. + +0xc000800f: SL_ERROR_HEAP_MAP +----------------------------- + +Description: + +This error is essentially the same as SL_ERROR_HEAP_WALK, but occurred dur= ing the +actual early_memremap() operation. + +0xc0008010: SL_ERROR_REGION_ABOVE_4GB +------------------------------------- + +Description: + +A memory region used by the MLE is above 4Gb. In general, this is not a pr= oblem +because memory > 4Gb can be protected from DMA. There are certain buffers = that +should never be above 4Gb, and one of these caused the violation. This is = most +likely a configuration issue in the pre-launch environment. It could also = be +the sign of an attempted attack. + +0xc0008011: SL_ERROR_HEAP_INVALID_DMAR +-------------------------------------- + +Description: + +The backup copy of the ACPI DMAR table, which is expected to be in the +TXT heap, could not be found. This is due to a bug in the platform's ACM m= odule +or in firmware. + +0xc0008012: SL_ERROR_HEAP_DMAR_SIZE +----------------------------------- + +Description: + +The backup copy of the ACPI DMAR table in the TXT heap is too large to be = stored +for later usage. This error is very unlikely to occur since the area reser= ved +for the copy is far larger than the DMAR should be. + +0xc0008013: SL_ERROR_HEAP_DMAR_MAP +---------------------------------- + +Description: + +The backup copy of the ACPI DMAR table in the TXT heap could not be mapped= . The +underlying issue is a failure to early_memremap() the DMAR table, most lik= ely +due to a resource shortage. + +0xc0008014: SL_ERROR_HI_PMR_BASE +-------------------------------- + +Description: + +On a system with more than 4Gb of RAM, the high PMR [2]_ base address shou= ld be +set to 4Gb. This error is due to that not being the case. This PMR value i= s set +by the pre-launch environment, so the issue most likely originates there. = It +could also be the sign of an attempted attack. + +0xc0008015: SL_ERROR_HI_PMR_SIZE +-------------------------------- + +Description: + +On a system with more than 4Gb of RAM, the high PMR [2]_ size should be se= t to +cover all RAM > 4Gb. This error is due to that not being the case. This PMR +value is set by the pre-launch environment, so the issue most likely origi= nates +there. It could also be the sign of an attempted attack. + +0xc0008016: SL_ERROR_LO_PMR_BASE +-------------------------------- + +Description: + +The low PMR [2]_ base should always be set to address zero. This error is = due +to that not being the case. This PMR value is set by the pre-launch enviro= nment +so the issue most likely originates there. It could also be the sign of an +attempted attack. + +0xc0008017: SL_ERROR_LO_PMR_MLE +------------------------------- + +Description: + +This error indicates the MLE image is not covered by the low PMR [2]_ rang= e. +The PMR values are set by the pre-launch environment, so the issue most li= kely +originates there. It could also be the sign of an attempted attack. + +0xc0008018: SL_ERROR_INITRD_TOO_BIG +----------------------------------- + +Description: + +The external initrd provided is larger than 4Gb. This is not a valid +configuration for Secure Launch due to managing DMA protection. + +0xc0008019: SL_ERROR_HEAP_ZERO_OFFSET +------------------------------------- + +Description: + +During a TXT heap walk, an invalid/zero next table offset value was found.= This +indicates the TXT heap is malformed. The TXT heap is initialized by the +pre-launch environment, so the issue most likely originates there. It could +also be a sign of an attempted attack. In addition, ACM is also responsibl= e for +manipulating parts of the TXT heap, so the issue could be due to a bug in = the +platform's ACM module. + +0xc000801a: SL_ERROR_WAKE_BLOCK_TOO_SMALL +----------------------------------------- + +Description: + +The AP wake block buffer passed to the MLE via the OS-MLE TXT heap table i= s not +large enough. This value is set by the pre-launch environment, so the issue +most likely originates there. It also could be the sign of an attempted at= tack. + +0xc000801b: SL_ERROR_MLE_BUFFER_OVERLAP +--------------------------------------- + +Description: + +One of the buffers passed to the MLE via the OS-MLE TXT heap table overlaps +with the MLE image in memory. This value is set by the pre-launch environm= ent +so the issue most likely originates there. It could also be the sign of an +attempted attack. + +0xc000801c: SL_ERROR_BUFFER_BEYOND_PMR +-------------------------------------- + +Description: + +One of the buffers passed to the MLE via the OS-MLE TXT heap table is not +protected by a PMR. This value is set by the pre-launch environment, so the +issue most likely originates there. It could also be the sign of an attemp= ted +attack. + +0xc000801d: SL_ERROR_OS_SINIT_BAD_VERSION +----------------------------------------- + +Description: + +The version of the OS-SINIT TXT heap table is bad. It must be 6 or greater. +This value is set by the pre-launch environment, so the issue most likely +originates there. It could also be the sign of an attempted attack. It is = also +possible though very unlikely that the platform is so old that the ACM bei= ng +used requires an unsupported version. + +0xc000801e: SL_ERROR_EVENTLOG_MAP +--------------------------------- + +Description: + +An error occurred in the Secure Launch module while mapping the TPM event = log. +The underlying issue is memremap() failure, most likely due to a resource +shortage. + +0xc000801f: SL_ERROR_TPM_INVALID_ALGS +------------------------------------- + +Description: + +The TPM 2.0 event log reports either no hashing algorithms, invalid algori= thm ID +or an algorithm size larger than the max size recognized by the TPM suppor= t code. + +0xc0008020: SL_ERROR_TPM_EVENT_COUNT +------------------------------------ + +Description: + +The TPM 2.0 event log contains an event with a digest count that is not eq= ual +to the algorithm count of the overall log. This is an invalid configuration +that could indicate either a bug or a possible attack. + +0xc0008021: SL_ERROR_TPM_INVALID_EVENT +-------------------------------------- + +Description: + +An invalid/malformed event was found in the TPM event log while reading it. +Since only trusted entities are supposed to be writing the event log, this +would indicate either a bug or a possible attack. + +0xc0008022: SL_ERROR_INVALID_SLRT +--------------------------------- + +Description: + +The Secure Launch Resource Table is invalid or malformed and is unusable. = This +implies the pre-launch code did not properly set up the SLRT. + +0xc0008023: SL_ERROR_SLRT_MISSING_ENTRY +--------------------------------------- + +Description: + +The Secure Launch Resource Table is missing a required entry within it. Th= is +implies the pre-launch code did not properly set up the SLRT. + +0xc0008024: SL_ERROR_SLRT_MAP +----------------------------- + +Description: + +An error occurred in the Secure Launch module while mapping the Secure Lau= nch +Resource table. The underlying issue is memremap() failure, most likely du= e to +a resource shortage. + + +Resources +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The TrenchBoot project: + +https://trenchboot.org + +Secure Launch Specification: + +https://trenchboot.org/specifications/Secure_Launch/ + +Trusted Computing Group's D-RTM Architecture: + +https://trustedcomputinggroup.org/wp-content/uploads/TCG_D-RTM_Architectur= e_v1-0_Published_06172013.pdf + +TXT documentation in the Intel TXT MLE Development Guide: + +https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-= txt-software-development-guide.pdf + +TXT instructions documentation in the Intel SDM Instruction Set volume: + +https://software.intel.com/en-us/articles/intel-sdm + +AMD SKINIT documentation in the System Programming manual: + +https://www.amd.com/system/files/TechDocs/24593.pdf + +GRUB Secure Launch support: + +https://github.com/TrenchBoot/grub/tree/grub-sl-fc-38-dlstub + +FOSDEM 2021: Secure Upgrades with DRTM + +https://archive.fosdem.org/2021/schedule/event/firmware_suwd/ + +.. [1] + MLE: Measured Launch Environment is the binary runtime that is measure= d and + then run by the TXT SINIT ACM. The TXT MLE Development Guide describes= the + requirements for the MLE in detail. + +.. [2] + PMR: Intel VTd has a feature in the IOMMU called Protected Memory Regi= sters. + There are two of these registers and they allow all DMA to be blocked + to large areas of memory. The low PMR can cover all memory below 4Gb o= n 2Mb + boundaries. The high PMR can cover all RAM on the system, again on 2Mb + boundaries. This feature is used during a Secure Launch by TXT. + +.. [3] + Secure Launch Specification: https://trenchboot.org/specifications/Sec= ure_Launch/ + +.. [4] + ACM: Intel's Authenticated Code Module. This is the 32b bit binary blo= b that + is run securely by the GETSEC[SENTER] during a measured launch. It is = described + in the Intel documentation on TXT and versions for various chipsets are + signed and distributed by Intel. --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F0D73F44FA for ; Fri, 15 May 2026 21:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879701; cv=none; b=SHykdrt41y7Q7+TrXATph508skXcq4m3oy3a1bCqrxYM0SI6V+ZdoEKoFNW6KKDBFk8n1qFxojLhOxMI0muqTO1OfQ29rQfHabROsB1yo3ZXOXKHHurIxYBEqC5jhVgeeppCF7C/siWH9yL5lby2TaGFCB4/3waKEgG/gIthyUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879701; c=relaxed/simple; bh=/w4xIQd+FodWBf21xbEabPQcoqxxR+rnVAOAKm/PKP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ndl16D8FAAaYLgj3Fr0JrPorchM+XjkVCDXAvzXtVeJ8DxHS7/n6e8RjewVB1orwxnrhDpN1X9mfb1aOBBIiP6omflVLFFyNKGl/8dDLsrJ9KLbzTlqSNZyrugkmfJzY2pmNyPoE7zrkyKd42JqOpEe0UPyLwuNYahxGYTjWngg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NAUkQYe1; arc=none smtp.client-ip=74.125.82.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NAUkQYe1" Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-2f3c623322bso1043640eec.0 for ; Fri, 15 May 2026 14:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879698; x=1779484498; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aFOHDGCsOHbtZzrbMRrMDpLy4uq6fKhTRLiSKMVovBw=; b=NAUkQYe17YCwOkozqdU8CpMHWdUFgHS6zfI0Ca2ILTLzMf2tiipFVvSkcGZcm/Vgv9 f8KEgse7WVm8d40kJddfU5qHJ7TbmtZZ9ZkaGR+rzkMct56vQpK5+h3Fsjqf42Di81AP zXblzjiLSj9yR7kZYhaSZlfFC+m78FgXqQNMD2x7IUyePyMWN5Ejv6UozaIP747+A4Af olt8sJ2zM8qz67HNBxVo8J3K33CGhOndM/yfhuS40Pm3WRAfEiYHCe+zPCzvX2U0wWSz ZRjNUNmR1iPXSD1f82xgt6JlXOYaYMNiuh0+zcrN7zOI6ZQzCGbFqcQipX9Qf8piThzb ybFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879698; x=1779484498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aFOHDGCsOHbtZzrbMRrMDpLy4uq6fKhTRLiSKMVovBw=; b=dEMfin6r3t5DgsOr0RIpdFKbAb0B7l/CSmPg/w54Ee9rpBuPPwhIi1eHp4ul+BVZp0 vHwZePSypGRS7nplITygxti+wNGEXP/iNOxnlpaKUs4frwqbpz7Wm/qG7AGv4OL8jbwt QvK4wKfffULDtIvsTCun0T15pJNgiPgmR4lm+lhKHS+BQEOdGHgp+VgJmrVxxj6YGgFb IcDAgt51HLj1B+W2cXT/9WcYWsnQZQih2VTez4voQMEBNpIXZd8Ka9DLCBfkfMyOIQXO 5q9M+gmsn/TwhhHRjv38q7BG1Ow4d2mO9SYVGbT03XTTU1WHN1Piane76K/8ozqOaENT g7nQ== X-Gm-Message-State: AOJu0Yw07wYYrzQHO25RPnCzNYJP/Q10IF/VIR+Sfx6EF1+vWitH/SKf hBGlBI+WPMz28Py9/0wQZnEn0HX9iMpeJIPuItynisjccThTCe6wmF/CpwPadxD7 X-Gm-Gg: Acq92OFPtS2ngfIGv9R7Do5J27yrY41PckZ6BYLWeXQv7P+SbZFDthVl/Odc00X5NCc UIrKdsTy7awHERzyTiYZLysHlh8kLHizDAFgDedb4wpbVrwJgdTOJzBWns+h+87Y83IdoLWDSP0 2BpGLo2uKoX1qBE1zkjR4BnyEfp3iub3CdxZ2fMnJlLwg8JzQCmCGYmJxv3WMTdVWtolkmEtS+Q q20xUAMzNHEDGdBAPUNhkK+kMWfVLQhrJex4dnpM/C/NcMKblu73f3WQ6+77noyhGl/3jYyYlA3 DwoXw11JKQaOrHinl0fqza45+1oGbhESerVU0blMgMXrOh8Doo0WWq4VsVKM9FTgkRwYzHf3RZZ I/1DiWon6l/ZtYjwawuRR5cJVD/OePbzgs4cikMktRTT6aItI1xOZqLh0d9Idh1XDuhLVrk0zAr bqhEw2VnMqC1T8SDR7JFxqfdsAVwTMg8x7OpDb39JW+g== X-Received: by 2002:a05:693c:8386:20b0:2df:919f:ce59 with SMTP id 5a478bee46e88-30398678a48mr2108609eec.19.1778879698427; Fri, 15 May 2026 14:14:58 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302973bbd50sm7961724eec.20.2026.05.15.14.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:14:58 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 16/38] x86: Secure Launch Kconfig Date: Fri, 15 May 2026 14:13:48 -0700 Message-ID: <20260515211410.31440-17-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an x86 Kconfig option for compiling in/out the Secure Launch feature. Secure Launch is controlled by a single on/off boolean. Signed-off-by: Ross Philipson --- arch/x86/Kconfig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index e2df1b147184..fd9edb0651d9 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1989,6 +1989,21 @@ config EFI_RUNTIME_MAP =20 See also Documentation/ABI/testing/sysfs-firmware-efi-runtime-map. =20 +config SECURE_LAUNCH + bool "Secure Launch DRTM support" + depends on X86_64 && X86_X2APIC && TCG_TIS && TCG_CRB + select CRYPTO_LIB_SHA1 + select CRYPTO_LIB_SHA256 + select CRYPTO_LIB_SHA512 + help + The Secure Launch feature allows a kernel to be launched directly + through a vendor neutral DRTM (Dynamic Root of Trust for Measurement) + solution, with Intel TXT being one example. The DRTM establishes an + environment where the CPU measures the kernel image, employing the TPM, + before starting it. Secure Launch then continues the measurement chain + over kernel configuration information and other launch artifacts (e.g. + any initramfs image). + source "kernel/Kconfig.hz" =20 config ARCH_SUPPORTS_KEXEC --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64C513F99EB for ; Fri, 15 May 2026 21:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879704; cv=none; b=X1T892sCUo+12/vMGeFxF2GZAxqiOJGNsgxLa8xW9gZjfcjMl/2I6URjh4WXhYMpZ+hyKjTGcFWhbMHHAovQqcB7B8UhL8BlpniTqpF5Y6WKp22TDI7QJXpMfsKhEeTp/vXm5u/tDI5xH2LQMpTDqVcaWlBbyUv/Wzn5OnTCT9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879704; c=relaxed/simple; bh=xWoPwNVeSnywWpOcGvmELTRW5jlGxq+dKcjO5PNtRQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OgKI9gKc5ZaAb4Uk9pSA0F4nNKyTim6ZF8Ndaz3V8DPBG6gRqmxpMiikDZU/cdEjWkPPwzly2B4qn+lItocM1sxECotvOnsRAk+XAE7ua2hk7+DyDxk04zIWhCkJXtccVB0Q2XtMmCQV1OKu3B+rqjX8yFluQgWc3HqlMj410iM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TML1/Alw; arc=none smtp.client-ip=74.125.82.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TML1/Alw" Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-2f00a567cfaso833154eec.0 for ; Fri, 15 May 2026 14:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879701; x=1779484501; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7H5BBOQhcOIL9Ie2ph8fKyZbD41fSwoTWiLEU5gST9s=; b=TML1/Alwf1J56nZnmLFnC6Z6dFQkcWs7FNQt/kRXfq+GMkjZIzhDPeefJNOyk30PoW cPck8KvGhJhoXhg9Enm/bD4+2l7LVKHTEUULH2y5HuBl60luRGlQjfwzodYujzjbCZ85 kgunYYQ0YcAC8j3iiERH2Ph5cpRst++49kNCmwq0kqFuSxCWfc7EERACLpo+hGMVxIoq lQ60lbyGss/jKaGWpOQEq83fgcF5abfULfrofm5AboQ0qSc2VtTviw5d8HDaTU3SVzNq KE9j4qUnU/VmduXBPIZo9x7f2P4E89g/HvB3s3l0xySd/aUJ+fK+LIJBraYJ0mDxVo02 /G3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879701; x=1779484501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7H5BBOQhcOIL9Ie2ph8fKyZbD41fSwoTWiLEU5gST9s=; b=KXS5Fd3aMixU99yY9xKgg9NXez98991bFNkU4udSGryPJ5eCNUw+/XbGWRT1Hblzq5 KyTAFdEPy/aig+TfKibwW/duXmSsB0BJTAXSQUM4+OEvLOqvIOP1PVv6jyx+QoUXXOmP gCBBa31vpAeDJhcQEm75LcWYQG1IKobxfxD4q5t9ltTwDgrpCLsumzv6BRcxESadf9xW cpZnRSDGsQ9554HBRXLAaFEoeh9pHex8Bx1DT+adAxZF2vruC5rrSOUwB7ksu0gwIHp6 wGG/AKO/Lcho+MNwIAyx4avoj9+cfJMUyCTPzZ9v//ixnx2OanUlqMBU2f40vi3Eihnv O7bg== X-Gm-Message-State: AOJu0YweXZ39oORJAP2pzWnSheu+HlVmIwLegL2XgmoYQzeYkFpBKSEn +4apdIjZZS4kcTvq48Y5PEh4kaOV7oM9puDFnDG0ohekaa8XF/BXhgX/Av9alxgY X-Gm-Gg: Acq92OFgNo2npPWkgFxw7acV1VUfdzgWiW1OzO7uhCvE2+7veV2Il5F25qzL+x0iGsg qzYPA3gwoCX6bmBq0ZQq1Vf3a6G1TRn7Bi1hB/pOCALtegxLzCooRiSh/o1CJ44rRxHS5Xy0Dhc j7F5r02pM18sEIIsvjC8wRikJSfpR+HFCj7SIBeJz00b2+2AvnvzpnJ1DSglJ+Q2ylTTBihNr4H 3fG3hGQYU1PgRdQfqu2v9GcvoXdONN3qeuG/GESKqgfcHZo/xWRjUFS7IMvu4/CSralKyW80bRg 7bwIyh9PXM28Gq79kM2N+syL4D9ic3/xfw4pcsLgxvEbOIwIPJeVrX+vXC/y5NkcvjPTp/Pxd6x xJ+Fd8PuZ5683HDOd0qSPrNkdxHR6PoLN8EnD0+6A2bkVQeT5Lj1sds4yYmauqCM6R08T67/IZf L7jbqFB/3TV2MTbOkBhN8Q/xIMI9YDIIKOAZlrUOMUiw== X-Received: by 2002:a05:7301:644b:b0:2d9:db50:c6ce with SMTP id 5a478bee46e88-3039785c4f8mr2519307eec.3.1778879701272; Fri, 15 May 2026 14:15:01 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302978b1a79sm8049096eec.28.2026.05.15.14.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:00 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 17/38] x86: Secure Launch Resource Table header file Date: Fri, 15 May 2026 14:13:49 -0700 Message-ID: <20260515211410.31440-18-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Secure Launch Specification is an architecture agnostic, software neutral API/ABI maintained by the TrenchBoot project. Its function is to allow any compliant boot loader to communicate the pre-launch configuration to any compliant post-launch kernel. The Secure Launch Resource Table, defined in the specification, presents the programmatic interface for this API/ABI. The specification can be found here: https://github.com/TrenchBoot/documentation/blob/master/specifications/secu= re-launch-specification.rst Signed-off-by: Ross Philipson --- include/linux/slr_table.h | 339 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100644 include/linux/slr_table.h diff --git a/include/linux/slr_table.h b/include/linux/slr_table.h new file mode 100644 index 000000000000..2cc542121414 --- /dev/null +++ b/include/linux/slr_table.h @@ -0,0 +1,339 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * TrenchBoot Secure Launch Resource Table + * + * The Secure Launch Resource Table (SLRT) is a TrenchBoot project defined + * specification to provide a cross-platform interface/ABI between + * the Secure Launch components. While most of the table is platform + * agnostic, platform or architecture specific entries can be added. + * + * See TrenchBoot Secure Launch kernel documentation for details. + * + * Copyright (c) 2026 Apertus Solutions, LLC + * Copyright (c) 2026, Oracle and/or its affiliates. + */ + +#ifndef _LINUX_SLR_TABLE_H +#define _LINUX_SLR_TABLE_H + +/* SLR table header values */ +#define SLR_TABLE_MAGIC 0x4452544d +#define SLR_TABLE_REVISION 1 + +/* Current revisions for the policy and UEFI config */ +#define SLR_POLICY_REVISION 1 +#define SLR_UEFI_CONFIG_REVISION 1 + +/* SLR defined architectures */ +#define SLR_INTEL_TXT 1 +#define SLR_AMD_SKINIT 2 + +/* SLR defined bootloaders */ +#define SLR_BOOTLOADER_INVALID 0 +#define SLR_BOOTLOADER_GRUB 1 + +/* Log formats */ +#define SLR_DRTM_TPM12_LOG 1 +#define SLR_DRTM_TPM20_LOG 2 + +/* DRTM Policy Entry Flags */ +#define SLR_POLICY_FLAG_MEASURED 0x1 +#define SLR_POLICY_IMPLICIT_SIZE 0x2 + +/* Array Lengths */ +#define TPM_EVENT_INFO_LENGTH 32 +#define TXT_VARIABLE_MTRRS_LENGTH 32 + +/* Tags */ +#define SLR_ENTRY_INVALID 0x0000 +#define SLR_ENTRY_DL_INFO 0x0001 +#define SLR_ENTRY_LOG_INFO 0x0002 +#define SLR_ENTRY_ENTRY_POLICY 0x0003 +#define SLR_ENTRY_INTEL_INFO 0x0004 +#define SLR_ENTRY_AMD_INFO 0x0005 +#define SLR_ENTRY_ARM_INFO 0x0006 +#define SLR_ENTRY_UEFI_INFO 0x0007 +#define SLR_ENTRY_UEFI_CONFIG 0x0008 +#define SLR_ENTRY_END 0xffff + +/* Entity Types */ +#define SLR_ET_UNSPECIFIED 0x0000 +#define SLR_ET_SLRT 0x0001 +#define SLR_ET_BOOT_PARAMS 0x0002 +#define SLR_ET_SETUP_DATA 0x0003 +#define SLR_ET_CMDLINE 0x0004 +#define SLR_ET_UEFI_MEMMAP 0x0005 +#define SLR_ET_RAMDISK 0x0006 +#define SLR_ET_TXT_OS2MLE 0x0010 +#define SLR_ET_UNUSED 0xffff + +#ifndef __ASSEMBLER__ + +/* + * Standard Secure Launch DLME header. + * + * All capable DRTM kernels must have an instance of this header. + * This header was derived from the Intel TXT Measured Launch + * Environment header and uses the predefined UUID: + * + * {5aac8290-6f47-a774-0f5c-55a2cb51b642} + */ +struct slr_dlme_header { + u32 uuid0; /* 9082AC5A */ + u32 uuid1; /* 74A7476F */ + u32 uuid2; /* A2555C0F */ + u32 uuid3; /* 42B651CB */ + u32 header_len; + u32 version; + u32 entry_point; + u32 first_valid_page; + u32 start; + u32 end; + u32 capabilities; + u32 cmdline_start; + u32 cmdline_end; +} __packed; + +/* + * Primary Secure Launch Resource Table header + */ +struct slr_table { + u32 magic; + u16 revision; + u16 architecture; + u32 size; + u32 max_size; + /* table entries */ +} __packed; + +/* + * Common SLRT entry header + */ +struct slr_entry_hdr { + u32 tag; + u32 size; +} __packed; + +/* + * Boot loader context and DLME setup + */ +struct slr_bl_context { + u16 bootloader; + u16 reserved[3]; + u64 context; +} __packed; + +struct slr_setup_dlme { + u64 dlme_base; + u64 dlme_header_offset; + u64 dlme_table; +} __packed; + +/* + * Dynamic Launch Callback Function + */ +typedef void (*dl_launch_func)(struct slr_bl_context *bl_context, + struct slr_setup_dlme *setup_dlme); + +/* + * DRTM Dynamic Launch Configuration + */ +struct slr_entry_dl_info { + struct slr_entry_hdr hdr; + u64 dce_size; + u64 dce_base; + u64 dlme_size; + u64 dlme_base; + u64 dlme_entry; + u64 dlme_header_offset; + u64 dlme_config_table; + struct slr_bl_context bl_context; + u64 dl_launch; +} __packed; + +/* + * TPM Log Information + */ +struct slr_entry_log_info { + struct slr_entry_hdr hdr; + u16 format; + u16 reserved; + u32 size; + u64 addr; +} __packed; + +/* + * DRTM Measurement Entry + */ +struct slr_policy_entry { + u16 pcr; + u16 entity_type; + u16 flags; + u16 reserved; + u64 size; + u64 entity; + char evt_info[TPM_EVENT_INFO_LENGTH]; +} __packed; + +/* + * DRTM Measurement Policy + */ +struct slr_entry_policy { + struct slr_entry_hdr hdr; + u16 reserved[2]; + u16 revision; + u16 nr_entries; + struct slr_policy_entry policy_entries[]; +} __packed; + +/* + * Secure Launch defined MTRR saving structures + */ +struct slr_txt_mtrr_pair { + u64 mtrr_physbase; + u64 mtrr_physmask; +} __packed; + +struct slr_txt_mtrr_state { + u64 default_mem_type; + u64 mtrr_vcnt; + struct slr_txt_mtrr_pair mtrr_pair[TXT_VARIABLE_MTRRS_LENGTH]; +} __packed; + +/* + * Intel TXT Info table + */ +struct slr_entry_intel_info { + struct slr_entry_hdr hdr; + u64 boot_params_addr; + u64 txt_heap; + u64 saved_misc_enable_msr; + struct slr_txt_mtrr_state saved_bsp_mtrrs; +} __packed; + +/* + * UEFI config measurement entry + */ +struct slr_uefi_cfg_entry { + u16 pcr; + u16 reserved; + u32 size; + u64 cfg; /* address or value */ + char evt_info[TPM_EVENT_INFO_LENGTH]; +} __packed; + +/* + * UEFI config measurements + */ +struct slr_entry_uefi_config { + struct slr_entry_hdr hdr; + u16 reserved[2]; + u16 revision; + u16 nr_entries; + struct slr_uefi_cfg_entry uefi_cfg_entries[]; +} __packed; + +/* + * The SLRT is laid out as a Tag-Length-Value (TLV) data structure + * allowing a flexible number of entries in the table. An instance + * of the slr_table structure is present as a header at the beginning. + * + * The following functions help to manipulate the SLRT structure + * and contents. + */ + +/* + * Return the address of the end of the SLRT past the final entry. + */ +static inline void *slr_end_of_entries(struct slr_table *table) +{ + return (void *)table + table->size; +} + +/* + * Return the next entry in the SLRT given the current entry passed + * to the function. NULL is returned if there are no entries to return. + */ +static inline void * +slr_next_entry(struct slr_table *table, + struct slr_entry_hdr *curr) +{ + struct slr_entry_hdr *next =3D (struct slr_entry_hdr *)((u8 *)curr + curr= ->size); + + if ((void *)next >=3D slr_end_of_entries(table)) + return NULL; + if (next->tag =3D=3D SLR_ENTRY_END) + return NULL; + + return next; +} + +/* + * Return the next entry with the given tag in the SLRT starting at the + * current entry. If entry is NULL, the search begins at the beginning of + * table. + */ +static inline void * +slr_next_entry_by_tag(struct slr_table *table, + struct slr_entry_hdr *entry, + u16 tag) +{ + if (!entry) /* Start from the beginning */ + entry =3D (struct slr_entry_hdr *)(((u8 *)table) + sizeof(*table)); + + for ( ; ; ) { + if (entry->tag =3D=3D tag) + return entry; + + entry =3D slr_next_entry(table, entry); + if (!entry) + return NULL; + } + + return NULL; +} + +/* + * Add an entry to the SLRT. Entries are placed at the end. + */ +static inline int +slr_add_entry(struct slr_table *table, + struct slr_entry_hdr *entry) +{ + struct slr_entry_hdr *end; + + if ((table->size + entry->size) > table->max_size) + return -1; + + memcpy((u8 *)table + table->size - sizeof(*end), entry, entry->size); + table->size +=3D entry->size; + + end =3D (struct slr_entry_hdr *)((u8 *)table + table->size - sizeof(*end)= ); + end->tag =3D SLR_ENTRY_END; + end->size =3D sizeof(*end); + + return 0; +} + +/* + * Initialize the SLRT for use. This prepares the meta-data in the SLRT + * header section of the table and table end entry. + */ +static inline void +slr_init_table(struct slr_table *slrt, u16 architecture, u32 max_size) +{ + struct slr_entry_hdr *end; + + slrt->magic =3D SLR_TABLE_MAGIC; + slrt->revision =3D SLR_TABLE_REVISION; + slrt->architecture =3D architecture; + slrt->size =3D sizeof(*slrt) + sizeof(*end); + slrt->max_size =3D max_size; + end =3D (struct slr_entry_hdr *)((u8 *)slrt + sizeof(*slrt)); + end->tag =3D SLR_ENTRY_END; + end->size =3D sizeof(*end); +} + +#endif /* !__ASSEMBLER__ */ + +#endif /* _LINUX_SLR_TABLE_H */ --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 145D53FD962 for ; Fri, 15 May 2026 21:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879706; cv=none; b=n/tHdObNU+2ygSyninBJ43OuFrNuHrzL1v9sNf0ln1CIk8LNQfjzJKUFFcN/g4eMoC8v54noDNYopfHc/le51FPx0PBLcenHniE8y1Wsx0dOzfH06D5CMBxYYRedzLfMCE7sNmJoeNjHc8A77U3zS1u4yFbp+4XheXwbcRCb8w4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879706; c=relaxed/simple; bh=qtwiEWwByfHHxjTrlTyTKX/7jH6vLFs54iG3FoiDWyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KG6O350MNDk2K1M/4Gw2qs92PIUvaUb9HLuMIqOn+IxXMoe0A3otvbVa4DYa6mtkrJ3fGOHyJR1Nf4zlZWX/eJRVWAMOuDx8gk7g7eAiqp19fCzHnz7AmFsUxlHGg0U3VSQtny5hfq7f33BWRZKnyzlddGjeU/oSQ1gMgnrv0mQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=s9V33mfU; arc=none smtp.client-ip=74.125.82.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s9V33mfU" Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-135200bc7d2so449453c88.0 for ; Fri, 15 May 2026 14:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879704; x=1779484504; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=azOcaoqgBG4GOjXSMRG7UYVXI2K8VE7Oo8FvV1FqK6Y=; b=s9V33mfUWQSz9b71/QS4bizbbARZHMDNvH7LsGEPdS45xkCfL7xQwNunkkk5UbevFy w0xSUPPpNM6DkKIOd8ilLXHV6pV05emWyPPWFgqfn9kayoO8I56TjLnTQkA83RLVQort j3HRyLu0UnCxhI9MZTxUqlGCDn49YnoTpH+Vqlwk9N40NWTRpfCfLfKeRrdYlaes3gpg yuziZP3k99tvGWE9sgFtiQ24002qiDICOLKL1JqwUpsBbLdAm5ybiYLaAYzWLrd9GBNt fY1FVQCWMDnCoY4L+hfoMxL2Tdsqm96Us8LZih0uGUthsPQYzPfDuEnCoG59+ipp3xMP vflA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879704; x=1779484504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=azOcaoqgBG4GOjXSMRG7UYVXI2K8VE7Oo8FvV1FqK6Y=; b=GAiujZ7SJ85CCEIw2PgpXpSaidvvSPLzQ4yzdeMYeOThsVRbwTGsIYCBhftzxBh6/E KKujtWRrSQgk2gbR19Mwrf0QwYd9Asof7J/Oc92hJ+NGRpfjAvJ0R1lcBNjMBWHTErLD U1d0j8G7wmoNGyTjw6ECSMKWO7Vb341wfSfR6uK7qFzF7qPijAR17ORvFltKz20uj6En WD6uPO1e0oppPtnxsmnoP+Nw+Demhn9kp2XiQEPkNOwCEg9b2hiKjMqCl+laiNO5z0Sh FZJ783rCIK+xm15DO4K3yz4uWZKBzBUkxfNZRswSNA9VMWYPu3zcGbzaFLs4DDI4ZFeR FRmw== X-Gm-Message-State: AOJu0YwbTcwNsmuK1T0baqmzzWVa+E3Hhmcwg8AEqDZjq3jYjKNR085i 9yYpoFTzJB6iYhpVuH/S957hPHaDSam0zOXMWgebz0lGXfgVEE/Et5NQwVNud/YG X-Gm-Gg: Acq92OHC5IOdlQN/3j4ilW2E6T9idgqL3c4S6QNoIqEkU9Du0DE3VCsHOrEkmX0fLYQ uL9tt35127FeB6kPvN+OaoaApk+/6wG3L7IQizIcq+fDJwJ+KxMc0MSmz/qlcegGdq/KEh9BtGA AdN26WvuDyZhqOxtmQ+JkZdcyK1WnRPlZD1+3P/+az9jqzNm1LkcmV7AYSAUuQ1Z3YUvMdicg4+ lsdCU7ylPv+pgbd+9ZA8WS0cVjXV7ptvbslDKaga8u5zqLL8xbTxDu/TYfOPiHSMzRyQJr23AHA prZogtLnGiUwiFgutLuVDIkNgYDqiqVPupRdnjnP5UaRvbCE9LKbyKAfnVEiYSlZujN19LBtbde RN/6YQ7u8Vr+V1hCgCtBVW458cIBRjtqfMFlmlMSIDqlBpu3iMiWmjuHxTT54eRX6W3bSYaJ/p9 E0lnZSc0B29b/AnsTEl14N/LMDI8sguds= X-Received: by 2002:a05:7022:239d:b0:133:598c:2b45 with SMTP id a92af1059eb24-1350494e3f6mr2888720c88.31.1778879703912; Fri, 15 May 2026 14:15:03 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cc3490bcsm9740638c88.15.2026.05.15.14.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:03 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 18/38] x86/efi: Secure Launch Resource Table EFI definitions header file Date: Fri, 15 May 2026 14:13:50 -0700 Message-ID: <20260515211410.31440-19-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Secure Launch EFI definitions are contained in the Secure Launch Specification. The definitions are split out into a separate header file for compilation purposes for EFI vs non-EFI environments in the kernel. The specification can be found here: https://github.com/TrenchBoot/documentation/blob/master/specifications/secu= re-launch-specification.rst Co-developed-by: Ard Biesheuvel Signed-off-by: Ard Biesheuvel Signed-off-by: Ross Philipson --- include/linux/slr_efi.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 include/linux/slr_efi.h diff --git a/include/linux/slr_efi.h b/include/linux/slr_efi.h new file mode 100644 index 000000000000..5de87a9b38aa --- /dev/null +++ b/include/linux/slr_efi.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * EFI Definitions for Secure Launch Resource Table + * + * See TrenchBoot Secure Launch kernel documentation for details. + * + * Copyright (c) 2026 Apertus Solutions, LLC + * Copyright (c) 2026, Oracle and/or its affiliates. + */ + +#ifndef _LINUX_SLR_EFI_H +#define _LINUX_SLR_EFI_H + +#include + +#ifndef __ASSEMBLER__ + +/* EFI Support */ + +/* SLR table GUID for registering as an EFI Configuration Table (put this = in efi.h if it becomes a standard) */ +#define SLR_TABLE_GUID EFI_GUID(0x877a9b2a, 0x0385, 0x45d1, 0xa0, 0x34, = 0x9d, 0xac, 0x9c, 0x9e, 0x56, 0x5f) + +/* Secure Launch EFI runtime protocol */ +#define EFI_SLAUNCH_PROTOCOL_GUID EFI_GUID(0x534189e0, 0x6fde, 0x413d, 0x= be, 0x91, 0xcd, 0x4e, 0x8d, 0x67, 0x2f, 0xea) + +struct efi_slaunch_protocol { + efi_status_t + (__efiapi *setup_dlme)(struct efi_slaunch_protocol *this, + u64 dlme_base, + u64 dlme_header_offset, + u64 dlme_table); + + efi_status_t + (__efiapi *launch)(struct efi_slaunch_protocol *this); +}; +typedef struct efi_slaunch_protocol efi_slaunch_protocol_t; + +#endif /* !__ASSEMBLER__ */ + +#endif /* _LINUX_SLR_EFI_H */ --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8819C40629F for ; Fri, 15 May 2026 21:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879709; cv=none; b=PyzJnUFpfWrOP4Bur5N84LpzELKbHnSpo7x9aNwtFFWBwZl3vU5EjJMftw5v3J/R5RtFAYIDwWkG0wg3PclP8SZAEUOEGbp29DeTJ+BeLRlspRigIIsiO/GyFebWpe7UqN7JXCRPMF8x2oP4HM9W2TN+io7m2jhs07bVS1JkWuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879709; c=relaxed/simple; bh=Tu9t8Jkh6fC+t56oYQneuDB8ZEA9SNOFnZ6DDoMFzQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BzGf/EANTo1syxFTFFzQISy7BjydoxjpInQCRQlTsE9SUQD9z8+1QUd1Xtu3ZRHARzOc1Ocp+5iKfFmd0L8AyfKLjz1Fa0fDxFiHMkjxDjgPM94dZWsTusK/peWnN1ob6kZ7Akp5GuGh/UV6ZW6Ovb+CvJPvyhZVUYIPQ+hl+oo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=q8RTMCDB; arc=none smtp.client-ip=74.125.82.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q8RTMCDB" Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1353c2f35cfso948418c88.1 for ; Fri, 15 May 2026 14:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879707; x=1779484507; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=riwrj5pQHn0ODreltS6IigjzckrdFiF16wrIV559GfE=; b=q8RTMCDBQNNpp+1B7uaytrz6bOhnFKw6mChy6QThpgUaMWY1wt6/G0aq4fmg1Z6w+N G9jsVnr6GYZvuTDjaQL7ES/cYyQ85ywKrNVJneolqmkLPYrDiEYWlaso2k1bQsb+1pqk F5wNhOU9xpBLmYHuGVk5baepwXbZByjWxp8AcqIEyz4z/VFqsxsYFYlWzhKfZJKurvSG GWh3HbqCJJoIFKTbH88tVNGVwLHaCh+kXTAtwSIGkNCwt1c4o/5uD61gn8mw7Fgad1Qy 2KUyCFh0Mfb65sG6B9GJj+RZLE44kIpBOlpLnjJirFpjA5J8OIAws76GMve/NAfNq7dF WxBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879707; x=1779484507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=riwrj5pQHn0ODreltS6IigjzckrdFiF16wrIV559GfE=; b=ReGKinYTXs4VelZ7mmFqvrihYzfZCLDUbunfg3EubUGemAqzMMgzOB9W2KqoW5MLlG kYhM79oQusAs9LvsIJBQfXRJu1dYIJyiVNVycif+BVYBWWCOyZCA5a383wx+e3QwpoPA RKNSPU+3zrfIcCBUgMZCyKOCsK0iPpS9K9TK0YTe+elHnJMGiIh9XoEwPAQ64rkWFWsM 4hL1tZtunZ/O2U7rQk1xrwhAntM5zIyGp4xqwTZBQfNTUvUaqwrJwwSql8CiUbDtdtiS 5eJ7YMd7MeRIpzfSoQJiN2272uIQmK0TBTnngmFakQ/7vnMldAnXaNfhRZb/av7jLRZm BfJw== X-Gm-Message-State: AOJu0Yxha7Pe24+JlD5DctQDKpDEJXy9v3b9d5ZEiU6lABsbe5VSHLyq PjyNSXHqxp66bNhe87/Hs22Irrtnxz11JGLuf0V1NzixUqcQWPAvotHXdhTRMMA4 X-Gm-Gg: Acq92OGk/zX9+xEeSXBZtC7ZjDBuGvp7I4pzatZtURoCredjsxIetsUl/eUW/d9kDxQ 6nkKw23asAHUbRN9K5XTdvGFZzZPXjEwj25ocxTqM6JdYalsnHiJfOLSUSFcRAxiiAHBzzPjZ/M EEmk655VSyT+ZxMbYMIs4rsEvuKFzeC8sHlZCEJiMGp8h1Ps8PDTww2X8ql3hLYzmzZtJo6q+iV hUqzrGg41+ohssv+NhLZYsx7q07TLTPCljX3SlDOja5nto+FqI/XlPLHam9ZJAMurwLViPI7+z3 bapjs77owCbUwLd2LH7n26fQ1Mb6uY3R5Ft4sHbswRvgC4RtDAIZXwrxOh2FKUWTTxm3aJyF6Qn Ir4Zhw4c9fzBb3ENGsh3XYs+7ZDzqcl9dsDsZp8BP/qicrkXOExPrFYMGYX/pnfWYPtfcyZZZFe ZF7W0B16G+o3d7ADcB5wxYVil/ilojhL0= X-Received: by 2002:a05:7022:1e11:b0:12d:de3f:d843 with SMTP id a92af1059eb24-1350494e25cmr2535293c88.38.1778879706757; Fri, 15 May 2026 14:15:06 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cc3490bcsm9740744c88.15.2026.05.15.14.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:06 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 19/38] x86: Secure Launch main header file Date: Fri, 15 May 2026 14:13:51 -0700 Message-ID: <20260515211410.31440-20-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce the main Secure Launch header file. This header file contains the platform neutral feature definitions: - Secure Launch error codes - DRTM TPM event logging definitions and helper functions - Other feature specific structures and definitions Signed-off-by: Ross Philipson --- include/linux/slaunch.h | 262 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 include/linux/slaunch.h diff --git a/include/linux/slaunch.h b/include/linux/slaunch.h new file mode 100644 index 000000000000..7874a49c27b5 --- /dev/null +++ b/include/linux/slaunch.h @@ -0,0 +1,262 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Main Secure Launch header file. + * + * Copyright (c) 2026 Apertus Solutions, LLC + * Copyright (c) 2026, Oracle and/or its affiliates. + */ + +#ifndef _LINUX_SLAUNCH_H +#define _LINUX_SLAUNCH_H + +#include + +/* + * Secure Launch Defined State Flags + */ +#define SL_FLAG_ACTIVE 0x00000001 +#define SL_FLAG_ARCH_TXT 0x00000002 + +/* + * Secure Launch CPU Type + */ +#define SL_CPU_INTEL 1 + +#define __SL32_CS 0x0008 +#define __SL32_DS 0x0010 +#define __SL64_CS 0x0018 + +/* + * Secure Launch Defined Error Codes used in MLE-initiated TXT resets. + * + * Intel Trusted Execution Technology (TXT) Software Development Guide + * Appendix I - ACM Error Codes + */ +#define SL_ERROR_GENERIC 0xc0008001 +#define SL_ERROR_TPM_INIT 0xc0008002 +#define SL_ERROR_TPM_INVALID_LOG20 0xc0008003 +#define SL_ERROR_TPM_LOGGING_FAILED 0xc0008004 +#define SL_ERROR_REGION_STRADDLE_4GB 0xc0008005 +#define SL_ERROR_TPM_EXTEND 0xc0008006 +#define SL_ERROR_MTRR_INV_VCNT 0xc0008007 +#define SL_ERROR_MTRR_INV_DEF_TYPE 0xc0008008 +#define SL_ERROR_MTRR_INV_BASE 0xc0008009 +#define SL_ERROR_MTRR_INV_MASK 0xc000800a +#define SL_ERROR_MSR_INV_MISC_EN 0xc000800b +#define SL_ERROR_INV_AP_INTERRUPT 0xc000800c +#define SL_ERROR_INTEGER_OVERFLOW 0xc000800d +#define SL_ERROR_HEAP_WALK 0xc000800e +#define SL_ERROR_HEAP_MAP 0xc000800f +#define SL_ERROR_REGION_ABOVE_4GB 0xc0008010 +#define SL_ERROR_HEAP_INVALID_DMAR 0xc0008011 +#define SL_ERROR_HEAP_DMAR_SIZE 0xc0008012 +#define SL_ERROR_HEAP_DMAR_MAP 0xc0008013 +#define SL_ERROR_HI_PMR_BASE 0xc0008014 +#define SL_ERROR_HI_PMR_SIZE 0xc0008015 +#define SL_ERROR_LO_PMR_BASE 0xc0008016 +#define SL_ERROR_LO_PMR_MLE 0xc0008017 +#define SL_ERROR_INITRD_TOO_BIG 0xc0008018 +#define SL_ERROR_HEAP_ZERO_OFFSET 0xc0008019 +#define SL_ERROR_WAKE_BLOCK_TOO_SMALL 0xc000801a +#define SL_ERROR_MLE_BUFFER_OVERLAP 0xc000801b +#define SL_ERROR_BUFFER_BEYOND_PMR 0xc000801c +#define SL_ERROR_OS_SINIT_BAD_VERSION 0xc000801d +#define SL_ERROR_EVENTLOG_MAP 0xc000801e +#define SL_ERROR_TPM_INVALID_ALGS 0xc000801f +#define SL_ERROR_TPM_EVENT_COUNT 0xc0008020 +#define SL_ERROR_TPM_INVALID_EVENT 0xc0008021 +#define SL_ERROR_INVALID_SLRT 0xc0008022 +#define SL_ERROR_SLRT_MISSING_ENTRY 0xc0008023 +#define SL_ERROR_SLRT_MAP 0xc0008024 + +/* + * Secure Launch Defined Limits + */ +#define SL_MAX_CPUS 512 +#define SL_BOOT_STACK_SIZE 128 + +/* + * Secure Launch event log entry type. The TXT specification defines the + * base event value as 0x400 for DRTM values. + * + * Intel Trusted Execution Technology (TXT) Software Development Guide + * Appendix F - TPM Event Log + */ +#define SL_EVTYPE_BASE 0x400 +#define SL_EVTYPE_SECURE_LAUNCH (SL_EVTYPE_BASE + 0x102) + +/* + * MLE scratch area offsets within TXT OS-MLE SL defined portion of the he= ap. + */ +#define SL_SCRATCH_AP_EBX 0 +#define SL_SCRATCH_AP_JMP_OFFSET 4 +#define SL_SCRATCH_AP_STACKS_OFFSET 8 + +#ifndef __ASSEMBLER__ + +#include +#include + +/* + * Secure Launch AP stack and monitor block + */ +struct sl_ap_stack_and_monitor { + u32 monitor; + u32 cache_pad[15]; + u32 stack_pad[15]; + u32 apicid; +} __packed; + +/* + * Secure Launch AP wakeup information fetched in SMP boot code. + */ +struct sl_ap_wake_info { + u32 ap_wake_block; + u32 ap_wake_block_size; + u32 ap_jmp_offset; + u32 ap_stacks_offset; +}; + +/* + * TXT Heap Map structure + */ +struct sl_txt_heap_info { + u64 size; + u64 offset; +}; + +/* + * Secure Launch defined OS/MLE TXT Heap table + * + * This table is defined at the top level by the TXT specification + * but the format of this structure is implementation specific. + * + * Intel Trusted Execution Technology (TXT) Software Development Guide + * Appendix C - Intel TXT Heap Memory + */ +struct txt_os_mle_data { + u32 version; + u32 reserved; + u64 slrt; + u64 txt_info; + u32 ap_wake_block; + u32 ap_wake_block_size; + u8 mle_scratch[64]; +} __packed; + +#ifdef CONFIG_SECURE_LAUNCH + +/* + * TPM event logging functions. + */ + +/* + * Log a TPM v1 formatted event to the given DRTM event log. + */ +static inline int tpm_log_event(void *evtlog_base, u32 evtlog_size, + u32 event_size, void *event) +{ + struct tpm_event_log_header *evtlog =3D + (struct tpm_event_log_header *)evtlog_base; + + if (memcmp(evtlog->signature, TPM_EVTLOG_SIGNATURE, + sizeof(TPM_EVTLOG_SIGNATURE))) + return -EINVAL; + + if (evtlog->container_size > evtlog_size) + return -EINVAL; + + if (evtlog->next_event_offset + event_size > evtlog->container_size) + return -E2BIG; + + memcpy(evtlog_base + evtlog->next_event_offset, event, event_size); + evtlog->next_event_offset +=3D event_size; + + return 0; +} + +/* + * Log a TPM v2 formatted event to the given DRTM event log. + */ +static inline int tpm2_log_event(struct txt_heap_event_log_pointer2_1_elem= ent *elem, + void *evtlog_base, u32 evtlog_size, + u32 event_size, void *event) +{ + struct tcg_pcr_event *header =3D + (struct tcg_pcr_event *)evtlog_base; + + /* Has to be at least big enough for the signature */ + if (header->event_size < sizeof(TCG_SPECID_SIG)) + return -EINVAL; + + if (memcmp((u8 *)header + sizeof(struct tcg_pcr_event), + TCG_SPECID_SIG, sizeof(TCG_SPECID_SIG))) + return -EINVAL; + + if (elem->allocated_event_container_size > evtlog_size) + return -EINVAL; + + if (elem->next_record_offset + event_size > + elem->allocated_event_container_size) + return -E2BIG; + + memcpy(evtlog_base + elem->next_record_offset, event, event_size); + elem->next_record_offset +=3D event_size; + + return 0; +} + +/* + * External functions available in mainline kernel. + */ +void slaunch_setup(void); +void slaunch_fixup_ap_wake_vector(void); +u32 slaunch_get_flags(void); +struct sl_txt_heap_info *slaunch_txt_get_heap_map(void); +void *slaunch_txt_get_heap_table(void *heap, u8 index); +struct sl_ap_wake_info *slaunch_get_ap_wake_info(void); +struct acpi_table_header *slaunch_get_dmar_table(struct acpi_table_header = *dmar); +void __noreturn slaunch_reset(void *ctx, const char *msg, u64 error); +void slaunch_finalize(int do_sexit); + +static inline bool slaunch_is_txt_launch(void) +{ + u32 mask =3D SL_FLAG_ACTIVE | SL_FLAG_ARCH_TXT; + + return (slaunch_get_flags() & mask) =3D=3D mask; +} + +#else + +static inline void slaunch_setup(void) +{ +} + +static inline void slaunch_fixup_ap_wake_vector(void) +{ +} + +static inline u32 slaunch_get_flags(void) +{ + return 0; +} + +static inline struct acpi_table_header *slaunch_get_dmar_table(struct acpi= _table_header *dmar) +{ + return dmar; +} + +static inline void slaunch_finalize(int do_sexit) +{ +} + +static inline bool slaunch_is_txt_launch(void) +{ + return false; +} + +#endif /* !CONFIG_SECURE_LAUNCH */ + +#endif /* !__ASSEMBLER__ */ + +#endif /* _LINUX_SLAUNCH_H */ --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CCD83EEAC0 for ; Fri, 15 May 2026 21:15:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879712; cv=none; b=sIQ9/kBcYMGSFOB3TyfCIvPOvFDaK3enAtuuv93CtVmj7F2ALju/ZFyqdnJBkaHXT7Ch3HyCkv0RXO0luAPAX1KgXzTcUiviSfzFVw14qlFzLzA7B3aB/e78552a/nXLrwvxpDv+2HYcT/EPAUiZzxit2AEujYsqE2Wrib3QMFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879712; c=relaxed/simple; bh=pAXY0cHMIh7GVzLL6RPpIUoU+IBO2kv57N0YT/cgq+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VaGBJbxbl1ZEzXsbRfUoPeCJWYLfRPfMSPZ5yzQ+4nSsKENUKtXb/lekjgCPVd5Ko0yN/zWiit3t8bzwsdiJIy60Y6RCZWfsSU5xZbK4oJnzi00kwOSyH3STNhXEqbgvYGCG5HSMJHN7HgakCs+pfK88KGp/Bu2DavIzuqPDusc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PsjuM1C+; arc=none smtp.client-ip=74.125.82.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PsjuM1C+" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-2f7ca62a3c4so297025eec.0 for ; Fri, 15 May 2026 14:15:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879710; x=1779484510; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f4K56Y7dB3RpP0PwvxsPRXyN2MFU4pj7XmWxeU528To=; b=PsjuM1C+3PP+EwtxvdqhNFen+oroC06LSGkrGwne3yeDnRGRb4iFQtAT58MezegbLH 8shvobNMQWh4Zqy8Io2xabmmL/5c+3ovwLcMUX28diBB3TbJeR491XZdeUaHdHF/cJE8 l+JmHuWFRP9ZEfuZUb4rKUKzmJvWh4dPc0+5d9u2DD8xfKqrDR5Q/OV+2LOVpFN5QHz5 2xm7JZ5/Nc1nMg39yXkQxi25BQpf6pMCXnp0cKRfTnRXv/asnEEYt0g3fTAZDOjOUsg7 J221wgFR20YPig4oGaELWXfbI2ZX1Fyr6gO+QAqi1FpuvU0Ek9rBgEZw/o44k6ki1w7g 6hRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879710; x=1779484510; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=f4K56Y7dB3RpP0PwvxsPRXyN2MFU4pj7XmWxeU528To=; b=B4BYkoLuspBwWUKBNGEkk0UK3KBTApsfFTfeDQiK49EXUoGF2zBc+w/sJkxeW/UO7O a2vu3Wu6duVmrNB2AC4JwCMQQOOzrv5GHHWiji1PiN4MvK31PckOIQJpaiBAYisErzsn JZm43NVu0uwtHFwwSjRP0Bx23/Pq1mamhboMoIGmL5h9Zyigtx02Mfw+aAgJUZnmpnMR MtZdcB9UbvCVEbkvUOf2IsLGQfr0csai6n8xJPoKyUp0PyvRb6NgcUqdZMm1trbebOcr vF/QnjfV+y1ZkL02Rx4YHw5W6f2ULLlxDFc2/N10J7Dx79rOPppRArb9jxmB/iz4sKhG e5hg== X-Gm-Message-State: AOJu0YxsXFcrS0KBdX9GuNUIHlr7BhFLZ4H5bhFK3Db1telmUoOK1n3t EXjXN37qW+SL5nnrrSzSas2aBassLeN9DthG64tklf80Ht+cejLNYe20cOCtXX4s X-Gm-Gg: Acq92OENNmhvh7EuIErVMWDtQ4dQjwWAiGwytDj+SazSp3lgWGM6zjFlngCAVAiKZIR DclgtuDMozffUZiyx0vEdV8d1tJ2NmwI2SuxNwbEMBqNAKqVLsyZSnrMhblOa7Tmwnyf0APBLPM MHwlXd3QbmwabwYwoDy8h7VjkFdEZZNxpHhZhvBmH8GCR8SWmbU7C3hn9VegfI2k92wR6HFUQDz lGGQfWYckJH7zn9IC27SxST1k/GNBJyXLKDTDSdyjHB+elNhLbkCQDINd5OCyLAzV5jHw2+Y/0Y /KzEiVjNikG697FEy5yUww51E2+QxjrInlJIuqs5E6Om5255dIZc4/phdjMwBD5EJVMz7LkpbR9 1xLA+tadU4BMCJCtkDO/HlfmPZ3LPiaOm2Ny/FPQs4wEBRzux5jEPJDjeAQmBGBCbA5WbnPjofp 1vCJy9wtAvnYA4EmT+mMcHDDHIWH4PZBY= X-Received: by 2002:a05:7301:688:b0:2e2:5bc5:f8eb with SMTP id 5a478bee46e88-303982c04demr2937773eec.9.1778879709562; Fri, 15 May 2026 14:15:09 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302973bbd50sm7962080eec.20.2026.05.15.14.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:09 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 20/38] x86/txt: Intel Trusted eXecution Technology (TXT) definitions Date: Fri, 15 May 2026 14:13:52 -0700 Message-ID: <20260515211410.31440-21-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Intel TXT architectural specific definitions. See the specification for detailed information: https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-t= xt-software-development-guide.pdf Signed-off-by: Ross Philipson --- arch/x86/include/asm/txt.h | 281 +++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 arch/x86/include/asm/txt.h diff --git a/arch/x86/include/asm/txt.h b/arch/x86/include/asm/txt.h new file mode 100644 index 000000000000..eaec915d4878 --- /dev/null +++ b/arch/x86/include/asm/txt.h @@ -0,0 +1,281 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Intel Trusted eXecution Technology (TXT) Definitions + * + * Copyright (c) 2026 Apertus Solutions, LLC + * Copyright (c) 2026, Oracle and/or its affiliates. + */ + +#ifndef _ASM_X86_TXT_H +#define _ASM_X86_TXT_H + +/* + * Intel Safer Mode Extensions (SMX) + * + * Intel SMX provides a programming interface to establish a Measured Laun= ched + * Environment (MLE). The measurement and protection mechanisms are suppor= ted by the + * capabilities of an Intel Trusted Execution Technology (TXT) platform. S= MX is + * the processor's programming interface in an Intel TXT platform. + * + * See: + * Intel SDM Volume 2 - 6.1 "Safer Mode Extensions Reference" + * Intel Trusted Execution Technology - Measured Launch Environment Deve= loper's Guide + */ + +/* + * SMX GETSEC Leaf Functions + */ +#define SMX_X86_GETSEC_SEXIT 5 +#define SMX_X86_GETSEC_SMCTRL 7 +#define SMX_X86_GETSEC_WAKEUP 8 + +/* + * Intel Trusted Execution Technology MMIO Registers Banks + */ +#define TXT_PUB_CONFIG_REGS_BASE 0xfed30000 +#define TXT_PRIV_CONFIG_REGS_BASE 0xfed20000 +#define TXT_NR_CONFIG_PAGES ((TXT_PUB_CONFIG_REGS_BASE - \ + TXT_PRIV_CONFIG_REGS_BASE) >> PAGE_SHIFT) + +/* + * Intel Trusted Execution Technology (TXT) Registers + */ +#define TXT_CR_STS 0x0000 +#define TXT_CR_ESTS 0x0008 +#define TXT_CR_ERRORCODE 0x0030 +#define TXT_CR_CMD_RESET 0x0038 +#define TXT_CR_CMD_CLOSE_PRIVATE 0x0048 +#define TXT_CR_DIDVID 0x0110 +#define TXT_CR_VER_EMIF 0x0200 +#define TXT_CR_CMD_UNLOCK_MEM_CONFIG 0x0218 +#define TXT_CR_SINIT_BASE 0x0270 +#define TXT_CR_SINIT_SIZE 0x0278 +#define TXT_CR_MLE_JOIN 0x0290 +#define TXT_CR_HEAP_BASE 0x0300 +#define TXT_CR_HEAP_SIZE 0x0308 +#define TXT_CR_SCRATCHPAD 0x0378 +#define TXT_CR_CMD_OPEN_LOCALITY1 0x0380 +#define TXT_CR_CMD_CLOSE_LOCALITY1 0x0388 +#define TXT_CR_CMD_OPEN_LOCALITY2 0x0390 +#define TXT_CR_CMD_CLOSE_LOCALITY2 0x0398 +#define TXT_CR_CMD_SECRETS 0x08e0 +#define TXT_CR_CMD_NO_SECRETS 0x08e8 +#define TXT_CR_E2STS 0x08f0 + +/* TXT default register value */ +#define TXT_REGVALUE_ONE 0x1ULL + +/* TXTCR_STS status bits */ +#define TXT_SENTER_DONE_STS BIT(0) +#define TXT_SEXIT_DONE_STS BIT(1) + +/* + * SINIT/MLE Capabilities Field Bit Definitions + */ +#define TXT_SINIT_MLE_CAP_RLP_WAKE_GETSEC 0 +#define TXT_SINIT_MLE_CAP_RLP_WAKE_MONITOR 1 + +/* + * OS/MLE Secure Launch Specific Definitions + */ +#define TXT_OS_MLE_STRUCT_VERSION 1 +#define TXT_OS_MLE_MAX_VARIABLE_MTRRS 32 + +#ifndef __ASSEMBLER__ + +/* + * TXT Heap extended data elements. + */ +struct txt_heap_ext_data_element { + u32 type; + u32 size; + /* Data */ +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_END 0 + +struct txt_heap_end_element { + u32 type; + u32 size; +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_TPM_EVENT_LOG_PTR 5 + +struct txt_heap_event_log_element { + u64 event_log_phys_addr; +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_EVENT_LOG_POINTER2_1 8 + +struct txt_heap_event_log_pointer2_1_element { + u64 phys_addr; + u32 allocated_event_container_size; + u32 first_record_offset; + u32 next_record_offset; +} __packed; + +/* + * TXT specification defined BIOS data TXT Heap table + */ +struct txt_bios_data { + u32 version; /* Currently 5 for TPM 1.2 and 6 for TPM 2.0 */ + u32 bios_sinit_size; + u64 reserved1; + u64 reserved2; + u32 num_logical_procs; + u32 sinit_flags; + u32 mle_flags; + /* Versions >=3D 5 with updates in version 6 */ + /* Ext Data Elements */ +} __packed; + +/* + * TXT specification defined OS/SINIT TXT Heap table + */ +struct txt_os_sinit_data { + u32 version; /* Currently 6 for TPM 1.2 and 7 for TPM 2.0 */ + u32 flags; + u64 mle_ptab; + u64 mle_size; + u64 mle_hdr_base; + u64 vtd_pmr_lo_base; + u64 vtd_pmr_lo_size; + u64 vtd_pmr_hi_base; + u64 vtd_pmr_hi_size; + u64 lcp_po_base; + u64 lcp_po_size; + u32 capabilities; + /* Version =3D 5 */ + u64 efi_rsdt_ptr; + /* Versions >=3D 6 */ + /* Ext Data Elements */ +} __packed; + +/* + * TXT specification defined SINIT/MLE TXT Heap table + */ +struct txt_sinit_mle_data { + u32 version; /* Current values are 6 through 9 */ + /* Versions <=3D 8 */ + u8 bios_acm_id[20]; + u32 edx_senter_flags; + u64 mseg_valid; + u8 sinit_hash[20]; + u8 mle_hash[20]; + u8 stm_hash[20]; + u8 lcp_policy_hash[20]; + u32 lcp_policy_control; + /* Versions >=3D 7 */ + u32 rlp_wakeup_addr; + u32 reserved; + u32 num_of_sinit_mdrs; + u32 sinit_mdrs_table_offset; + u32 sinit_vtd_dmar_table_size; + u32 sinit_vtd_dmar_table_offset; + /* Versions >=3D 8 */ + u32 processor_scrtm_status; + /* Versions >=3D 9 */ + /* Ext Data Elements */ +} __packed; + +/* + * TXT data reporting structure for memory types + */ +struct txt_sinit_memory_descriptor_record { + u64 address; + u64 length; + u8 type; + u8 reserved[7]; +} __packed; + +/* + * TXT data structure used by a responsive local processor (RLP) to start + * execution in response to a GETSEC[WAKEUP]. + */ +struct smx_rlp_mle_join { + u32 rlp_gdt_limit; + u32 rlp_gdt_base; + u32 rlp_seg_sel; /* cs (ds, es, ss are seg_sel+8) */ + u32 rlp_entry_point; /* phys addr */ +} __packed; + +/* + * TPM event log structures defined in both the TXT specification and + * the TCG documentation. + */ +#define TPM_EVTLOG_SIGNATURE "TXT Event Container" + +struct tpm_event_log_header { + char signature[20]; + char reserved[12]; + u8 container_ver_major; + u8 container_ver_minor; + u8 pcr_event_ver_major; + u8 pcr_event_ver_minor; + u32 container_size; + u32 pcr_events_offset; + u32 next_event_offset; + /* PCREvents[] */ +} __packed; + +/* + * Functions to extract data from the Intel TXT Heap Memory. The layout + * of the heap is as follows: + * +----------------------------+ + * | Size Bios Data table (u64) | + * +----------------------------+ + * | Bios Data table | + * +----------------------------+ + * | Size OS MLE table (u64) | + * +----------------------------+ + * | OS MLE table | + * +--------------------------- + + * | Size OS SINIT table (u64) | + * +----------------------------+ + * | OS SINIT table | + * +----------------------------+ + * | Size SINIT MLE table (u64) | + * +----------------------------+ + * | SINIT MLE table | + * +----------------------------+ + * + * NOTE: the table size fields include the 8 byte size field itself. + */ +enum { + TXT_BIOS_DATA_TABLE, + TXT_OS_MLE_DATA_TABLE, + TXT_OS_SINIT_DATA_TABLE, + TXT_SINIT_MLE_DATA_TABLE, + TXT_SINIT_TABLE_MAX, +}; + +/* + * Find the TPM v2 event log element in the TXT heap. This element contains + * the information about the size and location of the DRTM event log. Note + * this is a TXT specific structure. + * + * See: + * Intel Trusted Execution Technology - + * Measured Launch Environment Developer's Guide - Appendix C. + */ +static inline struct txt_heap_event_log_pointer2_1_element* +txt_find_log2_1_element(struct txt_os_sinit_data *os_sinit_data) +{ +#define ptr_after(p) ((void *)p + sizeof(*p)) +#define next_ext_elem(e) ((void *)e + e->size) + /* The extended element array is at the end of this table */ + struct txt_heap_ext_data_element *ext_elem =3D ptr_after(os_sinit_data); + + while (ext_elem->type !=3D TXT_HEAP_EXTDATA_TYPE_END) { + if (ext_elem->type =3D=3D TXT_HEAP_EXTDATA_TYPE_EVENT_LOG_POINTER2_1) + return ptr_after(ext_elem); + + ext_elem =3D next_ext_elem(ext_elem); + } + + return NULL; +} + +#endif /* !__ASSEMBLER__ */ + +#endif /* _ASM_X86_TXT_H */ --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6A1D3EEADE for ; Fri, 15 May 2026 21:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879715; cv=none; b=s0HDMppNUnMqIbfHIgg4XI1qBFbyugi09+FJlXuGdT8TuP6os6zvQJnYeI1WHXHh5dSCpnFSFH1kK+dqEw9J64n+MYVFyYORarG0gY2WiWFatw5US7ZbzmrZb/XBhN7sBJfjNENMJddpe80yFjKqsd9vkxB2b4u+Z2ClPp5+u2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879715; c=relaxed/simple; bh=9qOiZjuMb85ewhTujam6wtmPKlWhsGUjRgHlaJ5hOXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TzRpRDM8QBQg3SgLXOz8TuuaJ0FG2PM9qf8i6Uo2d3lnjqpO58GkX7Ze6UGQwUoDqkRWgh1zH+yxYcdmZ713LqyzexP8KNCUZiKf2rZkZii3c4AiMSsx5SL66o0ejQ69b3f57XxjPOc1vR63rMG4ObygKDvmE7w4trJkovwxey8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hbS/LYf2; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hbS/LYf2" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-3025d725a05so926293eec.1 for ; Fri, 15 May 2026 14:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879712; x=1779484512; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EseM1chjBypSoW0cp1ToXZvQ5KcO5EkTarmMMC63WUM=; b=hbS/LYf2dD1jw9aPBJqPXtrlyu6t+yl4dboWGs4zK1tvEQi2kZV761lDWhXi9oqxw0 LNnhI6Sy7QZcjjWWYFWuIdyhAFkaA3nrxxjFNi7qNxEkKRTQ2ey/HdhWvQ4ibAQ+TECl 82EVN3y6kfnl0qtvHMP1N92u42OmIb3325YRnwq4IiX45yedpdB//tKR8L1ZCZRE9o60 AffvmAizY573rtdjdT/VDLfMPJAaG8NCM3KhKh7K18UD2Qv2f4pOJ59SI4OfkA3F64cK fxRnpyaanO93DB50OAou6rWfvNG5Y/qTtjqt51dmW5FsRtx4Yef0RtxYOT/qa24UJRdN 0Ipw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879712; x=1779484512; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=EseM1chjBypSoW0cp1ToXZvQ5KcO5EkTarmMMC63WUM=; b=QKT7Vnx5CBGqxX5JEZC8k4vbb4/PPN5i4xpzFg6QsUbBPLPjbutCDz8Ife3D6u2if3 BL6qEpZFMAKK7RDSI2DpPi67OXUWeMzHnkh2+PjZ1fqQMQuwHdrD56CldsE3m0pkZ2gk 5sIDACdG7pp0ZBGRHOF3pKDG0fFH50W/aZV5BVrkyu29fhUvQmP3lCnJHxobSPu9hdfQ 8GI4iCIPCHmxqQ7xKH/MbdlJwJ1eoLLTiejolm9bkMvV2z8/RI1L0H+hpmBXSvjl/UOh kgW9pxwFUrhipPg8WCKoZNmJ9ydu7aZDafOBQD8EKId5IWwyrLY8G3EvuPKPPLzcnKKc I0DA== X-Gm-Message-State: AOJu0YyULgXk+/gUBzc8vws/TgrF/EcjDCizCYc3dNtAwT+NWto8qJKT 7/VV47Qj7VzwqhTTVyY+rHN35yLW2wmS/MKKftp/ld6SgWyMXk7+VPbEJB9QOwQ3 X-Gm-Gg: Acq92OHI16hXaa3G+LJYeBC1tGGflWsjehLHfKKiE8iFEmRaZbMJLuLDm8svmfWbW8F D88o0R2pSZ9hNjvsLi6TYFPvbYuepBJCzvTuDSrUIy6Fo6dLyPrV2NSTG8Kgx0wrRy5LpwXlqfP TH5zKLDP0DkUj71uMdf0C/2uW4cKp5t/A7H9ggARUBWA9FKLR0N8PEVATyp4Dl5t0KlkBUOkmz0 D8wrM4buw4dNp/4IAK4Uc8MHr3qZG+XBjDYeUnHfXjAFjH+S5dkodyD72UA5cYDhMEF5Nu0EPyG rT1PUjv4U/rSPLd6skJo0hnf0+PKstlxNM5urBzwhE4LVzxJHNpUfvLTWHrfYqL3QMoxsOEgVkH S5GSlmEWFxSTDNK6lsoIbh3ORreTVfs5cocEHKNMXYlV4i9mYbSaKJP6PQbjwP3mzp1o7mnKF0n gaX+At0cuR15eQzv7dk+rhs8NIfzd0q3A= X-Received: by 2002:a05:7301:19a5:b0:2ed:e17:d50d with SMTP id 5a478bee46e88-3039868c8bcmr2807177eec.32.1778879712290; Fri, 15 May 2026 14:15:12 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302978ad18asm8003129eec.26.2026.05.15.14.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:11 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 21/38] lib/crypto: Add SHA1 support for pre-boot environments Date: Fri, 15 May 2026 14:13:53 -0700 Message-ID: <20260515211410.31440-22-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow the SHA1 library code in lib/crypto/sha1.c to be used in pre-boot environments. Use the __DISABLE_EXPORTS macro to disable function exports and define the proper values for that environment as was done earlier for SHA256. Acked-by: Eric Biggers Signed-off-by: Ross Philipson --- lib/crypto/sha1.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/crypto/sha1.c b/lib/crypto/sha1.c index daf18c862fdf..f30b5ff3b31e 100644 --- a/lib/crypto/sha1.c +++ b/lib/crypto/sha1.c @@ -125,7 +125,7 @@ static void __maybe_unused sha1_blocks_generic(struct s= ha1_block_state *state, memzero_explicit(workspace, sizeof(workspace)); } =20 -#ifdef CONFIG_CRYPTO_LIB_SHA1_ARCH +#if defined(CONFIG_CRYPTO_LIB_SHA1_ARCH) && !defined(__DISABLE_EXPORTS) #include "sha1.h" /* $(SRCARCH)/sha1.h */ #else #define sha1_blocks sha1_blocks_generic @@ -207,6 +207,12 @@ void sha1(const u8 *data, size_t len, u8 out[SHA1_DIGE= ST_SIZE]) } EXPORT_SYMBOL_GPL(sha1); =20 +/* + * Pre-boot environments (as indicated by __DISABLE_EXPORTS being defined) + * don't need the SHA1 HMAC support code. + */ +#ifndef __DISABLE_EXPORTS + static void __hmac_sha1_preparekey(struct sha1_block_state *istate, struct sha1_block_state *ostate, const u8 *raw_key, size_t raw_key_len) @@ -302,6 +308,8 @@ void hmac_sha1_usingrawkey(const u8 *raw_key, size_t ra= w_key_len, } EXPORT_SYMBOL_GPL(hmac_sha1_usingrawkey); =20 +#endif /* !__DISABLE_EXPORTS */ + #if defined(sha1_mod_init_arch) || defined(CONFIG_CRYPTO_FIPS) static int __init sha1_mod_init(void) { --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4A874C6F1E for ; Fri, 15 May 2026 21:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879717; cv=none; b=k2B4pZbELHoFgVIRyECK0xg/nwTHZkno73oz9RT0RiJt8mPNf/AMAE/XbVmEr/AC9TsfrecpgEo77CsN9hB7VcmQkTiu8FclV/ghll9jZIx5Dg102sCY3edw/mpIQ3AWrrp4nFGg4npmJNyEoJvCIp6I1P8RcPERSMWPu79Fb8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879717; c=relaxed/simple; bh=7BAv62SCJAZd+nbTYMXdF5QJlgc01qXtbND56r+tijw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNJcCsdun2MRF/kjlkExLmXWh891G0pHUTbK6GIWxW2ssQvnEt8eVF2rcjH+z/e+rtl7+P7t0yE5H6H8sjfM36/knTmUAuu3/bYde55QwnSES0x6TJUbeXDeetMgVls8JdYm0FtQrNKsMrqnmrmXRYS7nOgNQJnDm2FuD3SV9fA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NNLKh2Ja; arc=none smtp.client-ip=74.125.82.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NNLKh2Ja" Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-30246cfd41aso1512879eec.1 for ; Fri, 15 May 2026 14:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879715; x=1779484515; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RpW1a/fScKIJOJjIsuP4+bGqNlbA4fQX64i8+rdO0zg=; b=NNLKh2Ja78Xg7YtTOJnXXrJO3+1web4zIBvPZyZZjN3nXzCs5iNssEUVficdqe3NQq 2Ch+FsviA0JHGUNEUHj+op4que+AYQY/kcO4XMy8ivf7STGAi/zNN7UAI1WDYx2IpkP+ 1zR5mNKwxB8V3nOiJEX9J+BtjNGEaIHEG61Dx+niQlhjaLnEuIvtCbpsgAKmOhjjN0IG D6TQMwFOq+D1z/OZiCdR6jvuxrrutyZQw+tIvLXkxIG4SMJSnB6TDS+xa4qiKGC36DCW oFs+Vt1gpdouFFwNzklH2Q1Dw2UlB/cUvflsjn2gEjePUqb2JIt1EPxSjNxsOp3LTwGZ IU2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879715; x=1779484515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RpW1a/fScKIJOJjIsuP4+bGqNlbA4fQX64i8+rdO0zg=; b=lRbVZENnQGshRIrdzZ6J73w5kFV+kJgQITyoia40hWeUPqbryYU5hGdEGAK6EXQYQ0 1mD7sCcv7tA9ah+FMyObboUlQPwevTte4ZssZN8/CXmFsohnGVGgEbzON6mimEQ6h77q mK0G8VQx5o6FJaaWSon6rr/8NPKWlYWhZcFpcabPyJEfzk/saByiOFIHFI27wFXt4a4A bJNMpBaTqJ9VdRQH8DB7RTXHUKUJCL5b605+wL7iqMoHj1qWW/yFYyFu+M2n+eujAhmR pRSdKIp4ThG/mP8es9kEt8NrV7JLBDtzr+Ksn20rcTSMYlBqdjxQ1JPnOzVS7ncrdbpZ ERLw== X-Gm-Message-State: AOJu0YzRu3ooth1RhBO2gYZ4Ckr9bXDP1QtW97zK4S1MzNmLO0pgrHPB 22CPdq1AKJwv5zD9aybTouW6JDTTqX25PSvzS7bEHoNBrOcaNk1aD46cFT10AqZK X-Gm-Gg: Acq92OEsr9zX/qnez36jHC3QnCFwvADu7C2QJbhjgZaqdZ9zQ5CzKSJE/+kj+QbF3F4 BRGzv2PnNjgWS8e9hYbaqgf2OjU4ZTOHJZJYhBOC7UR/Zqk9XnJQNCHEDdcGwWm195m9BE2wwYU YBoPmOQGdPb2Q1U9osKJThddp+r9OEmN+es0orS5TjwvHcnpg3j9VsJwXoqwC0fQDRf2+8UwlQn 54M/jHlo5n1QwMEQ5gpNdHCf4KiYOK3b/Y4+gObDxhp1axIXYu0GpzyR2JSq1We6/WRtesevCUU l2mrT4J3OFTw3Sbs/WlP0id0Nt/OG0j19jlqvhhjkwTFRyWwcN2IgXS7CqAmKMGBFOzfhNwp8ul KgrFaoz8HylhRGi/0dmO8E9dRfL23z5+WQYxZVQCc0verxfKzQLybLyPI0MwxCFQ2aDuy4uJP9s /7bO48E8loujL6EC3JsYDaF2Ae53owHSw= X-Received: by 2002:a05:7300:a94b:b0:2be:142f:d499 with SMTP id 5a478bee46e88-30398678a39mr2873251eec.16.1778879715061; Fri, 15 May 2026 14:15:15 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302978ad18asm8003208eec.26.2026.05.15.14.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:14 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 22/38] lib/crypto: Add SHA512 support for pre-boot environments Date: Fri, 15 May 2026 14:13:54 -0700 Message-ID: <20260515211410.31440-23-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow the SHA512 library code in lib/crypto/sha512.c to be used in pre-boot environments. Use the __DISABLE_EXPORTS macro to disable function exports and define the proper values for that environment as was done earlier for SHA256. Signed-off-by: Ross Philipson --- lib/crypto/sha512.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/crypto/sha512.c b/lib/crypto/sha512.c index 605eab51aabd..160e81d86da6 100644 --- a/lib/crypto/sha512.c +++ b/lib/crypto/sha512.c @@ -133,7 +133,7 @@ sha512_blocks_generic(struct sha512_block_state *state, } while (--nblocks); } =20 -#ifdef CONFIG_CRYPTO_LIB_SHA512_ARCH +#if defined(CONFIG_CRYPTO_LIB_SHA512_ARCH) && !defined(__DISABLE_EXPORTS) #include "sha512.h" /* $(SRCARCH)/sha512.h */ #else #define sha512_blocks sha512_blocks_generic @@ -250,6 +250,12 @@ void sha512(const u8 *data, size_t len, u8 out[SHA512_= DIGEST_SIZE]) } EXPORT_SYMBOL_GPL(sha512); =20 +/* + * Pre-boot environments (as indicated by __DISABLE_EXPORTS being defined) + * don't need the SHA2 HMAC support code. + */ +#ifndef __DISABLE_EXPORTS + static void __hmac_sha512_preparekey(struct sha512_block_state *istate, struct sha512_block_state *ostate, const u8 *raw_key, size_t raw_key_len, @@ -406,6 +412,8 @@ void hmac_sha512_usingrawkey(const u8 *raw_key, size_t = raw_key_len, } EXPORT_SYMBOL_GPL(hmac_sha512_usingrawkey); =20 +#endif /* !__DISABLE_EXPORTS */ + #if defined(sha512_mod_init_arch) || defined(CONFIG_CRYPTO_FIPS) static int __init sha512_mod_init(void) { --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F00AD426D0B for ; Fri, 15 May 2026 21:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879720; cv=none; b=cCsVvk0wRBRlwJWXd90u2HvBIxzbr5eR1kVlW8bUl3VqmbZlJZUkKVlbqLreI7K8x0Ln8VrYxHqpYbhx54A+ftKLjjeKSBocyDYfHIOuz9luw0g/oyhbiM50rQkXhpoj/e1Zk04F8+hl4Da4wCJJdj8HB9twY1KJw0uP0Zm+NL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879720; c=relaxed/simple; bh=Zcwz++VNrXh9y6soBYCC7hxdmV5RO3C0KhJ6H3w36Z4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IwhSXwa6UekuEqDk09j9LL/7TnSH4IMedKgx2olbsQ6HNzhxRxGo9zkidAK9b/HgrPD4G0gb8v1S5wGKn548kM4UxJBvksJ2ZOaSnQFOF0Wi2jlZmFnvzC5cefK1Pt5UgB19C7rKpYLAZcm67ggIsZBf6AqKPklt4cxWlXFY6k8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pS456OJH; arc=none smtp.client-ip=74.125.82.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pS456OJH" Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-2ee990e8597so746285eec.1 for ; Fri, 15 May 2026 14:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879718; x=1779484518; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=h8RkPwRSQGNgtwFGhMa45mhqNtBX9nLmlB3IzWi1i0E=; b=pS456OJH1AEeHSLqDqw4ui/jbQksci7GOMA5UlZbGUKa3b3cKwqxQ6MWm5xwlX57PI IZDJIMG8QqVi0ayPNo4/ypRXZdgRlhu+XjkAk73EqC7nB0IRpSRqGXxoy8vQd8Bgt0CQ WzXiDAw6KrRaOGBb/z0v7a61im0dlEScKq/wb4E9/cTIbcx67pmRYk290CD9S+K1KRL/ l6Fry/b26nnViZfxl9z6fED8dgvP5m7O9o1LjTQeMg92Ky/sK7+4svsAdj3UWxQlrHwX SF0UYmimTDOTR1kBR9t4IKWksrJIgXR9XanS7ZoycxoKXpmFEuhgVKLoq5LCGKnBYZTA SWvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879718; x=1779484518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=h8RkPwRSQGNgtwFGhMa45mhqNtBX9nLmlB3IzWi1i0E=; b=cvvGONPAP7ErINzXWUqTp3rf7tG3EHc0X5DcEfW1DGIC5D6gWLCXd1DdByNKugePaK 5hzAfhRkLEctg3xil9e5T+duLwArM0oYIlS16wK3xeWyzUKh9YCv4ufb2rVS05zBtECI hnmRFGRbbRf9CEUwgO8Fgwz1+Y33d5EyQ8LtFxmurGXtEGLbdV3KIDAcEKZJLSNEAKjD OuTNbj76F0R1K0AQjaWGTXy4yRpFyOiq+MZyolR49wkiwc/5hA38zyKinsbC0g3TzLW1 YtaRfBy/6jral+OwTWaXNWTF7UC3VVhhRqFbRYw0EryovRs5g6x6i/yhwr8Grgw7FGzu I8pg== X-Gm-Message-State: AOJu0Yzz+CzDL009f/H9W3yOeJE5Kc324xSUepHKhnXJi2wP0ZittWqS E9XF9tJMnco9Ft3pMaaNprRmYnVZbsANnrqzZXAOdp7phiL6GLLyV8C3iByDjmN2 X-Gm-Gg: Acq92OF7suN1MLgp2ey7uCgZkwcKWpo/t0clnmPAMvjiTX5U8lsf9oSptQtNU/AtU3L cATAP8C4Vn/XzK6fDjBewtBPzA2OA0prLo5QsKwZqUd1nNJosHTNObzpIc7vZfXoJiMtSKwYS4Z MQRejw0GBMzD4eOqHFu2vulP6mOUueoUPbqP7h12E6C4l3JiNDdLyRshcLgpp/YzV7dRWq/el/r hU0ro/XkQ4s3oI/vm8ukkhbn/KGoEbN2+jnMbhvzpMgnc40Z1zF2yynqDRH4oIZ+ysH54R4Tzkc wk+bgiRH2pM8fOOJSYyQyQTQu+e2NPPGYC+LFxQaUXdpiZcE3dp+ZL9VwqeRKHPcr//oK9Pyu34 48h2CbJb3XDiUMK5Cm0HvE+6uctcpHf0i4TX5Gj10H34c6mzqqOKkh1sI1aYAtvZJF19oQz+/xf FCZSd4wVZlTnSt3+/41COP7jOs7xxL3Jg= X-Received: by 2002:a05:7300:ad30:b0:2e7:5737:8364 with SMTP id 5a478bee46e88-303984e17ffmr3028118eec.15.1778879717789; Fri, 15 May 2026 14:15:17 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302947e917dsm8005268eec.12.2026.05.15.14.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:17 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 23/38] x86: Allow WARN_trap() macro to be included in pre-boot environments Date: Fri, 15 May 2026 14:13:55 -0700 Message-ID: <20260515211410.31440-24-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For pre-boot environments, do not use the static call definition of the WARN_trap() macro. Suggested-by: Peter Zijlstra Signed-off-by: Ross Philipson --- arch/x86/include/asm/bug.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index 80c1696d8d59..7899768ae644 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -138,8 +138,14 @@ do { \ #ifdef HAVE_ARCH_BUG_FORMAT_ARGS =20 #ifndef __ASSEMBLER__ + +#ifndef __DISABLE_EXPORTS #include DECLARE_STATIC_CALL(WARN_trap, __WARN_trap); +#define WARN_trap(...) static_call_mod(WARN_trap)(__VA_ARGS__) +#else /* __DISABLE_EXPORTS */ +#define WARN_trap(...) __WARN_trap(__VA_ARGS__) +#endif /* __DISABLE_EXPORTS */ =20 struct pt_regs; struct sysv_va_list { /* from AMD64 System V ABI */ @@ -172,7 +178,7 @@ extern void *__warn_args(struct arch_va_list *args, str= uct pt_regs *regs); #define __WARN_print_arg(flags, format, arg...) \ do { \ int __flags =3D (flags) | BUGFLAG_WARNING | BUGFLAG_ARGS ; \ - static_call_mod(WARN_trap)(__WARN_bug_entry(__flags, format), ## arg); \ + WARN_trap(__WARN_bug_entry(__flags, format), ## arg); \ asm (""); /* inhibit tail-call optimization */ \ } while (0) =20 --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C41A03F5BCE for ; Fri, 15 May 2026 21:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879723; cv=none; b=WSKcYDLA0T/T6JzYNCW2CWKK3ZmP/c8m9sKVey6ykphAbd2nDexgV95oesK74wlCEZoEJV+PXK+yLUeTM2lEUR0x4vX432bAwffnIoIVIH8qPIoiFh88XIr/P4QamwJ8AmjrQJ39ji/7O82AHinrFzCmnzj4hIiNUUWTUt7LZ0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879723; c=relaxed/simple; bh=EYoiytDPHAwrp//ZCSS8x2mbpMMq39lmGS1yWEcEk0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eGPdGsJ9ngfjEtige+UwDglQnLUAUY79MMTF7A/pJoqBIgS7goXt1KLxEAyGEIxlqc49+2HVl/XJ7AdoYJPhIXjt3srv+Vrabi6pSVjSl7OOfJIA1xUkjTy8z1QOz3K1UtysCDNAtwt6ENV+57BGhNXZERx1r0O2ujb0E1mcsok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F1qUkByA; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F1qUkByA" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-2bdcf5970cdso151255eec.0 for ; Fri, 15 May 2026 14:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879721; x=1779484521; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bjgxy9jrMUn+tA5MZsUkk9qLfIPrTHgv6m9jj+0YWR4=; b=F1qUkByArkNhkX8Vb784ExX/rl6QJS4DBW18WWjmqir3frGenB8qERsSXnGvklGLAv P95lUGWZ/GjM5Y8NDhtwk+h7BAZdVVuhvyz3q5hRMQNdOwOddJhcvGUoFa/vXVClvFKe wqjcw/pK5nDmkWn+eoT576g/DS1UOQF6lw1/oFI5+Mv5RZ6s3bdSJPul7HgcuiSoNehY aqCyhEYdbq1d7DY9fGbSDrwyFgxPSFLNb2nXjUjBvJQ/+WY7nO+CLHiKS8na6SFKYbbN kICn8lsE/ST/LYMxnVpC+KaX+OIkFBQXRIJmARETvIikWBupy+rK2Nc8yIpJ4zTTneK/ i97Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879721; x=1779484521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bjgxy9jrMUn+tA5MZsUkk9qLfIPrTHgv6m9jj+0YWR4=; b=c6iDiWuFG2EeL8M5JHb6zwAeXM6VQZ+QJyuFSn3o0D5EoCuVd7cWTSvVHpVoYvh1yX qvaMuFyd+blHnlAeeKsu9o3AUAmMBWAwW3giiQ+ENRHEO2S14stY1nlwYGNIg1tdFMeQ qOgVZftXvnj8k3ZFe/2IUxG0rmaAgtRt24PRSnx5A7hUfH1kdGrGGh5CpbEkzgvWVu3a 91d8STE8h2tOEfZBxb8wIeA4I9W0VpefEo0qi0uwESqJELaFeiesdwFBoMeliFNKENnA uVBs/ch+s4OOFh5FBASNogpSrjlMivkxdnMlT+dXpXdgORibRCinv5/L9kOjnKoEptSr DDKg== X-Gm-Message-State: AOJu0Ywh3XCRZ9QxT4pQlEDV3FVZwMt8cVlV6K871cKKkSCKDE583FnN Q3U0n/pWW/QBEBiaqDidZ2ZJLEin32WEaWSK8kzgnVy3oVfqyIbSq/fhl+QYXFLN X-Gm-Gg: Acq92OHRa2fuo2ai19FjMnD8aiwrD7HD3VSItSzlGSa4LzzAoQ8JZRkSIpM7caLrerP B/aVrRjOUit640bUbS4YxPp/+IqupwmBvtedBms/jEJvzHRLSC7fOVB9RqyvRMD1ms9E556t5V5 +Sbpovesa9MwEJmDiaayU1vjYkMiyBWpMflDzb2vLMEr0qRR5GLJFa6C2Z/jvVV7sLNNKmV26HV 1C8USsfvknt25+R5URfIVu999p2KV5w36Fbn8bSacHExXGNMhB3R5UnY1lZea+ZhYmn3kXw8NcE H5ppf0ThoodJoR9eqfr7jNi047BHwzi9vKcDA3l0sP9tOiUEg8NSUGOb3DmZP/tLOvFasVk9VA1 7LTdy+2qejQUtdCqQ7IB8tsvpSHpDxQ6PtaMAuGJqcnDkW2SSL/MO6lRBoHgpxl4eZsNyrJ7xja zsPJ7N3gYjHk5J/0tj5fF9Wqa62+reWQ4= X-Received: by 2002:a05:7300:2316:b0:2f3:5d44:eeba with SMTP id 5a478bee46e88-3025fa54325mr4525827eec.6.1778879720563; Fri, 15 May 2026 14:15:20 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2e3c0sm9975127eec.3.2026.05.15.14.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:20 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 24/38] x86/msr: Add variable MTRR base/mask and x2apic ID registers Date: Fri, 15 May 2026 14:13:56 -0700 Message-ID: <20260515211410.31440-25-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the MSR values required by Secure Launch to locate particular CPU cores during application processor (AP) startup, and restore the MTRR state after an Intel TXT launch. Signed-off-by: Ross Philipson --- arch/x86/include/asm/msr-index.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index 6673601246b3..2a95e3389622 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -408,6 +408,9 @@ #define MSR_IA32_RTIT_OUTPUT_BASE 0x00000560 #define MSR_IA32_RTIT_OUTPUT_MASK 0x00000561 =20 +#define MSR_MTRRphysBase0 0x00000200 +#define MSR_MTRRphysMask0 0x00000201 + #define MSR_MTRRfix64K_00000 0x00000250 #define MSR_MTRRfix16K_80000 0x00000258 #define MSR_MTRRfix16K_A0000 0x00000259 @@ -960,6 +963,8 @@ #define MSR_IA32_APICBASE_ENABLE (1<<11) #define MSR_IA32_APICBASE_BASE (0xfffff<<12) =20 +#define MSR_IA32_X2APIC_APICID 0x00000802 + #define MSR_IA32_UCODE_WRITE 0x00000079 =20 #define MSR_IA32_MCU_ENUMERATION 0x0000007b --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C3283F5BCB for ; Fri, 15 May 2026 21:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879725; cv=none; b=f4K96x8xTWSYKLZo5Ly603cIdoLNAetS3xZ7aVU5w43IHMq5B1y0dv2Mk1KA7qiSA0nn8wyE+jWZqF0bjZ9H8w2eMwJtsgvGBDemXt6SDy1YudVLOp9NBoHqyL4JzLG6HCnOmVtDnbGjdLP1NwWlc7/kdxO7ui7lIlWtbXcf+6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879725; c=relaxed/simple; bh=DULLarGA3N2WbmTOoIAH6Z6cAJNNwTwfc+oSbMTDbH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jFtxEZh3TxKIQ8bbIUYAa7acc/IjDaoKMFdmXRVvvycKFZ0p+l+P631QW6upSYnsR7Kw/bJvwhPTyyXSIeG/YNWBihIWLM2q80nIJqxHKo6dCuUdOQIaguPEMEEwWzQH8AG+N4FPMx576Nhsr62TO8n+xnsrKCjO7S2/DfKSuKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GfxRkan2; arc=none smtp.client-ip=74.125.82.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GfxRkan2" Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-2f3c623322bso1045198eec.0 for ; Fri, 15 May 2026 14:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879723; x=1779484523; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ER4IWQsMKw/HNZSo0sHiz6UgahZlpRSMvCUCrr/URAk=; b=GfxRkan2jXb/hDtBDF0b2sCZ9HhiKP1Jj/yCjehZ+FkCiZlTYroSSQI6ZCBGNx/FBH nB/APZdgfAjcUw2LfZ3ELWjaOwm/EVaIrw6+uWbd46OCgIH2/r/rsmi8lFGVmYlCYmz5 iihILkrwP8lqd2Dn4bjCqFt+vijLcekhje43yv4KJ8blEx7Jga1xd2AM5HfyT9v3Etfa aBW7LDioHVaE1M7oNwRvB5TxwC+2TRLlsekBab0tgxFWaCbgvF+FxIoX0AAFL6kw9CJV rm/gWOxfdEdyOeJakpFiJ9XLMAElhxeMRQzo54xa/6YGBaLUk0AH3FHDfgIQiVMNwZMb i+RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879723; x=1779484523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ER4IWQsMKw/HNZSo0sHiz6UgahZlpRSMvCUCrr/URAk=; b=Fl2Pyfo1EscA+TRLJCBcY0Utmp+GsFQkBNTwAWUMKNube8zQZXcyRiXVI9r4xDTfJH qblqDzeZLF9GkTjrfMimOdBHe5rWb05helJZ/x2eT23rI9hIIeG1J1zR9aXNbu0aquKw NTyq4jV6UpxSkihilHQrzU1NOD38DBWf9+rLDTV2uePw54t5+XBo11lckHtutok7RssY OMgXx+SD5sv6GtL3LE85JDKkLfkaq5qvotVmTsza5y/j9NTcd/oG0k30PpZ3jNl1/d0x 4aYSkSolSyhg8PT0Eez1wFM+0Rzw+wObFzbBHphkJhRm1Bn0xLyeKcqDzgPC4jOrdsq4 Q4xw== X-Gm-Message-State: AOJu0YzsGjn/cnGGAfuclXmL8Zqb8+/Z5wK1uCvgNTNz4Xy9vF9SiZyv 8AGv4Q/4AG8WAYKdppf4jAawoF4rMQW257Uf1d9MRgriugeGNpTCD7zj/xwyr3dI X-Gm-Gg: Acq92OEVW9bZaBqVO03EfFF0V0Otws/lWsbUCctO5MuZ2Lmd6zDvn9QDKHYBIr3ShTk uaN+fv89Ib0jJMQfDJ1Q/rDUcr3tPgzbQhOTz5+CqHgPxrPMcjmaOrW7WRvBMC5Gq26hrIrdwG9 gyt36Ja1y0cAnywcPj2i+oY5treIeCUyjQ12lK+z3370AAftew5ClyPzEhnMFWULsUJi2X7Nakj cGbatHJm6pfUPmkvcAhQlfYuRYGGgky/UyhSSkKz7/UTSlV0HVWKpsFfQTZxREKIhELM7NedB/d oz/5O2tuqvU2RHZEjWtTF/88Uqc6WJlX5+Ajbtru3nPdrb85/pZDDVm2CupHnqJmrVKq34kwxHm j6SYDJ1iTLNKUx7r9xDsEypzKwmVeuRxCwH5u+rClpiFoPhqlhmnAT02r8l1/OS6pNdWnBuj0AI q/1a7OPZgk4m3wBv45L6NGa68VQ7EkQz1Kljtq4mM8fA== X-Received: by 2002:a05:7301:4184:b0:2f4:3a9c:818c with SMTP id 5a478bee46e88-303986b1521mr2959973eec.29.1778879723496; Fri, 15 May 2026 14:15:23 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cbcb9ef5sm10736508c88.2.2026.05.15.14.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:23 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 25/38] x86/boot: Slight refactor of the 5 level paging logic Date: Fri, 15 May 2026 14:13:57 -0700 Message-ID: <20260515211410.31440-26-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel In preparation for adding Secure Launch support, which will require that the number of paging levels remains untouched, tweak the logic slightly so that the slaunch check can be inserted easily. No functional change intended. Signed-off-by: Ard Biesheuvel Signed-off-by: Ross Philipson --- arch/x86/boot/compressed/pgtable_64.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compress= ed/pgtable_64.c index 0e89e197e112..3e9d651da73e 100644 --- a/arch/x86/boot/compressed/pgtable_64.c +++ b/arch/x86/boot/compressed/pgtable_64.c @@ -102,6 +102,7 @@ static unsigned long find_trampoline_placement(void) =20 asmlinkage void configure_5level_paging(struct boot_params *bp, void *pgta= ble) { + bool l5_enabled =3D native_read_cr4() & X86_CR4_LA57; void (*toggle_la57)(void *cr3); bool l5_required =3D false; =20 @@ -118,10 +119,12 @@ asmlinkage void configure_5level_paging(struct boot_p= arams *bp, void *pgtable) * + CPUID leaf 7 is supported * + the leaf has the feature bit set */ - if (!cmdline_find_option_bool("no5lvl") && - native_cpuid_eax(0) >=3D 7 && (native_cpuid_ecx(7) & BIT(16))) { - l5_required =3D true; + if (native_cpuid_eax(0) < 7 || !(native_cpuid_ecx(7) & BIT(16))) + return; + + l5_required =3D !cmdline_find_option_bool("no5lvl"); =20 + if (l5_required) { /* Initialize variables for 5-level paging */ __pgtable_l5_enabled =3D 1; pgdir_shift =3D 48; @@ -132,7 +135,7 @@ asmlinkage void configure_5level_paging(struct boot_par= ams *bp, void *pgtable) * The trampoline will not be used if the paging mode is already set to * the desired one. */ - if (l5_required =3D=3D !!(native_read_cr4() & X86_CR4_LA57)) + if (l5_required =3D=3D l5_enabled) return; =20 trampoline_32bit =3D (unsigned long *)find_trampoline_placement(); --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CA0A413D97 for ; Fri, 15 May 2026 21:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879728; cv=none; b=p8UP4JZYwfc/MNxHYgY6wwGB+1hJ+sSeK39KonC9fXS5JyQPi9d43KGWtrNlNiqzfOHtvOx2WxugDlMpZVy+XY+MbRctdi2X95WcgbRGoTPtZIMYPYs//dCVItZsptuqyA3anTuTal+v5pfTsXL44syMTdkeinXaHp+LP80UwEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879728; c=relaxed/simple; bh=ws7RALHIgZvmMfHxpeYb691c/xou17qPzYNIPgpKvkw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ewvaPHIQkMMYry01zkysQki92pTQfASN3+9t/+PkBZKK/MrOVHoYm7Kx5o1vbKFUguP0ZzkGveh/VWTMWSv56On0l3xvIPDZeNKV/0/EFfVaXIMClIo3qqDB0OMayOMTeBLygXUymjTcBaj59BeKsQBOfubelOMh3yx92oIQJec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mLG862k+; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mLG862k+" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-2f7020a928eso392763eec.1 for ; Fri, 15 May 2026 14:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879726; x=1779484526; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zqo7CRqxUyGu2ximwHeynWdE4uCktJ1VQ9YKgYjfZfU=; b=mLG862k+XvHfYupXY2cGN3KGmsVEarkfn+irlqIgLRV7YTl1YOL7rWy18hQOrUcqlJ ksnEVDMtlJuORz9AHqXFw1cYhAdj/9o+vXaXOOzWe28wk3dys/zIToepw6+c9dHabvKa FiUYL7xyp4xQS5EoFtUZXt8tX4vME/asD+16w3nvjGBBr595Q0+FUwYlvG03IibGTq1F wdi40Wrv0EGMGgRZiRjvkTDMXd04nosit30VEIyD5KQIlIlUfalXz61hGUlhExwWOiAd 4UHGDn8sFl7bGSQ1rfhi58kXBo1l+ZYheebN8ogAtmUiyBkcGc5As9oKrf9bzH5BADsC 10Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879726; x=1779484526; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zqo7CRqxUyGu2ximwHeynWdE4uCktJ1VQ9YKgYjfZfU=; b=iURyRkNFCY8BK2jXZF9BuwvtoDImmhjftOUjnlsNuHKe2bMLuB9IAgsmIFbFxtBIpA 4jkDA74sti0urEPOSCLI8MPbM9Hsbu9J58UZngBmaGjSQdhJ6mSiGpfbJ0Esu+24pcUb uERsORTlxYkItSKeYuuGCrs+FOsOHZ7Um27hlnXIPnUsLQTvxdK/vgdzxLUClmnLdqPU z8zeaIozHkF0S6mrOxPmS5NuuxkNxSkQ04WTYbNS0PAszDJDfQNY7/LKbYGfw3ntT5W0 S5rgEz4LQruSzTzSj6aTGqL9dr4NDC4NHwbslci2mevLQoKmAPS2tM4SboM0la5fgyrl JeMg== X-Gm-Message-State: AOJu0YySV++K3JNl4qHW2UCbFAwWXdNztJW1XqG+QWhL/v7JPnkkNP6T EGQJTjk4bXva+dA90qYgNqRiI3kj3KIbVdvw5mu6PA/LtZeVdKHMP6WvXE9MDk3o X-Gm-Gg: Acq92OFza7J9lB3rX73ryYqGDVPBptj/OoXRxzdAX7JnrCyiGkFdGu2em09Pm2t0ibN JeDMPAQny+rdyMb+h1PjEWKXXtGeI2h2S5BFVEHrwQOIjimumlZnDXU4pQzicWqAkjSuwEJX8+B tjzbntu1hioXnv0cVjOKLI9a42xZImnnzjayo9gBQjIEkEH9vU1JhShl97bg6n6K2rgOaIociBr +VImqOKQKbo/PmfUDCJ3qWFYUtrqJZA90lfFejr7Kf8+Ewk++sjvjJpxGmKJd/CCNMq0cmfz5IY 5XzwHiQW9JgaCpy5LDZzDmpH0NIrrgjbWAr4We8JfFuRztNltGyYSQNsjZmDw/qu0q1MEuYBXIy lU7RJYIus6JSey3h903wXrmlDQ31SP5ln9OE1NARkDm5IegtVYm1mybdfrLCoxb4MEroc3fuewC /uGS29G0dQ0oCMvZQy6+q2IZGFE5/3pgg= X-Received: by 2002:a05:7300:fb83:b0:2de:cc07:e8b with SMTP id 5a478bee46e88-3039818afa7mr2863582eec.1.1778879726369; Fri, 15 May 2026 14:15:26 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302977a9474sm8155633eec.25.2026.05.15.14.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:25 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 26/38] x86: Add early SHA-1 support for Secure Launch early measurements Date: Fri, 15 May 2026 14:13:58 -0700 Message-ID: <20260515211410.31440-27-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" Secure Launch is written to be compliant with the Intel TXT Measured Launch Developer's Guide. The MLE Guide dictates that the system can be configured to use both the SHA-1 and SHA-2 hashing algorithms. Regardless of the preference towards SHA-2, if the firmware elected to start with the SHA-1 and SHA-2 banks active and the dynamic launch was configured to include SHA-1, Secure Launch is obligated to record measurements for all algorithms requested in the launch configuration. The user environment or the integrity management does not desire to use SHA-1, it is free to just ignore the SHA-1 bank in any integrity operation with the TPM. If there is a larger concern about the SHA-1 bank being active, it is free to deliberately cap the SHA-1 PCRs, recording the event in the DRTM log. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/boot/startup/Makefile | 4 ++++ arch/x86/boot/startup/lib-sha1.c | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 arch/x86/boot/startup/lib-sha1.c diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile index 5e499cfb29b5..e283ee4c1f45 100644 --- a/arch/x86/boot/startup/Makefile +++ b/arch/x86/boot/startup/Makefile @@ -20,6 +20,10 @@ KCOV_INSTRUMENT :=3D n =20 obj-$(CONFIG_X86_64) +=3D gdt_idt.o map_kernel.o obj-$(CONFIG_AMD_MEM_ENCRYPT) +=3D sme.o sev-startup.o + +slaunch-objs +=3D lib-sha1.o +obj-$(CONFIG_SECURE_LAUNCH) +=3D $(slaunch-objs) + pi-objs :=3D $(patsubst %.o,$(obj)/%.o,$(obj-y)) =20 lib-$(CONFIG_X86_64) +=3D la57toggle.o diff --git a/arch/x86/boot/startup/lib-sha1.c b/arch/x86/boot/startup/lib-s= ha1.c new file mode 100644 index 000000000000..8d679d12f6bf --- /dev/null +++ b/arch/x86/boot/startup/lib-sha1.c @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2026 Apertus Solutions, LLC + */ + +#include "../../../../lib/crypto/sha1.c" --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C3F240488D for ; Fri, 15 May 2026 21:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879732; cv=none; b=UQryYq2/ZINVC+7jva9iEHJ7QZHBQz2QAK/29cOoKqIGh7pzI+4g5F3gXDzQTne8dUbXCGYpZnXeMA7Dz029aYAkmlIdS4GG1mmDygxYf5x8ivdHlueBrXN06zua7L0V6kk+y+indh+gr1zGi3QP2sznkCi4iZAQq2MT59EdNUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879732; c=relaxed/simple; bh=kbvK6cuaNQpZn6Q9g72Q+TOpf/2ROUnAJihI0oZoubo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NsyWAW2wDvMOQvoCORJM4FFQmQwg1AloZ6TjNMB8e1/qJs3UD/q3C06mnNV0h9zGjK4YgOW2hafNtXCm1IAc52jC0WOYKp8lgFhAMwUDA+hhbLVNdlSTFzMeLC9S/d6yAfRBoadasquSSgjPEKzRnpqX4YIFs3wtubQL43p++V4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=o9OputCr; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o9OputCr" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2c156c4a9efso374986eec.1 for ; Fri, 15 May 2026 14:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879729; x=1779484529; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6v1a1pQ4RntgauZdGQ/AgmAZlKsDK24ag7JDuVxfuOw=; b=o9OputCrmArK0qB9XWlHF/QKy9zlHBWFInzZrLIt4PpmYMpSYUW/atSgYmLlgUM3f3 XQigHp+a4Zv2AXXBarW6f+KVLGlpORIk3Lz9XpkEPVhgevaX3pNxUgtWBbvcp0bd2SOT bXAHdAnn35Nia+1dkLc0jWevh3S7Wpl0bpu8juF223uNnqlu6TjcLkJ29SE3/imlzEsJ qrQ0p/s8SbX3PesAM/CSUB23lxUVz/gXlmeAStw17Jra8vDv4spFo+sgBeCI+aTcdrG5 4KPpFb8pNCMi68b71RFVGuY1sy7Y+uTy06kpVfSsgaeC6RLXeGW1CiQT8dg76RfN0yjZ jzvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879729; x=1779484529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6v1a1pQ4RntgauZdGQ/AgmAZlKsDK24ag7JDuVxfuOw=; b=VRCDFS/DtnA0VcyUhZUvnV3n0mS59UQ1aYw3+Mp9LqLgrrNqfT2JEk2C8Xg2L+fogq zsBRaDzks95fw0N5Ff9MetXUUHAzq31IVxAylOENRdPUMQSksQo5OJ49BpOvHr3UaVnN 5LrPZ4SX+Zyfk/Uuyxd7S1EnoZoKH+do8wD6VMUB5qOiAzvtbQpyjRSHM5khxjWkNRvd XCF6uym0SS1RFSay8XcoPV3DGJka/qIf5diLCYyk1T3XgUfbol28D1KwDPH5l6n9CQ+Q U033o6WLataT/ei/0fBrDxtkBmPzYNNXyjcPXL7OSlY4UGzLozutGqe6Biyxa+agMvAK YJPg== X-Gm-Message-State: AOJu0YwFCC54ErFZiugrpS/W2AIEwpsvbq1FG1BuNL/UEoX2OqSfMg6P Fzo2J49Eg3fgLx4HcgQirApOp7oic519OXRi97eBVUdCfaNd9Jv09kzRaJ+gKFkd X-Gm-Gg: Acq92OGgFWAK1urnOQ1gvgnE+X/Zml6r9g3H52k+2FbT4fUo0CHmD0T/cOCXshA6YLx V3oOmEHHMVSzJXQrM08SV3NtHet9WvreU2GVEVYJbqdZAnZropoiFCMQcNFT9zrQ4ARFtP7/c0X vZXpux7yc7idz2AIqpmHNmGP5SdC7UOgyftZjoJd0rUMa7hZ1zef6BPdxMVwTiSBbNIgEh84hht /mmN5lBFekQvjnuPvvf1O6V+s222Dkl+CcRejaXEyXpunBRHjIzcZDACzh6aaUSEgZh8aCwimUF KaGk7yuqedltDZ+2oI68tgBWwFTGU2NkQmigQNlO/JU3MGtOR1AU05Q5GtgxDUjpPwch37m5WrG O/tAyjDrkXWeUT9hPPGOd4BjRijU4CvVIrpdzDIq9Na2uAqHdP6Xtoe0ks45q1XBHnfFW03p+mz dHFNGNnoPE32fcQDxJLw/y6swofwZbSAY= X-Received: by 2002:a05:7300:818b:b0:2be:7885:31df with SMTP id 5a478bee46e88-30398618b3fmr3091136eec.17.1778879729276; Fri, 15 May 2026 14:15:29 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2ea6dsm8268038eec.4.2026.05.15.14.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:29 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 27/38] x86: Add early SHA-256 support for Secure Launch early measurements Date: Fri, 15 May 2026 14:13:59 -0700 Message-ID: <20260515211410.31440-28-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" The SHA-256 algorithm is necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA-256 library directly in the early boot code. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/boot/startup/Makefile | 1 + arch/x86/boot/startup/lib-sha256.c | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 arch/x86/boot/startup/lib-sha256.c diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile index e283ee4c1f45..071a90f23ae0 100644 --- a/arch/x86/boot/startup/Makefile +++ b/arch/x86/boot/startup/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_X86_64) +=3D gdt_idt.o map_kernel.o obj-$(CONFIG_AMD_MEM_ENCRYPT) +=3D sme.o sev-startup.o =20 slaunch-objs +=3D lib-sha1.o +slaunch-objs +=3D lib-sha256.o obj-$(CONFIG_SECURE_LAUNCH) +=3D $(slaunch-objs) =20 pi-objs :=3D $(patsubst %.o,$(obj)/%.o,$(obj-y)) diff --git a/arch/x86/boot/startup/lib-sha256.c b/arch/x86/boot/startup/lib= -sha256.c new file mode 100644 index 000000000000..f60df97f9244 --- /dev/null +++ b/arch/x86/boot/startup/lib-sha256.c @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2026 Apertus Solutions, LLC + */ + +#include "../../../../lib/crypto/sha256.c" --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06C594048B2 for ; Fri, 15 May 2026 21:15:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879735; cv=none; b=AAzoZIzv0qFRTbKJJ+sWPeaJX+492iI51cADilvvSM5pEpy6Hatf8rt4p8BgVvLJCOXUwwP9bzsGgm4A61idUEdkmOdiumJ/V3sUPfquOemhs45rOAyZCYU6qtIHt4FamYEpBaL5pTZy1a09c3nBz0/9nQt+RuzwefSABLP+XMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879735; c=relaxed/simple; bh=ILT1qaKW78nRQkC/CMCLSzr2h8dTPOcGoDMHkPnSKzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MkQIBwK7fyMTIDbDplSptzwsTkxltj2k2vZbpbzMAKdAHZgBffDG5sVBsmkTxRa0kdGoPzH28ogXhKmZc3IDJJmLbqk4x8cIq8VKVOJaxJiqm1IHNwyZWksmLdyhhd5fRQDDwSA7KU779WL0vkHP8PAMBwU3U3tbrq66A+PbZPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IYL3YWM0; arc=none smtp.client-ip=74.125.82.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IYL3YWM0" Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-12c1a170a50so288806c88.0 for ; Fri, 15 May 2026 14:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879732; x=1779484532; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aF0BH6dZpM5RACWLo6N4NcvxHw87HpE9a7jatFY2Xnk=; b=IYL3YWM0K72+PKBjUIotlkyudmp1jTzkcWSk+FsrFVXzSnegkXpcBDTHvkmgtyv013 1Fz+1cDxxzxpwH2cjTMD3XcK8OrL3KyPSBFqH8USMoVoBphH/PDfMppdjjf5WM9Uu+zw zdblTDDlg3ILJFwS88bKz+DpkkC4R874roDAz+B70ThKNQTz3lnAY6Vm18brrdmeKYlL nrRDow22yM9/5xyVwtbnB/WqwizcqZ8UTLFg96EIfVlIoQZejH3ZXpbdDCcTFwuaBYDe SBIe7CCRHOt+kHRuouqHqrJpRS0HE1SBm0toraK+5jwMRSnRo9h+dKmUj5IEOAw9IoLh DUQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879732; x=1779484532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aF0BH6dZpM5RACWLo6N4NcvxHw87HpE9a7jatFY2Xnk=; b=Nl2/Uh58h0QZ2Pf3q88+jghSCfje8TbOJ9OTfliUmM+m+PTgDZ8gg66B7LJMaHyY+l sQKZzeXwQlG2YnqCGnmdS9/33nJ9F3HGUEPeZlOIs2bI2F1xb6ddazjjMEzFaWlVw1bI X6EwxRwPtQmgxHqpaF2cSv//4dbdNp+y30eNaixiCCmFYGxe/7Zcf+56nmhlErZOvyx+ m2QCNxkxFzQuLtnN9XeCj1f2wo27wpNfL49iRNuxHQydVO0Y1EQZwntjZ4znZpVtGXwn jyDBiiFtyQ3KciK6WnrviT9yuntIhurp7XLcdwHzC11xdfQJ5nBpKl7tGjh8wCtBHKvh ikHQ== X-Gm-Message-State: AOJu0YwcpcMPA300Ib53poXSGSLG2/2/84xsyMK8lNHnomc2jiiXgJ/i DJNTMrlodA/HG7yBwJt0UzWdBigMHA6kPOkYyLsTeQ6QkcjAm6J9rS9O7tDMiFyK X-Gm-Gg: Acq92OHzwxuuGXz3np8SjaBpVyeqBuBq59CN6BAwXZFcHn4RtzIc+X1fNoNJ3HzxJmR SAmpzG2MFO1UT9C4z0oNU7rBTGTHD0CDNArkMmZ0FpPx9zOdxjCoigBs2bo/VVV95PE69vafXB/ Cm9KTFDY68OsmEP8P8hR89JcOtczAF/S3gE/6ayN3edeHF33kM3wIaDBCSwCgbEOQceLHFAjJHw bh92i8ZmndnWt2PKqLlp1Wd9OG69TeMGCE/S+EW6XwVk6I4Nogq00fhkm2qDyA0VxL0/Zmddyn+ OqI2zJ4aIi3TJ+6SZMJw4mJfYW7HaMSElP5QmIG6ORhJzgmD9ezYIjr7CN9yt4l3q5yZAcswUVU eHR1rN22qkP+EAe0oP+8TLfXxZVhh6ZfZUYEOdrVtl6B7gNYiB6UQ2NW5c1ttiy9Agn0xgoIJ0x eLB9Gq6dIo5005n3fwqZPmheZxTT9GG1kC6JeqzdE4CA== X-Received: by 2002:a05:7022:6621:b0:134:a710:d908 with SMTP id a92af1059eb24-1350451887emr2398095c88.13.1778879732067; Fri, 15 May 2026 14:15:32 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cc33a618sm11245224c88.12.2026.05.15.14.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:31 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 28/38] x86: Add early SHA-384/512 support for Secure Launch early measurements Date: Fri, 15 May 2026 14:14:00 -0700 Message-ID: <20260515211410.31440-29-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" On newer TPM 2 implementations, SHA 384 and 512 banks may be available for use. If these banks are enabled in firmware, they will be used for the Dynamic Launch. The DLME will also use these algorithms to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA-512 library directly in the early boot code. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/boot/startup/Makefile | 1 + arch/x86/boot/startup/lib-sha512.c | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 arch/x86/boot/startup/lib-sha512.c diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile index 071a90f23ae0..527cba7e4560 100644 --- a/arch/x86/boot/startup/Makefile +++ b/arch/x86/boot/startup/Makefile @@ -23,6 +23,7 @@ obj-$(CONFIG_AMD_MEM_ENCRYPT) +=3D sme.o sev-startup.o =20 slaunch-objs +=3D lib-sha1.o slaunch-objs +=3D lib-sha256.o +slaunch-objs +=3D lib-sha512.o obj-$(CONFIG_SECURE_LAUNCH) +=3D $(slaunch-objs) =20 pi-objs :=3D $(patsubst %.o,$(obj)/%.o,$(obj-y)) diff --git a/arch/x86/boot/startup/lib-sha512.c b/arch/x86/boot/startup/lib= -sha512.c new file mode 100644 index 000000000000..2afd5c5935cd --- /dev/null +++ b/arch/x86/boot/startup/lib-sha512.c @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2026 Apertus Solutions, LLC + */ + +#include "../../../../lib/crypto/sha512.c" --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3865B3F44C6 for ; Fri, 15 May 2026 21:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879738; cv=none; b=AEIzcX0cnRZKHNzVObyrZyI9hGpqJ/kDaQZnaAoxEl0H2mRnD7iPmc867unJGCIlhOyQitUhudX4ZyKls09wzbauU0jYP/DFnHMjFw/EXCbExOeMR2EzYCREdZPxXoEKI9a91vlDEXxxrMZ77kBsyoQ88BZSKV9JyCq5MQ+cpLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879738; c=relaxed/simple; bh=rNdJJ8YVhFpY/mOFackrLIoznhga5VyceHpT+Iq/eqk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HR+gNlBTfCLA42+TkcHAErvrG6Mi/dxs1zBC51OU6UW1D+sJLAgZb/qfiYUeLbr9klb5FTkVd8ei+Cep6ELVTYYxeLbzBnF0MkmUw1wXRipRr5R2ra/eKzz6MgAZ0XYpTOX6mWH4VPNkdOnxPcC3nzMvnYx+sLmvJ58Rd8uF5N4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HmB9JnH5; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HmB9JnH5" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2f0d3e07e30so1354453eec.0 for ; Fri, 15 May 2026 14:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879735; x=1779484535; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ViurL0csUM0y6zC2/BziEDI+4nTSab4FjJtc7RqXPgw=; b=HmB9JnH5XAg7V69IaDFpgbuA/suif2QUJJW+6W5xc3WvGjHRvnpxz6EBZNyt6/0rSt z8dbwurgr0wGbbh8vM+u4VwTc+aH0Wzch5Y6SW9yq4fCQQKTqhwwvrsjhBdWWaIZZsMB RlNTf+6rl3a1J+G0LRUcq+nPijGBBczTHqFUZltsOM0wM6Vvzp6wuvVirFzQC7J0SRzM jQj2mG1quOE0vJkdGgm5U2dqWncdxcoWrFVoYCrnlakxfIQBWBTbBD9Krl9GDyavLAY8 GFmcx7UXo1o7oLtVH0WxHrkxXd4B5NFwdnAf5jXzygs8ufHHiOGnD0gK2w8CijzHsquj spYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879735; x=1779484535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ViurL0csUM0y6zC2/BziEDI+4nTSab4FjJtc7RqXPgw=; b=eBSB2YUztE3Ra+WUk8rOtxs/EgdeGwJc49VBJjqvCoD+YUqJ13ziaxpDATpr8VWMiN NmY0ENGvm7/IQjwWxF9I6cCJr3qmDvMtK8QGZ5IKrsn9OLIXS1b7TitJsew1BCg0Tjdq k3B2APEARxA1XRTA3t4OwGMy4r4xmiZYYviBLjs8KQ9cdnkjxzHo7oT/IhOBvjvz+hhI 1pJGoyAO6sIqy0lJeQvbgAOTgjaPlsArVGPZ0QXIkjsVuC9lSdLGije6q66d+ofFTygG cSb2z4xcIZ9nhfPEfd3CFa9WHpkJN8pn4e4WM2OV/tP2ijgf1jFl201KvM7dyAiNHkIt fUqg== X-Gm-Message-State: AOJu0Yzr757Gl8TowkeqFzchRr0o5/aS5MLAqXTWaBqZRk1X5xMPdeb0 nUB2Df2gAvtt0PnJCJ5f8bbWO0KiAC1CDuYOP5Y8GFSDET9SRtCpKFWUREOQraeo X-Gm-Gg: Acq92OFO5HLrm2jqS8mybYf4cHraTs/OMbvQS0SHyQ+UpWTSfkSnNp3QYet5tw6I5Qv dF+8gvYSMOCfUi6mKyCn1aOSf4tsXKLupvscOolDr3bsFdWUknvmts96nWQs1yUsMlA7j0mEQgD RkkhCAOKVt+bco0RMBoFP2ru50BYEEXWwfdpDMHDvDvKZTfmAQegI/9qsjfpNfg4jpaZSvL4pTh CYg40Hiz9fOSCectiOSEyFbPDnhk143gFFKmjQs/MlFa4WphcdlY/yDmbFl4HGUKxec/fQ/ogun mM8o2BculikoVGkc5zwKKjbVxYLLgfo/aoaB8LJmYErvI/tl/gXW6HbdAXH1wCKuC8V7X+4mJ2/ uo/9VgRT5JyNbgmA28YZzTcvS1gyKuP1trtA51JZY24m/uyqb9LULW40OiOavhW49AXP3tn5lJW 3fswZQfzBj6AywfTB3EwuofO6sWfzagOJgY4iaoES3fg== X-Received: by 2002:a05:7300:510:b0:2c1:7b61:8731 with SMTP id 5a478bee46e88-303982be4d0mr3180070eec.10.1778879734916; Fri, 15 May 2026 14:15:34 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302944ffb85sm8214358eec.7.2026.05.15.14.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:34 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 29/38] x86/tpm: Early startup TPM PCR extending driver Date: Fri, 15 May 2026 14:14:01 -0700 Message-ID: <20260515211410.31440-30-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a driver that can interact minimally with the TPM. This allows the Secure Launch startup code to extend measurement values into the TPM's DRTM PCR banks early in the launch process. The driver implementation only currently supports basic initialization and PCR extend commands. An extend command can be sent to both TPM 2.0 or 1.2 chip but only the TIS/FIFO interface is currently supported. The TCG specs for these interface can be found here: https://trustedcomputinggroup.org/resource/pc-client-work-group-pc-client-s= pecific-tpm-interface-specification-tis/ https://trustedcomputinggroup.org/resource/tpm-2-0-mobile-command-response-= buffer-interface-specification/ Note this TPM driver implementation relies as much as possible on existing mainline kernel TPM code. Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Co-developed-by: Alec Brown Signed-off-by: Alec Brown Signed-off-by: Ross Philipson --- arch/x86/boot/startup/Makefile | 1 + arch/x86/boot/startup/exports.h | 7 + arch/x86/boot/startup/tpm.h | 47 +++ arch/x86/boot/startup/tpm_drv.c | 567 ++++++++++++++++++++++++++++++++ 4 files changed, 622 insertions(+) create mode 100644 arch/x86/boot/startup/tpm.h create mode 100644 arch/x86/boot/startup/tpm_drv.c diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile index 527cba7e4560..ecf86ce5ebf7 100644 --- a/arch/x86/boot/startup/Makefile +++ b/arch/x86/boot/startup/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_AMD_MEM_ENCRYPT) +=3D sme.o sev-startup.o slaunch-objs +=3D lib-sha1.o slaunch-objs +=3D lib-sha256.o slaunch-objs +=3D lib-sha512.o +slaunch-objs +=3D tpm_drv.o obj-$(CONFIG_SECURE_LAUNCH) +=3D $(slaunch-objs) =20 pi-objs :=3D $(patsubst %.o,$(obj)/%.o,$(obj-y)) diff --git a/arch/x86/boot/startup/exports.h b/arch/x86/boot/startup/export= s.h index 01d2363dc445..4b82ddbd62a8 100644 --- a/arch/x86/boot/startup/exports.h +++ b/arch/x86/boot/startup/exports.h @@ -12,3 +12,10 @@ PROVIDE(snp_cpuid =3D __pi_snp_cpuid); PROVIDE(snp_cpuid_get_table =3D __pi_snp_cpuid_get_table); PROVIDE(svsm_issue_call =3D __pi_svsm_issue_call); PROVIDE(svsm_process_result_codes =3D __pi_svsm_process_result_codes); + +#ifdef CONFIG_SECURE_LAUNCH +__pi_bcmp =3D bcmp; +__pi_memcmp =3D memcmp; +__pi_strlen =3D strlen; +__pi___WARN_trap =3D __WARN_trap; +#endif diff --git a/arch/x86/boot/startup/tpm.h b/arch/x86/boot/startup/tpm.h new file mode 100644 index 000000000000..1a11396b68c6 --- /dev/null +++ b/arch/x86/boot/startup/tpm.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * TPM early extend header file. + * + * Copyright (c) 2026 Apertus Solutions, LLC + * Copyright (c) 2026, Oracle and/or its affiliates. + */ + +#ifndef BOOT_COMPRESSED_TPM_H +#define BOOT_COMPRESSED_TPM_H + +enum early_tis_defaults { + TPM_TIMEOUT =3D 5, /* ms */ + TIS_DURATION =3D 120000, /* 120 secs in ms */ +}; + +enum tpm_family { + TPM_FAMILY_INVALID =3D 0, + TPM_FAMILY_12 =3D 1, + TPM_FAMILY_20 =3D 2 +}; + +struct tpm_chip { + enum tpm_family family; + u64 baseaddr; + int locality; + int did; + int vid; + + /* in ms */ + ktime_t timeout_a; + ktime_t timeout_b; + ktime_t timeout_c; + ktime_t timeout_d; +}; + +bool tpm_tis_check_locality(struct tpm_chip *chip, int loc); +void tpm_tis_release_locality(struct tpm_chip *chip); +int tpm_tis_request_locality(struct tpm_chip *chip, int loc); +void tpm_tis_disable_interrupts(struct tpm_chip *chip); +int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash); +int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, + struct tpm_digest *digests, u32 digest_count); +int early_tpm_init(struct tpm_chip *chip, u64 baseaddr); +int early_tpm_fini(struct tpm_chip *chip); + +#endif /* BOOT_COMPRESSED_TPM_H */ diff --git a/arch/x86/boot/startup/tpm_drv.c b/arch/x86/boot/startup/tpm_dr= v.c new file mode 100644 index 000000000000..99971b06f768 --- /dev/null +++ b/arch/x86/boot/startup/tpm_drv.c @@ -0,0 +1,567 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Based of the original tpm_tis.c implementation as found in the + * Linux 2.6 code base. + * + * Copyright (C) 2005, 2006 IBM Corporation + * + * Authors: + * Leendert van Doorn + * Kylene Hall + */ + +#include +#include + +#include +#include +#include + +#include "tpm.h" + +static u8 tpm_buf_page[PAGE_SIZE]; + +/* + * Single threaded environment only running on BSP. Use a single shared + * page for all TPM extend operations. + */ +static inline struct tpm_buf *tpm_buf_alloc_page(void) +{ + memset(tpm_buf_page, 0, PAGE_SIZE); + return (struct tpm_buf *)tpm_buf_page; +} + +static inline void tpm_buf_free_page(void) +{ + memset(tpm_buf_page, 0, PAGE_SIZE); +} + +/* Pull in TPM buffer management support */ +#include "../../../../drivers/char/tpm/tpm-buf.c" + +static u32 __init tpm_get_alg_size(u16 alg_id) +{ + switch (alg_id) { + case TPM_ALG_SHA1: + return TPM_DIGEST_SIZE; + case TPM_ALG_SHA256: + case TPM_ALG_SM3_256: + return SHA256_DIGEST_SIZE; + case TPM_ALG_SHA384: + return SHA384_DIGEST_SIZE; + case TPM_ALG_SHA512: + default: + return SHA512_DIGEST_SIZE; + }; +} + +static inline u8 tpm_read8(struct tpm_chip *chip, u32 field) +{ + return readb((void *)(chip->baseaddr | field)); +} + +static inline void tpm_write8(struct tpm_chip *chip, u32 field, u8 val) +{ + writeb(val, (void *)(chip->baseaddr | field)); +} + +static inline u32 tpm_read32(struct tpm_chip *chip, u32 field) +{ + return readl((void *)(chip->baseaddr | field)); +} + +static inline void tpm_write32(struct tpm_chip *chip, u32 field, u32 val) +{ + writel(val, (void *)(chip->baseaddr | field)); +} + +/* + * In the setup kernel environment, it is far too early to calibrate time. + * Assume a 5GHz processor (the upper end of the Fam19h range), allowing + * reasonable timeouts on slower systems. + */ +static unsigned long ticks_per_ms =3D (5UL * 1000 * 1000 /* CPU in KHz */); + +static inline ktime_t tpm_now_ms(void) +{ + return rdtsc()/ticks_per_ms; +} + +static inline void tpm_mdelay(unsigned int msecs) +{ + unsigned long ticks =3D msecs * ticks_per_ms; + unsigned long s, e; + + s =3D rdtsc(); + do { + cpu_relax(); + e =3D rdtsc(); + } while ((e - s) < ticks); +} + +static inline u8 __tis_status(struct tpm_chip *chip) +{ + return tpm_read8(chip, TPM_STS(chip->locality)); +} + +static inline void __tis_cancel(struct tpm_chip *chip) +{ + /* This causes the current command to be aborted */ + tpm_write8(chip, TPM_STS(chip->locality), TPM_STS_COMMAND_READY); +} + +static int __init __tis_get_burstcount(struct tpm_chip *chip) +{ + ktime_t stop; + int burstcnt; + + stop =3D tpm_now_ms() + chip->timeout_d; + do { + burstcnt =3D tpm_read8(chip, (TPM_STS(chip->locality) + 1)); + burstcnt +=3D tpm_read8(chip, TPM_STS(chip->locality) + 2) << 8; + + if (burstcnt) + return burstcnt; + + tpm_mdelay(TPM_TIMEOUT); + } while (tpm_now_ms() < stop); + + return -EBUSY; +} + +static int __init __tis_wait_for_stat(struct tpm_chip *chip, u8 mask, ktim= e_t timeout) +{ + ktime_t stop; + u8 status; + + if ((__tis_status(chip) & mask) =3D=3D mask) + return 0; + + stop =3D tpm_now_ms() + timeout; + do { + tpm_mdelay(TPM_TIMEOUT); + + status =3D __tis_status(chip); + if ((status & mask) =3D=3D mask) + return 0; + } while (tpm_now_ms() < stop); + + return -ETIME; +} + +static int __init __tis_recv_data(struct tpm_chip *chip, u8 *buf, int coun= t) +{ + int size =3D 0; + int burstcnt; + + while (size < count && + __tis_wait_for_stat(chip, + TPM_STS_DATA_AVAIL | TPM_STS_VALID, + chip->timeout_c) =3D=3D 0) { + burstcnt =3D __tis_get_burstcount(chip); + + for ( ; burstcnt > 0 && size < count; --burstcnt) + buf[size++] =3D tpm_read8(chip, TPM_DATA_FIFO(chip->locality)); + } + + return size; +} + +/** + * tpm_tis_check_locality - Check if the given locality is the active one + * @chip: The TPM chip instance + * @loc: The locality to check + * + * Return: true - locality active, false - not active + */ +bool __init tpm_tis_check_locality(struct tpm_chip *chip, int loc) +{ + u8 res =3D tpm_read8(chip, TPM_ACCESS(loc)); + + if ((res & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) =3D=3D + (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) { + chip->locality =3D loc; + return true; + } + + return false; +} + +/** + * tpm_tis_release_locality - Release the active locality + * @chip: The TPM chip instance + */ +void __init tpm_tis_release_locality(struct tpm_chip *chip) +{ + u8 res =3D tpm_read8(chip, TPM_ACCESS(chip->locality)); + + if ((res & (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) =3D=3D + (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) + tpm_write8(chip, TPM_ACCESS(chip->locality), TPM_ACCESS_RELINQUISH_LOCAL= ITY); + + chip->locality =3D 0; +} + +/** + * tpm_tis_request_locality - Request to make the given locality the activ= e one + * @chip: The TPM chip instance + * @loc: The locality to make active/set as current + * + * Return: + * >=3D 0 - Success, new active locality returned or locality already act= ive + * < 0 - Error occurred + */ +int __init tpm_tis_request_locality(struct tpm_chip *chip, int loc) +{ + ktime_t stop; + + if (tpm_tis_check_locality(chip, loc)) + return loc; + + /* Set the new locality */ + tpm_write8(chip, TPM_ACCESS(loc), TPM_ACCESS_REQUEST_USE); + + stop =3D tpm_now_ms() + chip->timeout_b; + do { + if (tpm_tis_check_locality(chip, loc)) + return loc; + + tpm_mdelay(TPM_TIMEOUT); + } while (tpm_now_ms() < stop); + + return -1; +} + +/** + * tpm_tis_disable_interrupts - Disable interrupts for the TPM, use pollin= g mode only + * @chip: The TPM chip instance + */ +void __init tpm_tis_disable_interrupts(struct tpm_chip *chip) +{ + u32 intmask; + + intmask =3D tpm_read32(chip, TPM_INT_ENABLE(chip->locality)); + /* Disable everything to make sure it is in a consistent state */ + intmask &=3D ~(TPM_GLOBAL_INT_ENABLE | TPM_INTF_CMD_READY_INT | + TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT | + TPM_INTF_DATA_AVAIL_INT); + tpm_write32(chip, TPM_INT_ENABLE(chip->locality), intmask); +} + +/** + * tpm_tis_recv - Receive response data from TPM via TIS FIFO + * @chip: The TPM chip instance + * @buf: The response buffer + * @count: Length of the response buffer + * + * Return: + * =3D 0 - Success, no response data + * > 0 - Success, value is the response data length + * < 0 - Error occurred + */ +static int __init tpm_tis_recv(struct tpm_chip *chip, u8 *buf, int count) +{ + int expected, status, size =3D 0, rc =3D -EIO; + + if (count < TPM_HEADER_SIZE) + goto out; + + /* Read first 10 bytes, including tag, paramsize, and result */ + size =3D __tis_recv_data(chip, buf, TPM_HEADER_SIZE); + if (size < TPM_HEADER_SIZE) + goto out; + + expected =3D be32_to_cpu(*((u32 *)(buf + 2))); + if (expected > count) + goto out; + + size +=3D __tis_recv_data(chip, &buf[TPM_HEADER_SIZE], expected - TPM_HEA= DER_SIZE); + if (size < expected) { + rc =3D -ETIME; + goto out; + } + + __tis_wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c); + + status =3D __tis_status(chip); + if (status & TPM_STS_DATA_AVAIL) { + rc =3D -EIO; + goto out; + } + + /* Done with receive, move to Command Ready state */ + __tis_cancel(chip); + + return size; +out: + __tis_cancel(chip); + tpm_tis_release_locality(chip); + return rc; +} + +/** + * tpm_tis_send - Send command to TPM via TIS FIFO + * @chip: The TPM chip instance + * @buf: The command buffer + * @len: Length of the command buffer to send + * + * Return: + * =3D len - Success, all data sent + * < 0 - Error occurred + */ +static int __init tpm_tis_send(struct tpm_chip *chip, u8 *buf, int len) +{ + int status, burstcnt =3D 0; + int count =3D 0; + int rc =3D 0; + + status =3D __tis_status(chip); + if ((status & TPM_STS_COMMAND_READY) =3D=3D 0) { + __tis_cancel(chip); + if (__tis_wait_for_stat(chip, TPM_STS_COMMAND_READY, chip->timeout_b) < = 0) { + rc =3D -ETIME; + goto out_err; + } + } + + while (count < len - 1) { + burstcnt =3D __tis_get_burstcount(chip); + for ( ; burstcnt > 0 && count < len - 1; --burstcnt) + tpm_write8(chip, TPM_DATA_FIFO(chip->locality), buf[count++]); + + __tis_wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c); + status =3D __tis_status(chip); + if ((status & TPM_STS_DATA_EXPECT) =3D=3D 0) { + rc =3D -EIO; + goto out_err; + } + } + + /* Write last byte */ + tpm_write8(chip, TPM_DATA_FIFO(chip->locality), buf[count]); + __tis_wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c); + status =3D __tis_status(chip); + if ((status & TPM_STS_DATA_EXPECT) !=3D 0) { + rc =3D -EIO; + goto out_err; + } + + /* Go and do it */ + tpm_write8(chip, TPM_STS(chip->locality), TPM_STS_GO); + + return len; + +out_err: + __tis_cancel(chip); + tpm_tis_release_locality(chip); + return rc; +} + +/** + * tpm_tis_transmit - Transmit a TPM FIFO command + * @chip: The TPM chip instance + * @buf: The request and response buffer object + * @bufsize: Entire size available in buffer + * + * Return: + * =3D 0 - Success, no returned data + * > 0 - Success, value is the return data length + * < 0 - Error occurred + */ +static int __init tpm_tis_transmit(struct tpm_chip *chip, u8 *buf, u32 buf= size) +{ + ktime_t stop; + u32 count; + u8 status; + int rc; + + count =3D be32_to_cpu(*((u32 *) (buf + 2))); + if (count =3D=3D 0) + return -ENODATA; + + if (count > bufsize) + return -E2BIG; + + rc =3D tpm_tis_send(chip, buf, count); + if (rc < 0) + goto out; + + stop =3D tpm_now_ms() + TIS_DURATION; + do { + status =3D __tis_status(chip); + if ((status & (TPM_STS_DATA_AVAIL | TPM_STS_VALID)) =3D=3D + (TPM_STS_DATA_AVAIL | TPM_STS_VALID)) + goto out_recv; + + if (status =3D=3D TPM_STS_COMMAND_READY) { + rc =3D -ECANCELED; + goto out; + } + + tpm_mdelay(TPM_TIMEOUT); + rmb(); + } while (tpm_now_ms() < stop); + + /* Cancel the command */ + __tis_cancel(chip); + rc =3D -ETIME; + goto out; + +out_recv: + rc =3D tpm_tis_recv(chip, buf, bufsize); + if (rc >=3D 0) { + if (rc > 0 && rc < TPM_HEADER_SIZE) + return -EFAULT; + return rc; + } + /* Else return was an error, nothing to receive */ + +out: + return rc; +} + +/** + * tpm_find_interface_and_family - interface FIFO/CRB, family 2.0 or 1.2 + * @chip: The TPM chip instance + * + * Return: TPM family ID enum + */ +static enum tpm_family __init tpm_find_interface_and_family(struct tpm_chi= p *chip) +{ + struct tpm_intf_capability intf_cap; + struct tpm_interface_id intf_id; + + /* Sort out whether it is 1.x */ + intf_cap.val =3D tpm_read32(chip, TPM_INTF_CAPS(0)); + if ((intf_cap.interface_version =3D=3D TPM_TIS_INTF_12) || + (intf_cap.interface_version =3D=3D TPM_TIS_INTF_13)) + return TPM_FAMILY_12; /* Always TIS */ + + /* Assume that it is 2.0 but check if the interface is CRB */ + intf_id.val =3D tpm_read32(chip, TPM_INTF_ID(0)); + if (intf_id.interface_type =3D=3D TPM_CRB_INTF_ACTIVE) + return TPM_FAMILY_INVALID; + + /* Else TPM 2.0 with TIS interface */ + return TPM_FAMILY_20; +} + +/** + * tpm1_pcr_extend - send a TPM1 extend command to the device + * @chip: a TPM chip to use + * @pcr_idx: the PCR index to extend for the current locality + * @hash: the SHA1 hash digest to extend + * + * Return: + * * 0 - OK + * * -errno - A system error + * * TPM_RC - A TPM error + */ +int __init tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *h= ash) +{ + struct tpm_buf *buf =3D tpm_buf_alloc_page(); + int rc =3D 0; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_EXTEND); + + tpm_buf_append_u32(buf, pcr_idx); + tpm_buf_append(buf, hash, TPM_DIGEST_SIZE); + + rc =3D tpm_tis_transmit(chip, buf->data, PAGE_SIZE); + + /* Ignoring output */ + if (rc > 0) + rc =3D 0; + + tpm_buf_free_page(); + + return rc; +} + +/** + * tpm2_pcr_extend() - send a TPM2 extend command to the device + * + * @chip: TPM chip to use. + * @pcr_idx: index of the PCR. + * @digests: list of PCR banks and corresponding digest values to extend. + * @digest_count: count of digests to extend + * + * Return: + * * 0 - OK + * * -errno - A system error + * * TPM_RC - A TPM error + */ +int __init tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, + struct tpm_digest *digests, u32 digest_count) +{ + struct tpm_buf *buf =3D tpm_buf_alloc_page(); + int rc =3D 0, i; + + tpm_buf_init(buf, TPM_BUFSIZE); + tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_PCR_EXTEND); + + tpm_buf_append_u32(buf, pcr_idx); + + /* Setup a NULL auth session for the command */ + tpm_buf_append_u32(buf, 9); + /* auth handle */ + tpm_buf_append_u32(buf, TPM2_RS_PW); + /* nonce */ + tpm_buf_append_u16(buf, 0); + /* attributes */ + tpm_buf_append_u8(buf, 0); + /* passphrase */ + tpm_buf_append_u16(buf, 0); + + tpm_buf_append_u32(buf, digest_count); + + for (i =3D 0; i < digest_count; i++) { + tpm_buf_append_u16(buf, digests[i].alg_id); + tpm_buf_append(buf, (const unsigned char *)&digests[i].digest, + tpm_get_alg_size(digests[i].alg_id)); + } + + rc =3D tpm_tis_transmit(chip, buf->data, PAGE_SIZE); + + /* Ignoring output */ + if (rc > 0) + rc =3D 0; + + tpm_buf_free_page(); + + return rc; +} + +int __init early_tpm_init(struct tpm_chip *chip, u64 baseaddr) +{ + u32 didvid; + + memset(chip, 0, sizeof(*chip)); + chip->baseaddr =3D baseaddr; + + chip->family =3D tpm_find_interface_and_family(chip); + if (chip->family =3D=3D TPM_FAMILY_INVALID) + return TPM_ERR_INVALID_FAMILY; + + /* Set default timeouts */ + chip->timeout_a =3D TIS_SHORT_TIMEOUT; + chip->timeout_b =3D TIS_LONG_TIMEOUT; + chip->timeout_c =3D TIS_SHORT_TIMEOUT; + chip->timeout_d =3D TIS_SHORT_TIMEOUT; + + /* Get the vendor and device ids */ + didvid =3D tpm_read32(chip, TPM_DID_VID(0)); + chip->did =3D didvid >> 16; + chip->vid =3D didvid & 0xFFFF; + + return TPM_SUCCESS; +} + +int __init early_tpm_fini(struct tpm_chip *chip) +{ + tpm_tis_release_locality(chip); + memset(chip, 0, sizeof(*chip)); + + return TPM_SUCCESS; +} --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CE7A405845 for ; Fri, 15 May 2026 21:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879742; cv=none; b=rdPzH9vdpRvKkh5jhQBAtGP85Oq3Lz8tQ9G3tgTQgv8EZi+ChZdQk+vByPXjtZEtJOCPRaa1uWP6Phy0LVL3OQTMbc284/8xJo+lF94QLnGBow8k/cbKfjR9dfgoAhwkwYp9tFqE5zQHweaxsBu64ZVr18EfDoO9bVxG9za8HP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879742; c=relaxed/simple; bh=KrBKqiI/11SRfq8AI/RjyJMaBvonJMkTwc8/qeUOIjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XPV+B1x94600LBAYE9Z4SRIoGOJhfGOS5QaCT8Za2lh4UhDF8xlOBS3nPJw+mard/7PhLImE7VXyB7rVPWG5bdQQVyqpMnVRqA21vXYdWugmphOEmZKvJa+qpqzjcM91EzScP/MKjwTsSL8cnESVqOJdvgMM+mObJxVcfxOPf9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Jrq5kVMS; arc=none smtp.client-ip=74.125.82.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Jrq5kVMS" Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-2f7ca62a3c4so297385eec.0 for ; Fri, 15 May 2026 14:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879738; x=1779484538; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R8y+5pcm0AAt3l5YBSo5Gboi+epX/2lV4aopgke6Vsw=; b=Jrq5kVMSd1V9O4AIppqVhYfKhtnbdWnFeo/1dKkcGAuycFmh+rGJJ//w2pWlhhrS8f Xe3bvW9tBo2qQ222SGjaYdLIeCVwFp2kcDahfXDiqcVJAAh7a5ijNygi9w6sXpuXu2Ud qmha19P7QSagIHDrQg2FIHrH5mYtzIeDPGj0UEK64w1imrdd9dQgVNJtNYtJHzgWxdUP nvtFEad6FQVci7Oi0BKhV4PEGomhlK1kL9FipN6UF14jLlB8Y26WZ7joIpy7zYMkasWj RU5FuT3jtO1NMe+U+RLGElzA1Cx+n7Ke7nAtuXCjVLpYpbeWD/Hfj/dDPHtJuIlT/H5n uZmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879738; x=1779484538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=R8y+5pcm0AAt3l5YBSo5Gboi+epX/2lV4aopgke6Vsw=; b=gQhMX69bYgNKdci2dCJAYqeJXUHgzNmmPJ4CBww9J0GpjHEf8sM/yQFynS4cC/l798 tUZeEm79KEKPjKx6Phs+yiYPO4gUonJT/YB890ro8ywX2/W+TfcbV4cHAWZrlE0Xe1A6 Q6+MAme2NL/AMnt4IpKXTmPGRjyMRfY+PXbWtVTnrUgRJax24KF0w/W+Gr8HEQ0/LrAC J2KcvF9dk+8guLhH/NQAWy+mrOuUsmUm05WCy4PibnWliVQI+IkaBLuxlzEHlnVDNbow oBpJS4Xn0ZU6S8lSyITB3aFB8h9a3aBaqJ/TsNcnSPbGUtYrTo3R6p7DB11yGK80+lUS Zq1A== X-Gm-Message-State: AOJu0YwcmC6TUv6WJFCUDwi2+VVMNj7+68Mrt9nHEa6aJwPC6HjAqNfJ U24RxH9PYUWoxG3gKzSGtQpS6zjUbhmggPXYih/ssSmDuVKCaJWhzg+IiKoLx+7q X-Gm-Gg: Acq92OF45Q8bGNbao6ZR6qkEXB3OGhTKdOw+c9wLYKDIirsKYQp+v4y6GX3yhfJNhtb 5wDyedxX95rU9TWxJdJpHdOdZfgKb3KdtD3woHqLwVW/jyJLzSLmJ9GlYpVp37ypTTqakPCGLMI LGi4LM+nh6SaoSIU5VeMpa6ksTvI7CdOL6hs0UXbU4BeseMA3OkUzjL87TU6yAfsarrI24LIlsy PBY8S23SAUgj3ZZ3ibjigL8aMqGcCIQTXpBi12CvQVxVrlQWWQlEiPGTqECwpwVNUDjdZZDI1lv fBMMDXO+ITsymstcdh3jv2yrHzvL8Hq5AwVGZNO8dJGYI/A2gRgbsrpnLN8Y7GCTFNKiJzXjtZp EWZDsS9aibFr8GyueBoWqex7+SZXYK4A8yAEeZZuEExBPbrZ1wpdz4rx6RZHYQzGtR8roo42tOn HHhY9wgX6KdvP0JBJfuB2qBVG2dRBY254= X-Received: by 2002:a05:7300:e7a2:b0:2dd:5641:f01 with SMTP id 5a478bee46e88-303986ab2a1mr2521759eec.28.1778879737961; Fri, 15 May 2026 14:15:37 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30294500a97sm9157996eec.9.2026.05.15.14.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:37 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 30/38] x86/slaunch: Add MLE header and Secure Launch entrypoint to the core kernel Date: Fri, 15 May 2026 14:14:02 -0700 Message-ID: <20260515211410.31440-31-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Measured Launch Environment (MLE) header is an Intel TXT specific structure that is used by the Intel ACM and Secure Launch implementation to determine the location and attributes of the secure kernel being launched. Also introduce the sl_stub.S code to create a 32-bit Secure Launch entry point into the core kernel and expose it via an MLE header. This is the entry point for starting a Secure Launch kernel, handling the post-launch CPU states and validating the environment. Co-developed-by: Ard Biesheuvel Signed-off-by: Ard Biesheuvel Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/boot/compressed/misc.c | 4 + arch/x86/boot/startup/Makefile | 1 + arch/x86/boot/startup/sl_main.c | 28 + arch/x86/include/asm/boot.h | 4 + arch/x86/include/uapi/asm/bootparam.h | 1 + arch/x86/kernel/Makefile | 1 + arch/x86/kernel/asm-offsets.c | 22 + arch/x86/kernel/sl_stub.S | 847 ++++++++++++++++++++++++++ arch/x86/kernel/vmlinux.lds.S | 5 + arch/x86/tools/relocs.c | 1 + 11 files changed, 915 insertions(+), 1 deletion(-) create mode 100644 arch/x86/boot/startup/sl_main.c create mode 100644 arch/x86/kernel/sl_stub.S diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/M= akefile index b8b2b7bea1d3..8b2e234d18cb 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -76,7 +76,7 @@ LDFLAGS_vmlinux +=3D -T hostprogs :=3D mkpiggy HOST_EXTRACFLAGS +=3D -I$(srctree)/tools/include =20 -sed-voffset :=3D -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_r= odata\|_sinittext\|__inittext_end\|__bss_start\|_end\)$$/\#define VO_\2 _AC= (0x\1,UL)/p' +sed-voffset :=3D -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_r= odata\|_sinittext\|mle_header\|__inittext_end\|__bss_start\|_end\)$$/\#defi= ne VO_\2 _AC(0x\1,UL)/p' =20 quiet_cmd_voffset =3D VOFFSET $@ cmd_voffset =3D $(NM) $< | sed -n $(sed-voffset) > $@ diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index 0f41ca0e52c0..e3b5177bfa6f 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -336,6 +336,10 @@ const unsigned long kernel_inittext_offset =3D VO__sin= ittext - VO__text; const unsigned long kernel_inittext_size =3D VO___inittext_end - VO__sinit= text; const unsigned long kernel_total_size =3D VO__end - VO__text; =20 +#ifdef CONFIG_SECURE_LAUNCH +const unsigned long mle_header_offset =3D VO_mle_header - VO__text; +#endif + static u8 boot_heap[BOOT_HEAP_SIZE] __aligned(4); =20 extern unsigned char input_data[]; diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile index ecf86ce5ebf7..c4b150a0253b 100644 --- a/arch/x86/boot/startup/Makefile +++ b/arch/x86/boot/startup/Makefile @@ -25,6 +25,7 @@ slaunch-objs +=3D lib-sha1.o slaunch-objs +=3D lib-sha256.o slaunch-objs +=3D lib-sha512.o slaunch-objs +=3D tpm_drv.o +slaunch-objs +=3D sl_main.o obj-$(CONFIG_SECURE_LAUNCH) +=3D $(slaunch-objs) =20 pi-objs :=3D $(patsubst %.o,$(obj)/%.o,$(obj-y)) diff --git a/arch/x86/boot/startup/sl_main.c b/arch/x86/boot/startup/sl_mai= n.c new file mode 100644 index 000000000000..1982cfb461dd --- /dev/null +++ b/arch/x86/boot/startup/sl_main.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Secure Launch early measurement and validation routines. + * + * Copyright (c) 2026, Oracle and/or its affiliates. + * Copyright (c) 2026 Apertus Solutions, LLC + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tpm.h" + +u32 sl_cpu_type __initdata; +u32 sl_mle_start __initdata; + +void sl_main(void *bootparams); + +asmlinkage __visible __init void sl_main(void *bootparams) +{ +} diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h index f7b67cb73915..84e87e0d3d82 100644 --- a/arch/x86/include/asm/boot.h +++ b/arch/x86/include/asm/boot.h @@ -86,6 +86,10 @@ extern const unsigned long kernel_inittext_offset; extern const unsigned long kernel_inittext_size; extern const unsigned long kernel_total_size; =20 +#ifdef CONFIG_SECURE_LAUNCH +extern const unsigned long mle_header_offset; +#endif + unsigned long decompress_kernel(unsigned char *outbuf, unsigned long virt_= addr, void (*error)(char *x)); =20 diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/= asm/bootparam.h index dafbf581c515..8155fa899f50 100644 --- a/arch/x86/include/uapi/asm/bootparam.h +++ b/arch/x86/include/uapi/asm/bootparam.h @@ -12,6 +12,7 @@ /* loadflags */ #define LOADED_HIGH (1<<0) #define KASLR_FLAG (1<<1) +#define SLAUNCH_FLAG (1<<2) #define QUIET_FLAG (1<<5) #define KEEP_SEGMENTS (1<<6) #define CAN_USE_HEAP (1<<7) diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 47a32f583930..7e247064b7d0 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -89,6 +89,7 @@ obj-y +=3D resource.o obj-y +=3D irqflags.o obj-y +=3D static_call.o =20 +obj-$(CONFIG_SECURE_LAUNCH) +=3D sl_stub.o obj-y +=3D process.o obj-y +=3D fpu/ obj-y +=3D ptrace.o diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c index 081816888f7a..684e6552d973 100644 --- a/arch/x86/kernel/asm-offsets.c +++ b/arch/x86/kernel/asm-offsets.c @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -133,4 +136,23 @@ static void __used common(void) BLANK(); DEFINE(ALT_INSTR_SIZE, sizeof(struct alt_instr)); DEFINE(EXTABLE_SIZE, sizeof(struct exception_table_entry)); + +#ifdef CONFIG_SECURE_LAUNCH + BLANK(); + OFFSET(SL_txt_info, txt_os_mle_data, txt_info); + OFFSET(SL_mle_scratch, txt_os_mle_data, mle_scratch); + OFFSET(SL_ap_wake_block, txt_os_mle_data, ap_wake_block); + OFFSET(SL_ap_wake_block_size, txt_os_mle_data, ap_wake_block_size); + OFFSET(SL_boot_params_addr, slr_entry_intel_info, boot_params_addr); + OFFSET(SL_saved_misc_enable_msr, slr_entry_intel_info, saved_misc_enable_= msr); + OFFSET(SL_saved_bsp_mtrrs, slr_entry_intel_info, saved_bsp_mtrrs); + OFFSET(SL_num_logical_procs, txt_bios_data, num_logical_procs); + OFFSET(SL_capabilities, txt_os_sinit_data, capabilities); + OFFSET(SL_mle_size, txt_os_sinit_data, mle_size); + OFFSET(SL_vtd_pmr_lo_base, txt_os_sinit_data, vtd_pmr_lo_base); + OFFSET(SL_vtd_pmr_lo_size, txt_os_sinit_data, vtd_pmr_lo_size); + OFFSET(SL_rlp_wakeup_addr, txt_sinit_mle_data, rlp_wakeup_addr); + OFFSET(SL_rlp_gdt_base, smx_rlp_mle_join, rlp_gdt_base); + OFFSET(SL_rlp_entry_point, smx_rlp_mle_join, rlp_entry_point); +#endif } diff --git a/arch/x86/kernel/sl_stub.S b/arch/x86/kernel/sl_stub.S new file mode 100644 index 000000000000..5121de563310 --- /dev/null +++ b/arch/x86/kernel/sl_stub.S @@ -0,0 +1,847 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Secure Launch protected mode entry point. + * + * Copyright (c) 2026, Oracle and/or its affiliates. + * Copyright (c) 2026 Assured Information Security, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* CPUID: leaf 1, ECX, SMX feature bit */ +#define X86_FEATURE_BIT_SMX (1 << 6) + +#define IDT_VECTOR_LO_BITS 0 +#define IDT_VECTOR_HI_BITS 6 + +/* + * See the comment in head_64.S for detailed information on what this macro + * and others like it are used for. The comment appears right at the top of + * the file. + */ +#define rva(X) ((X) - sl_stub_entry) + +/* + * The GETSEC op code is open coded because older versions of + * GCC do not support the getsec mnemonic. + */ +.macro GETSEC leaf + pushl %ebx + xorl %ebx, %ebx /* Must be zero for SMCTRL */ + movl \leaf, %eax /* Leaf function */ + .byte 0x0f, 0x37 /* GETSEC opcode */ + popl %ebx +.endm + +.macro TXT_RESET error + /* + * Set a sticky error value and reset. Note the movs to %eax act as + * TXT register barriers. + */ + movl \error, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ERRORCODE) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_NO_SECRETS) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_UNLOCK_MEM_CONFIG) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_RESET) +1: + hlt + jmp 1b +.endm + + .code32 + __INIT +SYM_CODE_START(sl_stub_entry) + UNWIND_HINT_END_OF_STACK + /* + * On entry, %ebx has the entry absolute offset to sl_stub_entry. The rva= () + * macro is used to generate relative references using %ebx as a base, as + * to avoid absolute relocations, which would require fixups at runtime. + * Only %cs and %ds segments are known good after a TXT launch and can be + * used to establish a new GDT and segments. + */ + + /* Load GDT, set segment regs and lret to __SL32_CS */ + leal rva(sl_gdt_desc)(%ebx), %eax + addl %eax, 2(%eax) + lgdt (%eax) + + movl $(__SL32_DS), %eax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + + /* + * Now that %ss is known good, take the first stack for the BSP. The + * AP stacks are only used on Intel. + */ + leal rva(sl_stacks_end)(%ebx), %esp + + leal rva(.Lsl_cs)(%ebx), %eax + pushl $(__SL32_CS) + pushl %eax + lret + +.Lsl_cs: + UNWIND_HINT_END_OF_STACK + /* Save our base pointer reg and page table for MLE */ + pushl %ebx + movl %ecx, %ebp + + /* See if SMX feature is supported. */ + movl $1, %eax + cpuid + testl $(X86_FEATURE_BIT_SMX), %ecx + jz .Ldo_unknown_cpu + + popl %ebx + + /* Know it is Intel */ + movl $(SL_CPU_INTEL), rva(__pi_sl_cpu_type)(%ebx) + + /* Locate the base of the MLE using the page tables in %ecx */ + call sl_find_mle_base + + /* Increment CPU count for BSP */ + incl rva(sl_txt_cpu_count)(%ebx) + + /* + * On the BSP, enable SMI with GETSEC[SMCTRL] which were disabled by SENT= ER. + * NMIs were also disabled by SENTER. Since there is no IDT for the BSP, + * allow the mainline kernel to re-enable them in the normal course of + * booting. + */ + GETSEC $(SMX_X86_GETSEC_SMCTRL) + + /* Clear the TXT error registers for a clean start of day */ + movl $0, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ERRORCODE) + movl $0xffffffff, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ESTS) + + /* Read physical base of the TXT heap into %eax */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* Read the size of the BIOS data into ECX (first 8 bytes) */ + movl (%eax), %ecx + /* Skip over BIOS data and size of OS to MLE data section */ + leal 8(%eax, %ecx), %eax + + /* Need to verify the values in the OS-MLE struct passed in */ + call sl_txt_verify_os_mle_struct + + /* + * Get the boot params address from the TXT info table in the SLRT. + * Note %esi and %ebx MUST be preserved across calls and operations. + */ + movl SL_txt_info(%eax), %edi + movl SL_boot_params_addr(%edi), %esi + + /* Save %ebx so the APs can find their way home */ + movl %ebx, (SL_mle_scratch + SL_SCRATCH_AP_EBX)(%eax) + + /* Fetch the AP wake code block address from the heap */ + movl SL_ap_wake_block(%eax), %edi + movl %edi, rva(sl_txt_ap_wake_block)(%ebx) + + /* Store the offset in the AP wake block to the jmp address */ + movl $(sl_ap_jmp_offset - sl_txt_ap_wake_begin), \ + (SL_mle_scratch + SL_SCRATCH_AP_JMP_OFFSET)(%eax) + + /* Store the offset in the AP wake block to the AP stacks block */ + movl $(sl_stacks - sl_txt_ap_wake_begin), \ + (SL_mle_scratch + SL_SCRATCH_AP_STACKS_OFFSET)(%eax) + + /* %eax still is the base of the OS-MLE block, save it */ + pushl %eax + + /* Relocate the AP wake code to the safe block */ + call sl_txt_reloc_ap_wake + + /* + * Wake up all APs that are blocked in the ACM and wait for them to + * halt. This should be done before restoring the MTRRs so the ACM is + * still properly in WB memory. + */ + call sl_txt_wake_aps + + /* Restore OS-MLE in %eax */ + popl %eax + + /* + * %edi is used by this routine to find the MTRRs which are in the SLRT + * in the Intel info. + */ + movl SL_txt_info(%eax), %edi + call sl_txt_load_regs + + jmp .Lcpu_setup_done + +.Ldo_unknown_cpu: + /* Non-Intel CPUs are not yet supported */ + ud2 + +.Lcpu_setup_done: + /* + * Don't enable MCE at this point. The kernel will enable + * it on the BSP later when it is ready. + */ + + /* Set up 1:1 mapping using 1G mappings in the page tables in %EBP */ + xorl %ecx, %ecx + movl $128, %edx +1: leal (,%ecx,4), %eax + .irpc l, 0123 + movl $(\l * PUD_SIZE) | _PAGE_PRESENT | _PAGE_RW | _PAGE_PSE, (\l * 8)(%e= bp,%eax,8) + movl %ecx, (\l * 8 + 4)(%ebp,%eax,8) + .endr + incl %ecx + cmpl %edx, %ecx + jc 1b + + leal (_PAGE_PRESENT | _PAGE_RW)(%ebp), %edx + addl $PAGE_SIZE, %ebp + + xorl %eax, %eax + movl %ebp, %edi + movl $PAGE_SIZE / 4, %ecx + rep stosl + + movl %edx, (%ebp) + movl %ebp, %cr3 + + /* Enable PAE */ + movl %cr4, %eax + btsl $X86_CR4_PAE_BIT, %eax + movl %eax, %cr4 + + /* Enable long mode */ + movl $MSR_EFER, %ecx + rdmsr + btsl $_EFER_LME, %eax + wrmsr + + /* Set up long return to 64-bit mode */ + leal rva(2f)(%ebx), %eax + pushl $__SL64_CS + pushl %eax + + /* Enable paging */ + movl $CR0_STATE, %eax + movl %eax, %cr0 + lretl + + .code64 + UNWIND_HINT_END_OF_STACK +2: andq $~0xf, %rsp + movq %rsi, %r15 + movq %rsi, %rdi + callq __pi_sl_main + movq %r15, %rsi + jmp startup_64 +SYM_CODE_END(sl_stub_entry) + + .code32 +SYM_FUNC_START_LOCAL(sl_find_mle_base) + /* %ecx has PDPT, get first PD */ + movl (%ebp), %eax + andl $(PAGE_MASK), %eax + /* Get first PT from first PDE */ + movl (%eax), %eax + andl $(PAGE_MASK), %eax + /* Get MLE base from first PTE */ + movl (%eax), %eax + andl $(PAGE_MASK), %eax + + movl %eax, rva(__pi_sl_mle_start)(%ebx) + RET +SYM_FUNC_END(sl_find_mle_base) + +SYM_FUNC_START_LOCAL(sl_check_buffer_mle_overlap) + /* %ecx: buffer begin %edx: buffer end */ + /* %ebx: MLE begin %edi: MLE end */ + /* %eax: region may be inside MLE */ + + cmpl %edi, %ecx + jb .Lnext_check + cmpl %edi, %edx + jbe .Lnext_check + jmp .Lvalid /* Buffer above MLE */ + +.Lnext_check: + cmpl %ebx, %edx + ja .Linside_check + cmpl %ebx, %ecx + jae .Linside_check + jmp .Lvalid /* Buffer below MLE */ + +.Linside_check: + cmpl $0, %eax + jz .Linvalid + cmpl %ebx, %ecx + jb .Linvalid + cmpl %edi, %edx + ja .Linvalid + jmp .Lvalid /* Buffer in MLE */ + +.Linvalid: + TXT_RESET $(SL_ERROR_MLE_BUFFER_OVERLAP) + +.Lvalid: + RET +SYM_FUNC_END(sl_check_buffer_mle_overlap) + +SYM_FUNC_START_LOCAL(sl_txt_verify_os_mle_struct) + pushl %ebx + /* + * %eax points to the base of the OS-MLE struct. Need to also + * read some values from the OS-SINIT struct too. + */ + movl -8(%eax), %ecx + /* Skip over OS to MLE data section and size of OS-SINIT structure */ + leal (%eax, %ecx), %edx + + /* Load MLE image base absolute offset */ + movl rva(__pi_sl_mle_start)(%ebx), %ebx + + /* Verify the value of the low PMR base. It should always be 0. */ + movl SL_vtd_pmr_lo_base(%edx), %esi + cmpl $0, %esi + jz .Lvalid_pmr_base + TXT_RESET $(SL_ERROR_LO_PMR_BASE) + +.Lvalid_pmr_base: + /* Grab some values from OS-SINIT structure */ + movl SL_mle_size(%edx), %edi + addl %ebx, %edi + jc .Loverflow_detected + movl SL_vtd_pmr_lo_size(%edx), %esi + + /* Check the AP wake block */ + movl SL_ap_wake_block(%eax), %ecx + movl SL_ap_wake_block_size(%eax), %edx + addl %ecx, %edx + jc .Loverflow_detected + pushl %eax + xorl %eax, %eax + call sl_check_buffer_mle_overlap + popl %eax + cmpl %esi, %edx + ja .Lbuffer_beyond_pmr + + /* + * Check the boot params. Note during a UEFI boot, the boot + * params will be inside the MLE image. Test for this case + * in the overlap case. + */ + movl SL_boot_params_addr(%eax), %ecx + movl $(PAGE_SIZE), %edx + addl %ecx, %edx + jc .Loverflow_detected + pushl %eax + movl $1, %eax + call sl_check_buffer_mle_overlap + popl %eax + cmpl %esi, %edx + ja .Lbuffer_beyond_pmr + + /* Check that the AP wake block is big enough */ + cmpl $(sl_txt_ap_wake_end - sl_txt_ap_wake_begin), \ + SL_ap_wake_block_size(%eax) + jae .Lwake_block_ok + TXT_RESET $(SL_ERROR_WAKE_BLOCK_TOO_SMALL) + +.Lwake_block_ok: + popl %ebx + RET + +.Loverflow_detected: + TXT_RESET $(SL_ERROR_INTEGER_OVERFLOW) + +.Lbuffer_beyond_pmr: + TXT_RESET $(SL_ERROR_BUFFER_BEYOND_PMR) +SYM_FUNC_END(sl_txt_verify_os_mle_struct) + +SYM_CODE_START_LOCAL(sl_txt_ap_entry) + UNWIND_HINT_END_OF_STACK + /* + * AP entry point, first order of business is to find where we are and + * save it in %ebx. + */ + + /* Read physical base of heap into EAX */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* Read the size of the BIOS data into ECX (first 8 bytes) */ + movl (%eax), %ecx + /* Skip over BIOS data and size of OS to MLE data section */ + leal 8(%eax, %ecx), %eax + + /* Saved %ebx from the BSP and stash OS-MLE pointer */ + movl (SL_mle_scratch + SL_SCRATCH_AP_EBX)(%eax), %ebx + + /* Save TXT info ptr in %edi for call to sl_txt_load_regs */ + movl SL_txt_info(%eax), %edi + + /* + * Only the %cs and %ds segments are known good after waking the AP, + * as with entry on the BSP. First locate a stack to use then establish + * a new GDT and segments. + */ + + /* Lock and get our stack index */ + movl $1, %ecx +.Lspin: + xorl %eax, %eax + lock cmpxchgl %ecx, rva(sl_txt_spin_lock)(%ebx) + pause + jnz .Lspin + + /* Increment the stack index and use the next value inside lock */ + incl rva(sl_txt_stack_index)(%ebx) + movl rva(sl_txt_stack_index)(%ebx), %eax + + /* Unlock */ + movl $0, rva(sl_txt_spin_lock)(%ebx) + + /* Location of the relocated AP wake block */ + movl rva(sl_txt_ap_wake_block)(%ebx), %ecx + + /* Load reloc GDT, set segment regs and lret to __SL32_CS */ + lgdt (sl_ap_gdt_desc - sl_txt_ap_wake_begin)(%ecx) + + movl $(__SL32_DS), %edx + movw %dx, %ds + movw %dx, %es + movw %dx, %fs + movw %dx, %gs + movw %dx, %ss + + /* Load our reloc AP stack */ + movl $(SL_BOOT_STACK_SIZE), %edx + mull %edx + leal (sl_stacks_end - sl_txt_ap_wake_begin)(%ecx), %esp + subl %eax, %esp + + /* Switch to AP code segment */ + leal rva(.Lsl_ap_cs)(%ebx), %eax + pushl $(__SL32_CS) + pushl %eax + lret + +.Lsl_ap_cs: + UNWIND_HINT_END_OF_STACK + /* Load the relocated AP IDT */ + lidt (sl_ap_idt_desc - sl_txt_ap_wake_begin)(%ecx) + + /* Fixup MTRRs and misc enable MSR on APs too */ + call sl_txt_load_regs + + /* Enable SMI with GETSEC[SMCTRL] */ + GETSEC $(SMX_X86_GETSEC_SMCTRL) + + /* IRET-to-self can be used to enable NMIs which SENTER disabled */ + leal rva(.Lnmi_enabled_ap)(%ebx), %eax + pushfl + pushl $(__SL32_CS) + pushl %eax + iret + +.Lnmi_enabled_ap: + UNWIND_HINT_END_OF_STACK + /* Put APs in X2APIC mode like the BSP */ + movl $(MSR_IA32_APICBASE), %ecx + rdmsr + orl $(XAPIC_ENABLE | X2APIC_ENABLE), %eax + wrmsr + + /* + * Basically done, increment the CPU count and jump off to the AP + * wake block to wait. + */ + lock incl rva(sl_txt_cpu_count)(%ebx) + + /* + * Final jump to the AP wake block (see comment below). Here the APs + * will idle until the Secure Launch SMP MONITOR/MWAIT framework + * releases them to mainline kernel control. + */ + movl rva(sl_txt_ap_wake_block)(%ebx), %eax + jmp *%eax + int3 +SYM_CODE_END(sl_txt_ap_entry) + +SYM_FUNC_START_LOCAL(sl_txt_reloc_ap_wake) + /* + * What is called the "AP wake block" is simply a chunk of protected + * memory that the bootloader handed the MLE. The MLE implementation will + * shuffle the AP entry point code from here in the setup kernel into thi= s wake + * block where it cannot be overwritten by kernel decompression, relocati= on, etc. + */ + + /* Save boot params register */ + pushl %esi + + movl rva(sl_txt_ap_wake_block)(%ebx), %edi + + /* Fixup AP IDT and GDT descriptor before relocating */ + leal rva(sl_ap_idt_desc)(%ebx), %eax + addl %edi, 2(%eax) + leal rva(sl_ap_gdt_desc)(%ebx), %eax + addl %edi, 2(%eax) + + /* + * Copy the AP wake code and AP GDT/IDT to the protected wake block + * provided by the loader. Destination already in %edi. + */ + movl $(sl_txt_ap_wake_end - sl_txt_ap_wake_begin), %ecx + leal rva(sl_txt_ap_wake_begin)(%ebx), %esi + rep movsb + + /* Setup the IDT for the APs to use in the relocation block */ + movl rva(sl_txt_ap_wake_block)(%ebx), %ecx + addl $(sl_ap_idt - sl_txt_ap_wake_begin), %ecx + xorl %edx, %edx + + /* Form the default reset vector relocation address */ + movl rva(sl_txt_ap_wake_block)(%ebx), %esi + addl $(sl_txt_int_reset - sl_txt_ap_wake_begin), %esi + +1: + cmpw $(NR_VECTORS), %dx + jz .Lap_idt_done + + cmpw $(X86_TRAP_NMI), %dx + jz 2f + + /* Load all other fixed vectors with reset handler */ + movl %esi, %eax + movw %ax, (IDT_VECTOR_LO_BITS)(%ecx) + shrl $16, %eax + movw %ax, (IDT_VECTOR_HI_BITS)(%ecx) + jmp 3f + +2: + /* Load single wake NMI IPI vector at the relocation address */ + movl rva(sl_txt_ap_wake_block)(%ebx), %eax + addl $(sl_txt_int_nmi - sl_txt_ap_wake_begin), %eax + movw %ax, (IDT_VECTOR_LO_BITS)(%ecx) + shrl $16, %eax + movw %ax, (IDT_VECTOR_HI_BITS)(%ecx) + +3: + incw %dx + addl $8, %ecx + jmp 1b + +.Lap_idt_done: + popl %esi + RET +SYM_FUNC_END(sl_txt_reloc_ap_wake) + +SYM_FUNC_START_LOCAL(sl_txt_load_regs) + /* Save base pointer register */ + pushl %ebx + + /* + * On Intel, the original variable MTRRs and Misc Enable MSR are + * restored on the BSP at early boot. Each AP will also restore + * its MTRRs and Misc Enable MSR. + */ + pushl %edi + addl $(SL_saved_bsp_mtrrs), %edi + movl (%edi), %ebx + pushl %ebx /* default_mem_type lo */ + addl $4, %edi + movl (%edi), %ebx + pushl %ebx /* default_mem_type hi */ + addl $4, %edi + movl (%edi), %ebx /* mtrr_vcnt lo, don't care about hi part */ + addl $8, %edi /* now at MTRR pair array */ + /* Write the variable MTRRs */ + movl $(MSR_MTRRphysBase0), %ecx +1: + cmpl $0, %ebx + jz 2f + + movl (%edi), %eax /* MTRRphysBaseX lo */ + addl $4, %edi + movl (%edi), %edx /* MTRRphysBaseX hi */ + wrmsr + addl $4, %edi + incl %ecx + movl (%edi), %eax /* MTRRphysMaskX lo */ + addl $4, %edi + movl (%edi), %edx /* MTRRphysMaskX hi */ + wrmsr + addl $4, %edi + incl %ecx + + decl %ebx + jmp 1b +2: + /* Write the default MTRR register */ + popl %edx + popl %eax + movl $(MSR_MTRRdefType), %ecx + wrmsr + + /* Return to beginning and write the misc enable msr */ + popl %edi + addl $(SL_saved_misc_enable_msr), %edi + movl (%edi), %eax /* saved_misc_enable_msr lo */ + addl $4, %edi + movl (%edi), %edx /* saved_misc_enable_msr hi */ + movl $(MSR_IA32_MISC_ENABLE), %ecx + wrmsr + + popl %ebx + RET +SYM_FUNC_END(sl_txt_load_regs) + +SYM_FUNC_START_LOCAL(sl_txt_wake_aps) + /* Save boot params register */ + pushl %esi + + /* + * First setup the MLE join structure and load it into the TXT register. + * This structure defines the information needed to wake the APs and + * safely be joined with the DRTM. + */ + leal rva(sl_gdt)(%ebx), %eax + leal rva(sl_txt_ap_entry)(%ebx), %ecx + leal rva(sl_smx_rlp_mle_join)(%ebx), %edx + movl %eax, SL_rlp_gdt_base(%edx) + movl %ecx, SL_rlp_entry_point(%edx) + movl %edx, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_MLE_JOIN) + + /* Another TXT heap walk to find various values needed to wake APs */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* At BIOS data size, find the number of logical processors */ + movl (SL_num_logical_procs + 8)(%eax), %edx + /* Skip over BIOS data */ + movl (%eax), %ecx + addl %ecx, %eax + /* Skip over OS to MLE */ + movl (%eax), %ecx + addl %ecx, %eax + /* At OS-SNIT size, get capabilities to know how to wake up the APs */ + movl (SL_capabilities + 8)(%eax), %esi + /* Skip over OS to SNIT */ + movl (%eax), %ecx + addl %ecx, %eax + /* At SINIT-MLE size, get the AP wake MONITOR address */ + movl (SL_rlp_wakeup_addr + 8)(%eax), %edi + + /* Determine how to wake up the APs */ + testl $(1 << TXT_SINIT_MLE_CAP_RLP_WAKE_MONITOR), %esi + jz .Lwake_getsec + + /* Wake using MWAIT MONITOR */ + movl $1, (%edi) + jmp .Laps_awake + +.Lwake_getsec: + /* Wake using GETSEC(WAKEUP) */ + GETSEC $(SMX_X86_GETSEC_WAKEUP) + +.Laps_awake: + /* + * All of the APs are woken up and rendezvous in the relocated wake + * block starting at sl_txt_ap_wake_begin. Wait for all of them to + * halt. + */ + pause + cmpl rva(sl_txt_cpu_count)(%ebx), %edx + jne .Laps_awake + + popl %esi + RET +SYM_FUNC_END(sl_txt_wake_aps) + + __INITDATA +/* This is the beginning of the relocated AP wake code block */ +sl_txt_ap_wake_begin: + /* + * Note on the stack layout for the APs. The individual 128 byte stacks + * fully occupy 2 cache lines. The first is for the MONITOR address + * and the second contains the APICID written to it. Note the whole + * cache line is unused other than the monitor field; nothing else should + * write the cache line and wake the monitor. + * + * esp -> +-----------+ + * | APIC ID | + * |-----------| + * | PAD[15] | + * |-----------| + * | PAD[15] | + * |-----------| + * | MONITOR | + * +-----------+ + */ + + /* Get the LAPIC ID for each AP and stash it on the stack */ + movl $(MSR_IA32_X2APIC_APICID), %ecx + rdmsr + pushl %eax + + /* + * Get a pointer to the monitor location on this APs stack to test below + * after mwait returns. Currently %esp points to just past the pushed APIC + * ID value. + */ + movl %esp, %edi + subl $(SL_BOOT_STACK_SIZE - 4), %edi + movl $0, (%edi) + +1: + /* Load eax and clear ecx/edx so no invalid extensions or hints are passe= d to monitor */ + movl %edi, %eax + xorl %ecx, %ecx + xorl %edx, %edx + + /* + * Arm the monitor and wait for it to be triggered by the SMP bringup cod= e. The mwait + * instruction can return for a number of reasons. Test to see if it retu= rned + * because the monitor was written to. + */ + monitor + + cmpl $0, (%eax) + jnz 2f + + /* Clear eax since there are no hints sent to mwait */ + xorl %eax, %eax + + mwait + jmp 1b + +2: + /* + * This is the long absolute jump to the 32b Secure Launch protected mode= stub + * code in sl_trampoline_start32() in the rmpiggy. The jump address will = be + * fixed in the SMP boot code when the first AP is brought up. This whole= area + * is provided and protected in the memory map by the prelaunch code. + */ + .byte 0xea +sl_ap_jmp_offset: + .long 0x00000000 + .word __SL32_CS + +SYM_CODE_START_LOCAL(sl_txt_int_nmi) + /* NMI context, just IRET */ + iret +SYM_CODE_END(sl_txt_int_nmi) + +SYM_FUNC_START_LOCAL(sl_txt_int_reset) + TXT_RESET $(SL_ERROR_INV_AP_INTERRUPT) +SYM_FUNC_END(sl_txt_int_reset) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_idt_desc) + .word sl_ap_idt_end - sl_ap_idt - 1 /* Limit */ + .long sl_ap_idt - sl_txt_ap_wake_begin /* Base */ +SYM_DATA_END_LABEL(sl_ap_idt_desc, SYM_L_LOCAL, sl_ap_idt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_idt) + .rept NR_VECTORS + .word 0x0000 /* Offset 15 to 0 */ + .word __SL32_CS /* Segment selector */ + .word 0x8e00 /* Present, DPL=3D0, 32b Vector, Interrupt */ + .word 0x0000 /* Offset 31 to 16 */ + .endr +SYM_DATA_END_LABEL(sl_ap_idt, SYM_L_LOCAL, sl_ap_idt_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_gdt_desc) + .word sl_ap_gdt_end - sl_ap_gdt - 1 + .long sl_ap_gdt - sl_txt_ap_wake_begin +SYM_DATA_END_LABEL(sl_ap_gdt_desc, SYM_L_LOCAL, sl_ap_gdt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_gdt) + .quad 0x0000000000000000 /* NULL */ + .quad 0x00cf9a000000ffff /* __SL32_CS */ + .quad 0x00cf92000000ffff /* __SL32_DS */ +SYM_DATA_END_LABEL(sl_ap_gdt, SYM_L_LOCAL, sl_ap_gdt_end) + + /* Small stacks for BSP and APs to work with */ + .balign 64 +SYM_DATA_START_LOCAL(sl_stacks) + .fill (SL_MAX_CPUS * SL_BOOT_STACK_SIZE), 1, 0 +SYM_DATA_END_LABEL(sl_stacks, SYM_L_LOCAL, sl_stacks_end) + +/* This is the end of the relocated AP wake code block */ +sl_txt_ap_wake_end: + + .balign 8 +SYM_DATA_START_LOCAL(sl_gdt_desc) + .word sl_gdt_end - sl_gdt - 1 + .long sl_gdt - sl_gdt_desc +SYM_DATA_END_LABEL(sl_gdt_desc, SYM_L_LOCAL, sl_gdt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_gdt) + .quad 0x0000000000000000 /* NULL */ + .quad 0x00cf9a000000ffff /* __SL32_CS */ + .quad 0x00cf92000000ffff /* __SL32_DS */ + .quad 0x00af9a000000ffff /* __SL64_CS */ +SYM_DATA_END_LABEL(sl_gdt, SYM_L_LOCAL, sl_gdt_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_smx_rlp_mle_join) + .long sl_gdt_end - sl_gdt - 1 /* GDT limit */ + .long 0x00000000 /* GDT base */ + .long __SL32_CS /* Seg Sel - CS (DS, ES, SS =3D seg_sel+8) */ + .long 0x00000000 /* Entry point physical address */ +SYM_DATA_END(sl_smx_rlp_mle_join) + +SYM_DATA_LOCAL(sl_txt_spin_lock, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_stack_index, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_cpu_count, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_ap_wake_block, .long 0x00000000) + + __INITRODATA + .balign 8 + /* + * The MLE Header per the TXT Specification, section 2.1 + * MLE capabilities, see table 4. Capabilities set: + * bit 0: Support for GETSEC[WAKEUP] for RLP wakeup + * bit 1: Support for RLP wakeup using MONITOR address + * bit 2: The ECX register will contain the pointer to the MLE page table + * bit 5: TPM 1.2 family: Details/authorities PCR usage support + * bit 9: Supported format of TPM 2.0 event log - TCG compliant + */ +SYM_DATA_START(mle_header) +0: .long 0x9082ac5a /* UUID0 */ + .long 0x74a7476f /* UUID1 */ + .long 0xa2555c0f /* UUID2 */ + .long 0x42b651cb /* UUID3 */ + .long 0x00000034 /* MLE header size */ + .long 0x00020002 /* MLE version 2.2 */ + .long __sl_stub_entry_offset - 0b /* Linear entry point of MLE (virt. add= ress) */ + .long 0x00000000 /* First valid page of MLE */ + .long 0x00000000 /* Offset within binary of first byte of MLE */ + .long __sl_mle_end_offset - 0b /* Offset within binary of last byte + 1 o= f MLE */ + .long 0x00000227 /* Bit vector of MLE-supported capabilities */ + .long 0x00000000 /* Starting linear address of command line (unused) */ + .long 0x00000000 /* Ending linear address of command line (unused) */ +SYM_DATA_END(mle_header) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 4711a35e706c..fc22a2b9c7d1 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -537,4 +537,9 @@ xen_elfnote_phys32_entry_value =3D ABSOLUTE(xen_elfnote_phys32_entry) + ABSOLUTE(pvh_start_xen - LOAD_OFFSET= ); #endif =20 +#ifdef CONFIG_SECURE_LAUNCH +__sl_stub_entry_offset =3D ABSOLUTE(mle_header) + ABSOLUTE(sl_stub_entry -= _text); +__sl_mle_end_offset =3D ABSOLUTE(mle_header) + ABSOLUTE(__bss_start - _= text); +#endif + #include "../boot/startup/exports.h" diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index e5a2b9a912d1..d4a5fc607c54 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -88,6 +88,7 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = =3D { "__end_rodata|" "__end_rodata_aligned|" "__initramfs_start|" + "__sl_.+offset|" "(jiffies|jiffies_64)|" #if ELF_BITS =3D=3D 64 "__end_rodata_hpage_align|" --=20 2.47.3 From nobody Mon May 25 08:11:31 2026 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2241940586E for ; Fri, 15 May 2026 21:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879744; cv=none; b=PmJERD4X810sjaKu/X7oUSZ5ILto9xcM6vNdRFcibDlJ3c+nj/vRLErpc0c/f0q+oxDZZtVh1Q77p5zXbmSuLstbq8mWEEfnGj08x5w5sluKRQJ26UsRQSZiJq/oytTXswWxlFW+GOZ6rYeknE1PKdpUOHfercG9qPonxBu/mak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879744; c=relaxed/simple; bh=e0yyIirk51jKbKjeSvwwc86YOmMN0kVT7bcodyWznw0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GqHVwtpFibAzqhAxbZuYsqgVeZT2tIm80MjMcgqTMuwzIReYVU3frt0Ru7XhgZdJL+wdIXONRx8FB2rqFKwnkHRzShBce9e6VspjlPFpvHmDCQkhGjNvvWMSIuifaxrKeo7RPs0sXLCpcTqrGIwjRF7o8tWYjgOyNd8pEDvK9/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BEx+1FSC; arc=none smtp.client-ip=74.125.82.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BEx+1FSC" Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-2ef8d6ba48bso106665eec.1 for ; Fri, 15 May 2026 14:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879741; x=1779484541; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vEqPpKnlZT3emBFthAb9OgKvlsNPtI0KrHZvILeiAis=; b=BEx+1FSCAC2VDyHx2jsKucZic9/qXOUxtRCWkk8iBdU5AV52bGQcBSI+8gjgO4KgQh BSebqAe0c4SELPulttZzYP/LsR9wjAiygJvmXW3LVXA7+vEP2X4k1gxhTfHTUx1aJWEm tf8tkaiXFmilx6F2X1iHHdVp/DHydvu0Yid2x+EVfn7nQOqIAqynNLHQlXYJOok0/x8S yZTFHZpxuiqwtDWEBXP0pfFJtftA47GFj2N7T2Ts6SLAZEKKBiv4qAGY7yLvysGE22Wi DDK3h4Ot0/oaTQVomg4FIjQhSlwB8rFBd7bU3O4pMRsv9p4jzCekyWosLrkhNjmaWm6J 8SGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879741; x=1779484541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vEqPpKnlZT3emBFthAb9OgKvlsNPtI0KrHZvILeiAis=; b=VIidr8y5lvfws/dmzwwOQTUTNC1JYYVFYZS7ij4UXjUL43YSL3yF1VqMdGekl7umVR bhT7YXXFQHolDJXYct59Pjae/IcBBadOJf3oSligB5egnnGxWEdr/0gTup9eqsevVM23 KxhQtNJZVHSrTEwJKGcpX3n2Z+yyQtLrFyQhoO4LgdqX9F917Vj72lkv9L48XQGYPk23 1UWg8y6xxT1abTpivedQT7H+zk+dFzJizQELuFU8tNnwW1GcnBI0ddk8VpWxXF+fr9b0 F/I66rgxoC5r4U1x8NXYMONMywtcin0QQX8I6c7Uq9vyzxTbyQlUvkjX+jAeyA+h4kUL 164w== X-Gm-Message-State: AOJu0YxYtW94vU7ezfIPKoOHuPJ9sFj8snAAhJGfsgmMl4htjUsrUZC5 gE0h2CEiPrfGz4YJeBKKV02dBZr2s/hHY880AyAI3IbFfgf5/H37HBGEjCvqp7vY X-Gm-Gg: Acq92OFYj0Fcyh96mHBy2yhAFfmMO8dfaYOtnWNUczp+xabE5QlTv/AIUGfLWNELhEh BEcdDBt+fqmF2T4txAb6i+xm1m0gfH/UFm9zkfFwfeX/N1Q6cYG7af7xV9p/CDcHf4pBSMZUujt 8VD0L/dxBEWFGDYaGzyxISnvcpRgKxPnigODNwwZsGSZ3sCIXXVD1pEqXhk0ZusK++27GO1bfkY rNibkFolRVYctN6Fn+pgHDOfV8PVQ9rwmw28pR6rPBIxm1Rs579Ryj+dlAmW0UWPuzspTL/dRx0 aHbgYBVniVyrHaE5v2d1GeqdkPtFsHoJAjTUZolLsAppDtek4yFDqsEcPjUZanesXepQwW1NVay vSwEqugreGQixER3FxZA3M4lF54rm24KoLzhBFk8T2zJnbBa55r/3SLW5/EgIFICftM2OnK2gei sxCNlXdL+brwljlS7D7mD5F6Jbsz27RAc= X-Received: by 2002:a05:7300:d511:b0:2f9:1004:b2cd with SMTP id 5a478bee46e88-30262f3895emr5218501eec.20.1778879740764; Fri, 15 May 2026 14:15:40 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2e3c0sm9976142eec.3.2026.05.15.14.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:40 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 31/38] x86/slaunch: Secure Launch kernel early boot initialization Date: Fri, 15 May 2026 14:14:03 -0700 Message-ID: <20260515211410.31440-32-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sl_main() routine is responsible for measuring configuration and module information before it is used by the kernel. An example of entities measured on Intel x86 are the boot params, the kernel command line, the TXT heap, any external initramfs, etc. In addition this routine does some early setup and validation of the environment like locating the TPM event log and validating the location of various buffers to ensure they are protected and not overlapping. Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/boot/startup/sl_main.c | 610 ++++++++++++++++++++++++++++++++ 1 file changed, 610 insertions(+) diff --git a/arch/x86/boot/startup/sl_main.c b/arch/x86/boot/startup/sl_mai= n.c index 1982cfb461dd..0110392470d0 100644 --- a/arch/x86/boot/startup/sl_main.c +++ b/arch/x86/boot/startup/sl_main.c @@ -15,14 +15,624 @@ #include #include #include +#include =20 #include "tpm.h" =20 +#define CAPS_VARIABLE_MTRR_COUNT_MASK 0xff + +#define SL_TPM_LOG 1 +#define SL_TPM2_LOG 2 + +static void *evtlog_base; +static u32 evtlog_size; +static struct txt_heap_event_log_pointer2_1_element *log21_elem; +static u32 tpm_log_ver =3D SL_TPM_LOG; +static u32 tpm_num_algs; +static struct tcg_efi_specid_event_algs *tpm_algs; +static u8 event_buf[PAGE_SIZE]; + +/* Simple instance of a TPM chip object */ +static struct tpm_chip chip __initdata; + +static struct slr_table *slrt __initdata; + u32 sl_cpu_type __initdata; u32 sl_mle_start __initdata; =20 void sl_main(void *bootparams); =20 +static void *txt_regs =3D (void *)TXT_PRIV_CONFIG_REGS_BASE; +#define sl_txt_read(r) readq(txt_regs + r) +#define sl_txt_write(r, v) writeq(v, txt_regs + r) + +static void *txt_heap __initdata; +static struct sl_txt_heap_info txt_heap_map[TXT_SINIT_TABLE_MAX] __initdat= a; + +struct sl_txt_heap_info * __init sl_txt_get_heap_map(void); +void * __init sl_txt_get_heap_table(void *heap, u8 index); + +struct sl_txt_heap_info * __init sl_txt_get_heap_map(void) +{ + return txt_heap_map; +} + +void * __init sl_txt_get_heap_table(void *heap, u8 index) +{ + return heap + txt_heap_map[index].offset; +} + +static void __init txt_parse_heap_map(void *heap) +{ + void *tmp =3D heap; + + for (u8 i =3D 0; i < TXT_SINIT_TABLE_MAX; i++) { + txt_heap_map[i].size =3D *((u64 *) tmp); + txt_heap_map[i].offset =3D tmp - heap + sizeof(txt_heap_map[i].size); + tmp +=3D txt_heap_map[i].size; + } +} + +void __warn_printk(const char *fmt, ...) +{ +} + +static void __noreturn __init sl_txt_reset(u64 error) +{ + /* Reading the E2STS register acts as a barrier for TXT registers */ + sl_txt_write(TXT_CR_ERRORCODE, error); + sl_txt_read(TXT_CR_E2STS); + sl_txt_write(TXT_CR_CMD_UNLOCK_MEM_CONFIG, 1); + sl_txt_read(TXT_CR_E2STS); + sl_txt_write(TXT_CR_CMD_RESET, 1); + + for ( ; ; ) + asm volatile ("hlt"); + + unreachable(); +} + +static inline u64 __init sl_rdmsr(u32 reg) +{ + struct msr m; + + raw_rdmsr(reg, &m); + + return m.q; +} + +static struct slr_table *__init sl_locate_and_validate_slrt(void) +{ + struct txt_os_mle_data *os_mle_data; + struct slr_table *slrt; + + os_mle_data =3D sl_txt_get_heap_table(txt_heap, TXT_OS_MLE_DATA_TABLE); + + if (!os_mle_data->slrt) + sl_txt_reset(SL_ERROR_INVALID_SLRT); + + slrt =3D (struct slr_table *)os_mle_data->slrt; + + if (slrt->magic !=3D SLR_TABLE_MAGIC) + sl_txt_reset(SL_ERROR_INVALID_SLRT); + + if (slrt->architecture !=3D SLR_INTEL_TXT) + sl_txt_reset(SL_ERROR_INVALID_SLRT); + + return slrt; +} + +/* + * This is a validation routine that allows checking if a block of memory + * is protected from external access by being in a PMR range. If allow_hi = is + * set, ranges above 4GB are allowed. + */ +static void __init sl_check_pmr_coverage(void *base, u32 size, bool allow_= hi) +{ + struct txt_os_sinit_data *os_sinit_data; + void *end =3D base + size; + + if (!(sl_cpu_type & SL_CPU_INTEL)) + return; + + os_sinit_data =3D sl_txt_get_heap_table(txt_heap, TXT_OS_SINIT_DATA_TABLE= ); + + if ((u64)end >=3D SZ_4G && (u64)base < SZ_4G) + sl_txt_reset(SL_ERROR_REGION_STRADDLE_4GB); + + /* + * Note that the late stub code validates that the hi PMR covers + * all memory above 4G. At this point the code can only check that + * regions are within the hi PMR but that is sufficient. + */ + if ((u64)end > SZ_4G && (u64)base >=3D SZ_4G) { + if (allow_hi) { + if (end >=3D (void *)(os_sinit_data->vtd_pmr_hi_base + + os_sinit_data->vtd_pmr_hi_size)) + sl_txt_reset(SL_ERROR_BUFFER_BEYOND_PMR); + } else { + sl_txt_reset(SL_ERROR_REGION_ABOVE_4GB); + } + } + + if (end >=3D (void *)os_sinit_data->vtd_pmr_lo_size) + sl_txt_reset(SL_ERROR_BUFFER_BEYOND_PMR); +} + +/* + * Some MSRs are modified by the pre-launch code including the MTRRs. + * The early MLE code has to restore these values. This code validates + * the values after they are measured. + */ +static void __init sl_txt_validate_msrs(struct txt_os_mle_data *os_mle_dat= a) +{ + struct slr_txt_mtrr_state *saved_bsp_mtrrs; + u64 mtrr_caps, mtrr_def_type, mtrr_var; + struct slr_entry_intel_info *txt_info; + u64 misc_en_msr; + u32 vcnt, i; + + txt_info =3D (struct slr_entry_intel_info *)os_mle_data->txt_info; + saved_bsp_mtrrs =3D &txt_info->saved_bsp_mtrrs; + + mtrr_caps =3D sl_rdmsr(MSR_MTRRcap); + vcnt =3D (u32)(mtrr_caps & CAPS_VARIABLE_MTRR_COUNT_MASK); + + if (saved_bsp_mtrrs->mtrr_vcnt > vcnt) + sl_txt_reset(SL_ERROR_MTRR_INV_VCNT); + if (saved_bsp_mtrrs->mtrr_vcnt > TXT_OS_MLE_MAX_VARIABLE_MTRRS) + sl_txt_reset(SL_ERROR_MTRR_INV_VCNT); + + mtrr_def_type =3D sl_rdmsr(MSR_MTRRdefType); + if (saved_bsp_mtrrs->default_mem_type !=3D mtrr_def_type) + sl_txt_reset(SL_ERROR_MTRR_INV_DEF_TYPE); + + for (i =3D 0; i < saved_bsp_mtrrs->mtrr_vcnt; i++) { + mtrr_var =3D sl_rdmsr(MTRRphysBase_MSR(i)); + if (saved_bsp_mtrrs->mtrr_pair[i].mtrr_physbase !=3D mtrr_var) + sl_txt_reset(SL_ERROR_MTRR_INV_BASE); + mtrr_var =3D sl_rdmsr(MTRRphysMask_MSR(i)); + if (saved_bsp_mtrrs->mtrr_pair[i].mtrr_physmask !=3D mtrr_var) + sl_txt_reset(SL_ERROR_MTRR_INV_MASK); + } + + misc_en_msr =3D sl_rdmsr(MSR_IA32_MISC_ENABLE); + if (txt_info->saved_misc_enable_msr !=3D misc_en_msr) + sl_txt_reset(SL_ERROR_MSR_INV_MISC_EN); +} + +static void __init sl_find_drtm_event_log(struct slr_table *slrt) +{ + struct txt_os_sinit_data *os_sinit_data; + struct slr_entry_log_info *log_info; + + log_info =3D slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_LOG_INFO); + if (!log_info) + sl_txt_reset(SL_ERROR_SLRT_MISSING_ENTRY); + + evtlog_base =3D (void *)log_info->addr; + evtlog_size =3D log_info->size; + + /* + * For TPM 2.0, the TXT event log 2.1 extended data structure has to also + * be located to find the actual log. + */ + os_sinit_data =3D sl_txt_get_heap_table(txt_heap, TXT_OS_SINIT_DATA_TABLE= ); + + /* + * Only support version 6 and later that properly handle the + * list of ExtDataElements in the OS-SINIT structure. + */ + if (os_sinit_data->version < 6) + sl_txt_reset(SL_ERROR_OS_SINIT_BAD_VERSION); + + /* Find the TPM2.0 logging extended heap element */ + log21_elem =3D txt_find_log2_1_element(os_sinit_data); + + /* If found, this implies TPM2 log and family */ + if (log21_elem) + tpm_log_ver =3D SL_TPM2_LOG; +} + +static void __init sl_validate_event_log_buffer(void) +{ + struct txt_os_sinit_data *os_sinit_data; + void *mle_base, *mle_end; + void *evtlog_end; + void *txt_end; + + if ((u64)evtlog_size > (LLONG_MAX - (u64)evtlog_base)) + sl_txt_reset(SL_ERROR_INTEGER_OVERFLOW); + evtlog_end =3D evtlog_base + evtlog_size; + + txt_end =3D txt_heap + sl_txt_read(TXT_CR_HEAP_SIZE); + os_sinit_data =3D sl_txt_get_heap_table(txt_heap, TXT_OS_SINIT_DATA_TABLE= ); + + mle_base =3D (void *)(u64)sl_mle_start; + mle_end =3D mle_base + os_sinit_data->mle_size; + + /* + * This check is to ensure the event log buffer does not overlap with + * the MLE image. + */ + if (evtlog_base >=3D mle_end && evtlog_end > mle_end) + goto pmr_check; /* above */ + + if (evtlog_end <=3D mle_base && evtlog_base < mle_base) + goto pmr_check; /* below */ + + sl_txt_reset(SL_ERROR_MLE_BUFFER_OVERLAP); + +pmr_check: + /* + * The TXT heap is protected by the DPR. If the TPM event log is + * inside the TXT heap, there is no need for a PMR check. + */ + if (evtlog_base > txt_heap && evtlog_end < txt_end) + return; + + sl_check_pmr_coverage(evtlog_base, evtlog_size, true); +} + +static void __init sl_find_event_log_algorithms(void) +{ + struct tcg_efi_specid_event_head *efi_head =3D + (struct tcg_efi_specid_event_head *)(evtlog_base + + sizeof(struct tcg_pcr_event)); + u32 i; + + if (efi_head->num_algs =3D=3D 0) + sl_txt_reset(SL_ERROR_TPM_INVALID_ALGS); + + tpm_algs =3D &efi_head->digest_sizes[0]; + tpm_num_algs =3D efi_head->num_algs; + + for (i =3D 0; i < tpm_num_algs; i++) { + if (tpm_algs[i].digest_size > TPM2_MAX_DIGEST_SIZE) + sl_txt_reset(SL_ERROR_TPM_INVALID_ALGS); + /* Alg ID 0 is invalid and maps to TPM_ALG_ERROR */ + if (tpm_algs[i].alg_id =3D=3D TPM_ALG_ERROR) + sl_txt_reset(SL_ERROR_TPM_INVALID_ALGS); + } +} + +static void __init sl_tpm1_extend(u32 pcr, u32 event_type, + const u8 *data, u32 length, + const u8 *event_data, u32 event_size) +{ + u8 sha1_hash[SHA1_DIGEST_SIZE] =3D {0}; + struct tcg_pcr_event *pcr_event; + u32 total_size; + + /* Clear on each use */ + memset(event_buf, 0, PAGE_SIZE); + + pcr_event =3D (struct tcg_pcr_event *)event_buf; + pcr_event->pcr_idx =3D pcr; + pcr_event->event_type =3D event_type; + if (length > 0) { + sha1(data, length, &sha1_hash[0]); + memcpy(&pcr_event->digest[0], &sha1_hash[0], SHA1_DIGEST_SIZE); + } + pcr_event->event_size =3D event_size; + if (event_size > 0) + memcpy((u8 *)pcr_event + sizeof(*pcr_event), + event_data, event_size); + + total_size =3D sizeof(*pcr_event) + event_size; + + /* Do the TPM extend then log the event */ + if (tpm1_pcr_extend(&chip, pcr, &sha1_hash[0])) + sl_txt_reset(SL_ERROR_TPM_EXTEND); + + if (tpm_log_event(evtlog_base, evtlog_size, total_size, pcr_event)) + sl_txt_reset(SL_ERROR_TPM_LOGGING_FAILED); +} + +static void __init sl_tpm2_extend(u32 pcr, u32 event_type, + const u8 *data, u32 length, + const u8 *event_data, u32 event_size) +{ + struct tcg_pcr_event2_head *head; + struct tcg_event_field *event; + u8 digest[TPM2_MAX_DIGEST_SIZE]; + u32 total_size, alg_idx; + u16 *alg_ptr; + u8 *dgst_ptr; + int rc; + + /* Clear on each use */ + memset(event_buf, 0, PAGE_SIZE); + + head =3D (struct tcg_pcr_event2_head *)event_buf; + head->pcr_idx =3D pcr; + head->event_type =3D event_type; + total_size =3D sizeof(*head); + alg_ptr =3D (u16 *)(event_buf + sizeof(*head)); + + for (alg_idx =3D 0; alg_idx < tpm_num_algs; alg_idx++) { + memset(digest, 0, TPM2_MAX_DIGEST_SIZE); + + *alg_ptr =3D tpm_algs[alg_idx].alg_id; + dgst_ptr =3D (u8 *)alg_ptr + sizeof(u16); + + if (tpm_algs[alg_idx].alg_id =3D=3D TPM_ALG_SHA256) { + sha256(data, length, &digest[0]); + } else if (tpm_algs[alg_idx].alg_id =3D=3D TPM_ALG_SHA384) { + sha384(data, length, &digest[0]); + } else if (tpm_algs[alg_idx].alg_id =3D=3D TPM_ALG_SHA512) { + sha512(data, length, &digest[0]); + } else if (tpm_algs[alg_idx].alg_id =3D=3D TPM_ALG_SHA1) { + sha1(data, length, &digest[0]); + } else { + /* + * If there are TPM banks in use that are not supported + * in software here, the PCR in that bank will be capped with + * the well-known value 1 as the Intel ACM does. + */ + digest[0] =3D 0x01; + } + + memcpy(dgst_ptr, &digest[0], tpm_algs[alg_idx].digest_size); + total_size +=3D tpm_algs[alg_idx].digest_size + sizeof(u16); + alg_ptr =3D (u16 *)((u8 *)alg_ptr + + tpm_algs[alg_idx].digest_size + sizeof(u16)); + + head->count++; + } + + event =3D (struct tcg_event_field *)(event_buf + total_size); + event->event_size =3D event_size; + if (event_size > 0) + memcpy((u8 *)event + sizeof(*event), event_data, event_size); + total_size +=3D sizeof(*event) + event_size; + + /* + * Do the TPM extend then log the event. Note the digest list is packed + * in the event behind the event header. + */ + rc =3D tpm2_pcr_extend(&chip, pcr, (struct tpm_digest *)(event_buf + size= of(*head)), + head->count); + if (rc) + sl_txt_reset(SL_ERROR_TPM_EXTEND); + + if (tpm2_log_event(log21_elem, evtlog_base, evtlog_size, + total_size, &event_buf[0])) + sl_txt_reset(SL_ERROR_TPM_LOGGING_FAILED); +} + +static void __init sl_tpm_extend(u32 pcr, u32 type, const u8 *data, u32 le= ngth, + const char *desc) +{ + if (chip.family =3D=3D TPM_FAMILY_20) + sl_tpm2_extend(pcr, type, data, length, (const u8 *)desc, strlen(desc)); + else + sl_tpm1_extend(pcr, type, data, length, (const u8 *)desc, strlen(desc)); +} + +static void __init sl_handle_setup_data(struct setup_data *curr, + struct slr_policy_entry *entry) +{ + struct setup_indirect *ind; + + /* SETUP_INDIRECT instances have to be handled differently */ + if (curr->type =3D=3D SETUP_INDIRECT) { + ind =3D (struct setup_indirect *)((u8 *)curr + + offsetof(struct setup_data, data)); + + sl_check_pmr_coverage((void *)ind->addr, ind->len, true); + + sl_tpm_extend(entry->pcr, SL_EVTYPE_SECURE_LAUNCH, (void *)ind->addr, + ind->len, entry->evt_info); + } + + sl_check_pmr_coverage(((u8 *)curr) + sizeof(*curr), + curr->len, true); + + sl_tpm_extend(entry->pcr, SL_EVTYPE_SECURE_LAUNCH, ((u8 *)curr) + sizeof(= *curr), + curr->len, entry->evt_info); +} + +/* + * The setup_data linked list in the boot_params (if present) must be + * processed element by element. Indirect elements need to have their + * pointers followed to the actual data to measure. + */ +static void __init sl_extend_setup_data(struct slr_policy_entry *entry) +{ + struct setup_data *data =3D (void *)(unsigned long)entry->entity; + + /* + * Measure any setup_data entries including e820 extended entries. + * Note that the e820 fixed entries are in the boot params structure + * itself and measured there. + */ + while (data) { + sl_handle_setup_data(data, entry); + data =3D (void *)(unsigned long)data->next; + } +} + +static void __init sl_extend_slrt(struct slr_policy_entry *entry) +{ + struct slr_table *slrt =3D (struct slr_table *)entry->entity; + struct slr_entry_intel_info *intel_info; + struct slr_entry_intel_info intel_tmp; + + /* + * In revision one of the SLRT, the only table that needs to be + * measured is the Intel info table. Everything else is meta-data, + * addresses and sizes. Note the size of what to measure is not set. + * The flag SLR_POLICY_IMPLICIT_SIZE leaves it to the measuring code + * to sort out. + */ + if (slrt->revision =3D=3D 1) { + intel_info =3D slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_INTEL_INFO); + if (!intel_info) + sl_txt_reset(SL_ERROR_SLRT_MISSING_ENTRY); + + /* + * Make a temp copy and zero out address fields since they should + * not be measured. + */ + intel_tmp =3D *intel_info; + intel_tmp.boot_params_addr =3D 0; + intel_tmp.txt_heap =3D 0; + + sl_tpm_extend(entry->pcr, SL_EVTYPE_SECURE_LAUNCH, (void *)&intel_tmp, + sizeof(*intel_info), entry->evt_info); + } +} + +static void __init sl_extend_txt_os2mle(struct slr_policy_entry *entry) +{ + struct txt_os_mle_data *os_mle_data; + + os_mle_data =3D sl_txt_get_heap_table(txt_heap, TXT_OS_MLE_DATA_TABLE); + + /* + * Version 1 of the OS-MLE heap structure has no fields to measure. It ju= st + * has addresses and sizes and a scratch buffer. + */ + if (os_mle_data->version =3D=3D 1) + return; +} + +/* + * Process all policy entries and extend the measurements to the evtlog. N= ote + * that some entries need special processing which is done in subroutines. + */ +static void __init sl_process_extend_policy(struct slr_table *slrt) +{ + struct slr_entry_policy *policy; + u16 i; + + policy =3D slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_ENTRY_POLICY); + if (!policy) + sl_txt_reset(SL_ERROR_SLRT_MISSING_ENTRY); + + for (i =3D 0; i < policy->nr_entries; i++) { + switch (policy->policy_entries[i].entity_type) { + case SLR_ET_SETUP_DATA: + sl_extend_setup_data(&policy->policy_entries[i]); + break; + case SLR_ET_SLRT: + sl_extend_slrt(&policy->policy_entries[i]); + break; + case SLR_ET_TXT_OS2MLE: + sl_extend_txt_os2mle(&policy->policy_entries[i]); + break; + case SLR_ET_UNUSED: + continue; + default: + sl_tpm_extend(policy->policy_entries[i].pcr, + SL_EVTYPE_SECURE_LAUNCH, + (void *)policy->policy_entries[i].entity, + policy->policy_entries[i].size, + policy->policy_entries[i].evt_info); + } + } +} + +/* + * Process all EFI config entries and extend the measurements to the evtlog + */ +static void __init sl_process_extend_uefi_config(struct slr_table *slrt) +{ + struct slr_entry_uefi_config *uefi_config; + u16 i; + + uefi_config =3D slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_UEFI_CONFIG); + + /* Optionally here depending on how SL kernel was booted */ + if (!uefi_config) + return; + + for (i =3D 0; i < uefi_config->nr_entries; i++) { + sl_tpm_extend(uefi_config->uefi_cfg_entries[i].pcr, + SL_EVTYPE_SECURE_LAUNCH, + (void *)uefi_config->uefi_cfg_entries[i].cfg, + uefi_config->uefi_cfg_entries[i].size, + uefi_config->uefi_cfg_entries[i].evt_info); + } +} + asmlinkage __visible __init void sl_main(void *bootparams) { + struct boot_params *bp =3D (struct boot_params *)bootparams; + struct txt_os_mle_data *os_mle_data; + + /* + * Ensure loadflags do not indicate a secure launch was done + * unless it really was. + */ + bp->hdr.loadflags &=3D ~SLAUNCH_FLAG; + + /* + * Currently only Intel TXT is supported for Secure Launch. Testing + * this value also indicates that the kernel was booted successfully + * through the Secure Launch entry point and is in SMX mode. + */ + if (!(sl_cpu_type & SL_CPU_INTEL)) + return; + + txt_heap =3D (void *)sl_txt_read(TXT_CR_HEAP_BASE); + txt_parse_heap_map(txt_heap); + + /* Find the SLRT setup by the pre-launch stage */ + slrt =3D sl_locate_and_validate_slrt(); + + /* Locate the TPM event log. */ + sl_find_drtm_event_log(slrt); + + /* Validate the location of the event log buffer before using it */ + sl_validate_event_log_buffer(); + + /* + * Find the TPM hash algorithms used by the ACM and recorded in the + * event log. + */ + if (tpm_log_ver =3D=3D SL_TPM2_LOG) + sl_find_event_log_algorithms(); + + /* + * Prepare the early TPM driver to do PCR extends for the DRTM + * measurements. On a successful DRTM launch, TPM locality 2 + * should be available to open/acquire. + * + * Note that the early TPM driver does not use interrupts but + * rather polling for command completion (there is no infrastructure + * setup for servicing interrupts in the setup kernel). + */ + if (early_tpm_init(&chip, TIS_MEM_X86_LPC_BASE)) + sl_txt_reset(SL_ERROR_TPM_INIT); + if (tpm_tis_request_locality(&chip, TPM_LOCALITY_2) < 0) + sl_txt_reset(SL_ERROR_TPM_INIT); + if (chip.family =3D=3D TPM_FAMILY_20 && tpm_log_ver !=3D SL_TPM2_LOG) + sl_txt_reset(SL_ERROR_TPM_INIT); + tpm_tis_disable_interrupts(&chip); + + /* + * Set the SLAUNCH_FLAG early since if anything fails, the system will + * reset anyway. + */ + bp->hdr.loadflags |=3D SLAUNCH_FLAG; + + sl_check_pmr_coverage(bootparams, PAGE_SIZE, false); + + /* + * Extend measurements into the TPM for entities specified in the + * SLRT policies. + */ + sl_process_extend_policy(slrt); + sl_process_extend_uefi_config(slrt); + + /* No PMR check is needed, the TXT heap is covered by the DPR */ + os_mle_data =3D sl_txt_get_heap_table(txt_heap, TXT_OS_MLE_DATA_TABLE); + + /* + * Now that the OS-MLE data is measured, ensure the MTRR and + * misc enable MSRs are what we expect. + */ + sl_txt_validate_msrs(os_mle_data); } --=20 2.47.3 From nobody Mon May 25 08:11:32 2026 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5145E3F44C6 for ; Fri, 15 May 2026 21:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879748; cv=none; b=SlKn0PyXXGuy3lmK5x+nKW7LpobpQMsvbvZ8Fznn6k96JixpfYn9dCyMVqHdOUxTxUktc42SpmIDtqHb243vsq2Zbzvr8FouOwLlk+P+PBchS1nzSz5qUm+Vd0otR3yxgOyJkrhp7/3CBOi+QwCP23GCu3NYgXiDeo0XwlQZ1f8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879748; c=relaxed/simple; bh=fuaYWYwKVQ6aLboy8oYmRTr/G1nqpxQMACpXpaVo+2Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MgVGEoY4xJzgZcNCnAzP58TxFHkn9rJdDvb5DsHLj7S3jeAKdRIYgwG++W40XBY4xHL66p59bbJ9bBSQVqKD+vvIV3DdzpZ7P1yM8oFDtVGf/pOFYkFEWU+ntAirBjyC8s1TO9zjOiwO5CmwSUar/sY4IeQahBpt5wyiHhXOjM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Tc6J8FWB; arc=none smtp.client-ip=74.125.82.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tc6J8FWB" Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1354403c610so393466c88.0 for ; Fri, 15 May 2026 14:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879744; x=1779484544; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/fB2vCYcV4hiVqJPN4jIXwcIlKSoWixUeLliDOf5rFU=; b=Tc6J8FWB7r5UYRzhayRhA2x6420aq8+ikaC0Pp8c97dhO1UyeUyNLp9cThyvilk+1a KsYcuzFBeboJICmotsIUlrpCRvDLRa7tPZNpxP6g17iqmxSlgdbwxTBplLy2n3+mmYQk IapgvvRg7OMztaJmqt8cojjJTBQZi3gZhRESr41oy4d6gDePz2976JD3evFLpU9VjTvs Dmk0gsuDoP5Op0ICfs4sHxLdagYiAVaXfCZf8wTG7Ux4XLkdQs4ALbRBiD5EvPcXhEDN CMl/MagotVU7sbXcUbcMni3HFaiVkP0aBBijxuh6DzaN6nP3gDFpmp0cLzcqIQO74QYj G4/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879744; x=1779484544; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/fB2vCYcV4hiVqJPN4jIXwcIlKSoWixUeLliDOf5rFU=; b=DpTskaf/q7ZxnfzQwc4kWhVqNfbQQfwdFgmyv5zn/QhxpkOFMNjgMm6Ffu235upjHq XfPaAx/ffMAtwb1SpjTEzGEeZhQT5rlRhsGif2csSRmsJ0Q0eMS12dNXDikxoR+O0f0m 9ikKm/Sb1DsRoX4n8KLy9lYrTGDakurW53jZfV2ybhAHXrsKzwqoYzjdyqvud8qf1uyN 6D8fVX/unAv/IngZGEAOLHzEeScQ2HBRh2XlFJu4I61lwT7HG/T5cc3j2hyEUdfhpx6Q lhtHkCwInRhaHTqVoGPTyr5UjxzTG3MtTraW+Bt/Rmn8tpOnEn+iAueTcJqJaQ5LOagg ow0g== X-Gm-Message-State: AOJu0YwppGYfOORPwqfv96TX0AkGWLlcHjzvM283JokwdpsiFXJaUTPS 2AoqB1AqacLhK958nhRErIe9R5hWr7UVfy7C44Fxx5UzRqf4tQy+vwlrvnpl0Qqh X-Gm-Gg: Acq92OHaU9A2zwO9OcBBgePn1vNqHIKqqdI+WYtOMocdoRPt1v74JCnwme+OLOqaE+f wmBHJx3Ds/a2/cyxWW6NhnkEuCMUegv/mI07s+2UJp7cb/k5o2prB+xJ+aKiqvqJKW47Xk3FOaO zDFzMY5LZbYzdyC1GJRZFVX8/rgoGvoE0KAw7XrWYKX18nc4huIGKk3MYEnMXOKCEzw5ZTI7u/K 4K6KuRDmWnoSR3viVxGwKnVhX6yUEPPyG4pDGwaPHrA/2xqE0dxXcu4lGDHrFRD0F+yynBUJJTN 2bUi6OIU7uKNKMaRijbMQj4xRdneT3uIeRt1KaKVUxQP9Hl8RWbKnQhai05H47Xx5HB5QDW9yHq PjIiM6i9MPzN6vrQBLHzfeb8x666OkC5S4crN5vYr9ihMOA++A9stALxKRMaQzXlynjEogyRo/8 3JzWlU1tzR1r+7n+ZK5ICbxZPyO61aZ+E= X-Received: by 2002:a05:7022:220a:b0:134:d708:1a24 with SMTP id a92af1059eb24-13504c5f09fmr2683112c88.17.1778879743612; Fri, 15 May 2026 14:15:43 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cc33a618sm11245870c88.12.2026.05.15.14.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:43 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 32/38] x86/slaunch: Secure Launch kernel late boot initialization Date: Fri, 15 May 2026 14:14:04 -0700 Message-ID: <20260515211410.31440-33-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The routine slaunch_setup() is called out of the x86 specific setup_arch() routine during early kernel boot. After determining what platform is present, various operations specific to that platform occur. This includes finalizing setting for the platform late launch and verifying that memory protections are in place. In addition this routine reserves key memory regions used by Secure Launch (e.g. the TXT heap, AP startup block etc) as well as fetching values needed later from the TXT heap and SLRT. Intel VT-d/IOMMU hardware provides special registers called Protected Memory Regions (PMRs) that allow all memory to be protected from DMA during a TXT DRTM launch. This coverage is validated during the late setup process to ensure DMA protection is in place prior to the IOMMUs being initialized and configured by the mainline kernel. See the Intel Trusted Execution Technology - Measured Launch Environment Developer's Guide for more details: https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-t= xt-software-development-guide.pdf Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/setup.c | 3 + arch/x86/kernel/slaunch.c | 513 +++++++++++++++++++++++++++++++++++++ drivers/iommu/intel/dmar.c | 4 + 4 files changed, 521 insertions(+) create mode 100644 arch/x86/kernel/slaunch.c diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 7e247064b7d0..bf2471701662 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -97,6 +97,7 @@ obj-$(CONFIG_X86_32) +=3D tls.o obj-$(CONFIG_IA32_EMULATION) +=3D tls.o obj-y +=3D step.o obj-$(CONFIG_INTEL_TXT) +=3D tboot.o +obj-$(CONFIG_SECURE_LAUNCH) +=3D slaunch.o obj-$(CONFIG_ISA_DMA_API) +=3D i8237.o obj-y +=3D stacktrace.o obj-y +=3D cpu/ diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index eebcc9db1a1b..82029d7640bf 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include =20 @@ -1027,6 +1028,8 @@ void __init setup_arch(char **cmdline_p) early_gart_iommu_check(); #endif =20 + slaunch_setup(); + /* * partially used pages are not usable - thus * we are rounding upwards: diff --git a/arch/x86/kernel/slaunch.c b/arch/x86/kernel/slaunch.c new file mode 100644 index 000000000000..0179ff855b62 --- /dev/null +++ b/arch/x86/kernel/slaunch.c @@ -0,0 +1,513 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Secure Launch late validation/setup and finalization support. + * + * Copyright (c) 2026, Oracle and/or its affiliates. + * Copyright (c) 2026 Apertus Solutions, LLC + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static u32 sl_flags __ro_after_init; +static struct sl_ap_wake_info ap_wake_info __ro_after_init; +static u64 evtlog_addr __ro_after_init; +static u32 evtlog_size __ro_after_init; +static u64 vtd_pmr_lo_size __ro_after_init; + +/* This should be plenty of room */ +static u8 txt_dmar[PAGE_SIZE] __aligned(16); + +/* + * Get the Secure Launch flags that indicate what kind of launch is being = done. + * E.g. a TXT launch is in progress or no Secure Launch is happening. + */ +u32 slaunch_get_flags(void) +{ + return sl_flags; +} + +/* + * Return the AP wakeup information used in the SMP boot code to start up + * the APs that are parked using MONITOR/MWAIT. + */ +struct sl_ap_wake_info *slaunch_get_ap_wake_info(void) +{ + return &ap_wake_info; +} + +/* Saved TXT heap map accessors for easy heap parsing */ +struct sl_txt_heap_info *__pi_sl_txt_get_heap_map(void); + +struct sl_txt_heap_info *__init slaunch_txt_get_heap_map(void) +{ + return __pi_sl_txt_get_heap_map(); +} + +void *__pi_sl_txt_get_heap_table(void *heap, u8 index); + +void *__init slaunch_txt_get_heap_table(void *heap, u8 index) +{ + return __pi_sl_txt_get_heap_table(heap, index); +} + +/* + * On Intel platforms, TXT passes a safe copy of the DMAR ACPI table to the + * DRTM. The DRTM is supposed to use this instead of the one found in the + * ACPI tables. + */ +struct acpi_table_header *slaunch_get_dmar_table(struct acpi_table_header = *dmar) +{ + /* The DMAR is only stashed and provided via TXT on Intel systems */ + if (memcmp(txt_dmar, "DMAR", 4)) + return dmar; + + return (struct acpi_table_header *)(txt_dmar); +} + +/* + * If running within a TXT established DRTM, this is the proper way to res= et + * the system if a failure occurs or a security issue is found. + */ +static void __noreturn slaunch_txt_reset(void __iomem *txt, const char *ms= g, u64 error) +{ + u64 one =3D 1, val; + + pr_err("%s", msg); + + /* + * This performs a TXT reset with a sticky error code. The reads of + * TXT_CR_E2STS act as barriers. + */ + memcpy_toio(txt + TXT_CR_ERRORCODE, &error, sizeof(error)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + memcpy_toio(txt + TXT_CR_CMD_NO_SECRETS, &one, sizeof(one)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + memcpy_toio(txt + TXT_CR_CMD_UNLOCK_MEM_CONFIG, &one, sizeof(one)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + memcpy_toio(txt + TXT_CR_CMD_RESET, &one, sizeof(one)); + + for ( ; ; ) + asm volatile ("hlt"); + + unreachable(); +} + +/* + * Handle fatal errors during DRTM initialization. + */ +void __noreturn slaunch_reset(void *ctx, const char *msg, u64 error) +{ + if (slaunch_is_txt_launch()) + slaunch_txt_reset(ctx, msg, error); + + /* Generic handler for x86 */ + pr_err("Secure Launch: %s - error: 0x%llx", msg, error); + asm volatile ("ud2"); + + unreachable(); +} + +/* + * The TXT heap is too big to map all at once with early_ioremap + * so it is done a table at a time. + */ +static void __init *txt_early_get_heap_table(void __iomem *txt, u32 type, + u32 bytes) +{ + struct sl_txt_heap_info *heap_map; + void *heap; + u64 base; + + if (type >=3D TXT_SINIT_TABLE_MAX) + slaunch_reset(txt, "Error invalid table type for early heap walk\n", + SL_ERROR_HEAP_WALK); + + memcpy_fromio(&base, txt + TXT_CR_HEAP_BASE, sizeof(base)); + + heap_map =3D slaunch_txt_get_heap_map(); + base +=3D heap_map[type].offset; + + heap =3D early_memremap(base, bytes); + if (!heap) + slaunch_reset(txt, "Error early_memremap of heap section\n", + SL_ERROR_HEAP_MAP); + + return heap; +} + +static void __init txt_early_put_heap_table(void *addr, unsigned long size) +{ + early_memunmap(addr, size); +} + +/* + * TXT uses a special set of VTd registers to protect all of memory from D= MA + * until the IOMMU can be programmed to protect memory. There is the low + * memory PMR that can protect all memory up to 4G. The high memory PMR can + * be setup to protect all memory beyond 4Gb. Validate that these values c= over + * what is expected. + */ +static void __init slaunch_verify_pmrs(void __iomem *txt) +{ + struct txt_os_sinit_data *os_sinit_data; + u32 field_offset, err =3D 0; + const char *errmsg =3D ""; + unsigned long last_pfn; + + field_offset =3D offsetof(struct txt_os_sinit_data, lcp_po_base); + os_sinit_data =3D txt_early_get_heap_table(txt, TXT_OS_SINIT_DATA_TABLE, + field_offset); + + /* Save a copy */ + vtd_pmr_lo_size =3D os_sinit_data->vtd_pmr_lo_size; + + last_pfn =3D e820__end_of_ram_pfn(); + + /* + * First make sure the hi PMR covers all memory above 4G. In the + * unlikely case where there is < 4G on the system, the hi PMR will + * not be set. + */ + if (os_sinit_data->vtd_pmr_hi_base !=3D 0x0ULL) { + if (os_sinit_data->vtd_pmr_hi_base !=3D 0x100000000ULL) { + err =3D SL_ERROR_HI_PMR_BASE; + errmsg =3D "Error hi PMR base\n"; + goto out; + } + + if (PFN_PHYS(last_pfn) > os_sinit_data->vtd_pmr_hi_base + + os_sinit_data->vtd_pmr_hi_size) { + err =3D SL_ERROR_HI_PMR_SIZE; + errmsg =3D "Error hi PMR size\n"; + goto out; + } + } + + /* + * Lo PMR base should always be 0. This was already checked in + * early stub. + */ + + /* + * Check that if the kernel was loaded below 4G, that it is protected + * by the lo PMR. Note this is the decompressed kernel. The ACM would + * have ensured the compressed kernel (the MLE image) was protected. + */ + if (__pa_symbol(_end) < 0x100000000ULL && + __pa_symbol(_end) > os_sinit_data->vtd_pmr_lo_size) { + err =3D SL_ERROR_LO_PMR_MLE; + errmsg =3D "Error lo PMR does not cover MLE kernel\n"; + } + + /* + * Other regions of interest like boot param, AP wake block, cmdline + * already checked for PMR coverage in the early stub code. + */ + +out: + txt_early_put_heap_table(os_sinit_data, field_offset); + + if (err) + slaunch_reset(txt, errmsg, err); +} + +static void __init slaunch_txt_reserve_range(u64 base, u64 size) +{ + int type; + + type =3D e820__get_entry_type(base, base + size - 1); + if (type =3D=3D E820_TYPE_RAM) { + pr_info("memblock reserve base: %llx size: %llx\n", base, size); + memblock_reserve(base, size); + } +} + +/* + * For Intel, certain regions of memory must be marked as reserved by putt= ing + * them on the memblock reserved list if they are not already e820 reserve= d. + * This includes: + * - The TXT heap + * - The ACM area + * - The TXT private register bank + * - The MDR list sent to the MLE by the ACM (see TXT specification) + * (Normally the above are properly reserved by firmware but if it was not + * done, reserve them now) + * - The AP wake block + * - TPM log external to the TXT heap + * + * Also if the low PMR doesn't cover all memory < 4G, any RAM regions above + * the low PMR must be reserved too. + */ +static void __init slaunch_txt_reserve(void __iomem *txt) +{ + struct txt_sinit_memory_descriptor_record *mdr; + struct txt_sinit_mle_data *sinit_mle_data; + u64 base, size, heap_base, heap_size; + u32 mdrnum, mdroffset, mdrslen; + u32 field_offset, i; + void *mdrs; + + base =3D TXT_PRIV_CONFIG_REGS_BASE; + size =3D TXT_PUB_CONFIG_REGS_BASE - TXT_PRIV_CONFIG_REGS_BASE; + slaunch_txt_reserve_range(base, size); + + memcpy_fromio(&heap_base, txt + TXT_CR_HEAP_BASE, sizeof(heap_base)); + memcpy_fromio(&heap_size, txt + TXT_CR_HEAP_SIZE, sizeof(heap_size)); + slaunch_txt_reserve_range(heap_base, heap_size); + + memcpy_fromio(&base, txt + TXT_CR_SINIT_BASE, sizeof(base)); + memcpy_fromio(&size, txt + TXT_CR_SINIT_SIZE, sizeof(size)); + slaunch_txt_reserve_range(base, size); + + field_offset =3D offsetof(struct txt_sinit_mle_data, + sinit_vtd_dmar_table_size); + sinit_mle_data =3D txt_early_get_heap_table(txt, TXT_SINIT_MLE_DATA_TABLE, + field_offset); + + mdrnum =3D sinit_mle_data->num_of_sinit_mdrs; + mdroffset =3D sinit_mle_data->sinit_mdrs_table_offset; + + txt_early_put_heap_table(sinit_mle_data, field_offset); + + if (!mdrnum) + goto nomdr; + + mdrslen =3D mdrnum * sizeof(*mdr); + + mdrs =3D txt_early_get_heap_table(txt, TXT_SINIT_MLE_DATA_TABLE, + mdroffset + mdrslen - 8); + + mdr =3D mdrs + mdroffset - 8; + + for (i =3D 0; i < mdrnum; i++, mdr++) { + /* Spec says some entries can have length 0, ignore them */ + if (mdr->type > 0 && mdr->length > 0) + slaunch_txt_reserve_range(mdr->address, mdr->length); + } + + txt_early_put_heap_table(mdrs, mdroffset + mdrslen - 8); + +nomdr: + slaunch_txt_reserve_range(ap_wake_info.ap_wake_block, + ap_wake_info.ap_wake_block_size); + + /* + * Earlier checks ensured that the event log was properly situated + * either inside the TXT heap or outside. This is a check to see if the + * event log needs to be reserved. If it is in the TXT heap, it is + * already reserved. + */ + if (evtlog_addr < heap_base || evtlog_addr > (heap_base + heap_size)) + slaunch_txt_reserve_range(evtlog_addr, evtlog_size); + + for (i =3D 0; i < e820_table->nr_entries; i++) { + base =3D e820_table->entries[i].addr; + size =3D e820_table->entries[i].size; + if (base >=3D vtd_pmr_lo_size && base < 0x100000000ULL) + slaunch_txt_reserve_range(base, size); + else if (base < vtd_pmr_lo_size && base + size > vtd_pmr_lo_size) + slaunch_txt_reserve_range(vtd_pmr_lo_size, + base + size - vtd_pmr_lo_size); + } +} + +/* + * TXT stashes a safe copy of the DMAR ACPI table to prevent tampering. + * It is stored in the TXT heap. Fetch it from there and make it available + * to the IOMMU driver. + */ +static void __init slaunch_copy_dmar_table(void __iomem *txt) +{ + struct txt_sinit_mle_data *sinit_mle_data; + u32 field_offset, dmar_size, dmar_offset; + void *dmar; + + field_offset =3D offsetof(struct txt_sinit_mle_data, + processor_scrtm_status); + sinit_mle_data =3D txt_early_get_heap_table(txt, TXT_SINIT_MLE_DATA_TABLE, + field_offset); + + dmar_size =3D sinit_mle_data->sinit_vtd_dmar_table_size; + dmar_offset =3D sinit_mle_data->sinit_vtd_dmar_table_offset; + + txt_early_put_heap_table(sinit_mle_data, field_offset); + + if (!dmar_size || !dmar_offset) + slaunch_reset(txt, "Error DMAR table values\n", SL_ERROR_HEAP_INVALID_DM= AR); + + if (unlikely(dmar_size > PAGE_SIZE)) + slaunch_reset(txt, "Error DMAR too big to store\n", SL_ERROR_HEAP_DMAR_S= IZE); + + dmar =3D txt_early_get_heap_table(txt, TXT_SINIT_MLE_DATA_TABLE, + dmar_offset + dmar_size - 8); + if (!dmar) + slaunch_reset(txt, "Error early_ioremap of DMAR\n", SL_ERROR_HEAP_DMAR_M= AP); + + memcpy(txt_dmar, dmar + dmar_offset - 8, dmar_size); + + txt_early_put_heap_table(dmar, dmar_offset + dmar_size - 8); +} + +/* + * The location of the safe AP wake code block is stored in the TXT heap. + * Fetch needed values here in the early init code for later use in SMP + * startup. + * + * Also the TPM event log values are in the SLRT and have to be fetched. + * They will be put on the memblock reserve list later. + */ +static void __init slaunch_fetch_values(void __iomem *txt) +{ + struct txt_os_mle_data *os_mle_data; + struct slr_entry_log_info *log_info; + u8 *jmp_offset, *stacks_offset; + struct slr_table *slrt; + u32 size; + + os_mle_data =3D txt_early_get_heap_table(txt, TXT_OS_MLE_DATA_TABLE, + sizeof(*os_mle_data)); + + ap_wake_info.ap_wake_block =3D os_mle_data->ap_wake_block; + ap_wake_info.ap_wake_block_size =3D os_mle_data->ap_wake_block_size; + + jmp_offset =3D os_mle_data->mle_scratch + SL_SCRATCH_AP_JMP_OFFSET; + ap_wake_info.ap_jmp_offset =3D *((u32 *)jmp_offset); + + stacks_offset =3D os_mle_data->mle_scratch + SL_SCRATCH_AP_STACKS_OFFSET; + ap_wake_info.ap_stacks_offset =3D *((u32 *)stacks_offset); + + slrt =3D (struct slr_table *)early_memremap(os_mle_data->slrt, sizeof(*sl= rt)); + if (!slrt) + slaunch_reset(txt, "Error early_memremap of SLRT failed\n", + SL_ERROR_SLRT_MAP); + + size =3D slrt->size; + early_memunmap(slrt, sizeof(*slrt)); + + slrt =3D (struct slr_table *)early_memremap(os_mle_data->slrt, size); + if (!slrt) + slaunch_reset(txt, "Error early_memremap of SLRT failed\n", + SL_ERROR_SLRT_MAP); + + log_info =3D slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_LOG_INFO); + + if (!log_info) + slaunch_reset(txt, "SLRT missing logging info entry\n", + SL_ERROR_SLRT_MISSING_ENTRY); + + evtlog_addr =3D log_info->addr; + evtlog_size =3D log_info->size; + + early_memunmap(slrt, size); + + txt_early_put_heap_table(os_mle_data, sizeof(*os_mle_data)); +} + +/* + * Intel TXT specific late stub setup and validation called from within + * x86 specific setup_arch(). + */ +static void __init slaunch_setup_txt(void) +{ + u64 one =3D TXT_REGVALUE_ONE, val; + void __iomem *txt; + + /* + * See if SENTER was done by reading the status register in the + * public space. If the public register space cannot be read, TXT may + * be disabled. + */ + txt =3D early_ioremap(TXT_PUB_CONFIG_REGS_BASE, + TXT_NR_CONFIG_PAGES * PAGE_SIZE); + if (!txt) + panic("Error early_ioremap in TXT setup failed\n"); + + memcpy_fromio(&val, txt + TXT_CR_STS, sizeof(val)); + early_iounmap(txt, TXT_NR_CONFIG_PAGES * PAGE_SIZE); + + /* SENTER should have been done */ + if (!(val & TXT_SENTER_DONE_STS)) + panic("Error TXT.STS SENTER_DONE not set\n"); + + /* SEXIT should have been cleared */ + if (val & TXT_SEXIT_DONE_STS) + panic("Error TXT.STS SEXIT_DONE set\n"); + + /* Now we want to use the private register space */ + txt =3D early_ioremap(TXT_PRIV_CONFIG_REGS_BASE, + TXT_NR_CONFIG_PAGES * PAGE_SIZE); + if (!txt) { + /* This is really bad, no where to go from here */ + panic("Error early_ioremap of TXT priv registers\n"); + } + + /* + * Try to read the Intel VID from the TXT private registers to see if + * TXT measured launch happened properly and the private space is + * available. + */ + memcpy_fromio(&val, txt + TXT_CR_DIDVID, sizeof(val)); + if ((val & 0xffff) !=3D 0x8086) { + /* + * Can't do a proper TXT reset since it appears something is + * wrong even though SENTER happened and it should be in SMX + * mode. + */ + panic("Invalid TXT vendor ID, not in SMX mode\n"); + } + + /* Set flags so subsequent code knows the status of the launch */ + sl_flags |=3D (SL_FLAG_ACTIVE | SL_FLAG_ARCH_TXT); + + /* + * Reading the proper DIDVID from the private register space means we + * are in SMX mode and private registers are open for read/write. + */ + + /* On Intel, have to handle TPM localities via TXT */ + memcpy_toio(txt + TXT_CR_CMD_SECRETS, &one, sizeof(one)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + memcpy_toio(txt + TXT_CR_CMD_OPEN_LOCALITY1, &one, sizeof(one)); + memcpy_fromio(&val, txt + TXT_CR_E2STS, sizeof(val)); + + slaunch_fetch_values(txt); + + slaunch_verify_pmrs(txt); + + slaunch_txt_reserve(txt); + + slaunch_copy_dmar_table(txt); + + early_iounmap(txt, TXT_NR_CONFIG_PAGES * PAGE_SIZE); + + pr_info("Intel TXT setup complete\n"); +} + +void __init slaunch_setup(void) +{ + /* + * If booted through secure launch entry point, the loadflags + * option will be set. + */ + if (!(boot_params.hdr.loadflags & SLAUNCH_FLAG)) + return; + + if (boot_cpu_has(X86_FEATURE_SMX)) + slaunch_setup_txt(); +} diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 69222dbd2af0..f41b4f702565 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -28,6 +28,7 @@ #include #include #include +#include #include =20 #include "iommu.h" @@ -661,6 +662,9 @@ parse_dmar_table(void) */ dmar_tbl =3D tboot_get_dmar_table(dmar_tbl); =20 + /* If Secure Launch is active, it has similar logic */ + dmar_tbl =3D slaunch_get_dmar_table(dmar_tbl); + dmar =3D (struct acpi_table_dmar *)dmar_tbl; if (!dmar) return -ENODEV; --=20 2.47.3 From nobody Mon May 25 08:11:32 2026 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A0F840587D for ; Fri, 15 May 2026 21:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879749; cv=none; b=Jizehj2pwgDo/DuNZyQXw9z06CLAfv43tB7b0C/XSfobx2rEP/WExHWvj87lAl2N8ife8oejxqeyWBunUZH6BnLgPRaXwHL3vc2lTqWT6Jq1N0KLQ+xvR9Q9HWuSObkyhROeL+2lkJLvgY8KCR4fTmx2rtHPktN/kcNcn5ok/cI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879749; c=relaxed/simple; bh=lguMqdiHzuRecBR+f+YcsvaeXBnj2IIKNWDOALqRyPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=INLU1dwh3qdw8ULjRx4nwKPYrA6syoPwNe5iPSxQwXTQNJQ9PLHxhPpJ2RT/PIuDsDwSDjFOknSqwfnWxZnPstFPPyFaSFJJntLMxhf1qOFZRwqPgWeRUn4PB52NRWMXk3GSkGX3U24AELVM9SdU66jXy9jcZ9UHrxLOb+6gOVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nFwAoLTA; arc=none smtp.client-ip=74.125.82.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nFwAoLTA" Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-2f0d3e07e30so1355420eec.0 for ; Fri, 15 May 2026 14:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879747; x=1779484547; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ermZy1JOQ3bL4uNXgDw9lpn60RTdyK+Y6D8PtSjZ40A=; b=nFwAoLTAbT7PoWVgyyHu35oq2IRVVhfS4E0QjEF1jxxk3+8W3gaGB2vDJEiOOSLh5A X/vBzlFR6FDEZCWJgpNFj4PHD+cV+GdutZ9vrrNjHAhv3S8fX3vZu3fhx12trXfDrucw duR9WF4Nn01rYoO8l0OI7+tDlascPxdTYkKWwGIUOBmWCrolTdhBR56/FWlR4eEIutmw dVgkA6d6aru1RY5UaH4dDyf1Hf2z+6jadRvaF4/pGC61SPzwXBIaCEK+YgLFCvNV5r+3 tzhIRonpBTyVqNyndhGoYYkHToCzkIJclu1Akesu8dT0yrZzp9q6nMGZImUrLsJyeJoS 4P7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879747; x=1779484547; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ermZy1JOQ3bL4uNXgDw9lpn60RTdyK+Y6D8PtSjZ40A=; b=fHELEwjlXcOe75qZVWIOiAZG+ju3XaIRsrgL9lHaVC1VnbbKiBzhpl5h5GYUMOj1E2 inY4a72c7YU2gjTPdhX/DIX73PuF4f5uim27SoRyNl7SXBxBvWnphW3t1tFjmLcqoH2B ycolKAZWpjOWvYAtFc5Z2ggzjNEtbDye+Q2O7hdQur7kuUpWulMnzrs1BVEFdc9b/vw3 l2l6aIIA14LuQr45QYdZ9fgZGJc5X74eeDOWB7PVa3xPXB8qM2DIwzdKK1bfx5urzCgW MvWEwCbes3hF5vB0kk/kffVa794nJ4DfxjJ3ZNlg9hA0o2jiTVXI8Y3u1JxmAehICDCX DZNw== X-Gm-Message-State: AOJu0YxGVOsV+aDbYiEkBSAG3MnzOB055aKTDxUltP9XSDEcEsxYSuCK Csf3W7CtL6hfTNetmXNUEoUZw5W7WL8nuKgPiLZvYXKbEgPgJip2jlzJhQjTZdz2 X-Gm-Gg: Acq92OFvE121lmR+89S9XkIFCp00wrGMo/u06s4MoJaXbLk8CrPPB7RAY0g3SZe4CCx 8JujG08zw23ljfWoMJa0qGAryIbbEq0/ed4361vjeetqygg/mZHcBsdo+o02S/VRtkRlTLykZoe dPdz9oMhseGNePMiaUeLsjT9h3X1LWPSLsQnyPNRJvcBVhMuYojCLAWo0bNbE0equFIIGq0RFBa svYOHeLZk2lmHEu+EJNz1ql0ronNanMBII7h+IioiOijFY13YqtsPqX1X+zOgtQJvkEs5wc1KUc 8hPbQS6vBfmbJkZngcWrCKBuZErtvBNfQd8/xDFXtMTtOi2tGw+MsaguNOsrRgAy36i+t8Yhusm xbJizm+AFGbvvUQqZ+q7QhqTmASfmrO3/w8oSRms3IQ42ThiN+ccmexdsfc7niYRCw3m4ybxAY1 0ATjr1lQMhV5QdC5Dgf2isLCYNb7+1h7M4hWPUPu0TQA== X-Received: by 2002:a05:7300:d706:b0:2d3:f43c:d684 with SMTP id 5a478bee46e88-30398191408mr2749976eec.2.1778879746758; Fri, 15 May 2026 14:15:46 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2e69esm9916134eec.1.2026.05.15.14.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:46 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 33/38] x86/slaunch: Secure Launch SMP bringup support Date: Fri, 15 May 2026 14:14:05 -0700 Message-ID: <20260515211410.31440-34-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On Intel, the APs are left in a well documented state after TXT performs the secure launch. Specifically, they cannot have #INIT asserted on them so a standard startup via INIT/SIPI/SIPI cannot be performed. Instead the early SL stub code uses MONITOR and MWAIT to park the APs. The realmode/init.c code updates the jump address for the waiting APs with the location of the Secure Launch entry point in the rmpiggy image. The rmpiggy image is a payload contained in the kernel used to start the APs (in 16b or 32b modes). It is loaded at runtime so its location and entry point must be updated in the long jump for the waiting APs by the running kernel. As the APs are woken up by writing the monitor, the APs jump to the Secure Launch entry point in the rmpiggy which mimics what the real mode code would do then jumps to the standard rmpiggy protected mode entry point. Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/include/asm/realmode.h | 3 ++ arch/x86/kernel/slaunch.c | 26 +++++++++++++++ arch/x86/kernel/smpboot.c | 47 ++++++++++++++++++++++++++-- arch/x86/realmode/init.c | 8 +++++ arch/x86/realmode/rm/header.S | 3 ++ arch/x86/realmode/rm/trampoline_64.S | 32 +++++++++++++++++++ 6 files changed, 117 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmod= e.h index e406a1e92c63..e3336c49d26b 100644 --- a/arch/x86/include/asm/realmode.h +++ b/arch/x86/include/asm/realmode.h @@ -38,6 +38,9 @@ struct real_mode_header { #ifdef CONFIG_X86_64 u32 machine_real_restart_seg; #endif +#ifdef CONFIG_SECURE_LAUNCH + u32 sl_trampoline_start32; +#endif }; =20 /* This must match data at realmode/rm/trampoline_{32,64}.S */ diff --git a/arch/x86/kernel/slaunch.c b/arch/x86/kernel/slaunch.c index 0179ff855b62..f6e6f1b7e18c 100644 --- a/arch/x86/kernel/slaunch.c +++ b/arch/x86/kernel/slaunch.c @@ -511,3 +511,29 @@ void __init slaunch_setup(void) if (boot_cpu_has(X86_FEATURE_SMX)) slaunch_setup_txt(); } + +/* + * After a launch, the APs are woken up, enter the DRTM and are left to + * wait for a wakeup call on a MONITOR address. The block where they are + * idle has a long jump to the AP startup code in the mainline kernel. + * This address has to be calculated at runtime and "fixed up" to point + * to the SL startup location in the rmpiggy SMP startup image. This image + * is loaded into separate memory at kernel start time. + */ +void __init slaunch_fixup_ap_wake_vector(void) +{ + struct sl_ap_wake_info *ap_wake_info; + u32 *ap_jmp_ptr; + + if (!slaunch_is_txt_launch()) + return; + + ap_wake_info =3D slaunch_get_ap_wake_info(); + + ap_jmp_ptr =3D (u32 *)__va(ap_wake_info->ap_wake_block + + ap_wake_info->ap_jmp_offset); + + *ap_jmp_ptr =3D real_mode_header->sl_trampoline_start32; + + pr_info("TXT AP startup vector address updated\n"); +} diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 294a8ea60298..16a0f2718a38 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -61,6 +61,7 @@ #include #include #include +#include =20 #include #include @@ -989,6 +990,45 @@ int common_cpu_up(unsigned int cpu, struct task_struct= *idle) return 0; } =20 +#if (IS_ENABLED(CONFIG_SECURE_LAUNCH)) + +/* + * TXT AP startup is quite different than normal. The APs cannot have #INIT + * asserted on them or receive SIPIs. The early Secure Launch code has par= ked + * the APs using MONITOR/MWAIT in the safe AP wake block area (details in + * sl_stub.S). The SMP boot will wake the APs by writing the MONITOR assoc= iated + * with the AP and have them jump to the protected mode code in the rmpigg= y where + * the rest of the SMP boot of the AP will proceed normally. + * + * Intel Trusted Execution Technology (TXT) Software Development Guide + * Section 2.3 - MLE Initialization + */ +static void slaunch_wakeup_cpu_from_txt(int cpu, int apicid) +{ + struct sl_ap_stack_and_monitor *stack_monitor; + struct sl_ap_wake_info *ap_wake_info; + + ap_wake_info =3D slaunch_get_ap_wake_info(); + + stack_monitor =3D (struct sl_ap_stack_and_monitor *)__va(ap_wake_info->ap= _wake_block + + ap_wake_info->ap_stacks_offset); + + for (unsigned int i =3D SL_MAX_CPUS - 1; i >=3D 0; i--) { + if (stack_monitor[i].apicid =3D=3D apicid) { + stack_monitor[i].monitor =3D 1; + break; + } + } +} + +#else + +static inline void slaunch_wakeup_cpu_from_txt(int cpu, int apicid) +{ +} + +#endif /* IS_ENABLED(CONFIG_SECURE_LAUNCH) */ + /* * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad * (ie clustered apic addressing mode), this is a LOGICAL apic ID. @@ -998,7 +1038,7 @@ int common_cpu_up(unsigned int cpu, struct task_struct= *idle) static int do_boot_cpu(u32 apicid, unsigned int cpu, struct task_struct *i= dle) { unsigned long start_ip =3D real_mode_header->trampoline_start; - int ret; + int ret =3D 0; =20 #ifdef CONFIG_X86_64 /* If 64-bit wakeup method exists, use the 64-bit mode trampoline IP */ @@ -1043,12 +1083,15 @@ static int do_boot_cpu(u32 apicid, unsigned int cpu= , struct task_struct *idle) =20 /* * Wake up a CPU in difference cases: + * - Intel TXT DRTM launch uses its own method to wake the APs * - Use a method from the APIC driver if one defined, with wakeup * straight to 64-bit mode preferred over wakeup to RM. * Otherwise, * - Use an INIT boot APIC message */ - if (apic->wakeup_secondary_cpu_64) + if (slaunch_is_txt_launch()) + slaunch_wakeup_cpu_from_txt(cpu, apicid); + else if (apic->wakeup_secondary_cpu_64) ret =3D apic->wakeup_secondary_cpu_64(apicid, start_ip, cpu); else if (apic->wakeup_secondary_cpu) ret =3D apic->wakeup_secondary_cpu(apicid, start_ip, cpu); diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c index 88be32026768..ded4dafc6a0a 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -4,6 +4,7 @@ #include #include #include +#include =20 #include #include @@ -213,6 +214,13 @@ void __init init_real_mode(void) =20 setup_real_mode(); set_real_mode_permissions(); + + /* + * If Secure Launch is active, it will use the rmpiggy to do the TXT AP + * startup. Secure Launch has its own entry stub in the rmpiggy and this = prepares + * it for SMP boot. + */ + slaunch_fixup_ap_wake_vector(); } =20 static int __init do_init_real_mode(void) diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S index 2eb62be6d256..3b5cbcbbfc90 100644 --- a/arch/x86/realmode/rm/header.S +++ b/arch/x86/realmode/rm/header.S @@ -37,6 +37,9 @@ SYM_DATA_START(real_mode_header) #ifdef CONFIG_X86_64 .long __KERNEL32_CS #endif +#ifdef CONFIG_SECURE_LAUNCH + .long pa_sl_trampoline_start32 +#endif SYM_DATA_END(real_mode_header) =20 /* End signature, used to verify integrity */ diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/tr= ampoline_64.S index 14d9c7daf90f..b0ce6205d7ea 100644 --- a/arch/x86/realmode/rm/trampoline_64.S +++ b/arch/x86/realmode/rm/trampoline_64.S @@ -122,6 +122,38 @@ SYM_CODE_END(sev_es_trampoline_start) =20 .section ".text32","ax" .code32 +#ifdef CONFIG_SECURE_LAUNCH + .balign 4 +SYM_CODE_START(sl_trampoline_start32) + /* + * The early secure launch stub AP wakeup code has taken care of all + * the vagaries of launching out of TXT. This bit just mimics what the + * 16b entry code does and jumps off to the real startup_32. + */ + cli + wbinvd + + /* + * The %ebx provided is not terribly useful since it is the physical + * address of tb_trampoline_start and not the base of the image. + * Use pa_real_mode_base, which is fixed up, to get a run time + * base register to use for offsets to location that do not have + * pa_ symbols. + */ + movl $pa_real_mode_base, %ebx + + LOCK_AND_LOAD_REALMODE_ESP lock_pa=3D1 + + lgdt tr_gdt(%ebx) + lidt tr_idt(%ebx) + + movw $__KERNEL_DS, %dx # Data segment descriptor + + /* Jump to where the 16b code would have jumped */ + ljmpl $__KERNEL32_CS, $pa_startup_32 +SYM_CODE_END(sl_trampoline_start32) +#endif + .balign 4 SYM_CODE_START(startup_32) movl %edx, %ss --=20 2.47.3 From nobody Mon May 25 08:11:32 2026 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 700E2409E08 for ; Fri, 15 May 2026 21:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879752; cv=none; b=LPw4pWfzT1boe0Rhb7TmZwoYBSdoHv+CEJDcgcMopNIiXEOw4N1i6IStD2+o8RJYnxHsZCqhaLE++G7hmJtpG80Ex6mc0vVsUOSlwwugLyUCRsRjNiNN8P0BxOvPfvvIvj2/Hrh7JhHuLACJK5/CVF255SVuzZi+uDtJVtrbJdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879752; c=relaxed/simple; bh=XbUQZxHpNqBquc7KQic463MCIdXLrI/jlIpArje4CQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aGhmf1yuVCp/zy5UPBVdeARmYohdYk14lQm7ARokiceEyFVy5BhguB92033wx5wQL1cav2k53DDg9cqPhXsJ+pUrkQMSNkWwg2qWGF8XT3F8nxkPX+bwLX3pPK5kHLt/1g79RiZrMJ+xg2oUVTH/zfaGT1YakYXAxSBnOOUhgVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CAGQ8a4i; arc=none smtp.client-ip=74.125.82.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CAGQ8a4i" Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-30246cfd41aso1516063eec.1 for ; Fri, 15 May 2026 14:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879750; x=1779484550; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+XRl4qspUk2kb6S4/X/JxR4OkIHL9zexMUP1DlnAUlQ=; b=CAGQ8a4iH3SSfmaF4RFgv7YATJ5hLTx06I7TdBd+XDrkvC6tnQMpcT31yKe+LlZ9eB YbnhOnhixK1Oqvrp2w2OiYYVXQ4w04Ahlk6hz2e8n6HUb7CEygsVYiKsFLYw5tS1rNgm sdm8mqMqRI8gJTDDBJNxpp+iEmvQyJRSVxb8iAN7Fb4XYUqx12BZpKi9ghmDtPPDZzqo X1jq/0LqaQjl/FEiSf3ZBiKcc2+V+6ZvaoR7QeTqb9G2suC/lmEfAYR0w43FvjyCzdCV aMK/gCSz8IVOKKNUL6cdey//sfpHeSfRLV6IZLstHLAiDJH4tHJSxqvlo+2n2hdiQMjC hEtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879750; x=1779484550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+XRl4qspUk2kb6S4/X/JxR4OkIHL9zexMUP1DlnAUlQ=; b=ccVfAR851PFBe50W65Irr+fFmtPTIsEiVCmsYb3UQOKei7OvnFbRQd24WNWUVLtoO5 we6Mzvpny3FuTeEssBO7PS/8vy/4DAmgfgv9jvq2PxCUl1J58vKi25KnegOnh2wDlkvV 3Cy+w9cFP+SH9vRK9M/WzPKvHDSqhvhJGfBjOD9RxTc3QCznaE0Db286iSGzAaoES38h x5RRyIaZpK0sXrT+LxyheI1dB8CRCYS5kTdUSHZX0S1CiJotR89yPFiwWGvjUcIVpupN h3TjOu+dtUjs87nIwa2jTuup93mBiLtFLvp3XH2i2HC7t4FuS31NFRxOvp47kUkauz3V zEWA== X-Gm-Message-State: AOJu0Yyg9jHgr8f2GD9yl1M6i/fBcZWbAa5zND7Fv1kN+n7hOc5IfN80 5BHwl+3C5QI9duuxcruSNCwdy4pZ4cmth1nyfmT5sjdsXYKraK6HiRNu4ET/mTYM X-Gm-Gg: Acq92OG0P7tlDK2UIQeNHOCRN20+sHZK7biH4bp9kMVQBvRL9BC6emsS3P5ngavQsgl ib2l93jwyb/T6lhzSvxY1tsQq4aWc+ZP7W2nd0L/0IcA9hwyuGN2Lc6oRsCZqXvXeoTmoXYeUiF BX6/ikjQc+XXi33pSAUDTbRqwNLqtDDnhqk4a6u38s9FHsKz54mNankeS3deGWpEO8t18x0EjvK PBbglE0eqk1QGrjHaTDjq2+03XmwQ99+XvjrTJxJVD0EbRR34VonJwDhIGBcIeA9jbHnDUqn5Sw V0f4SvYaQsxa66z4G/PbKrG3jLXnHJe8eP+9uu1B1zXTCKznr9D3/K4m4d/DkIfpjpO6ywxsLmm nQcKGh3k16TOrRcdSmTg4s95HDFHxaw984JAoVRuJLUMCp2ctuLbvqmzQEoTeYDUnb6RhmGTG6B Kwx1nQkvagl5GYDKgHvpOCeKs6afIXpJg= X-Received: by 2002:a05:7300:3252:b0:2ea:5057:a31d with SMTP id 5a478bee46e88-3039818a864mr3228730eec.1.1778879749634; Fri, 15 May 2026 14:15:49 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30293e2e686sm9461192eec.5.2026.05.15.14.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:49 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 34/38] kexec/slaunch: Secure Launch kexec SEXIT support Date: Fri, 15 May 2026 14:14:06 -0700 Message-ID: <20260515211410.31440-35-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Prior to running the next kernel via kexec, the Secure Launch code closes down private SMX resources and does an SEXIT. This allows the next kernel to start normally, effectively exiting the DRTM environment. The function slaunch_finalize() takes a boolean argument that controls whether a GETSEC[SEXIT] can be issued. When true, the finalize code can completely shutdown and exit the DRTM. This allows another kernel to start normally and in turn can re-establish another DRTM session. In cases where the machine has not been fully shutdown (e.g. when machine_shutdown() was not called), the SEXIT step cannot be done (SEXIT will fail if other processors are busy). In these cases SEXIT is not attempted. This normally occurs on power off or reboot operations where it doesn't really matter. Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/kernel/slaunch.c | 80 +++++++++++++++++++++++++++++++++++++++ kernel/kexec_core.c | 8 ++++ 2 files changed, 88 insertions(+) diff --git a/arch/x86/kernel/slaunch.c b/arch/x86/kernel/slaunch.c index f6e6f1b7e18c..b34997a5f541 100644 --- a/arch/x86/kernel/slaunch.c +++ b/arch/x86/kernel/slaunch.c @@ -537,3 +537,83 @@ void __init slaunch_fixup_ap_wake_vector(void) =20 pr_info("TXT AP startup vector address updated\n"); } + +static inline void smx_getsec_sexit(void) +{ + asm volatile ("getsec\n" : : "a" (SMX_X86_GETSEC_SEXIT)); +} + +/* + * Used during kexec and on reboot paths to finalize the TXT state + * and do an SEXIT SMX operation, exiting the DRTM and disabling SMX mode. + */ +void slaunch_finalize(int do_sexit) +{ + u64 one =3D TXT_REGVALUE_ONE, val; + void __iomem *config; + + if (!slaunch_is_txt_launch()) + return; + + config =3D ioremap(TXT_PRIV_CONFIG_REGS_BASE, TXT_NR_CONFIG_PAGES * PAGE_= SIZE); + if (!config) { + pr_emerg("TXT: SEXIT failed to ioremap TXT private registers\n"); + return; + } + + /* Clear secrets bit for SEXIT */ + memcpy_toio(config + TXT_CR_CMD_NO_SECRETS, &one, sizeof(one)); + memcpy_fromio(&val, config + TXT_CR_E2STS, sizeof(val)); + + /* Unlock memory configurations */ + memcpy_toio(config + TXT_CR_CMD_UNLOCK_MEM_CONFIG, &one, sizeof(one)); + memcpy_fromio(&val, config + TXT_CR_E2STS, sizeof(val)); + + /* Close the TXT private register space */ + memcpy_toio(config + TXT_CR_CMD_CLOSE_PRIVATE, &one, sizeof(one)); + memcpy_fromio(&val, config + TXT_CR_E2STS, sizeof(val)); + + /* + * Calls to iounmap are skipped due to the system state this late in the + * kexec process. Local IRQs are disabled and iounmap causes a TLB flush + * which in turn causes a warning. Leaving these mappings is not an issue + * since the next kernel is going to completely re-setup memory managemen= t. + */ + + /* Map public registers and do a final read fence */ + config =3D ioremap(TXT_PUB_CONFIG_REGS_BASE, TXT_NR_CONFIG_PAGES * + PAGE_SIZE); + if (!config) { + pr_emerg("TXT: SEXIT failed to ioremap TXT public registers\n"); + return; + } + + memcpy_fromio(&val, config + TXT_CR_E2STS, sizeof(val)); + + pr_emerg("TXT clear secrets bit and unlock memory complete.\n"); + + /* + * Mostly finalized but the system is still in SMX mode. At this point if= the + * system has been quiesced, the APs are halted and the current process is + * running on the BSP, a final GETSEC(SEXIT) can be done exiting DRTM/SMX= mode. + * This cannot be done on certain boot paths where the system has not bee= n quiesced + * (e.g. where machine_shutdown() has not been called). + */ + if (!do_sexit) + return; + + if (smp_processor_id() !=3D 0) + panic("TXT: SEXIT must be called on CPU 0\n"); + + /* + * In case SMX mode was disabled, enable it for SEXIT. Clearing the bit + * anytime during DRTM operation will not have an affect until the next + * GETSEC() op is performed. + */ + cr4_set_bits(X86_CR4_SMXE); + + /* Do the SEXIT SMX operation */ + smx_getsec_sexit(); + + pr_info("TXT SEXIT complete.\n"); +} diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 2fea396d29b9..dd284e5043ab 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -43,6 +43,7 @@ #include #include #include +#include =20 #include #include @@ -1201,6 +1202,13 @@ int kernel_kexec(void) cpu_hotplug_enable(); pr_notice("Starting new kernel\n"); machine_shutdown(); + + /* + * If a Secure Launch is in progress and the current kernel is + * running as a DRTM with TXT, finalize the Secure Launch state + * and do the GETSEC(SEXIT) returning from SMX mode to do the KEXEC. + */ + slaunch_finalize(1); } =20 kmsg_dump(KMSG_DUMP_SHUTDOWN); --=20 2.47.3 From nobody Mon May 25 08:11:32 2026 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E08B40C5AD for ; Fri, 15 May 2026 21:15:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879755; cv=none; b=ovPxtVAhuxAPKoQSK9YR/4nAIOqdtn8Lzbu8cslW/I23QcPM1A+MI3Wr3u9AsSBD60sCDUxFmXne2sGa5PcKLyyQ9GAjNk+kxsGb0MdXCtvcGX+FTPhMQiYnr6uMPhBAUMqkvsNYYfXzhPQQd6OZzuvqDSNDlJMclrGB1n8H5dE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879755; c=relaxed/simple; bh=k11liqjn7SKCyf9jqrs9rTU6kFg+eJg4IVC5ddHmpkI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OIjc6D/GPfXJWuwACytF/km+7ts/5vPIIffXzua6Rad8ZkD136rNu2UBIsMkL+hqmLmK+IKxSKmX73X2S3Nv4GPrhZNej3eoxyLLN7POTr6G5D7Z6Xpyx869KeMhNkeHnxQQ+tq0NCVNigdcXTyRrvRkDJUcisNcr91++6XzY10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MW3f6p1L; arc=none smtp.client-ip=74.125.82.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MW3f6p1L" Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-30246cfd41aso1516329eec.1 for ; Fri, 15 May 2026 14:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879753; x=1779484553; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d0sYZnhQeLyzvjO7vpNeSMDXaPgGF/81BOZ3a8GGZZ8=; b=MW3f6p1L5kudegGCItpuYAXS0RaiDi4aNt4p22EfgX11pgRsZn0lkRN/b11rRXCWh4 Timw43kcCzZdNRr8jfGYUIrLHf+Zq71fP9atGwGnaPZPEuqF3JRXOybBWGN4Bcj7+wZV pJXY/7KvNXuCNw2IDafGifFgt/qPqSJgSY4Fyjg3I1GtfYy446IuqHKyhO1W93TZhUv0 I3XOK9esj/N/vrNMe11n9gSuwnxhphCC0RvnmwruX4gebJ+nWhpgGJcvAQ9cDtmshGJX SYNUKSX8YPQrZ/gxyiK/aMBuXXZaVh9FhVgzgM56noTmG9GcF6/S4kcU1vGe9grQL/2I yu8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879753; x=1779484553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=d0sYZnhQeLyzvjO7vpNeSMDXaPgGF/81BOZ3a8GGZZ8=; b=a6AiI6DmfI/lKd31PT5USnSxug6OMe7ilICrfyfK4xGGPIVPbcRWnOTA16VqP4oIzT pUsJzVUjiXfFBttAI/WLzcdle/RSuznxSqaaiYKaDoUTXYwXEaDYihLaY4VqoXJHmuEQ Fhh90snX/P7iIT/1wgtF1p+mS1f7pAH9hi4PqQA6TapkmvKXkYUVqRpn7/KYhVo1z/8W Ncw5YYkENhhLYNP3Alic7K1ewEOtlw3/8NVGzdYHQPU/6aoklEYz8NOg0YQsm537a+rn 41UZCdwm9FJOflvml7mvbr6t13GxCfy5aUr6V4Q9UeXj7azlToEOP80081OOz59sCpNc 1EgA== X-Gm-Message-State: AOJu0YzENTIx6GeUgSp/CzCPTF+24Xc8B1fz7qt9Q96PkHEqBuvgKAqZ EGxVK9q57eetUJy+XdgRYgY06TQsXv8V/pU9UkK79evVRmXY0xDBl6yq4H0lBPxy X-Gm-Gg: Acq92OHLIxe7adHFLoLCJRY8mzPeL3PQBWy1pP8WqrkqZN7p62iDUP+2vMmTjaK2kFE s8lhlJAx73VKLtFnfdk9cV0vtArS07N1BXSl0WoQqx5ln9eKxg/snabDijM6k/F4uYFKdtm/NPo emqqUpycZ5jcljgDjsaR4OMyZiMjOziVR3JlmUAxVjuIU+e7XoFYxdorFhcc1EfHdSdTv//ZPZO VHZvFnVF1ncOS2oUURqgp+XHyd903o9onosRbvlQzM3sZ3l9lJ+OOLnY/o5RNSWWwR4GLgmYdbK MQKGxOjNVoaq/njlwHU9quOWWxcZ2F05D9Za6VFa++RLam7BhwpSbtugG4Ru2lbB8xg5hi2vKZT enn6RT0c0TG8nHurHcF787JnSNfGNz4kuQYqKGYdOFNqcMBYdQydp2KCtgqOU0xU++3FRbaj7Pk aMQMYXvKzpbmtWyrA5or+EjlGo8UJrmT8FvycK+hHvJA== X-Received: by 2002:a05:7301:290f:b0:2da:7e33:9261 with SMTP id 5a478bee46e88-3039869b7b3mr2853046eec.27.1778879752504; Fri, 15 May 2026 14:15:52 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30297bbc9a3sm8132550eec.31.2026.05.15.14.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:52 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 35/38] reboot/slaunch: Secure Launch SEXIT support on reboot paths Date: Fri, 15 May 2026 14:14:07 -0700 Message-ID: <20260515211410.31440-36-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the MLE kernel is being powered off, rebooted or halted, then SEXIT must be called. Note that the GETSEC[SEXIT] leaf can only be called after a machine_shutdown() has been done on these paths. The machine_shutdown() is not called on a few paths like when poweroff action does not have a poweroff callback (into ACPI code) or when an emergency reset is done. In these cases, just the TXT registers are finalized but SEXIT is skipped. Co-developed-by: Daniel P. Smith Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/kernel/reboot.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index 6032fa9ec753..87835706bb4f 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -779,6 +780,12 @@ static void native_machine_restart(char *__unused) =20 if (!reboot_force) machine_shutdown(); + /* + * The comments for slaunch_finalize() provides the explanation for the + * conditions required to do the SEXIT op reflected in the conditional + * parameter do_sexit. + */ + slaunch_finalize(!reboot_force); __machine_emergency_restart(0); } =20 @@ -789,6 +796,8 @@ static void native_machine_halt(void) =20 tboot_shutdown(TB_SHUTDOWN_HALT); =20 + slaunch_finalize(1); + stop_this_cpu(NULL); } =20 @@ -797,8 +806,12 @@ static void native_machine_power_off(void) if (kernel_can_power_off()) { if (!reboot_force) machine_shutdown(); + slaunch_finalize(!reboot_force); do_kernel_power_off(); + } else { + slaunch_finalize(0); } + /* A fallback in case there is no PM info available */ tboot_shutdown(TB_SHUTDOWN_HALT); } @@ -826,6 +839,7 @@ void machine_shutdown(void) =20 void machine_emergency_restart(void) { + slaunch_finalize(0); __machine_emergency_restart(1); } =20 --=20 2.47.3 From nobody Mon May 25 08:11:32 2026 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D10040C5DA for ; Fri, 15 May 2026 21:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879758; cv=none; b=hrpTI7GqwmnO6wFo5VHhn1J7OaIWilslsBdqRabfUaEK80yS/KjQasNz5T37GzPdIH2Kj0vsO1l4cNbbA0r4QdQi9euOd/CLVtoS6+ubhV+ZBSknGL58fWObONsdpkcRt5Lyf6lml2WLjDvq5bixhT6LWhHPkjCbyJMeHMf8CIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879758; c=relaxed/simple; bh=7kz9F/A7fTabBES64n2mJiXuxrlDHAgKavRF6IJZP/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZZfRZfzxCUqRnIjO94n4LW4qV/K3R2sovCBXehpjVMY61YMG8CK8/xbr5LxjJCYIuS51zX9aq3yZFABcFv6w+/5RvPyTO+D6/0qGys6FOvbYf3CdYWpvLF3HUD6T7zZ1EcYuhZuLZMR44+fafZueNDVW80+IeKMSjaaFRG+ZxEE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cqHNMISC; arc=none smtp.client-ip=74.125.82.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cqHNMISC" Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1353c2f35cfso952049c88.1 for ; Fri, 15 May 2026 14:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879755; x=1779484555; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Gc9QK/7ZvXL3YWAwN0KCcbTGVvK6GenZl2ozt4yOZIg=; b=cqHNMISCPJsQTmlqCfNSv/ih/pdG3fy0Q3ykxPB7roAESvauGz36GurYGmOjECRKFv DSeE4Gmfh5qRU+4LaP7o4Ck6McG1bDINdimpxdvKk7rGpaNAF6s0RzDbLLWz6MFbbrUf 5W2qyKydoVi5N3IDsYARGhC9KyfdLfVsFt0e+VEaiTUhiVGIdyeaJZ+MGHl+KSNhg7In RYNF2fvXCa2gRPi6fgxfSLpfwioAn53yp3LqWKnr7vucUgo0PQ3zDJyAghG5rTUsBVIA rn5r1Gzt1gYfdbcCAazVvlV0mSrm4taWqtl3MpMFaEFZ4m9ml/Y535xseiIVg1kjW/eG fmkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879755; x=1779484555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Gc9QK/7ZvXL3YWAwN0KCcbTGVvK6GenZl2ozt4yOZIg=; b=rFMZmwU9b0eR1LglSXTwwN0GDA8GjZTnpGgYHXqaRG8UGAoV1b3+l4iLbN7881azaH hymyB1U6+U0hRndrtE4M/S5iBYwcE5lWTMTLroTuA8sD+P1kgoUyYQjvm5kZjMW3saxq CUnDOGGX4lLNLlbJcvgICelK0D0a7uLuGS1SlJtmqnU8+03XRO1DlmyoQbiTiKYyKMX2 AipDHR2BVJopuXixB0cDAkeb2eAtOofmUmrjoyuyyLt4Px5x2841AWnBgMAnfs6KKzix twurt0v1WdDFuaQ3CJMXNJzahgzTl0veQfBEAnrpuCvJiyKNtCeqJQC5mgJAYT2l/cKa BQuQ== X-Gm-Message-State: AOJu0YxFKnyp2FUrCE4JsxfbP1M9202DglJMLN+Y+cXUV1bkXlcOo+P7 iVDlIy1nB7o9SpUqS3cOTNtmu89jU2UIL9sJcHdldGLPx+Qe2sERrozavsDwKDle X-Gm-Gg: Acq92OGLa6bSTkKfi8lS/k/LWu6cHsBhH8IhSmzo+l4QN5QEbBnfzMYpYlVLkFAdwg8 8lk7jEJSQzZIj4xoqJInT5kx6IN6DVYiC0NiOnArHvBrSCvAfVEKmYDtMg4K+1sLq4BgMeMqMHH z4m//vVKdz5lh8+W3Y8sKHm59tjg5aqAQO4M9UyyoXBQg6V0zcldT6iWMtBobKOUNm7ByRyOt5I Hr7+C+EwkP+x5W67VqhssEblXplI11Te61aQ4sYn7mU5X6jI+oTVK4/mDpRe91EFvrOIXeY7gI2 U5M1WxR55kuNEttLaJwpvfimQUnmcbzVzGghuoHXIqStagAksL2bSFZ7uY2U5/T1G9iHuBnG/2E BEvE8KBDlt756rTVY6fyUo5ewlz08mW8KKYfblqE9Z2BMHpM6suLi/PJDN1pwhUr5YuG//iwNKn E9c/8pTGP25a2Bta4FgbNTA5dFNSeVq/s4hymJ/HHOTw== X-Received: by 2002:a05:7022:661e:b0:12d:de3f:d844 with SMTP id a92af1059eb24-13504951829mr2578587c88.39.1778879755329; Fri, 15 May 2026 14:15:55 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cbdcf140sm11368464c88.5.2026.05.15.14.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:54 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 36/38] x86/slaunch: Secure Launch late initcall platform module Date: Fri, 15 May 2026 14:14:08 -0700 Message-ID: <20260515211410.31440-37-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Daniel P. Smith" The Secure Launch platform module is a late init module. During the init call, the TPM event log is read and measurements taken in the early boot stub code are located. These measurements are extended into the TPM PCRs using the mainline TPM kernel driver. The platform module also registers the securityfs nodes to allow fetching and writing events from/to the DRTM TPM event log. In addition, on Intel, access to TXT register fields is made available for reading. Co-developed-by: garnetgrimm Signed-off-by: garnetgrimm Co-developed-by: Ross Philipson Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/slmodule.c | 353 +++++++++++++++++++++++++++++++++++++ 2 files changed, 354 insertions(+) create mode 100644 arch/x86/kernel/slmodule.c diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index bf2471701662..8b039ed0a902 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -98,6 +98,7 @@ obj-$(CONFIG_IA32_EMULATION) +=3D tls.o obj-y +=3D step.o obj-$(CONFIG_INTEL_TXT) +=3D tboot.o obj-$(CONFIG_SECURE_LAUNCH) +=3D slaunch.o +obj-$(CONFIG_SECURE_LAUNCH) +=3D slmodule.o obj-$(CONFIG_ISA_DMA_API) +=3D i8237.o obj-y +=3D stacktrace.o obj-y +=3D cpu/ diff --git a/arch/x86/kernel/slmodule.c b/arch/x86/kernel/slmodule.c new file mode 100644 index 000000000000..9688249e274c --- /dev/null +++ b/arch/x86/kernel/slmodule.c @@ -0,0 +1,353 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Secure Launch late validation/setup, securityfs exposure and finalizati= on. + * + * Copyright (c) 2026 Apertus Solutions, LLC + * Copyright (c) 2026 Assured Information Security, Inc. + * Copyright (c) 2026, Oracle and/or its affiliates. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The macro DECLARE_TXT_PUB_READ_U is used to read values from the TXT + * public registers as unsigned values. + */ +#define DECLARE_TXT_PUB_READ_U(size, fmt, msg_size) \ +static ssize_t txt_pub_read_u##size(unsigned int offset, \ + loff_t *read_offset, \ + size_t read_len, \ + char __user *buf) \ +{ \ + char msg_buffer[msg_size]; \ + u##size reg_value =3D 0; \ + void __iomem *txt; \ + \ + txt =3D ioremap(TXT_PUB_CONFIG_REGS_BASE, \ + TXT_NR_CONFIG_PAGES * PAGE_SIZE); \ + if (!txt) \ + return -EFAULT; \ + memcpy_fromio(®_value, txt + offset, sizeof(u##size)); \ + iounmap(txt); \ + snprintf(msg_buffer, msg_size, fmt, reg_value); \ + return simple_read_from_buffer(buf, read_len, read_offset, \ + &msg_buffer, msg_size); \ +} + +DECLARE_TXT_PUB_READ_U(8, "%#04x\n", 6); +DECLARE_TXT_PUB_READ_U(32, "%#010x\n", 12); +DECLARE_TXT_PUB_READ_U(64, "%#018llx\n", 20); + +#define DECLARE_TXT_FOPS(reg_name, reg_offset, reg_size) \ +static ssize_t txt_##reg_name##_read(struct file *flip, \ + char __user *buf, size_t read_len, loff_t *read_offset) \ +{ \ + return txt_pub_read_u##reg_size(reg_offset, read_offset, \ + read_len, buf); \ +} \ +static const struct file_operations reg_name##_ops =3D { \ + .read =3D txt_##reg_name##_read, \ +} + +DECLARE_TXT_FOPS(sts, TXT_CR_STS, 64); +DECLARE_TXT_FOPS(ests, TXT_CR_ESTS, 8); +DECLARE_TXT_FOPS(errorcode, TXT_CR_ERRORCODE, 32); +DECLARE_TXT_FOPS(didvid, TXT_CR_DIDVID, 64); +DECLARE_TXT_FOPS(e2sts, TXT_CR_E2STS, 64); +DECLARE_TXT_FOPS(ver_emif, TXT_CR_VER_EMIF, 32); +DECLARE_TXT_FOPS(scratchpad, TXT_CR_SCRATCHPAD, 64); + +/* + * Securityfs exposure + */ +struct memfile { + char *name; + void *addr; + size_t size; +}; + +static struct memfile sl_evtlog =3D { "eventlog", NULL, 0 }; +static void *txt_heap; +static struct txt_heap_event_log_pointer2_1_element *evtlog21; +static DEFINE_MUTEX(sl_evt_log_mutex); +static struct tcg_efi_specid_event_head *efi_head; + +static ssize_t sl_evtlog_read(struct file *file, char __user *buf, + size_t count, loff_t *pos) +{ + ssize_t size; + + if (!sl_evtlog.addr) + return 0; + + mutex_lock(&sl_evt_log_mutex); + size =3D simple_read_from_buffer(buf, count, pos, sl_evtlog.addr, + sl_evtlog.size); + mutex_unlock(&sl_evt_log_mutex); + + return size; +} + +static ssize_t sl_evtlog_write(struct file *file, const char __user *buf, + size_t datalen, loff_t *ppos) +{ + ssize_t result; + char *data; + + if (!sl_evtlog.addr) + return 0; + + /* No partial writes. */ + result =3D -EINVAL; + if (*ppos !=3D 0) + goto out; + + data =3D memdup_user(buf, datalen); + if (IS_ERR(data)) { + result =3D PTR_ERR(data); + goto out; + } + + mutex_lock(&sl_evt_log_mutex); + if (evtlog21) + result =3D tpm2_log_event(evtlog21, sl_evtlog.addr, + sl_evtlog.size, datalen, data); + else + result =3D tpm_log_event(sl_evtlog.addr, sl_evtlog.size, + datalen, data); + mutex_unlock(&sl_evt_log_mutex); + + kfree(data); +out: + return result; +} + +static const struct file_operations sl_evtlog_ops =3D { + .read =3D sl_evtlog_read, + .write =3D sl_evtlog_write, + .llseek =3D default_llseek, +}; + +struct sfs_file { + const char *name; + const struct file_operations *fops; +}; + +#define SL_TXT_ENTRY_COUNT 7 +static const struct sfs_file sl_txt_files[] =3D { + { "sts", &sts_ops }, + { "ests", &ests_ops }, + { "errorcode", &errorcode_ops }, + { "didvid", &didvid_ops }, + { "ver_emif", &ver_emif_ops }, + { "scratchpad", &scratchpad_ops }, + { "e2sts", &e2sts_ops } +}; + +/* sysfs file handles */ +static struct dentry *slaunch_dir; +static struct dentry *event_file; +static struct dentry *txt_dir; +static struct dentry *txt_entries[SL_TXT_ENTRY_COUNT]; + +static long slaunch_expose_securityfs(void) +{ + long ret =3D 0; + int i; + + slaunch_dir =3D securityfs_create_dir("slaunch", NULL); + if (IS_ERR(slaunch_dir)) + return PTR_ERR(slaunch_dir); + + if (slaunch_get_flags() & SL_FLAG_ARCH_TXT) { + txt_dir =3D securityfs_create_dir("txt", slaunch_dir); + if (IS_ERR(txt_dir)) { + ret =3D PTR_ERR(txt_dir); + goto remove_slaunch; + } + + for (i =3D 0; i < ARRAY_SIZE(sl_txt_files); i++) { + txt_entries[i] =3D + securityfs_create_file(sl_txt_files[i].name, 0440, txt_dir, + NULL, sl_txt_files[i].fops); + if (IS_ERR(txt_entries[i])) { + ret =3D PTR_ERR(txt_entries[i]); + goto remove_files; + } + } + } + + if (sl_evtlog.addr) { + event_file =3D securityfs_create_file(sl_evtlog.name, 0440, + slaunch_dir, NULL, + &sl_evtlog_ops); + if (IS_ERR(event_file)) { + ret =3D PTR_ERR(event_file); + goto remove_files; + } + } + + return 0; + +remove_files: + if (slaunch_get_flags() & SL_FLAG_ARCH_TXT) { + while (--i >=3D 0) + securityfs_remove(txt_entries[i]); + securityfs_remove(txt_dir); + } + +remove_slaunch: + securityfs_remove(slaunch_dir); + + return ret; +} + +static void slaunch_teardown_securityfs(void) +{ + int i; + + securityfs_remove(event_file); + if (sl_evtlog.addr) { + memunmap(sl_evtlog.addr); + sl_evtlog.addr =3D NULL; + } + sl_evtlog.size =3D 0; + + if (slaunch_get_flags() & SL_FLAG_ARCH_TXT) { + for (i =3D 0; i < ARRAY_SIZE(sl_txt_files); i++) + securityfs_remove(txt_entries[i]); + + securityfs_remove(txt_dir); + + if (txt_heap) { + memunmap(txt_heap); + txt_heap =3D NULL; + } + } + + securityfs_remove(slaunch_dir); +} + +static void __init slaunch_intel_evtlog(void __iomem *txt) +{ + struct slr_entry_log_info *log_info; + struct txt_os_mle_data *params; + struct slr_table *slrt; + void *os_sinit_data; + u64 base, size; + + memcpy_fromio(&base, txt + TXT_CR_HEAP_BASE, sizeof(base)); + memcpy_fromio(&size, txt + TXT_CR_HEAP_SIZE, sizeof(size)); + + /* now map TXT heap */ + txt_heap =3D memremap(base, size, MEMREMAP_WB); + if (!txt_heap) + slaunch_reset(txt, "Error memremap TXT heap failed\n", SL_ERROR_HEAP_MAP= ); + + params =3D (struct txt_os_mle_data *)slaunch_txt_get_heap_table(txt_heap, + TXT_OS_MLE_DATA_TABLE); + + /* Get the SLRT and remap it */ + slrt =3D memremap(params->slrt, sizeof(*slrt), MEMREMAP_WB); + if (!slrt) + slaunch_reset(txt, "Error memremap SLR Table failed\n", SL_ERROR_SLRT_MA= P); + size =3D slrt->size; + memunmap(slrt); + + slrt =3D memremap(params->slrt, size, MEMREMAP_WB); + if (!slrt) + slaunch_reset(txt, "Error memremap SLR Table failed\n", SL_ERROR_SLRT_MA= P); + + log_info =3D slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_LOG_INFO); + if (!log_info) + slaunch_reset(txt, "Error SLR Table missing entry\n", SL_ERROR_SLRT_MISS= ING_ENTRY); + + sl_evtlog.size =3D log_info->size; + sl_evtlog.addr =3D memremap(log_info->addr, log_info->size, MEMREMAP_WB); + if (!sl_evtlog.addr) + slaunch_reset(txt, "Error memremap TPM event log failed\n", SL_ERROR_EVE= NTLOG_MAP); + + memunmap(slrt); + + /* Determine if this is TPM 1.2 or 2.0 event log */ + if (memcmp(sl_evtlog.addr + sizeof(struct tcg_pcr_event), + TCG_SPECID_SIG, sizeof(TCG_SPECID_SIG))) + return; /* looks like it is not 2.0 */ + + /* For TPM 2.0 logs, the extended heap element must be located */ + os_sinit_data =3D slaunch_txt_get_heap_table(txt_heap, TXT_OS_SINIT_DATA_= TABLE); + + evtlog21 =3D txt_find_log2_1_element(os_sinit_data); + + /* + * If this fails, things are in really bad shape. Any attempt to write + * events to the log will fail. + */ + if (!evtlog21) + slaunch_reset(txt, "Error locate TPM20 event log element failed\n", + SL_ERROR_TPM_INVALID_LOG20); + + /* Save pointer to the EFI SpecID log header */ + efi_head =3D (struct tcg_efi_specid_event_head *)(sl_evtlog.addr + + sizeof(struct tcg_pcr_event)); +} + +static void __init slaunch_tpm_open_locality2(void __iomem *txt) +{ + struct tpm_chip *tpm; + int rc; + + tpm =3D tpm_default_chip(); + if (!tpm) + slaunch_reset(txt, "Could not get default TPM chip\n", SL_ERROR_TPM_INIT= ); + + rc =3D tpm_chip_set_locality(tpm, 2); + if (rc) + slaunch_reset(txt, "Could not set TPM chip locality 2\n", SL_ERROR_TPM_I= NIT); +} + +static int __init slaunch_module_init(void) +{ + void __iomem *txt; + + /* Check to see if Secure Launch happened */ + if ((slaunch_get_flags() & (SL_FLAG_ACTIVE|SL_FLAG_ARCH_TXT)) !=3D + (SL_FLAG_ACTIVE | SL_FLAG_ARCH_TXT)) + return 0; + + txt =3D ioremap(TXT_PRIV_CONFIG_REGS_BASE, TXT_NR_CONFIG_PAGES * + PAGE_SIZE); + if (!txt) + panic("Error ioremap of TXT priv registers\n"); + + /* Only Intel TXT is supported at this point */ + slaunch_intel_evtlog(txt); + slaunch_tpm_open_locality2(txt); + iounmap(txt); + + return slaunch_expose_securityfs(); +} + +static void __exit slaunch_module_exit(void) +{ + slaunch_teardown_securityfs(); +} + +late_initcall(slaunch_module_init); +__exitcall(slaunch_module_exit); --=20 2.47.3 From nobody Mon May 25 08:11:32 2026 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F2D4405C25 for ; Fri, 15 May 2026 21:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879760; cv=none; b=fubq0gJ8g7whtzryU4LzwO+Q3swf+hfEMoFGCE542HHFDZ72trP7tHkfotrA2OxOdgTeNzK69pEqpULeAMKuxEa8giEMeDJQPR9dPowaGFPq2IatQQqtaMAjYo7A43O787c8+ZiplFSJJLnqciM7efNoscTSdLwdQ89JuYDudcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879760; c=relaxed/simple; bh=UwbTsginbKatRYw5xm/hcVI6EpyOnfrhKVxHAkEoevA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sKUYBCPT0/3/Wf1Ctg0Re7TWf7kOS02xr/T1LAx096H+OXcoN3S/O22C8DCe8aP8P5JdVVVO3qAh8l6f3ABasJdo93p3YYxVcMQWAJvS6KFtEqkzR0+001p3Cd14SZp36ckcRgONb8RFAVVdHNvFqIKWQjBr8c1Aif2dF3a9hxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H0EnfCoh; arc=none smtp.client-ip=74.125.82.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H0EnfCoh" Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-2f7ca62a3c4so297625eec.0 for ; Fri, 15 May 2026 14:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879758; x=1779484558; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yh0gWGTCHr3HLLSp6B0/bzede+AfJuos48AZ5KwqkJE=; b=H0EnfCohdl1bs0kKz2FPoOIqyc6u0VgIFzR65lCeNZEzgd9nrqvyx0/h9XI3mw+hkL vZONkm9lquaPNgG2TQBYIMvEgeq2rhteWq4YafnLi0uDtizXhJRxhEfookA9/krXWYsm b+1MHtLVhwaPpHW/oxj4hZgRd0Le+ENBrPh3yOrfTgJsWagEm4az4Hud+F3vwZYDpuZX zFqnc27fWBZEDYvfaKrWtgowbjYCsvpep5IvSW9JHZ9SRbsDihSuPutQWYUqnohMUfZV QRILxCI4J4vPXh4xNqy51RZPY5d0e6FLSXB0wABvNy7jK/pZAiQGXJq7VqFSpXtM9wBo 1ANw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879758; x=1779484558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yh0gWGTCHr3HLLSp6B0/bzede+AfJuos48AZ5KwqkJE=; b=JJFXRMeCgLwUAmn7CwfxXQpz30xzRAJb9IzWgfNXSmJYGt/iF/gREqgBr8gyAvGYsh lWK1x0o4z4Xb90iH87iev5VdxIGMjj7aN8wm9yUbIcqkV+Ob1OlntLzKCvrYs7DTBQH/ 6McRD0cwx7bv+NNFBLzKNsFGhMYEn+KxWTYqIG6mGozm4ABHJMxstTZlZQ5mErH2bxAL Kd6Cu9Tlmfa1Y1m49zXwcn29VQ5U0/6LeTVRYU8Ba71Qw94pgs8AwFEYJknvVKZISzkh CL8zA6MQNe0xvrdeeWYcsjAhQtPB3w3TmUZvvmDoTgaZXkKp0VGID4NUD+zHMMkLH3yb 2uUw== X-Gm-Message-State: AOJu0YzTdaFjM1lZQLxUerHa3cJqekYoTsuXoXJVGccIET5fwUGV88dO ZN4DWcJDVFs7moS4AUBCYl9GoaH3g/OWkDMT87MNs7zrTZcB3aMhhEhx6pKQ5hcK X-Gm-Gg: Acq92OFVONzuhraEUqNUi5Kku/MdJR/7C2o5pYU2qr+yE5upErEj/PLOH8E08WmVBXU tJZFxWk1rzJA20OqGWD9B35R9b+heDax9VP3Kh5/vPE1rqXkQNFIt1vs2p06S+aAhFPCQMRvbQ8 q27REg4FHJCmKLf6anbB7a3b11mWjhDrwq9PdwBGh749284irLYUdlmUtFoTIzyJwV4ICW3Nu7h MO5culPab2iUfPuQg+sL9LXLoEpcZaB275oJIcyvksF/suKi1BsIB8zmWQ6ZY4HJSmHny/ny7Gl ioO7Bx0K6NWiKWQY44CHD+doIGKiHPm5mwvNKJ8roS60/6VeT2huaW/A/wSCFvlV3RX7KRXi2Ne R0newmOSZzzP/7+5rFBiy9NXFp5k30GYrViaLpTGJN6POdTWhrgQcI7JgHGyTrg8KMF5drwFTSq SuWzYxE+heFVoT5+zEBO+tXN5QgI9XIG+WLo4PgzisQw== X-Received: by 2002:a05:7301:7c12:b0:2ed:e14:7f57 with SMTP id 5a478bee46e88-303986c651cmr3242643eec.33.1778879758108; Fri, 15 May 2026 14:15:58 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-302947e917dsm8006639eec.12.2026.05.15.14.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:15:57 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 37/38] x86/efistub: EFI stub DRTM support for Secure Launch Date: Fri, 15 May 2026 14:14:09 -0700 Message-ID: <20260515211410.31440-38-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Invoke the Secure Launch protocol exposed by the boot loader at the appropriate time to perform a measured launch of the decompressed kernel after ExitBootServices(). Co-developed-by: Ross Philipson Signed-off-by: Ard Biesheuvel Signed-off-by: Ross Philipson --- drivers/firmware/efi/libstub/Makefile | 1 + drivers/firmware/efi/libstub/efistub.h | 24 ++++++++++++++ drivers/firmware/efi/libstub/x86-slaunch.c | 38 ++++++++++++++++++++++ drivers/firmware/efi/libstub/x86-stub.c | 27 ++++++++++++--- 4 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 drivers/firmware/efi/libstub/x86-slaunch.c diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/l= ibstub/Makefile index e386ffd009b7..fd5eaf3142b2 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -86,6 +86,7 @@ lib-$(CONFIG_ARM) +=3D arm32-stub.o lib-$(CONFIG_ARM64) +=3D kaslr.o arm64.o arm64-stub.o smbios.o lib-$(CONFIG_X86) +=3D x86-stub.o smbios.o lib-$(CONFIG_X86_64) +=3D x86-5lvl.o +lib-$(CONFIG_SECURE_LAUNCH) +=3D x86-slaunch.o lib-$(CONFIG_RISCV) +=3D kaslr.o riscv.o riscv-stub.o lib-$(CONFIG_LOONGARCH) +=3D loongarch.o loongarch-stub.o =20 diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/= libstub/efistub.h index 979a21818cc1..18301ba3ae0f 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -1267,4 +1267,28 @@ void arch_accept_memory(phys_addr_t start, phys_addr= _t end); efi_status_t efi_zboot_decompress_init(unsigned long *alloc_size); efi_status_t efi_zboot_decompress(u8 *out, unsigned long outlen); =20 +#ifdef CONFIG_SECURE_LAUNCH +efi_status_t efi_secure_launch_init(efi_handle_t image_handle); +efi_status_t efi_secure_launch_prepare(struct boot_params *boot_params, + phys_addr_t base); +void efi_secure_launch(void); +#else +static inline +efi_status_t efi_secure_launch_init(efi_handle_t image_handle) +{ + return EFI_UNSUPPORTED; +} + +static inline +efi_status_t efi_secure_launch_prepare(struct boot_params *boot_params, + phys_addr_t base) +{ + return EFI_SUCCESS; +} + +static inline void efi_secure_launch(void) +{ +} +#endif + #endif diff --git a/drivers/firmware/efi/libstub/x86-slaunch.c b/drivers/firmware/= efi/libstub/x86-slaunch.c new file mode 100644 index 000000000000..98ff15f94996 --- /dev/null +++ b/drivers/firmware/efi/libstub/x86-slaunch.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "efistub.h" + +static struct efi_slaunch_protocol *slaunch; + +efi_status_t efi_secure_launch_init(efi_handle_t image_handle) +{ + return efi_bs_call(handle_protocol, image_handle, + &EFI_SLAUNCH_PROTOCOL_GUID, (void **)&slaunch); +} + +efi_status_t efi_secure_launch_prepare(struct boot_params *boot_params, + phys_addr_t base) +{ + if (!slaunch) + return EFI_SUCCESS; + + return slaunch->setup_dlme(slaunch, base, mle_header_offset, (u64)boot_pa= rams); +} + +void efi_secure_launch(void) +{ + if (!slaunch) + return; + + slaunch->launch(slaunch); +} diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index cef32e2c82d8..339e63ae84ef 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -833,7 +833,8 @@ static efi_status_t parse_options(const char *cmdline) } =20 static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry, - struct boot_params *boot_params) + struct boot_params *boot_params, + unsigned long alloc_limit) { unsigned long virt_addr =3D LOAD_PHYSICAL_ADDR; unsigned long addr, alloc_size, entry; @@ -877,8 +878,7 @@ static efi_status_t efi_decompress_kernel(unsigned long= *kernel_entry, =20 status =3D efi_random_alloc(alloc_size, CONFIG_PHYSICAL_ALIGN, &addr, seed[0], EFI_LOADER_CODE, - LOAD_PHYSICAL_ADDR, - EFI_X86_KERNEL_ALLOC_LIMIT); + LOAD_PHYSICAL_ADDR, alloc_limit); if (status !=3D EFI_SUCCESS) return status; =20 @@ -890,6 +890,10 @@ static efi_status_t efi_decompress_kernel(unsigned lon= g *kernel_entry, =20 *kernel_entry =3D addr + entry; =20 + status =3D efi_secure_launch_prepare(boot_params, addr); + if (status !=3D EFI_SUCCESS) + return status; + return efi_adjust_memory_range_protection(addr, kernel_text_size) ?: efi_adjust_memory_range_protection(addr + kernel_inittext_offset, kernel_inittext_size); @@ -914,6 +918,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle, struct boot_params *boot_params) =20 { + unsigned long alloc_limit =3D EFI_X86_KERNEL_ALLOC_LIMIT; efi_guid_t guid =3D EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID; const struct linux_efi_initrd *initrd =3D NULL; unsigned long kernel_entry; @@ -925,6 +930,17 @@ void __noreturn efi_stub_entry(efi_handle_t handle, if (efi_system_table->hdr.signature !=3D EFI_SYSTEM_TABLE_SIGNATURE) efi_exit(handle, EFI_INVALID_PARAMETER); =20 + status =3D efi_secure_launch_init(handle); + switch (status) { + case EFI_SUCCESS: + alloc_limit =3D U32_MAX; + break; + case EFI_UNSUPPORTED: + break; + default: + efi_exit(handle, status); + } + if (!IS_ENABLED(CONFIG_EFI_HANDOVER_PROTOCOL) || !boot_params) { status =3D efi_allocate_bootparams(handle, &boot_params); if (status !=3D EFI_SUCCESS) @@ -974,7 +990,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle, if (efi_mem_encrypt > 0) hdr->xloadflags |=3D XLF_MEM_ENCRYPTION; =20 - status =3D efi_decompress_kernel(&kernel_entry, boot_params); + status =3D efi_decompress_kernel(&kernel_entry, boot_params, alloc_limit); if (status !=3D EFI_SUCCESS) { efi_err("Failed to decompress kernel\n"); goto fail; @@ -1029,6 +1045,9 @@ void __noreturn efi_stub_entry(efi_handle_t handle, goto fail; } =20 + /* If a Secure Launch is in progress, this never returns */ + efi_secure_launch(); + /* * Call the SEV init code while still running with the firmware's * GDT/IDT, so #VC exceptions will be handled by EFI. --=20 2.47.3 From nobody Mon May 25 08:11:32 2026 Received: from mail-dl1-f50.google.com (mail-dl1-f50.google.com [74.125.82.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BEB7405C4E for ; Fri, 15 May 2026 21:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879764; cv=none; b=nQWH/GzcuenM+fJfaND7wgXfiXjgXyouzd2GB/pCtHayWGJfRvJNFoe4gh1UJpVNyh7/FNXGGZ2B2vqd5avOycxyf2+l/bFVx86cF2ZdckPcenRAtAbrY9J1loZclUHIyilqofD5xzIRfVtO0reuwSNVrpqLAHZZDIBUrhaJe8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778879764; c=relaxed/simple; bh=Yb8MnWED6Q7bAT/hqKNGG8lkKmGIJFI2VweKIbS2p4w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C6xBnOeuoBbzX5TXGo69P9IoSLviLponpVPLZOmjw4jP+gC6KI5QYeVqqz4DL2XwuJTYAImaBu9wL3boTrBrz1SN445UoPWEzGkDxreTTm7PRcyAmesJGqg19Q+/ypgbV7dudY06jIzLSQe+0LYHWjCcfSBSYtCd12uikw+rqjk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BF56TtPm; arc=none smtp.client-ip=74.125.82.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BF56TtPm" Received: by mail-dl1-f50.google.com with SMTP id a92af1059eb24-1354403c610so394543c88.0 for ; Fri, 15 May 2026 14:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778879761; x=1779484561; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UCBpSoWd+DzhR5w/L2qTUePdSLNQuDLLzBvZ0vft3Fw=; b=BF56TtPmbTq/ykC8PdHqLL2T52MU6o1OuGFsPhF6ynYNpWVBeiSvCagbcZxtobjddA xexaxNpjpT7SjCuVkLzRxN1AiPOoYkIe3NCnWxNp8aEWbCIaIjx9ozVYBYKc69mHI3t1 cmhkh4WEmi7Ax0rxbTg9QkQpikFSs1q0NqeF3bEFDZn03MJX7OsocK3Sr/O8UlpX/P4Y IcczdzzNyATeOkj00G7LTkEmkHAk7flzvVbai4qA4ibYRHCbnjVIwocwTADiEtvJTKI1 JWoSdHMS7BnisdwKjfCIzp8ncdxHCX1VIPaHE7wrI6lrms4o/Dp1o7D3YCFluVOHP+v3 lukg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778879761; x=1779484561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UCBpSoWd+DzhR5w/L2qTUePdSLNQuDLLzBvZ0vft3Fw=; b=mxJxVPCPlOx1Hp9J+YuBkfawtw+1ej5cX6BRu6NXNUo0oVwnOGpQO3Owdg8CLDRnKN y/aq/qAjRZmZINUKEB//n28cI5MDIZtFSd25syb6mSemzYCWfNc02QAnCfksraGKEpV3 Ect7gsQ6b8dr0GfNkcjcUxKhYDFCd9TCdk7/i+bM6DukIs05pOCixxmfdWa1nsePYxAz o2IyQHzcdSlQ9ZcM86Px180ckwWt0MwCiBInAu3Uwft30JChqGSboeVPG0+/zUFArK14 LrAd14rmbEDCBJP0qLoEiE46VcknzgmylqqbWelJ+l/cs/ntZnpyI1nKyrdQ9Ct7sr6A 6nGg== X-Gm-Message-State: AOJu0Ywlne2z4lBdu9aV2zobhYnNsQK3KOBfkDAkJ1fzZcgO4hJDoB9D n8HXEw+80vWkhqWXbQD9ANIstUcyvsPC8vGIhi0jn9fHki78j1i+qu1E+896yGIr X-Gm-Gg: Acq92OE2+hBGGDBn3lkOG7ybz0bYUHl2bPGmH8woXZldFLfRAo8VsnLwlaC9OBI6vH1 Cz9Epxs+q7Khc9vGrGKTSzRWXuQ2hExdUcr5oqDiHvS3I0nRp9knz9l3KwULIZduQYSdRERGLf3 MGNNUbEUBDg8rMQ/QlhCd6q/nEoEoPKP/hYKTZd9REPX0EctKhVn8Remha83tqgc5q+Kubg1Sy6 bfy77lYXvgA8khaiN2msI7poFNIjGURRB6paxy6J9Boo/Ixf/vYonmkQuYU+J4ywOD+XSZvZSsw yKlhuxS9skM6MTCNZraJekEoPHFRJYJV0WemJO8Fz9MJQrx2yeKf2HWhqCZa41byosaSqZwXpYk l5hJTrdBmATKwH740e190Yep/Ccufwal+1gSQKMFIq+11oJk+8l6DVkjQEiZYHQKCinlWwSS9cf ORJdkz+OJWha7YpKKEO2rVq0oUaHqxmTc= X-Received: by 2002:a05:7022:1a85:b0:12d:d972:b96e with SMTP id a92af1059eb24-1350542e8e5mr2758254c88.20.1778879760953; Fri, 15 May 2026 14:16:00 -0700 (PDT) Received: from mimas.lan ([2603:8000:df01:38f7:a6bb:6dff:fecf:e71a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-134cb5b3c20sm11529163c88.0.2026.05.15.14.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 14:16:00 -0700 (PDT) From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux.dev Cc: ross.philipson@gmail.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, daniel.kiper@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v16 38/38] x86/boot: Legacy boot DRTM support for Secure Launch Date: Fri, 15 May 2026 14:14:10 -0700 Message-ID: <20260515211410.31440-39-ross.philipson@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515211410.31440-1-ross.philipson@gmail.com> References: <20260515211410.31440-1-ross.philipson@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Implement Secure Launch D-RTM of the decompressed kernel via a callback interface exposed by the Secure Launch Resource Table (SLRT), a reference to which is added to struct boot_params. This permits a boot loader to set up the Secure Launch, allow the decompressor to execute up to the point where it would otherwise boot the core kernel, and at that point, perform the Dynamic Launch Event in a architecture/vendor specific manner. This is similar to how EFI boot achieves this, using a EFI protocol exposed by the boot loader. This requires that the decompressor unpacks the kernel into the buffer that it was started from itself, and so physical KASLR needs to be omitted (although the boot loader is free to place the decompressor at any suitably aligned locations in system memory, and so it can perform the physical randomization itself). It also relies on the demand paging logic in the decompressor, to ensure that the SLRT and the entry point it describes are callable, at least to the extent that allows the callback code to re-establish its own execution environment. Co-developed-by: Ross Philipson Signed-off-by: Ard Biesheuvel Signed-off-by: Ross Philipson --- Documentation/arch/x86/zero-page.rst | 1 + arch/x86/boot/compressed/misc.c | 51 ++++++++++++++++++++++++--- arch/x86/boot/compressed/pgtable_64.c | 7 ++++ arch/x86/include/uapi/asm/bootparam.h | 2 +- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/Documentation/arch/x86/zero-page.rst b/Documentation/arch/x86/= zero-page.rst index 45aa9cceb4f1..dd98b467929c 100644 --- a/Documentation/arch/x86/zero-page.rst +++ b/Documentation/arch/x86/zero-page.rst @@ -20,6 +20,7 @@ Offset/Size Proto Name Meaning 060/010 ALL ist_info Intel SpeedStep (IST) BIOS support information (struct ist_info) 070/008 ALL acpi_rsdp_addr Physical address of ACPI RSDP table +078/008 ALL slr_table_addr Physical address of Secure Launch Resource Ta= ble 080/010 ALL hd0_info hd0 disk parameter, OBSOLETE!! 090/010 ALL hd1_info hd1 disk parameter, OBSOLETE!! 0A0/010 ALL sys_desc_table System description table (struct sys_desc_tab= le), diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index e3b5177bfa6f..eaaface4cd7d 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -17,6 +17,7 @@ #include "../string.h" #include "../voffset.h" #include +#include =20 /* * WARNING!! @@ -391,6 +392,36 @@ static void early_sev_detect(void) lines =3D cols =3D 0; } =20 +#ifdef CONFIG_SECURE_LAUNCH +static void sl_initiate_launch(unsigned long table, unsigned long base) +{ + struct slr_table *slrt =3D (void *)table; + struct slr_entry_dl_info *dl_info; + struct slr_setup_dlme dlme; + dl_launch_func launch_fn; + + dlme.dlme_base =3D base; + dlme.dlme_header_offset =3D mle_header_offset; + dlme.dlme_table =3D 0; + + if (!slrt) + return; + + dl_info =3D slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_DL_INFO); + if (!dl_info) + return; + + launch_fn =3D (void *)dl_info->dl_launch; + + /* Do the Dynamic Launch Event */ + launch_fn(&dl_info->bl_context, &dlme); +} +#else +static inline void sl_initiate_launch(unsigned long table, unsigned long b= ase) +{ +} +#endif + /* * The compressed kernel image (ZO), has been moved so that its position * is against the end of the buffer used to hold the uncompressed kernel @@ -491,10 +522,15 @@ asmlinkage __visible void *extract_kernel(void *rmode= , unsigned char *output) debug_putaddr(trampoline_32bit); #endif =20 - choose_random_location((unsigned long)input_data, input_len, - (unsigned long *)&output, - needed_size, - &virt_addr); + /* + * When doing a secure launch, the actual launch will be initiated by + * jumping back to the bootloader. Omit physical KASLR in that case, to + * avoid trampling on its code or data inadvertently. + */ + if (!boot_params_ptr->slr_table_addr) + choose_random_location((unsigned long)input_data, input_len, + (unsigned long *)&output, + needed_size, &virt_addr); =20 /* Validate memory location choices. */ if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1)) @@ -528,6 +564,13 @@ asmlinkage __visible void *extract_kernel(void *rmode,= unsigned char *output) debug_puthex(entry_offset); debug_putstr(").\n"); =20 + /* + * Secure Launch involves calling back into the bootloader, so this + * needs to happen before disabling exception handling, to ensure that + * the entry point will be mapped on demand if needed. + */ + sl_initiate_launch(boot_params_ptr->slr_table_addr, (unsigned long)output= ); + /* Disable exception handling before booting the kernel */ cleanup_exception_handling(); =20 diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compress= ed/pgtable_64.c index 3e9d651da73e..f82094669ac0 100644 --- a/arch/x86/boot/compressed/pgtable_64.c +++ b/arch/x86/boot/compressed/pgtable_64.c @@ -124,6 +124,13 @@ asmlinkage void configure_5level_paging(struct boot_pa= rams *bp, void *pgtable) =20 l5_required =3D !cmdline_find_option_bool("no5lvl"); =20 + /* + * Don't change the number of levels when doing a Secure Launch. The + * Secure Launch stub will take care of that if needed. + */ + if (bp->slr_table_addr) + l5_required =3D l5_enabled; + if (l5_required) { /* Initialize variables for 5-level paging */ __pgtable_l5_enabled =3D 1; diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/= asm/bootparam.h index 8155fa899f50..bc2ef37096af 100644 --- a/arch/x86/include/uapi/asm/bootparam.h +++ b/arch/x86/include/uapi/asm/bootparam.h @@ -121,7 +121,7 @@ struct boot_params { __u64 tboot_addr; /* 0x058 */ struct ist_info ist_info; /* 0x060 */ __u64 acpi_rsdp_addr; /* 0x070 */ - __u8 _pad3[8]; /* 0x078 */ + __u64 slr_table_addr; /* 0x078 */ __u8 hd0_info[16]; /* obsolete! */ /* 0x080 */ __u8 hd1_info[16]; /* obsolete! */ /* 0x090 */ struct sys_desc_table sys_desc_table; /* obsolete! */ /* 0x0a0 */ --=20 2.47.3