linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: "Frédéric JOUEN" <fjouen@sealsq.com>
Cc: "peterhuewe@gmx.de" <peterhuewe@gmx.de>,
	"jgg@ziepe.ca" <jgg@ziepe.ca>,
	"linux-integrity@vger.kernel.org"
	<linux-integrity@vger.kernel.org>
Subject: Re: Issue with TPM kernel code
Date: Thu, 18 Sep 2025 19:27:58 +0300	[thread overview]
Message-ID: <aMwzDvvpGH4dfj2O@kernel.org> (raw)
In-Reply-To: <GVAP278MB0280F83F8CE1884D26A0BA35B116A@GVAP278MB0280.CHEP278.PROD.OUTLOOK.COM>

On Thu, Sep 18, 2025 at 08:50:39AM +0000, Frédéric JOUEN wrote:
> Good morning All,
> 
>  
> 
> I have created two issues into the raspberrypi linux github regarding the TPM
> driver interface. 
> 
> Issues are :
> 
>   ● https://github.com/raspberrypi/linux/issues/7053

For this I'd hope to get some sort of draft of a patch at minimum
(e.g. with RFC tag). It does not have to be fully working if it
shows the problem.

>   ● https://github.com/raspberrypi/linux/issues/7054


I.e. this: https://trustedcomputinggroup.org/wp-content/uploads/PC-Client-Specific-Platform-TPM-Profile-for-TPM-2p0-Version-1p06_pub.pdf

It can be updated. I don't think that timeout did exist when at
the time this was first implemented i.e. it's an improvement
not a bug fix and thus I'd reconsider this:

static u8 tpm2_ordinal_duration_index(u32 ordinal)
{
	switch (ordinal) {
	/* Startup */
	case TPM2_CC_STARTUP:                 /* 144 */
		return TPM_MEDIUM;

	case TPM2_CC_SELF_TEST:               /* 143 */
		return TPM_LONG;

	case TPM2_CC_GET_RANDOM:              /* 17B */
		return TPM_LONG;

	case TPM2_CC_SEQUENCE_UPDATE:         /* 15C */
		return TPM_MEDIUM;
	case TPM2_CC_SEQUENCE_COMPLETE:       /* 13E */
		return TPM_MEDIUM;
	case TPM2_CC_EVENT_SEQUENCE_COMPLETE: /* 185 */
		return TPM_MEDIUM;
	case TPM2_CC_HASH_SEQUENCE_START:     /* 186 */
		return TPM_MEDIUM;

	case TPM2_CC_VERIFY_SIGNATURE:        /* 177 */
		return TPM_LONG_LONG;

	case TPM2_CC_PCR_EXTEND:              /* 182 */
		return TPM_MEDIUM;

	case TPM2_CC_HIERARCHY_CONTROL:       /* 121 */
		return TPM_LONG;
	case TPM2_CC_HIERARCHY_CHANGE_AUTH:   /* 129 */
		return TPM_LONG;

	case TPM2_CC_GET_CAPABILITY:          /* 17A */
		return TPM_MEDIUM;

	case TPM2_CC_NV_READ:                 /* 14E */
		return TPM_LONG;

	case TPM2_CC_CREATE_PRIMARY:          /* 131 */
		return TPM_LONG_LONG;
	case TPM2_CC_CREATE:                  /* 153 */
		return TPM_LONG_LONG;
	case TPM2_CC_CREATE_LOADED:           /* 191 */
		return TPM_LONG_LONG;

	default:
		return TPM_UNDEFINED;
	}
}


It's quite horrible with all the indirection and everything and
hard to patch.

We'd be better of with something like 

static const struct {
	unsigned long ordinal;
	unsigned logn duration; /* msecs */
} tpm2_duration_map[] = {
	{TPM2_CC_STARTUP, 750},
	{TPM2_CC_SELFTEST, 3000},
	{TPM2_CC_GET_RANDOM, 2000}
	/* ... */
}

And change tpm2_calc_ordinal_duration as:

unsigned long tpm2_ordinal_to_duration(u32 ordinal)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(tpm2_duration_table); i++) {
		if (ordinal == tpm2_duration_map[i].ordinal)
			return tpm2_duration_map[i].duration;
	}

	return TPM2_DURATION_DEFAULT;
}

This essentially drops the chip parameter: as of today we have only
common table from TPM2 and tpm_tis is the only driver that modifies
chip->duration. Further, tpm_tis does this exactly for TPM 1 devices.

If there's ever need to make it laaf driver specific it's easy 
enough to make a copy of the template into something like
'chip->duration_map' but right now there is no such use.

I think this would be a pretty good long-term solution for this
and similar issues.

> 
>  
> 
> For both Phil Elwell redirects me to you. 
> 
> How can address these issues in a proper way ?
> 
>  
> 
> On my side I’m currently working  in SEALSQ France (a WISeKey company). 
> 
> We are about to release a new TPM device including PQC features.
> 
> But today we are facing some troubles such as the issues listed above with
> using current linux kernel.
> 
>  
> 
> Best Regards,
> 
> Frederic Jouen
> 
>  
> 

Polite remark, and this also how vger works: use plain text email.
The list drops HTML mail and thus your original message won't
appear at lore.kernel.org (but since I responded this response
luckily will).

BR, Jarkko

  reply	other threads:[~2025-09-18 16:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18  8:50 Issue with TPM kernel code Frédéric JOUEN
2025-09-18 16:27 ` Jarkko Sakkinen [this message]
2025-09-18 17:10   ` 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=aMwzDvvpGH4dfj2O@kernel.org \
    --to=jarkko@kernel.org \
    --cc=fjouen@sealsq.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@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;
as well as URLs for NNTP newsgroup(s).