diff mbox

tpm: do handle area size validation only when TPM space used

Message ID 20170326210815.21252-1-jarkko.sakkinen@iki.fi (mailing list archive)
State New, archived
Headers show

Commit Message

Jarkko Sakkinen March 26, 2017, 9:08 p.m. UTC
In order to not cause backwards compatibility issues with
/dev/tpm0 disable handle area size validation if tpm_transmit
is not called with a TPM space.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@iki.fi>
---
 drivers/char/tpm/tpm-interface.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Jarkko Sakkinen March 28, 2017, 10:24 a.m. UTC | #1
So do you need this or not?

/Jarkko

On Mon, Mar 27, 2017 at 12:08:15AM +0300, Jarkko Sakkinen wrote:
> In order to not cause backwards compatibility issues with
> /dev/tpm0 disable handle area size validation if tpm_transmit
> is not called with a TPM space.
> 
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@iki.fi>
> ---
>  drivers/char/tpm/tpm-interface.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index bf0c3fa..158c1db 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -328,7 +328,9 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
>  }
>  EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
>  
> -static bool tpm_validate_command(struct tpm_chip *chip, const u8 *cmd,
> +static bool tpm_validate_command(struct tpm_chip *chip,
> +				 struct tpm_space *space,
> +				 const u8 *cmd,
>  				 size_t len)
>  {
>  	const struct tpm_input_header *header = (const void *)cmd;
> @@ -340,6 +342,9 @@ static bool tpm_validate_command(struct tpm_chip *chip, const u8 *cmd,
>  	if (len < TPM_HEADER_SIZE)
>  		return false;
>  
> +	if (!space)
> +		return true;
> +
>  	if (chip->flags & TPM_CHIP_FLAG_TPM2 && chip->nr_commands) {
>  		cc = be32_to_cpu(header->ordinal);
>  
> @@ -386,7 +391,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
>  	unsigned long stop;
>  	bool need_locality;
>  
> -	if (!tpm_validate_command(chip, buf, bufsiz))
> +	if (!tpm_validate_command(chip, space, buf, bufsiz))
>  		return -EINVAL;
>  
>  	if (bufsiz > TPM_BUFSIZE)
> -- 
> 2.9.3
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexander Steffen March 28, 2017, 11:27 a.m. UTC | #2
WWVzLCB0aGlzIGZpeGVzIHRoZSBpc3N1ZSBmb3IgbWUuIFRoYW5rcy4NCg0KQWxleGFuZGVyDQoN
Cj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogSmFya2tvIFNha2tpbmVuIFtt
YWlsdG86amFya2tvLnNha2tpbmVuQGxpbnV4LmludGVsLmNvbV0NCj4gU2VudDogVHVlc2RheSwg
TWFyY2ggMjgsIDIwMTcgMTI6MjUgUE0NCj4gVG86IFN0ZWZmZW4gQWxleGFuZGVyIChJRkFHIEND
UyBFU1MgRCBTVyBBKQ0KPiBDYzogdHBtZGQtZGV2ZWxAbGlzdHMuc291cmNlZm9yZ2UubmV0OyBs
aW51eC1zZWN1cml0eS0NCj4gbW9kdWxlQHZnZXIua2VybmVsLm9yZzsgUGV0ZXIgSHVld2U7IE1h
cmNlbCBTZWxob3JzdDsgSmFzb24gR3VudGhvcnBlOw0KPiBvcGVuIGxpc3QNCj4gU3ViamVjdDog
UmU6IFtQQVRDSF0gdHBtOiBkbyBoYW5kbGUgYXJlYSBzaXplIHZhbGlkYXRpb24gb25seSB3aGVu
IFRQTQ0KPiBzcGFjZSB1c2VkDQo+IA0KPiBTbyBkbyB5b3UgbmVlZCB0aGlzIG9yIG5vdD8NCj4g
DQo+IC9KYXJra28NCj4gDQo+IE9uIE1vbiwgTWFyIDI3LCA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
KCF0cG1fdmFsaWRhdGVfY29tbWFuZChjaGlwLCBidWYsIGJ1ZnNpeikpDQo+ID4gKwlpZiAoIXRw
bV92YWxpZGF0ZV9jb21tYW5kKGNoaXAsIHNwYWNlLCBidWYsIGJ1ZnNpeikpDQo+ID4gIAkJcmV0
dXJuIC1FSU5WQUw7DQo+ID4NCj4gPiAgCWlmIChidWZzaXogPiBUUE1fQlVGU0laRSkNCj4gPiAt
LQ0KPiA+IDIuOS4zDQo+ID4NCg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jarkko Sakkinen March 28, 2017, 12:47 p.m. UTC | #3
On Tue, Mar 28, 2017 at 11:27:53AM +0000, Alexander.Steffen@infineon.com wrote:
> Yes, this fixes the issue for me. Thanks.
> 
> Alexander

Great. I will squash this to the infrastructure patch. Thank you.

/Jarkko

> > -----Original Message-----
> > From: Jarkko Sakkinen [mailto:jarkko.sakkinen@linux.intel.com]
> > Sent: Tuesday, March 28, 2017 12:25 PM
> > To: Steffen Alexander (IFAG CCS ESS D SW A)
> > Cc: tpmdd-devel@lists.sourceforge.net; linux-security-
> > module@vger.kernel.org; Peter Huewe; Marcel Selhorst; Jason Gunthorpe;
> > open list
> > Subject: Re: [PATCH] tpm: do handle area size validation only when TPM
> > space used
> > 
> > So do you need this or not?
> > 
> > /Jarkko
> > 
> > On Mon, Mar 27, 2017 at 12:08:15AM +0300, Jarkko Sakkinen wrote:
> > > In order to not cause backwards compatibility issues with
> > > /dev/tpm0 disable handle area size validation if tpm_transmit is not
> > > called with a TPM space.
> > >
> > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@iki.fi>
> > > ---
> > >  drivers/char/tpm/tpm-interface.c | 9 +++++++--
> > >  1 file changed, 7 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/char/tpm/tpm-interface.c
> > > b/drivers/char/tpm/tpm-interface.c
> > > index bf0c3fa..158c1db 100644
> > > --- a/drivers/char/tpm/tpm-interface.c
> > > +++ b/drivers/char/tpm/tpm-interface.c
> > > @@ -328,7 +328,9 @@ unsigned long tpm_calc_ordinal_duration(struct
> > > tpm_chip *chip,  }  EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
> > >
> > > -static bool tpm_validate_command(struct tpm_chip *chip, const u8
> > > *cmd,
> > > +static bool tpm_validate_command(struct tpm_chip *chip,
> > > +				 struct tpm_space *space,
> > > +				 const u8 *cmd,
> > >  				 size_t len)
> > >  {
> > >  	const struct tpm_input_header *header = (const void *)cmd; @@ -
> > 340,6
> > > +342,9 @@ static bool tpm_validate_command(struct tpm_chip *chip,
> > const u8 *cmd,
> > >  	if (len < TPM_HEADER_SIZE)
> > >  		return false;
> > >
> > > +	if (!space)
> > > +		return true;
> > > +
> > >  	if (chip->flags & TPM_CHIP_FLAG_TPM2 && chip->nr_commands) {
> > >  		cc = be32_to_cpu(header->ordinal);
> > >
> > > @@ -386,7 +391,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct
> > tpm_space *space,
> > >  	unsigned long stop;
> > >  	bool need_locality;
> > >
> > > -	if (!tpm_validate_command(chip, buf, bufsiz))
> > > +	if (!tpm_validate_command(chip, space, buf, bufsiz))
> > >  		return -EINVAL;
> > >
> > >  	if (bufsiz > TPM_BUFSIZE)
> > > --
> > > 2.9.3
> > >
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index bf0c3fa..158c1db 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -328,7 +328,9 @@  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
 }
 EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
 
-static bool tpm_validate_command(struct tpm_chip *chip, const u8 *cmd,
+static bool tpm_validate_command(struct tpm_chip *chip,
+				 struct tpm_space *space,
+				 const u8 *cmd,
 				 size_t len)
 {
 	const struct tpm_input_header *header = (const void *)cmd;
@@ -340,6 +342,9 @@  static bool tpm_validate_command(struct tpm_chip *chip, const u8 *cmd,
 	if (len < TPM_HEADER_SIZE)
 		return false;
 
+	if (!space)
+		return true;
+
 	if (chip->flags & TPM_CHIP_FLAG_TPM2 && chip->nr_commands) {
 		cc = be32_to_cpu(header->ordinal);
 
@@ -386,7 +391,7 @@  ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
 	unsigned long stop;
 	bool need_locality;
 
-	if (!tpm_validate_command(chip, buf, bufsiz))
+	if (!tpm_validate_command(chip, space, buf, bufsiz))
 		return -EINVAL;
 
 	if (bufsiz > TPM_BUFSIZE)