From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795903050; b=qaMNBWo34X2AiJRisgHs3PX8V2B5A0VuH2l2suVbRgc4ZRQRMhOIPWC1LoV1rbHBB3tO nufCy5IiBN0o5h6YDSurxyQ5qkRjfNbEtR0RjYMZKV8faLjJ0gulr+GKUuo3HvW4srBZh 2h4n7QSKhJQ3oMCpt5z5wakFCapBjDpDLYOaycxKpjBSWgiiB7G0TCzvG/6QZZTTvG8rC +dV2Sg9dzkD7m2XNJSgRwqIEyktuiarnKFQAONZWLjntYhpOykVqz6NNUDSCmWSMCymnf 4savrzAXfZuW/7nIW888d7++1I+av0KBxjd+FNUOab93x8WUIOXMDEN54LgZq9XDhWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795903050; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=S57fRmiks6sFgNdNLrnjofv2zuSPueoeDrPBL6H6Rc0=; b=Xh3oK5YUxn+0L/y/eccfowUL0uYNvJsoIYxLeQ3aHu8qcN5nJhv0Lgo1TJYGcjAQA6OM 1ntDgxqeFXHns/Vp9MFQD33lS5NF0vXN1/42/6z+Yx9yaSlgWrcGk4Ri0nDxT/ryaJRbT Zc1sVS1+172UtVehlI5GG75dhk+xCyJyWttx2ZDNXb3NV4TGi0aC2qpErHxk1wqbaP80j SSg1dOd/sXEe8tgUBZeFRkRq9OCQMPofw66sC4HkzzGemmhGBES3jB3SWkRg/XmZhIFOg tEOvwtR97k82cG+g99gJkGQLzh1kzzUzZmk13M6KoLMPHksibjnB4S9p81s9X8731Lg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Dykh9Ojd; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 34E04606A324; Sat, 28 Nov 2026 21:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Dykh9Ojd Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 1459F1F0089A; Sat, 28 Nov 2026 21:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795903049; bh=S57fRmiks6sFgNdNLrnjofv2zuSPueoeDrPBL6H6Rc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Dykh9OjdQHlZufOEbgl+nbXD0H3YM0ZP4l954+PIdVwJrYrT3TFGQP3/gEFuz5Qfp DIIbtxduJm8HWEGPyyZfnTrL4eSx/7fvKezZSzwFf2c5vmaD5I0828C1qZn+Ai7KdT 34guU2LH/WOgcdnqjmcj05emhRYscEwKhkRTTUJSr6j4ipDhknciW0yXY3/ECAJekG RuW7vlp2ucuYNanakoDAdZkl62r0mUsKYsP+cstjO/iZJ2t6YFt5eevQIOihBU9yKV LbGt1qNGYcRlgqadlc9w9L2M+d8Bl5i9zVTCA/6cDNqNP7GMpDh0W8xW8UWfQHjNMB 4pDpnBM4+a2BA== From: Jarkko Sakkinen To: keyrings@vger.kernel.org Cc: Jarkko Sakkinen , dm-devel@lists.linux.dev, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Ahmad Fatoum , Alasdair Kergon , Andrew Morton , Benjamin Marzinski , David Gstir , David Howells , David Laight , "David S. Miller" , David Woodhouse , Eric Biggers , Herbert Xu , Ignat Korchagin , James Bottomley , James Morris , James Prestwood , Jason Gunthorpe , Jonathan Corbet , Jonathan McDowell , Lukas Wunner , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Mike Snitzer , Mikulas Patocka , Mimi Zohar , Paul Moore , Peter Huewe , Randy Dunlap , "Serge E. Hallyn" , Shuah Khan , Sumit Garg Subject: [PATCH v6 14/18] KEYS: trusted: Add private backend data to trusted_key_payload Date: Sat, 28 Nov 2026 23:56:16 +0200 Message-ID: <20261128215621.2253928-15-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261128215621.2253928-1-jarkko@kernel.org> References: <20261128215621.2253928-1-jarkko@kernel.org> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a backend-private pointer to struct trusted_key_payload and free it sensitively via trusted_payload_free() on teardown and error paths. This prepares for asymmetric TPM2 keys, which retain backend key metadata across runtime pkey operations instead of unsealing a raw key at load time. Signed-off-by: Jarkko Sakkinen --- include/keys/trusted-type.h | 14 ++++++++++++++ security/keys/trusted-keys/trusted_core.c | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/keys/trusted-type.h b/include/keys/trusted-type.h index 3db61b57cf73..6b31b66c0d35 100644 --- a/include/keys/trusted-type.h +++ b/include/keys/trusted-type.h @@ -27,12 +27,26 @@ #define MAX_PCRINFO_SIZE 64 #define MAX_DIGEST_SIZE 64 +/** + * struct trusted_key_payload - In-kernel representation of a trusted key + * @rcu: RCU head for deferred payload reclamation on key update. + * @key_len: Byte length of the unsealed symmetric @key, or %0 when the + * payload represents a hardware-bound asymmetric key. + * @blob_len: Byte length of the trust-source-wrapped @blob. + * @migratable: Non-zero if the key may be resealed with %KEYCTL_UPDATE. + * @old_format: Non-zero if @blob uses the legacy non-ASN.1 TPM 2.0 format. + * @private: Optional backend-owned runtime context freed sensitively with + * the payload. + * @key: Unsealed symmetric key material for in-kernel consumers. + * @blob: Wrapped key blob exported in ASCII hex by %KEYCTL_READ. + */ struct trusted_key_payload { struct rcu_head rcu; unsigned int key_len; unsigned int blob_len; unsigned char migratable; unsigned char old_format; + void *private; unsigned char key[MAX_KEY_SIZE + 1]; unsigned char blob[MAX_BLOB_SIZE]; }; diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c index 665b2c37734b..1db6497ba297 100644 --- a/security/keys/trusted-keys/trusted_core.c +++ b/security/keys/trusted-keys/trusted_core.c @@ -149,6 +149,14 @@ static struct trusted_key_payload *trusted_payload_alloc(struct key *key) return p; } +static void trusted_payload_free(struct trusted_key_payload *p) +{ + if (!p) + return; + kfree_sensitive(p->private); + kfree_sensitive(p); +} + /* * trusted_instantiate - create a new trusted key * @@ -223,7 +231,7 @@ static int trusted_instantiate(struct key *key, if (!ret) rcu_assign_keypointer(key, payload); else - kfree_sensitive(payload); + trusted_payload_free(payload); return ret; } @@ -232,7 +240,7 @@ static void trusted_rcu_free(struct rcu_head *rcu) struct trusted_key_payload *p; p = container_of(rcu, struct trusted_key_payload, rcu); - kfree_sensitive(p); + trusted_payload_free(p); } /* @@ -269,7 +277,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) ret = datablob_parse(&datablob, new_p); if (ret != Opt_update) { ret = -EINVAL; - kfree_sensitive(new_p); + trusted_payload_free(new_p); goto out; } @@ -283,7 +291,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) ret = static_call(trusted_key_seal)(new_p, datablob); if (ret < 0) { pr_info("key_seal failed (%d)\n", ret); - kfree_sensitive(new_p); + trusted_payload_free(new_p); goto out; } @@ -322,7 +330,7 @@ static long trusted_read(const struct key *key, char *buffer, */ static void trusted_destroy(struct key *key) { - kfree_sensitive(key->payload.data[0]); + trusted_payload_free(key->payload.data[0]); } struct key_type key_type_trusted = { -- 2.47.3