linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tpm: fix buffer overflow in /dev/tpm0
@ 2016-09-11 12:19 Jarkko Sakkinen
  2016-09-11 12:51 ` Jarkko Sakkinen
  2016-09-12  4:05 ` Jason Gunthorpe
  0 siblings, 2 replies; 5+ messages in thread
From: Jarkko Sakkinen @ 2016-09-11 12:19 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Jarkko Sakkinen, Marcel Selhorst, Jason Gunthorpe,
	moderated list:TPM DEVICE DRIVER, open list

tpm_write() does not check whether the buffer has at least enough space
for the header before passing it to tpm_transmit() so an overflow can
happen.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm-interface.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index fd863ff..6a67f7f 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -337,6 +337,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
 	u32 count, ordinal;
 	unsigned long stop;
 
+	if (bufsiz < TPM_HEADER_SIZE)
+		return -EINVAL;
+
 	if (bufsiz > TPM_BUFSIZE)
 		bufsiz = TPM_BUFSIZE;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tpm: fix buffer overflow in /dev/tpm0
  2016-09-11 12:19 [PATCH] tpm: fix buffer overflow in /dev/tpm0 Jarkko Sakkinen
@ 2016-09-11 12:51 ` Jarkko Sakkinen
  2016-09-11 18:57   ` Jarkko Sakkinen
  2016-09-12  4:05 ` Jason Gunthorpe
  1 sibling, 1 reply; 5+ messages in thread
From: Jarkko Sakkinen @ 2016-09-11 12:51 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Marcel Selhorst, Jason Gunthorpe,
	moderated list:TPM DEVICE DRIVER, open list

On Sun, Sep 11, 2016 at 03:19:00PM +0300, Jarkko Sakkinen wrote:
> tpm_write() does not check whether the buffer has at least enough space
> for the header before passing it to tpm_transmit() so an overflow can
> happen.
> 
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

This is usable neither as read nor write primitive for an exploit. Still
it makes sense to validate the input here.

/Jarkko

> ---
>  drivers/char/tpm/tpm-interface.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index fd863ff..6a67f7f 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -337,6 +337,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
>  	u32 count, ordinal;
>  	unsigned long stop;
>  
> +	if (bufsiz < TPM_HEADER_SIZE)
> +		return -EINVAL;
> +
>  	if (bufsiz > TPM_BUFSIZE)
>  		bufsiz = TPM_BUFSIZE;
>  
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tpm: fix buffer overflow in /dev/tpm0
  2016-09-11 12:51 ` Jarkko Sakkinen
@ 2016-09-11 18:57   ` Jarkko Sakkinen
  0 siblings, 0 replies; 5+ messages in thread
From: Jarkko Sakkinen @ 2016-09-11 18:57 UTC (permalink / raw)
  To: Peter Huewe
  Cc: Marcel Selhorst, Jason Gunthorpe,
	moderated list:TPM DEVICE DRIVER, open list

On Sun, Sep 11, 2016 at 03:51:42PM +0300, Jarkko Sakkinen wrote:
> On Sun, Sep 11, 2016 at 03:19:00PM +0300, Jarkko Sakkinen wrote:
> > tpm_write() does not check whether the buffer has at least enough space
> > for the header before passing it to tpm_transmit() so an overflow can
> > happen.
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> 
> This is usable neither as read nor write primitive for an exploit. Still
> it makes sense to validate the input here.

Cannot add fixes line for this one as it's from pre-GIT times...

/Jarkko

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tpm: fix buffer overflow in /dev/tpm0
  2016-09-11 12:19 [PATCH] tpm: fix buffer overflow in /dev/tpm0 Jarkko Sakkinen
  2016-09-11 12:51 ` Jarkko Sakkinen
@ 2016-09-12  4:05 ` Jason Gunthorpe
  2016-09-12  7:50   ` Jarkko Sakkinen
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2016-09-12  4:05 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Peter Huewe, Marcel Selhorst, moderated list:TPM DEVICE DRIVER,
	open list

On Sun, Sep 11, 2016 at 03:19:00PM +0300, Jarkko Sakkinen wrote:
> tpm_write() does not check whether the buffer has at least enough space
> for the header before passing it to tpm_transmit() so an overflow can
> happen.

Eh?

tpm_write uses a hard wired buffer size of TPM_BUFSIZE when working
with tpm_transmit.

in_size is never used except for the copy. We should probably fix that
to sanity check the header length vs in_size.

That doesn't seem to be a security issue however because the header
length is propery limited to TPM_BUFSIZE and the data buffer is
allocated specifically for that process using kzalloc.

Jason

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tpm: fix buffer overflow in /dev/tpm0
  2016-09-12  4:05 ` Jason Gunthorpe
@ 2016-09-12  7:50   ` Jarkko Sakkinen
  0 siblings, 0 replies; 5+ messages in thread
From: Jarkko Sakkinen @ 2016-09-12  7:50 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Peter Huewe, Marcel Selhorst, moderated list:TPM DEVICE DRIVER,
	open list

On Sun, Sep 11, 2016 at 10:05:46PM -0600, Jason Gunthorpe wrote:
> On Sun, Sep 11, 2016 at 03:19:00PM +0300, Jarkko Sakkinen wrote:
> > tpm_write() does not check whether the buffer has at least enough space
> > for the header before passing it to tpm_transmit() so an overflow can
> > happen.
> 
> Eh?
> 
> tpm_write uses a hard wired buffer size of TPM_BUFSIZE when working
> with tpm_transmit.
> 
> in_size is never used except for the copy. We should probably fix that
> to sanity check the header length vs in_size.
> 
> That doesn't seem to be a security issue however because the header
> length is propery limited to TPM_BUFSIZE and the data buffer is
> allocated specifically for that process using kzalloc.

I was working on something else when I bumped into this. The commit
message is not the best possible but still the issue is valid although
it does not cause any imaginable harm because there is always
TPM_BUFSIZE of room in the buffer passed by tpm_write.

I'll update the commit message not to speak about tpm_write.

"tpm_transmit() does not check whether the bufsiz can contain the TPM
header. Add check for this and return -EINVAL if it the buffer is too
small."

The check should be in tpm_transmit() and also the commit message should
be only about that.

> Jason

/Jarkko

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-12  7:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-11 12:19 [PATCH] tpm: fix buffer overflow in /dev/tpm0 Jarkko Sakkinen
2016-09-11 12:51 ` Jarkko Sakkinen
2016-09-11 18:57   ` Jarkko Sakkinen
2016-09-12  4:05 ` Jason Gunthorpe
2016-09-12  7:50   ` Jarkko Sakkinen

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).