From: sashiko-bot@kernel.org
To: "Jarkko Sakkinen" <jarkko@kernel.org>,
"David Howells" <dhowells@redhat.com>
Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
"Alec Brown" <alec.r.brown@oracle.com>,
"Daniel P. Smith" <dpsmith@apertussolutions.com>,
"James Bottomley" <James.Bottomley@HansenPartnership.com>,
"James Morris" <jmorris@namei.org>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Jonathan McDowell" <noodles@earth.li>,
"Matthew Garrett" <mjg59@srcf.ucam.org>,
"Mimi Zohar" <zohar@linux.ibm.com>,
"Paul Moore" <paul@paul-moore.com>,
"Peter Huewe" <peterhuewe@gmx.de>,
"Ross Philipson" <ross.philipson@gmail.com>,
"Serge E. Hallyn" <serge@hallyn.com>
Subject: Re: [PATCH 4/4] tpm2-sessions: Re-orchestrate tpm2_read_public() use
Date: Sun, 15 Nov 2026 22:56:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-215893@kernel.org> (raw)
In-Reply-To: <20261115224722.1450498-5-jarkko@kernel.org>
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@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
prev parent reply other threads:[~2026-11-15 22:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 22:47 [PATCH 0/4] Unsorted tpm2-sessions improvements Jarkko Sakkinen
2026-11-15 22:47 ` [PATCH 1/4] tpm2-sessions: Drop TPM2_NAME_SIZE Jarkko Sakkinen
2026-11-15 22:51 ` sashiko-bot
2026-11-15 22:47 ` [PATCH 2/4] KEYS: trusted: Open code tpm2_buf_append_auth() Jarkko Sakkinen
2026-11-15 22:51 ` sashiko-bot
2026-11-15 22:47 ` [PATCH 3/4] KEYS: trusted: Remove dead branch from tpm2_unseal_cmd Jarkko Sakkinen
2026-11-15 22:50 ` sashiko-bot
2026-11-15 22:47 ` [PATCH 4/4] tpm2-sessions: Re-orchestrate tpm2_read_public() use Jarkko Sakkinen
2026-11-15 22:56 ` sashiko-bot [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=sashiko-outbox-215893@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alec.r.brown@oracle.com \
--cc=dhowells@redhat.com \
--cc=dpsmith@apertussolutions.com \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mjg59@srcf.ucam.org \
--cc=noodles@earth.li \
--cc=paul@paul-moore.com \
--cc=peterhuewe@gmx.de \
--cc=ross.philipson@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=serge@hallyn.com \
--cc=zohar@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.