From: James Bottomley <jejb@linux.ibm.com>
To: Dov Murik <dovmurik@linux.ibm.com>, linux-coco@lists.linux.dev
Subject: Re: [RFC 1/3] tpm: add generic platform device
Date: Thu, 05 Jan 2023 07:28:23 -0500 [thread overview]
Message-ID: <6d61034c9e2f0a7e9f30dfd56005a47fd10676cd.camel@linux.ibm.com> (raw)
In-Reply-To: <f7d0bd07-ba1b-894e-5e39-15fb1817bc8b@linux.ibm.com>
On Thu, 2023-01-05 at 10:08 +0200, Dov Murik wrote:
[...]
> > +static int tpm_platform_send(struct tpm_chip *chip, u8 *buf,
> > size_t
> > len)
> > +{
> > + int ret;
> > + struct tpm_send_cmd_req *req = (struct tpm_send_cmd_req
> > *)buffer;
> > +
> > + if (len > TPM_PLATFORM_MAX_BUFFER - sizeof(*req))
> > + return -EINVAL;
> > + req->cmd = TPM_SEND_COMMAND;
> > + req->locality = locality;
> > + req->inbuf_size = len;
>
> In include/linux/tpm_platform.h (below) the comment says:
>
> + * Note that @inbuf_size must be large enough to hold the response
> so
> + * represents the maximum buffer size, not the size of the specific
> + * TPM command.
>
> but here we don't set req->inbuf_size to the maximum size (which is
> TPM_PLATFORM_MAX_BUFFER - sizeof(*req) ). Is that OK?
I'll fix the comment. Unfortunately the ms TPM has a check in the
ExecuteCommand() routine that checks the command and request size are
equal. I had originally thought to use this field to communicate max
size, but it's not really any problem to make it a define.
>
>
> > + memcpy(req->inbuf, buf, len);
> > +
> > + ret = pops->sendrcv(buffer);
> > + if (ret)
> > + return ret;
> > +
> > + return 0;
> > +}
> > +
> > +static int tpm_platform_recv(struct tpm_chip *chip, u8 *buf,
> > size_t
> > len)
> > +{
> > + struct tpm_resp *resp = (struct tpm_resp *)buffer;
> > +
> > + if (resp->size < 0)
> > + return resp->size;
> > +
> > + if (len < resp->size)
> > + return -E2BIG;
>
>
> I suggest another check before the memcpy:
>
> if (resp->size > TPM_PLATFORM_MAX_BUFFER - sizeof(*resp))
> return -EINVAL; // Invalid response from the platform TPM
Yes, I already added that because of your matrix comments.
>
>
> > +
> > + memcpy(buf, buffer + sizeof(*resp), resp->size);
> > +
> > + return resp->size;
>
> Is there a possibility of a double recv?
> Should we set resp->size = 0 (or -1) before returning? (while still
> returning the original value)
Not according to the way ->recv() is used, but even if there were, it
should return the previous command until there is a new one.
[...]
> > +/**
> > + * struct tpm_platform_ops - the share platform operations
> > + *
> > + * @sendrecv: Send a TPM command using the MSSIM protocol.
> > + *
> > + * The MSSIM protocol is designed for a network, so the buffers
> > are
> > + * self describing. The minimum buffer size is sizeof(u32).
> > Every
> > + * MSSIM command defines its own transport buffer and the command
> > is
> > + * sent in the first u32 array. The only modification we make is
> > that
> > + * the MSSIM uses network order and we use the endianness of the
> > + * architecture. The response to every command (in the same
> > buffer)
> > + * is a u32 size preceded array. Most of the MSSIM commands
> > simply
> > + * return zero here because they have no defined response.
> > + *
> > + * The only command with a defined request/response size is
> > TPM_SEND_COMMAND
> > + * The definition is in the structures below
> > + */
> > +struct tpm_platform_ops {
> > + int (*sendrcv)(u8 *buffer);
>
> nit: In the commit message and struct description you
> use "sendrecv" but the member here is called "sendrcv".
OK, I'll; make the comments consistent (kernel docbook would complain
to the people who bother to run it).
James
next prev parent reply other threads:[~2023-01-05 12:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-03 21:01 [RFC 0/3] Enlightened vTPM support for SVSM on SEV-SNP James Bottomley
2023-01-03 21:02 ` [RFC 1/3] tpm: add generic platform device James Bottomley
2023-01-05 8:08 ` Dov Murik
2023-01-05 12:28 ` James Bottomley [this message]
2023-01-03 21:04 ` [RFC 2/2] x86/sev: add a SVSM vTPM " James Bottomley
2023-01-03 21:05 ` [RFC 3/3] edk2: Add SVSM based vTPM James Bottomley
2023-01-04 22:44 ` [RFC 0/3] Enlightened vTPM support for SVSM on SEV-SNP Tom Lendacky
2023-01-04 22:59 ` James Bottomley
2024-11-06 11:19 ` Stefano Garzarella
2024-11-06 14:54 ` James Bottomley
2024-11-06 15:33 ` Stefano Garzarella
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=6d61034c9e2f0a7e9f30dfd56005a47fd10676cd.camel@linux.ibm.com \
--to=jejb@linux.ibm.com \
--cc=dovmurik@linux.ibm.com \
--cc=linux-coco@lists.linux.dev \
/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).