[PATCH 4/4] tpm2-sessions: Re-orchestrate tpm2_read_public() use

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sun Nov 15 22:56:28 UTC 2026


Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] tpm: unsequenced modification of offset in tpm2_read_public()
  [1]
--

commit ebd1e7509520c997eb3480a23e996d7c9abd6acd
Author: Jarkko Sakkinen <jarkko at kernel.org>

tpm2-sessions: Re-orchestrate tpm2_read_public() use

This commit exports tpm2_read_public() and moves TPM handle name
resolution out of tpm_buf_append_name() so that callers resolve handle
names explicitly before starting an authorization session.

> diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
> index 94c11135beb3f..36308b384a5e3 100644
> --- a/drivers/char/tpm/tpm2-sessions.c
> +++ b/drivers/char/tpm/tpm2-sessions.c
[ ... ]
> @@ -163,7 +163,17 @@ static int name_size(const u8 *name)
>  	}
>  }
>  
> -static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
> +/**
> + * tpm2_read_public() - Resolve TPM name for a handle
> + * @chip:	TPM chip to use.
> + * @handle:	TPM handle.
> + * @name:	Buffer for returning the name blob. Must have a capacity of at
> + *		least %TPM2_MAX_NAME_SIZE bytes.
> + *
> + * Return: Size of the TPM handle name on success, or a negative errno when
> + * TPM2_ReadPublic fails.
> + */
> +int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
>  {
>  	u32 mso = tpm2_handle_mso(handle);
>  	off_t offset = TPM_HEADER_SIZE;
> @@ -172,7 +182,7 @@ static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
>  
>  	if (mso != TPM2_MSO_PERSISTENT && mso != TPM2_MSO_VOLATILE &&
>  	    mso != TPM2_MSO_NVRAM) {
> -		memcpy(name, &handle, sizeof(u32));
> +		put_unaligned_be32(handle, name);
>  		return sizeof(u32);
>  	}
>  
> @@ -212,39 +222,34 @@ static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
>  	memcpy(name, &buf->data[offset], rc);
>  	return name_size_alg;
>  }
> +EXPORT_SYMBOL_GPL(tpm2_read_public);

[Severity: High]
This problem wasn't introduced by this patch, but does the modification of
offset in tpm2_read_public() [1] have unsequenced side effects?

drivers/char/tpm/tpm2-sessions.c:tpm2_read_public() {
	...
	/* Skip TPMT_PUBLIC: */
	offset += tpm_buf_read_u16(buf, &offset);
	...
}

tpm_buf_read_u16() increments offset by 2 through &offset, while the +=
operator also reads and writes offset without a sequence point between
evaluating the left operand and calling tpm_buf_read_u16().  If the
compiler evaluates the left operand before the call, += adds the returned
length to the old offset and discards the +2 increment, misaligning the
subsequent TPM2B_NAME and TPMT_HA reads.

[1] https://sashiko.dev/#/bug/linux-332997a7-b4f3-4fb9-b9c8-65529918139d

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115224722.1450498-1-jarkko@kernel.org?part=4



More information about the Linux-security-module-archive mailing list