Re: [PATCH v2 1/9] KEYS: trusted: Allow ASN.1 TPM2 sealed data shorter than MIN_KEY_SIZE
From: David Laight
Date: Wed Nov 25 2026 - 16:27:00 EST
On Wed, 25 Nov 2026 17:36:24 +0200
Jarkko Sakkinen <jarkko@xxxxxxxxxx> wrote:
> On Wed, Nov 25, 2026 at 09:09:30AM +0000, David Laight wrote:
> > On Tue, 24 Nov 2026 21:40:35 +0200
> > Jarkko Sakkinen <jarkko@xxxxxxxxxx> wrote:
> >
> > > tpm2_unseal_cmd() rejects unsealed payloads shorter than MIN_KEY_SIZE (32
> > > bytes) with -EFAULT even when loading an ASN.1 TPMKey (OID_TPMSealedData,
> > > 2.23.133.10.1.5) blob.
> > >
> > > While kernel-generated trusted keys ("new <keylen>") and legacy old_format
> > > blobs are at least 32 bytes long, external TPM2 tools allow sealing any
> > > non-empty payload up to 128 bytes.
> > >
> > > Keep MIN_KEY_SIZE for legacy old_format blobs and accept 1..MAX_KEY_SIZE
> > > bytes for ASN.1 TPMKey sealed blobs.
> > >
> > > Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
> > > ---
> > > security/keys/trusted-keys/trusted_tpm2.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c
> > > index 30188a0ec676..d7336f25b514 100644
> > > --- a/security/keys/trusted-keys/trusted_tpm2.c
> > > +++ b/security/keys/trusted-keys/trusted_tpm2.c
> > > @@ -559,9 +559,11 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
> > > rc = tpm_buf_check_hmac_response(chip, buf, rc);
> > >
> > > if (!rc) {
> > > + u16 min_len = payload->old_format ? MIN_KEY_SIZE : 1;
> >
> > There is no point using u16, just use unsigned int.
> >
> > The same goes for data_len.
>
> Hmm... or just int?
Unsigned int can generate slightly better code - especially for
array indexes.
I sort of prefer it for values that can never be negative.
David
>
>
> >
> > David
>
>
> Br, Jarkko