diff mbox

[tpmdd-devel,2/2] tpm: fix byte-order for the value read by tpm2_get_tpm_pt

Message ID 1468544838-9990-3-git-send-email-apronin@chromium.org
State New
Headers show

Commit Message

apronin@chromium.org July 15, 2016, 1:07 a.m. UTC
Change-Id: I7d71cd379b1a3b7659d20a1b6008216762596590
Signed-off-by: Andrey Pronin <apronin@chromium.org>
---
 drivers/char/tpm/tpm2-cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Gunthorpe July 15, 2016, 3:10 a.m. UTC | #1
On Thu, Jul 14, 2016 at 06:07:18PM -0700, Andrey Pronin wrote:
> Change-Id: I7d71cd379b1a3b7659d20a1b6008216762596590
> Signed-off-by: Andrey Pronin <apronin@chromium.org>
>  drivers/char/tpm/tpm2-cmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index a1673dc..a88b31e 100644
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -703,7 +703,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
>  
>  	rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), desc);
>  	if (!rc)
> -		*value = cmd.params.get_tpm_pt_out.value;
> +		*value = be32_to_cpu(cmd.params.get_tpm_pt_out.value);

Huh.

Jarkko: Are you running sparse on the tpm stuff? The annotations look
right here, sparse should have complained on this? Andrey, did sparse
complain here or is there something more serious wrong as well??

Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>

Jason

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
apronin@chromium.org July 15, 2016, 3:17 a.m. UTC | #2
On Thu, Jul 14, 2016 at 09:10:46PM -0600, Jason Gunthorpe wrote:
> On Thu, Jul 14, 2016 at 06:07:18PM -0700, Andrey Pronin wrote:
> > Change-Id: I7d71cd379b1a3b7659d20a1b6008216762596590
> > Signed-off-by: Andrey Pronin <apronin@chromium.org>
> >  drivers/char/tpm/tpm2-cmd.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> > index a1673dc..a88b31e 100644
> > +++ b/drivers/char/tpm/tpm2-cmd.c
> > @@ -703,7 +703,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
> >  
> >  	rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), desc);
> >  	if (!rc)
> > -		*value = cmd.params.get_tpm_pt_out.value;
> > +		*value = be32_to_cpu(cmd.params.get_tpm_pt_out.value);
> 
> Huh.
> 
> Jarkko: Are you running sparse on the tpm stuff? The annotations look
> right here, sparse should have complained on this? Andrey, did sparse
> complain here or is there something more serious wrong as well??
> 
> Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> 
> Jason

No, this is not sparse complaining. I tried using tpm2_get_tpm_pt() to
read permanent flags and discovered that it was missing byte-ordering
conversion. The only place tpm2_get_tpm_pt() was used before was in
tpm2_gen_interrupt, which discarded the result. So, nobody noticed,
I guess.

Andrey

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
Jason Gunthorpe July 15, 2016, 3:35 a.m. UTC | #3
On Thu, Jul 14, 2016 at 08:17:01PM -0700, Andrey Pronin wrote:
> conversion. The only place tpm2_get_tpm_pt() was used before was in
> tpm2_gen_interrupt, which discarded the result. So, nobody noticed,
> I guess.

If you have a moment can you run sparse on this file before/after this
change and make sure it did complain and that there are not other
endian errors?

Jason

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
apronin@chromium.org July 15, 2016, 7:31 p.m. UTC | #4
On Thu, Jul 14, 2016 at 09:35:53PM -0600, Jason Gunthorpe wrote:
> On Thu, Jul 14, 2016 at 08:17:01PM -0700, Andrey Pronin wrote:
> > conversion. The only place tpm2_get_tpm_pt() was used before was in
> > tpm2_gen_interrupt, which discarded the result. So, nobody noticed,
> > I guess.
> 
> If you have a moment can you run sparse on this file before/after this
> change and make sure it did complain and that there are not other
> endian errors?
> 

I ran sparse. In my case it didn't complain before or after the change.
It only complains about using cpu_to_be32() in tpm_capabilities and
tpm_sub_capabilities enum in tpm.h and the use of those enums in
tpm_getcap() in tpm-interface.c

I even tried changing the code there to
	__be32 vv = cmd.params.get_tpm_pt_out.value;
	u32 ret = vv;
to make it clear what's going on. Still, no complaints from sparse.

be32_to_cpu() should cleary be done in this case, though. As value
is defined as __be32 in struct tpm2_get_tpm_pt_out, and we return u32
in that parameter from tpm2_get_tpm_pt(). Plus, it's consistent with
the spec. It's just nobody has used this value yet in the existing
code, thus it went unnoticed.

To address "no dead code" comment, I'll drop defining various tpm2
properties and bits from this patchset and move it to the sysfs for
tpm2 patchset where they'll be needed for tpm2-specific attributes.
But this fix is valid on its own in my opinion.


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
Jason Gunthorpe July 15, 2016, 7:39 p.m. UTC | #5
On Fri, Jul 15, 2016 at 12:31:43PM -0700, Andrey Pronin wrote:

> I even tried changing the code there to
> 	__be32 vv = cmd.params.get_tpm_pt_out.value;
> 	u32 ret = vv;
> to make it clear what's going on. Still, no complaints from sparse.

Hum, I'm not an expert at sparse, but I expect a warning from it here?

Maybe Jarkko knows when he gets back?

Jason

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
Jarkko Sakkinen July 18, 2016, 7:04 p.m. UTC | #6
On Thu, Jul 14, 2016 at 06:07:18PM -0700, Andrey Pronin wrote:
> Change-Id: I7d71cd379b1a3b7659d20a1b6008216762596590
> Signed-off-by: Andrey Pronin <apronin@chromium.org>

Please remove the internal commit ID next time. This is also lacking a
description but this time I can write it down.

This not needed for the stable for obvious reasons (only used for
probing).

Fixes: 7a1d7e6dd76a ("tpm: TPM 2.0 baseline support")
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/tpm2-cmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index a1673dc..a88b31e 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -703,7 +703,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
>  
>  	rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), desc);
>  	if (!rc)
> -		*value = cmd.params.get_tpm_pt_out.value;
> +		*value = be32_to_cpu(cmd.params.get_tpm_pt_out.value);
>  
>  	return rc;
>  }
> -- 
> 2.6.6
> 

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
Jarkko Sakkinen July 18, 2016, 7:05 p.m. UTC | #7
On Fri, Jul 15, 2016 at 01:39:28PM -0600, Jason Gunthorpe wrote:
> On Fri, Jul 15, 2016 at 12:31:43PM -0700, Andrey Pronin wrote:
> 
> > I even tried changing the code there to
> > 	__be32 vv = cmd.params.get_tpm_pt_out.value;
> > 	u32 ret = vv;
> > to make it clear what's going on. Still, no complaints from sparse.
> 
> Hum, I'm not an expert at sparse, but I expect a warning from it here?
> 
> Maybe Jarkko knows when he gets back?

I do run sparse regularly. If look at the commit log there are even
couple of recent bug fixes related to sparse errors.

/Jarkko

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
Jarkko Sakkinen July 18, 2016, 7:09 p.m. UTC | #8
On Mon, Jul 18, 2016 at 10:04:21PM +0300, Jarkko Sakkinen wrote:
> On Thu, Jul 14, 2016 at 06:07:18PM -0700, Andrey Pronin wrote:
> > Change-Id: I7d71cd379b1a3b7659d20a1b6008216762596590
> > Signed-off-by: Andrey Pronin <apronin@chromium.org>
> 
> Please remove the internal commit ID next time. This is also lacking a
> description but this time I can write it down.
> 
> This not needed for the stable for obvious reasons (only used for
> probing).
> 
> Fixes: 7a1d7e6dd76a ("tpm: TPM 2.0 baseline support")
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

Applied.

/Jarkko

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
apronin@chromium.org July 18, 2016, 7:13 p.m. UTC | #9
On Mon, Jul 18, 2016 at 10:04:21PM +0300, Jarkko Sakkinen wrote:
> On Thu, Jul 14, 2016 at 06:07:18PM -0700, Andrey Pronin wrote:
> > Change-Id: I7d71cd379b1a3b7659d20a1b6008216762596590
> > Signed-off-by: Andrey Pronin <apronin@chromium.org>
> 
> Please remove the internal commit ID next time. This is also lacking a
> description but this time I can write it down.
>
Yes, sorry for the commit ID, missed it in this patch :(

> This not needed for the stable for obvious reasons (only used for
> probing).
> 

I intend to use tpm2_get_tpm_pt for tpm2 sysfs attributes
implementation (permanent and startup_clear flags). Just
submitted as a separate patch since it fixes a more generic
bug.


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
diff mbox

Patch

diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index a1673dc..a88b31e 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -703,7 +703,7 @@  ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
 
 	rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), desc);
 	if (!rc)
-		*value = cmd.params.get_tpm_pt_out.value;
+		*value = be32_to_cpu(cmd.params.get_tpm_pt_out.value);
 
 	return rc;
 }