From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: James Bottomley <jejb@linux.vnet.ibm.com>
Cc: tpmdd-devel@lists.sourceforge.net,
open list <linux-kernel@vger.kernel.org>,
linux-security-module@vger.kernel.org
Subject: Re: [tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces
Date: Fri, 13 Jan 2017 18:28:55 +0200 [thread overview]
Message-ID: <20170113162855.dddgsomp7m4c3inc@intel.com> (raw)
In-Reply-To: <1484253532.5807.16.camel@linux.vnet.ibm.com>
On Thu, Jan 12, 2017 at 12:38:52PM -0800, James Bottomley wrote:
> On Thu, 2017-01-12 at 19:46 +0200, Jarkko Sakkinen wrote:
> > +static int tpm2_map_response(struct tpm_chip *chip, u32 cc, u8 *rsp,
> > size_t len)
> > +{
> > + struct tpm_space *space = &chip->work_space;
> > + u32 phandle;
> > + u32 vhandle;
> > + u32 attrs;
> > + int i;
> > + int rc;
> > +
> > + if (!tpm2_find_cc_attrs(chip, cc, &attrs)) {
> > + /* should never happen */
> > + dev_err(&chip->dev, "TPM returned a different CC:
> > 0x%04x\n",
> > + cc);
> > + rc = -EFAULT;
> > + goto out_err;
> > + }
> > +
> > + if (!((attrs >> TPM2_CC_ATTR_RHANDLE) & 1))
> > + return 0;
> > +
> > + phandle = be32_to_cpup((__be32 *)&rsp[TPM_HEADER_SIZE]);
>
> I think we have to check the command return code here. We can't
> blindly fish handles out of the response if the TPM returned an error
> because they won't exist and we'll pull rubbish from the buffer.
> Incremental patch below.
>
> Note I think we should use get_unaligned_be32 because we're pulling a
> 32 bit word from something that's on byte 6 (so misaligned): some
> architectures will trigger an unaligned trap for this (it's not a
> problem: they trap handle it, it just slows down processing a lot).
>
> James
>
> ---
>
> commit d17ad905ff7b114f7efd23f930e9a541ccdf7621
> Author: James Bottomley <James.Bottomley@HansenPartnership.com>
> Date: Wed Jan 11 22:01:29 2017 -0800
>
> check return code
>
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 61422e6..8009ed4 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -90,6 +90,7 @@ enum tpm2_structures {
> };
>
> enum tpm2_return_codes {
> + TPM2_RC_SUCCESS = 0x0000,
> TPM2_RC_HASH = 0x0083, /* RC_FMT1 */
> TPM2_RC_HANDLE = 0x008B,
> TPM2_RC_INITIALIZE = 0x0100, /* RC_VER1 */
> diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
> index ca55feb..44e5501 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -16,6 +16,7 @@
> */
>
> #include <linux/gfp.h>
> +#include <asm/unaligned.h>
> #include "tpm.h"
>
> enum tpm2_handle_types {
> @@ -167,9 +168,13 @@ static int tpm2_map_response(struct tpm_chip *chip, u32 cc, u8 *rsp, size_t len)
> u32 phandle;
> u32 vhandle;
> u32 attrs;
> + u32 return_code = get_unaligned_be32((__be32 *)&rsp[6]);
> int i;
> int rc;
>
> + if (return_code != TPM2_RC_SUCCESS)
> + return 0;
> +
> if (!tpm2_find_cc_attrs(chip, cc, &attrs)) {
> /* should never happen */
> dev_err(&chip->dev, "TPM returned a different CC: 0x%04x\n",
>
[x]
I'll squash this to the next patch set version.
/Jarkko
next prev parent reply other threads:[~2017-01-13 16:29 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-12 17:46 [PATCH RFC v2 0/5] RFC: in-kernel resource manager Jarkko Sakkinen
2017-01-12 17:46 ` [PATCH RFC v2 1/5] tpm: validate TPM 2.0 commands Jarkko Sakkinen
2017-01-12 20:34 ` Jarkko Sakkinen
2017-01-12 17:46 ` [PATCH RFC v2 2/5] tpm: export tpm2_flush_context_cmd Jarkko Sakkinen
2017-01-12 17:46 ` [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces Jarkko Sakkinen
2017-01-12 18:38 ` [tpmdd-devel] " James Bottomley
2017-01-12 20:31 ` Jarkko Sakkinen
2017-01-12 20:38 ` James Bottomley
2017-01-13 16:28 ` Jarkko Sakkinen [this message]
[not found] ` <o5dohv$60l$1@blaine.gmane.org>
2017-01-16 9:52 ` Jarkko Sakkinen
2017-01-12 20:50 ` Jarkko Sakkinen
2017-01-13 1:17 ` [tpmdd-devel] " James Bottomley
2017-01-13 16:31 ` Jarkko Sakkinen
2017-01-16 9:09 ` Jarkko Sakkinen
2017-01-16 14:24 ` James Bottomley
2017-01-16 14:48 ` Jarkko Sakkinen
2017-01-16 14:58 ` James Bottomley
2017-01-16 16:52 ` Jarkko Sakkinen
2017-01-12 17:46 ` [PATCH RFC v2 4/5] tpm: split out tpm-dev.c into tpm-dev.c and tpm-common-dev.c Jarkko Sakkinen
2017-01-13 19:18 ` [tpmdd-devel] " James Bottomley
2017-01-12 17:46 ` [PATCH RFC v2 5/5] tpm2: expose resource manager via a device link /dev/tpms<n> Jarkko Sakkinen
2017-01-12 18:39 ` Jason Gunthorpe
2017-01-13 19:20 ` [tpmdd-devel] " James Bottomley
2017-01-13 19:47 ` Jason Gunthorpe
2017-01-13 20:02 ` James Bottomley
2017-01-13 21:23 ` Jason Gunthorpe
2017-01-14 1:10 ` James Bottomley
2017-01-16 16:54 ` Jason Gunthorpe
2017-01-12 19:46 ` James Bottomley
2017-01-12 20:56 ` Jarkko Sakkinen
2017-01-13 17:25 ` Jason Gunthorpe
2017-01-13 17:40 ` [tpmdd-devel] " James Bottomley
2017-01-13 18:01 ` Jason Gunthorpe
2017-01-13 18:11 ` James Bottomley
2017-01-16 9:45 ` 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=20170113162855.dddgsomp7m4c3inc@intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=tpmdd-devel@lists.sourceforge.net \
/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
Powered by JetHome