* FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree
@ 2025-12-29 12:34 gregkh
2026-01-02 2:45 ` [PATCH 6.12.y] tpm2-sessions: Fix tpm2_read_public range checks Sasha Levin
2026-01-08 12:35 ` FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree Jarkko Sakkinen
0 siblings, 2 replies; 4+ messages in thread
From: gregkh @ 2025-12-29 12:34 UTC (permalink / raw)
To: jarkko, noodles; +Cc: stable
The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x bda1cbf73c6e241267c286427f2ed52b5735d872
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025122907-stream-lasso-ba6e@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From bda1cbf73c6e241267c286427f2ed52b5735d872 Mon Sep 17 00:00:00 2001
From: Jarkko Sakkinen <jarkko@kernel.org>
Date: Mon, 1 Dec 2025 15:38:02 +0200
Subject: [PATCH] tpm2-sessions: Fix tpm2_read_public range checks
tpm2_read_public() has some rudimentary range checks but the function does
not ensure that the response buffer has enough bytes for the full TPMT_HA
payload.
Re-implement the function with necessary checks and validation, and return
name and name size for all handle types back to the caller.
Cc: stable@vger.kernel.org # v6.10+
Fixes: d0a25bb961e6 ("tpm: Add HMAC session name/handle append")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Jonathan McDowell <noodles@meta.com>
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index be4a9c7f2e1a..34e3599f094f 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -11,8 +11,11 @@
* used by the kernel internally.
*/
+#include "linux/dev_printk.h"
+#include "linux/tpm.h"
#include "tpm.h"
#include <crypto/hash_info.h>
+#include <linux/unaligned.h>
static bool disable_pcr_integrity;
module_param(disable_pcr_integrity, bool, 0444);
diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
index 385014dbca39..3f389e2f6f58 100644
--- a/drivers/char/tpm/tpm2-sessions.c
+++ b/drivers/char/tpm/tpm2-sessions.c
@@ -163,53 +163,61 @@ static int name_size(const u8 *name)
}
}
-static int tpm2_parse_read_public(char *name, struct tpm_buf *buf)
+static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
{
- struct tpm_header *head = (struct tpm_header *)buf->data;
+ u32 mso = tpm2_handle_mso(handle);
off_t offset = TPM_HEADER_SIZE;
- u32 tot_len = be32_to_cpu(head->length);
- int ret;
- u32 val;
-
- /* we're starting after the header so adjust the length */
- tot_len -= TPM_HEADER_SIZE;
-
- /* skip public */
- val = tpm_buf_read_u16(buf, &offset);
- if (val > tot_len)
- return -EINVAL;
- offset += val;
- /* name */
- val = tpm_buf_read_u16(buf, &offset);
- ret = name_size(&buf->data[offset]);
- if (ret < 0)
- return ret;
-
- if (val != ret)
- return -EINVAL;
-
- memcpy(name, &buf->data[offset], val);
- /* forget the rest */
- return 0;
-}
-
-static int tpm2_read_public(struct tpm_chip *chip, u32 handle, char *name)
-{
+ int rc, name_size_alg;
struct tpm_buf buf;
- int rc;
+
+ if (mso != TPM2_MSO_PERSISTENT && mso != TPM2_MSO_VOLATILE &&
+ mso != TPM2_MSO_NVRAM) {
+ memcpy(name, &handle, sizeof(u32));
+ return sizeof(u32);
+ }
rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_READ_PUBLIC);
if (rc)
return rc;
tpm_buf_append_u32(&buf, handle);
- rc = tpm_transmit_cmd(chip, &buf, 0, "read public");
- if (rc == TPM2_RC_SUCCESS)
- rc = tpm2_parse_read_public(name, &buf);
- tpm_buf_destroy(&buf);
+ rc = tpm_transmit_cmd(chip, &buf, 0, "TPM2_ReadPublic");
+ if (rc) {
+ tpm_buf_destroy(&buf);
+ return tpm_ret_to_err(rc);
+ }
- return rc;
+ /* Skip TPMT_PUBLIC: */
+ offset += tpm_buf_read_u16(&buf, &offset);
+
+ /*
+ * 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);
+ return -EIO;
+ }
+
+ rc = tpm_buf_read_u16(&buf, &offset);
+ name_size_alg = name_size(&buf.data[offset]);
+
+ if (name_size_alg < 0)
+ return name_size_alg;
+
+ if (rc != name_size_alg) {
+ tpm_buf_destroy(&buf);
+ return -EIO;
+ }
+
+ if (offset + rc > tpm_buf_length(&buf)) {
+ tpm_buf_destroy(&buf);
+ return -EIO;
+ }
+
+ memcpy(name, &buf.data[offset], rc);
+ return name_size_alg;
}
#endif /* CONFIG_TCG_TPM2_HMAC */
@@ -243,6 +251,7 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
#ifdef CONFIG_TCG_TPM2_HMAC
enum tpm2_mso_type mso = tpm2_handle_mso(handle);
struct tpm2_auth *auth;
+ u16 name_size_alg;
int slot;
int ret;
#endif
@@ -273,8 +282,10 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
mso == TPM2_MSO_NVRAM) {
if (!name) {
ret = tpm2_read_public(chip, handle, auth->name[slot]);
- if (ret)
+ if (ret < 0)
goto err;
+
+ name_size_alg = ret;
}
} else {
if (name) {
@@ -286,13 +297,8 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
}
auth->name_h[slot] = handle;
- if (name) {
- ret = name_size(name);
- if (ret < 0)
- goto err;
-
- memcpy(auth->name[slot], name, ret);
- }
+ if (name)
+ memcpy(auth->name[slot], name, name_size_alg);
#endif
return 0;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 6.12.y] tpm2-sessions: Fix tpm2_read_public range checks
2025-12-29 12:34 FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree gregkh
@ 2026-01-02 2:45 ` Sasha Levin
2026-01-08 12:35 ` FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree Jarkko Sakkinen
1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-01-02 2:45 UTC (permalink / raw)
To: stable; +Cc: Jarkko Sakkinen, Jonathan McDowell, Sasha Levin
From: Jarkko Sakkinen <jarkko@kernel.org>
[ Upstream commit bda1cbf73c6e241267c286427f2ed52b5735d872 ]
tpm2_read_public() has some rudimentary range checks but the function does
not ensure that the response buffer has enough bytes for the full TPMT_HA
payload.
Re-implement the function with necessary checks and validation, and return
name and name size for all handle types back to the caller.
Cc: stable@vger.kernel.org # v6.10+
Fixes: d0a25bb961e6 ("tpm: Add HMAC session name/handle append")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Jonathan McDowell <noodles@meta.com>
[ different semantics around u8 name_size() ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/char/tpm/tpm2-cmd.c | 3 ++
drivers/char/tpm/tpm2-sessions.c | 85 ++++++++++++++++++++------------
2 files changed, 56 insertions(+), 32 deletions(-)
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index dfdcbd009720..5c525987ff65 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -11,8 +11,11 @@
* used by the kernel internally.
*/
+#include "linux/dev_printk.h"
+#include "linux/tpm.h"
#include "tpm.h"
#include <crypto/hash_info.h>
+#include <linux/unaligned.h>
static bool disable_pcr_integrity;
module_param(disable_pcr_integrity, bool, 0444);
diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
index cf0b83154044..a10db4a4aced 100644
--- a/drivers/char/tpm/tpm2-sessions.c
+++ b/drivers/char/tpm/tpm2-sessions.c
@@ -156,47 +156,60 @@ static u8 name_size(const u8 *name)
return size_map[alg] + 2;
}
-static int tpm2_parse_read_public(char *name, struct tpm_buf *buf)
+static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
{
- struct tpm_header *head = (struct tpm_header *)buf->data;
+ u32 mso = tpm2_handle_mso(handle);
off_t offset = TPM_HEADER_SIZE;
- u32 tot_len = be32_to_cpu(head->length);
- u32 val;
-
- /* we're starting after the header so adjust the length */
- tot_len -= TPM_HEADER_SIZE;
-
- /* skip public */
- val = tpm_buf_read_u16(buf, &offset);
- if (val > tot_len)
- return -EINVAL;
- offset += val;
- /* name */
- val = tpm_buf_read_u16(buf, &offset);
- if (val != name_size(&buf->data[offset]))
- return -EINVAL;
- memcpy(name, &buf->data[offset], val);
- /* forget the rest */
- return 0;
-}
-
-static int tpm2_read_public(struct tpm_chip *chip, u32 handle, char *name)
-{
- struct tpm_buf buf;
int rc;
+ u8 name_size_alg;
+ struct tpm_buf buf;
+
+ if (mso != TPM2_MSO_PERSISTENT && mso != TPM2_MSO_VOLATILE &&
+ mso != TPM2_MSO_NVRAM) {
+ memcpy(name, &handle, sizeof(u32));
+ return sizeof(u32);
+ }
rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_READ_PUBLIC);
if (rc)
return rc;
tpm_buf_append_u32(&buf, handle);
- rc = tpm_transmit_cmd(chip, &buf, 0, "read public");
- if (rc == TPM2_RC_SUCCESS)
- rc = tpm2_parse_read_public(name, &buf);
- tpm_buf_destroy(&buf);
+ rc = tpm_transmit_cmd(chip, &buf, 0, "TPM2_ReadPublic");
+ if (rc) {
+ tpm_buf_destroy(&buf);
+ return tpm_ret_to_err(rc);
+ }
- return rc;
+ /* Skip TPMT_PUBLIC: */
+ offset += tpm_buf_read_u16(&buf, &offset);
+
+ /*
+ * 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);
+ return -EIO;
+ }
+
+ rc = tpm_buf_read_u16(&buf, &offset);
+ name_size_alg = name_size(&buf.data[offset]);
+
+ if (rc != name_size_alg) {
+ tpm_buf_destroy(&buf);
+ return -EIO;
+ }
+
+ if (offset + rc > tpm_buf_length(&buf)) {
+ tpm_buf_destroy(&buf);
+ return -EIO;
+ }
+
+ memcpy(name, &buf.data[offset], rc);
+ tpm_buf_destroy(&buf);
+ return name_size_alg;
}
#endif /* CONFIG_TCG_TPM2_HMAC */
@@ -229,6 +242,7 @@ void tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
enum tpm2_mso_type mso = tpm2_handle_mso(handle);
struct tpm2_auth *auth;
int slot;
+ int ret;
#endif
if (!tpm2_chip_auth(chip)) {
@@ -251,8 +265,11 @@ void tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
if (mso == TPM2_MSO_PERSISTENT ||
mso == TPM2_MSO_VOLATILE ||
mso == TPM2_MSO_NVRAM) {
- if (!name)
- tpm2_read_public(chip, handle, auth->name[slot]);
+ if (!name) {
+ ret = tpm2_read_public(chip, handle, auth->name[slot]);
+ if (ret < 0)
+ goto err;
+ }
} else {
if (name)
dev_err(&chip->dev, "TPM: Handle does not require name but one is specified\n");
@@ -261,6 +278,10 @@ void tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
auth->name_h[slot] = handle;
if (name)
memcpy(auth->name[slot], name, name_size(name));
+ return;
+
+err:
+ tpm2_end_auth_session(chip);
#endif
}
EXPORT_SYMBOL_GPL(tpm_buf_append_name);
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree
2025-12-29 12:34 FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree gregkh
2026-01-02 2:45 ` [PATCH 6.12.y] tpm2-sessions: Fix tpm2_read_public range checks Sasha Levin
@ 2026-01-08 12:35 ` Jarkko Sakkinen
2026-01-09 9:45 ` Greg KH
1 sibling, 1 reply; 4+ messages in thread
From: Jarkko Sakkinen @ 2026-01-08 12:35 UTC (permalink / raw)
To: gregkh; +Cc: noodles, stable
On Mon, Dec 29, 2025 at 01:34:07PM +0100, gregkh@linuxfoundation.org wrote:
>
> The patch below does not apply to the 6.12-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.
>
> To reproduce the conflict and resubmit, you may use the following commands:
>
> git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
> git checkout FETCH_HEAD
> git cherry-pick -x bda1cbf73c6e241267c286427f2ed52b5735d872
> # <resolve conflicts, build, test, etc.>
> git commit -s
> git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025122907-stream-lasso-ba6e@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
>
> Possible dependencies:
>
>
>
> thanks,
>
> greg k-h
>
> ------------------ original commit in Linus's tree ------------------
>
> From bda1cbf73c6e241267c286427f2ed52b5735d872 Mon Sep 17 00:00:00 2001
> From: Jarkko Sakkinen <jarkko@kernel.org>
> Date: Mon, 1 Dec 2025 15:38:02 +0200
> Subject: [PATCH] tpm2-sessions: Fix tpm2_read_public range checks
>
> tpm2_read_public() has some rudimentary range checks but the function does
> not ensure that the response buffer has enough bytes for the full TPMT_HA
> payload.
>
> Re-implement the function with necessary checks and validation, and return
> name and name size for all handle types back to the caller.
>
> Cc: stable@vger.kernel.org # v6.10+
> Fixes: d0a25bb961e6 ("tpm: Add HMAC session name/handle append")
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> Reviewed-by: Jonathan McDowell <noodles@meta.com>
>
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index be4a9c7f2e1a..34e3599f094f 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -11,8 +11,11 @@
> * used by the kernel internally.
> */
>
> +#include "linux/dev_printk.h"
> +#include "linux/tpm.h"
> #include "tpm.h"
> #include <crypto/hash_info.h>
> +#include <linux/unaligned.h>
>
> static bool disable_pcr_integrity;
> module_param(disable_pcr_integrity, bool, 0444);
> diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
> index 385014dbca39..3f389e2f6f58 100644
> --- a/drivers/char/tpm/tpm2-sessions.c
> +++ b/drivers/char/tpm/tpm2-sessions.c
> @@ -163,53 +163,61 @@ static int name_size(const u8 *name)
> }
> }
>
> -static int tpm2_parse_read_public(char *name, struct tpm_buf *buf)
> +static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
> {
> - struct tpm_header *head = (struct tpm_header *)buf->data;
> + u32 mso = tpm2_handle_mso(handle);
> off_t offset = TPM_HEADER_SIZE;
> - u32 tot_len = be32_to_cpu(head->length);
> - int ret;
> - u32 val;
> -
> - /* we're starting after the header so adjust the length */
> - tot_len -= TPM_HEADER_SIZE;
> -
> - /* skip public */
> - val = tpm_buf_read_u16(buf, &offset);
> - if (val > tot_len)
> - return -EINVAL;
> - offset += val;
> - /* name */
> - val = tpm_buf_read_u16(buf, &offset);
> - ret = name_size(&buf->data[offset]);
> - if (ret < 0)
> - return ret;
> -
> - if (val != ret)
> - return -EINVAL;
> -
> - memcpy(name, &buf->data[offset], val);
> - /* forget the rest */
> - return 0;
> -}
> -
> -static int tpm2_read_public(struct tpm_chip *chip, u32 handle, char *name)
> -{
> + int rc, name_size_alg;
> struct tpm_buf buf;
> - int rc;
> +
> + if (mso != TPM2_MSO_PERSISTENT && mso != TPM2_MSO_VOLATILE &&
> + mso != TPM2_MSO_NVRAM) {
> + memcpy(name, &handle, sizeof(u32));
> + return sizeof(u32);
> + }
>
> rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_READ_PUBLIC);
> if (rc)
> return rc;
>
> tpm_buf_append_u32(&buf, handle);
> - rc = tpm_transmit_cmd(chip, &buf, 0, "read public");
> - if (rc == TPM2_RC_SUCCESS)
> - rc = tpm2_parse_read_public(name, &buf);
>
> - tpm_buf_destroy(&buf);
> + rc = tpm_transmit_cmd(chip, &buf, 0, "TPM2_ReadPublic");
> + if (rc) {
> + tpm_buf_destroy(&buf);
> + return tpm_ret_to_err(rc);
> + }
>
> - return rc;
> + /* Skip TPMT_PUBLIC: */
> + offset += tpm_buf_read_u16(&buf, &offset);
> +
> + /*
> + * 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);
> + return -EIO;
> + }
> +
> + rc = tpm_buf_read_u16(&buf, &offset);
> + name_size_alg = name_size(&buf.data[offset]);
> +
> + if (name_size_alg < 0)
> + return name_size_alg;
> +
> + if (rc != name_size_alg) {
> + tpm_buf_destroy(&buf);
> + return -EIO;
> + }
> +
> + if (offset + rc > tpm_buf_length(&buf)) {
> + tpm_buf_destroy(&buf);
> + return -EIO;
> + }
> +
> + memcpy(name, &buf.data[offset], rc);
> + return name_size_alg;
> }
> #endif /* CONFIG_TCG_TPM2_HMAC */
>
> @@ -243,6 +251,7 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
> #ifdef CONFIG_TCG_TPM2_HMAC
> enum tpm2_mso_type mso = tpm2_handle_mso(handle);
> struct tpm2_auth *auth;
> + u16 name_size_alg;
> int slot;
> int ret;
> #endif
> @@ -273,8 +282,10 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
> mso == TPM2_MSO_NVRAM) {
> if (!name) {
> ret = tpm2_read_public(chip, handle, auth->name[slot]);
> - if (ret)
> + if (ret < 0)
> goto err;
> +
> + name_size_alg = ret;
> }
> } else {
> if (name) {
> @@ -286,13 +297,8 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
> }
>
> auth->name_h[slot] = handle;
> - if (name) {
> - ret = name_size(name);
> - if (ret < 0)
> - goto err;
> -
> - memcpy(auth->name[slot], name, ret);
> - }
> + if (name)
> + memcpy(auth->name[slot], name, name_size_alg);
> #endif
> return 0;
>
>
This will apply on top of https://lore.kernel.org/linux-integrity/aV-kD5iKi9fwluU0@kernel.org/T/#t
BR, Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree
2026-01-08 12:35 ` FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree Jarkko Sakkinen
@ 2026-01-09 9:45 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-01-09 9:45 UTC (permalink / raw)
To: Jarkko Sakkinen; +Cc: noodles, stable
On Thu, Jan 08, 2026 at 02:35:57PM +0200, Jarkko Sakkinen wrote:
> On Mon, Dec 29, 2025 at 01:34:07PM +0100, gregkh@linuxfoundation.org wrote:
> >
> > The patch below does not apply to the 6.12-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.
> >
> > To reproduce the conflict and resubmit, you may use the following commands:
> >
> > git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
> > git checkout FETCH_HEAD
> > git cherry-pick -x bda1cbf73c6e241267c286427f2ed52b5735d872
> > # <resolve conflicts, build, test, etc.>
> > git commit -s
> > git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025122907-stream-lasso-ba6e@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
> >
> > Possible dependencies:
> >
> >
> >
> > thanks,
> >
> > greg k-h
> >
> > ------------------ original commit in Linus's tree ------------------
> >
> > From bda1cbf73c6e241267c286427f2ed52b5735d872 Mon Sep 17 00:00:00 2001
> > From: Jarkko Sakkinen <jarkko@kernel.org>
> > Date: Mon, 1 Dec 2025 15:38:02 +0200
> > Subject: [PATCH] tpm2-sessions: Fix tpm2_read_public range checks
> >
> > tpm2_read_public() has some rudimentary range checks but the function does
> > not ensure that the response buffer has enough bytes for the full TPMT_HA
> > payload.
> >
> > Re-implement the function with necessary checks and validation, and return
> > name and name size for all handle types back to the caller.
> >
> > Cc: stable@vger.kernel.org # v6.10+
> > Fixes: d0a25bb961e6 ("tpm: Add HMAC session name/handle append")
> > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> > Reviewed-by: Jonathan McDowell <noodles@meta.com>
> >
> > diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> > index be4a9c7f2e1a..34e3599f094f 100644
> > --- a/drivers/char/tpm/tpm2-cmd.c
> > +++ b/drivers/char/tpm/tpm2-cmd.c
> > @@ -11,8 +11,11 @@
> > * used by the kernel internally.
> > */
> >
> > +#include "linux/dev_printk.h"
> > +#include "linux/tpm.h"
> > #include "tpm.h"
> > #include <crypto/hash_info.h>
> > +#include <linux/unaligned.h>
> >
> > static bool disable_pcr_integrity;
> > module_param(disable_pcr_integrity, bool, 0444);
> > diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
> > index 385014dbca39..3f389e2f6f58 100644
> > --- a/drivers/char/tpm/tpm2-sessions.c
> > +++ b/drivers/char/tpm/tpm2-sessions.c
> > @@ -163,53 +163,61 @@ static int name_size(const u8 *name)
> > }
> > }
> >
> > -static int tpm2_parse_read_public(char *name, struct tpm_buf *buf)
> > +static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
> > {
> > - struct tpm_header *head = (struct tpm_header *)buf->data;
> > + u32 mso = tpm2_handle_mso(handle);
> > off_t offset = TPM_HEADER_SIZE;
> > - u32 tot_len = be32_to_cpu(head->length);
> > - int ret;
> > - u32 val;
> > -
> > - /* we're starting after the header so adjust the length */
> > - tot_len -= TPM_HEADER_SIZE;
> > -
> > - /* skip public */
> > - val = tpm_buf_read_u16(buf, &offset);
> > - if (val > tot_len)
> > - return -EINVAL;
> > - offset += val;
> > - /* name */
> > - val = tpm_buf_read_u16(buf, &offset);
> > - ret = name_size(&buf->data[offset]);
> > - if (ret < 0)
> > - return ret;
> > -
> > - if (val != ret)
> > - return -EINVAL;
> > -
> > - memcpy(name, &buf->data[offset], val);
> > - /* forget the rest */
> > - return 0;
> > -}
> > -
> > -static int tpm2_read_public(struct tpm_chip *chip, u32 handle, char *name)
> > -{
> > + int rc, name_size_alg;
> > struct tpm_buf buf;
> > - int rc;
> > +
> > + if (mso != TPM2_MSO_PERSISTENT && mso != TPM2_MSO_VOLATILE &&
> > + mso != TPM2_MSO_NVRAM) {
> > + memcpy(name, &handle, sizeof(u32));
> > + return sizeof(u32);
> > + }
> >
> > rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_READ_PUBLIC);
> > if (rc)
> > return rc;
> >
> > tpm_buf_append_u32(&buf, handle);
> > - rc = tpm_transmit_cmd(chip, &buf, 0, "read public");
> > - if (rc == TPM2_RC_SUCCESS)
> > - rc = tpm2_parse_read_public(name, &buf);
> >
> > - tpm_buf_destroy(&buf);
> > + rc = tpm_transmit_cmd(chip, &buf, 0, "TPM2_ReadPublic");
> > + if (rc) {
> > + tpm_buf_destroy(&buf);
> > + return tpm_ret_to_err(rc);
> > + }
> >
> > - return rc;
> > + /* Skip TPMT_PUBLIC: */
> > + offset += tpm_buf_read_u16(&buf, &offset);
> > +
> > + /*
> > + * 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);
> > + return -EIO;
> > + }
> > +
> > + rc = tpm_buf_read_u16(&buf, &offset);
> > + name_size_alg = name_size(&buf.data[offset]);
> > +
> > + if (name_size_alg < 0)
> > + return name_size_alg;
> > +
> > + if (rc != name_size_alg) {
> > + tpm_buf_destroy(&buf);
> > + return -EIO;
> > + }
> > +
> > + if (offset + rc > tpm_buf_length(&buf)) {
> > + tpm_buf_destroy(&buf);
> > + return -EIO;
> > + }
> > +
> > + memcpy(name, &buf.data[offset], rc);
> > + return name_size_alg;
> > }
> > #endif /* CONFIG_TCG_TPM2_HMAC */
> >
> > @@ -243,6 +251,7 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
> > #ifdef CONFIG_TCG_TPM2_HMAC
> > enum tpm2_mso_type mso = tpm2_handle_mso(handle);
> > struct tpm2_auth *auth;
> > + u16 name_size_alg;
> > int slot;
> > int ret;
> > #endif
> > @@ -273,8 +282,10 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
> > mso == TPM2_MSO_NVRAM) {
> > if (!name) {
> > ret = tpm2_read_public(chip, handle, auth->name[slot]);
> > - if (ret)
> > + if (ret < 0)
> > goto err;
> > +
> > + name_size_alg = ret;
> > }
> > } else {
> > if (name) {
> > @@ -286,13 +297,8 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
> > }
> >
> > auth->name_h[slot] = handle;
> > - if (name) {
> > - ret = name_size(name);
> > - if (ret < 0)
> > - goto err;
> > -
> > - memcpy(auth->name[slot], name, ret);
> > - }
> > + if (name)
> > + memcpy(auth->name[slot], name, name_size_alg);
> > #endif
> > return 0;
> >
> >
>
> This will apply on top of https://lore.kernel.org/linux-integrity/aV-kD5iKi9fwluU0@kernel.org/T/#t
Already in the last 6.12.y release.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-09 9:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-29 12:34 FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree gregkh
2026-01-02 2:45 ` [PATCH 6.12.y] tpm2-sessions: Fix tpm2_read_public range checks Sasha Levin
2026-01-08 12:35 ` FAILED: patch "[PATCH] tpm2-sessions: Fix tpm2_read_public range checks" failed to apply to 6.12-stable tree Jarkko Sakkinen
2026-01-09 9:45 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox