Linux Integrity Measurement development
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Yuqi Xu <xuyuqiabc@gmail.com>
Cc: linux-integrity@vger.kernel.org, Peter Huewe <peterhuewe@gmx.de>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Jerry Snitselaar <jsnitsel@redhat.com>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	stable@vger.kernel.org, Vega <vega@nebusec.ai>,
	Ren Wei <weir@nebusec.ai>,
	xuyq21@lenovo.com
Subject: Re: [PATCH v2 1/1] tpm: reject duplicate PCR banks in tpm2_get_pcr_allocation
Date: Wed, 30 Sep 2026 00:25:06 +0300	[thread overview]
Message-ID: <arwssp0czGg9XKv7@kernel.org> (raw)
In-Reply-To: <9d27c4513a3c6fc32f9574ba192cd3bfcb2bac98.1790568982.git.xuyuqiabc@gmail.com>

On Mon, Sep 28, 2026 at 04:27:00PM +0800, Yuqi Xu wrote:
> The TPM2_CAP_PCRS response is external input. tpm2_get_pcr_allocation()
> adds every active selection to allocated_banks, while
> tpm_sysfs_add_device() has one group slot per distinct hash algorithm.
> Eight duplicate selections can therefore write past chip->groups[].
> 
> The TPM protocol does not allow a hash algorithm to appear twice in
> this capability response. Treat a duplicate as a broken TPM and return
> -EIO so the chip is not enabled, instead of silently dropping the
> extra selection.
> 
> Fixes: aab73d952402 ("tpm: add sysfs exports for all banks of PCR registers")
> Cc: stable@vger.kernel.org
> Reported-by: Vega <vega@nebusec.ai>
> Assisted-by: LLM
> Signed-off-by: Yuqi Xu <xuyuqiabc@gmail.com>
> Reviewed-by: Ren Wei <weir@nebusec.ai>
> ---
> Changes in v2:
>  - Return -EIO on a duplicate PCR bank instead of silently ignoring
>    it, as requested by Jarkko Sakkinen. A duplicate violates the TPM
>    protocol, so the chip is not enabled.
>  - v1 Link: https://lore.kernel.org/all/cover.1789800840.git.xuyuqiabc@gmail.com/
>  drivers/char/tpm/tpm2-cmd.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index ae22295df798..a94f4395c198 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -527,6 +527,7 @@ ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>  	u32 rsp_len;
>  	int rc;
>  	int i = 0;
> +	int j;
>  
>  	struct tpm_buf *buf __free(kfree) = kzalloc(TPM_BUFSIZE, GFP_KERNEL);
>  	if (!buf)
> @@ -569,6 +570,23 @@ ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>  		pcr_select_offset = memchr_inv(pcr_selection.pcr_select, 0,
>  					       pcr_selection.size_of_select);
>  		if (pcr_select_offset) {
> +			for (j = 0; j < nr_alloc_banks; j++) {
> +				if (chip->allocated_banks[j].alg_id == hash_alg)
> +					break;
> +			}
> +
> +			/*
> +			 * The TPM protocol does not allow the same hash
> +			 * algorithm twice.  A duplicate means this device
> +			 * is not behaving; do not enable it.
> +			 */
> +			if (j != nr_alloc_banks) {
> +				pr_err("tpm: duplicate PCR bank for algorithm 0x%04x\n",
> +				       hash_alg);
> +				rc = -EIO;
> +				break;
> +			}
> +
>  			chip->allocated_banks[nr_alloc_banks].alg_id = hash_alg;
>  
>  			rc = tpm2_init_bank_info(chip, nr_alloc_banks);
> -- 
> 2.55.0
> 

Yeah, so in some places like this some of the TPM driver code does
return -EFAULT but I'd like to progressively refactor so that any
corrupted traffic is always -EIO and use -EFAULT for memory related
issues. 

Thank you!

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

Br, Jarkko

  reply	other threads:[~2026-09-29 21:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28  8:26 [PATCH v2 0/1] tpm: reject duplicate PCR banks in tpm2_get_pcr_allocation Yuqi Xu
2026-09-28  8:27 ` [PATCH v2 1/1] " Yuqi Xu
2026-09-29 21:25   ` Jarkko Sakkinen [this message]
2026-09-29 22:34     ` Jarkko Sakkinen
2026-09-30  3:33       ` Yuqi Xu
2026-09-30  6:30         ` Yuan Tan
2026-10-02  3:14         ` Jarkko Sakkinen

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=arwssp0czGg9XKv7@kernel.org \
    --to=jarkko@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=jgg@ziepe.ca \
    --cc=jsnitsel@redhat.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=stable@vger.kernel.org \
    --cc=vega@nebusec.ai \
    --cc=weir@nebusec.ai \
    --cc=xuyq21@lenovo.com \
    --cc=xuyuqiabc@gmail.com \
    /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