mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Guo Zihao <guozh23@xiaopeng.com>
Cc: Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] tpm: sessions: bound the primary public area by the response size
Date: Mon, 9 Nov 2026 16:50:50 +0200	[thread overview]
Message-ID: <avHdynG1rKStCVUO@kernel.org> (raw)
In-Reply-To: <20261109014955.2777635-1-guozh23@xiaopeng.com>

On Mon, Nov 09, 2026 at 09:49:54AM +0800, Guo Zihao wrote:
> tpm2_parse_create_primary() reads the size of the TPM2B_PUBLIC area
> from the response and hashes it to compute the object name:
> 
> 	len = tpm_buf_read_u16(buf, &offset_r);
> 	offset_t = offset_r;
> 	if (name) {
> 		/*
> 		 * now we have the public area, compute the name of
> 		 * the object
> 		 */
> 		put_unaligned_be16(TPM_ALG_SHA256, name);
> 		sha256(&buf->data[offset_r], len, name + 2);
> 	}
> 
> The length is only checked against the response later, after the
> hash has been taken. A TPM that reports a public area longer than
> what it actually sent makes the sha256() run past the end of the
> received data and hash whatever follows the response in the buffer.
> 
> Check that the public area fits in the response before hashing it.
> 
> Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
> ---
> 
> v2: Drop the Fixes and Cc: stable tags, as suggested by Jarkko
> Sakkinen: a TPM reporting an oversized public area is not known
> to violate the TCG specification, so this is hardening rather
> than a bug fix. No code changes.
> 
>  drivers/char/tpm/tpm2-sessions.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
> index cf8f1fd6790b..e140079dbc13 100644
> --- a/drivers/char/tpm/tpm2-sessions.c
> +++ b/drivers/char/tpm/tpm2-sessions.c
> @@ -1125,6 +1125,8 @@ static int tpm2_parse_create_primary(struct tpm_chip *chip, struct tpm_buf *buf,
>  		return -EINVAL;
>  	len = tpm_buf_read_u16(buf, &offset_r);
>  	offset_t = offset_r;
> +	if (offset_r + len > tpm_buf_length(buf))
> +		return -EINVAL;
>  	if (name) {
>  		/*
>  		 * now we have the public area, compute the name of
> -- 
> 2.50.1
> 

Thanks this change itself is great and well described.

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

Br, Jarkko

      parent reply	other threads:[~2026-11-09 14:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06  1:49 [PATCH " Guo Zihao
2026-11-06  1:49 ` [PATCH 2/2] tpm: sessions: bound the parameter decryption " Guo Zihao
2026-11-06 15:21   ` Jarkko Sakkinen
2026-11-06 15:21 ` [PATCH 1/2] tpm: sessions: bound the primary public area " Jarkko Sakkinen
2026-11-09  1:49   ` [PATCH v2 " Guo Zihao
2026-11-09  1:49     ` [PATCH v2 2/2] tpm: sessions: bound the parameter decryption " Guo Zihao
2026-11-09 14:51       ` Jarkko Sakkinen
2026-11-09 14:50     ` Jarkko Sakkinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avHdynG1rKStCVUO@kernel.org \
    --to=jarkko@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=ardb@kernel.org \
    --cc=guozh23@xiaopeng.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®