From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: Claudio Carvalho <cclaudio@linux.ibm.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
linux-coco@lists.linux.dev, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Peter Huewe <peterhuewe@gmx.de>, "H. Peter Anvin" <hpa@zytor.com>,
linux-integrity@vger.kernel.org, x86@kernel.org,
Joerg Roedel <jroedel@suse.de>, Jason Gunthorpe <jgg@ziepe.ca>,
Jarkko Sakkinen <jarkko@kernel.org>,
linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dov Murik <dovmurik@linux.ibm.com>,
Oliver Steffen <osteffen@redhat.com>
Subject: Re: [PATCH 1/3] tpm: add generic platform device
Date: Thu, 12 Dec 2024 10:41:40 -0500 [thread overview]
Message-ID: <d84a9a960e419cf8cbfd086e8210b6c4a112d04f.camel@HansenPartnership.com> (raw)
In-Reply-To: <cnq6nzhvrsas6ud7t4woybktpesepm7a3sq5sd5yldq4hr5kyl@ezm4xi3o7eax>
On Thu, 2024-12-12 at 16:30 +0100, Stefano Garzarella wrote:
> On Thu, Dec 12, 2024 at 09:35:46AM -0500, James Bottomley wrote:
> > On Thu, 2024-12-12 at 10:51 +0100, Stefano Garzarella wrote:
> > > On Tue, Dec 10, 2024 at 03:34:21PM +0100, Stefano Garzarella
> > > wrote:
> > [...]
> > > > +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;
> > >
> > > While reviewing Oliver's work for the driver in edk2[1], I
> > > noticed that there wasn't this check and asked to add it, but
> > > talking to him and looking in the code/spec, we realized that
> > > it's strange that tpm_resp.size field is signed.
> > >
> > > From SVSM spec it looks like it can't be negative:
> > >
> > > Table 17: TPM_SEND_COMMAND Response Structure
> > >
> > > Byte Size Meaning
> > > Offset (Bytes)
> > > 0x000 4 Response size (in bytes)
> > > 0x004 Variable Variable Response
> > >
> > > And also Coconut SVSM remap it to the `responseSize` of the TCG
> > > TPM implementation which is unsigned:
> > >
> > > LIB_EXPORT void _plat__RunCommand(
> > > uint32_t requestSize, // IN: command buffer size
> > > unsigned char* request, // IN: command buffer
> > > uint32_t* responseSize, // IN/OUT: response buffer
> > > size
> > > unsigned char** response // IN/OUT: response buffer
> > > )
> > >
> > > @James, @Claudio, @Tom, should we use u32 for tpm_resp.size?
> >
> > The original idea was to allow the protocol to return an error
> > (like out of memory or something) before the command ever got to
> > the TPM rather than having to wrap it up in a TPM error. However,
> > that's done in the actual return from the SVSM call, which the
> > sendrecv routine checks, so I agree this can be removed and a u32
> > done for the length.
>
> Thanks for the details!
> I'll fix it in v2 and put a comment also in the edk2 PR.
>
> > Dov did recommend we should check the returned length against the
> > maximum allowable:
> >
> > https://lore.kernel.org/linux-coco/f7d0bd07-ba1b-894e-5e39-15fb1817bc8b@linux.ibm.com/
>
> I added in this version the check he suggested:
>
> if (resp->size > TPM_PLATFORM_MAX_BUFFER - sizeof(*resp))
> return -EINVAL; // Invalid response from the
> platform TPM
>
> Were you referring to that?
Yes, the theory being that we're required to provide a buffer of this
length for the response, but if someone can inject a bogus response
they could induce us to copy beyond the end of the buffer we provided.
Regards,
James
next prev parent reply other threads:[~2024-12-12 15:41 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 14:34 [PATCH 0/3] Enlightened vTPM support for SVSM on SEV-SNP Stefano Garzarella
2024-12-10 14:34 ` [PATCH 1/3] tpm: add generic platform device Stefano Garzarella
2024-12-12 9:51 ` Stefano Garzarella
2024-12-12 14:35 ` James Bottomley
2024-12-12 15:30 ` Stefano Garzarella
2024-12-12 15:41 ` James Bottomley [this message]
2024-12-12 16:12 ` Stefano Garzarella
2024-12-10 14:34 ` [PATCH 2/3] x86/sev: add SVSM call macros for the vTPM protocol Stefano Garzarella
2024-12-10 14:34 ` [PATCH 3/3] x86/sev: add a SVSM vTPM platform device Stefano Garzarella
2024-12-10 14:40 ` Jason Gunthorpe
2024-12-10 14:55 ` James Bottomley
2024-12-10 15:04 ` Jason Gunthorpe
2024-12-11 8:19 ` Stefano Garzarella
2024-12-11 15:00 ` Jason Gunthorpe
2024-12-11 15:38 ` Stefano Garzarella
2024-12-11 15:53 ` Jason Gunthorpe
2024-12-11 16:42 ` Stefano Garzarella
2024-12-19 15:35 ` Stefano Garzarella
2024-12-19 15:40 ` Jarkko Sakkinen
2024-12-19 16:06 ` Stefano Garzarella
2025-01-14 10:42 ` Stefano Garzarella
2025-01-14 13:07 ` Jason Gunthorpe
2025-01-14 16:51 ` Stefano Garzarella
2025-01-14 17:33 ` Jason Gunthorpe
2025-01-14 22:46 ` Jarkko Sakkinen
2025-01-14 22:48 ` Jarkko Sakkinen
2025-01-14 23:12 ` Jarkko Sakkinen
2025-01-22 21:29 ` Dionna Amalie Glaze
2025-01-23 9:50 ` Jarkko Sakkinen
2025-01-23 10:09 ` Stefano Garzarella
2025-01-23 11:46 ` Jarkko Sakkinen
2025-01-23 11:49 ` Jarkko Sakkinen
2025-01-23 12:29 ` Stefano Garzarella
2024-12-11 16:30 ` Tom Lendacky
2024-12-11 16:55 ` Stefano Garzarella
2024-12-11 17:02 ` James Bottomley
2024-12-13 11:48 ` 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=d84a9a960e419cf8cbfd086e8210b6c4a112d04f.camel@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=bp@alien8.de \
--cc=cclaudio@linux.ibm.com \
--cc=dave.hansen@linux.intel.com \
--cc=dovmurik@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=jroedel@suse.de \
--cc=linux-coco@lists.linux.dev \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=osteffen@redhat.com \
--cc=peterhuewe@gmx.de \
--cc=sgarzare@redhat.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/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