linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tpm: Wrap the buffer from the caller to tpm_buf in tpm_send()
@ 2019-09-16  8:50 Jarkko Sakkinen
  2019-09-16 21:03 ` Jerry Snitselaar
  0 siblings, 1 reply; 4+ messages in thread
From: Jarkko Sakkinen @ 2019-09-16  8:50 UTC (permalink / raw)
  To: linux-integrity
  Cc: Jarkko Sakkinen, Mimi Zohar, stable, Peter Huewe,
	Jason Gunthorpe, Arnd Bergmann, Greg Kroah-Hartman, open list

tpm_send() does not give anymore the result back to the caller. This
would require another memcpy(), which kind of tells that the whole
approach is somewhat broken. Instead, as Mimi suggested, this commit
just wraps the data to the tpm_buf, and thus the result will not go to
the garbage.

Obviously this assumes from the caller that it passes large enough
buffer, which makes the whole API somewhat broken because it could be
different size than @buflen but since trusted keys is the only module
using this API right now I think that this fix is sufficient for the
moment.

In the near future the plan is to replace the parameters with a tpm_buf
created by the caller.

Reported-by: Mimi Zohar <zohar@linux.ibm.com>
Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
Cc: stable@vger.kernel.org
Fixes: 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm-interface.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index d9ace5480665..2459d36dd8cc 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -358,13 +358,9 @@ int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
 	if (!chip)
 		return -ENODEV;
 
-	rc = tpm_buf_init(&buf, 0, 0);
-	if (rc)
-		goto out;
-
-	memcpy(buf.data, cmd, buflen);
+	buf.data = cmd;
 	rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to a send a command");
-	tpm_buf_destroy(&buf);
+
 out:
 	tpm_put_ops(chip);
 	return rc;
-- 
2.20.1


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

* Re: [PATCH] tpm: Wrap the buffer from the caller to tpm_buf in tpm_send()
  2019-09-16  8:50 [PATCH] tpm: Wrap the buffer from the caller to tpm_buf in tpm_send() Jarkko Sakkinen
@ 2019-09-16 21:03 ` Jerry Snitselaar
  2019-09-16 21:04   ` Jerry Snitselaar
  0 siblings, 1 reply; 4+ messages in thread
From: Jerry Snitselaar @ 2019-09-16 21:03 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: linux-integrity, Mimi Zohar, stable, Peter Huewe,
	Jason Gunthorpe, Arnd Bergmann, Greg Kroah-Hartman, open list

On Mon Sep 16 19, Jarkko Sakkinen wrote:
>tpm_send() does not give anymore the result back to the caller. This
>would require another memcpy(), which kind of tells that the whole
>approach is somewhat broken. Instead, as Mimi suggested, this commit
>just wraps the data to the tpm_buf, and thus the result will not go to
>the garbage.
>
>Obviously this assumes from the caller that it passes large enough
>buffer, which makes the whole API somewhat broken because it could be
>different size than @buflen but since trusted keys is the only module
>using this API right now I think that this fix is sufficient for the
>moment.
>
>In the near future the plan is to replace the parameters with a tpm_buf
>created by the caller.
>
>Reported-by: Mimi Zohar <zohar@linux.ibm.com>
>Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
>Cc: stable@vger.kernel.org
>Fixes: 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter")
>Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>---
> drivers/char/tpm/tpm-interface.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
>index d9ace5480665..2459d36dd8cc 100644
>--- a/drivers/char/tpm/tpm-interface.c
>+++ b/drivers/char/tpm/tpm-interface.c
>@@ -358,13 +358,9 @@ int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
> 	if (!chip)
> 		return -ENODEV;
>
>-	rc = tpm_buf_init(&buf, 0, 0);
>-	if (rc)
>-		goto out;
>-
>-	memcpy(buf.data, cmd, buflen);
>+	buf.data = cmd;
> 	rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to a send a command");
>-	tpm_buf_destroy(&buf);
>+
> out:
> 	tpm_put_ops(chip);
> 	return rc;
>-- 
>2.20.1
>

Nothing uses the out label any longer so it should be dropped as well, but other than that...

Acked-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH] tpm: Wrap the buffer from the caller to tpm_buf in tpm_send()
  2019-09-16 21:03 ` Jerry Snitselaar
@ 2019-09-16 21:04   ` Jerry Snitselaar
  2019-09-17 19:13     ` Jarkko Sakkinen
  0 siblings, 1 reply; 4+ messages in thread
From: Jerry Snitselaar @ 2019-09-16 21:04 UTC (permalink / raw)
  To: Jarkko Sakkinen, linux-integrity, Mimi Zohar, stable,
	Peter Huewe, Jason Gunthorpe, Arnd Bergmann, Greg Kroah-Hartman,
	open list

On Mon Sep 16 19, Jerry Snitselaar wrote:
>On Mon Sep 16 19, Jarkko Sakkinen wrote:
>>tpm_send() does not give anymore the result back to the caller. This
>>would require another memcpy(), which kind of tells that the whole
>>approach is somewhat broken. Instead, as Mimi suggested, this commit
>>just wraps the data to the tpm_buf, and thus the result will not go to
>>the garbage.
>>
>>Obviously this assumes from the caller that it passes large enough
>>buffer, which makes the whole API somewhat broken because it could be
>>different size than @buflen but since trusted keys is the only module
>>using this API right now I think that this fix is sufficient for the
>>moment.
>>
>>In the near future the plan is to replace the parameters with a tpm_buf
>>created by the caller.
>>
>>Reported-by: Mimi Zohar <zohar@linux.ibm.com>
>>Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
>>Cc: stable@vger.kernel.org
>>Fixes: 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter")
>>Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>>---
>>drivers/char/tpm/tpm-interface.c | 8 ++------
>>1 file changed, 2 insertions(+), 6 deletions(-)
>>
>>diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
>>index d9ace5480665..2459d36dd8cc 100644
>>--- a/drivers/char/tpm/tpm-interface.c
>>+++ b/drivers/char/tpm/tpm-interface.c
>>@@ -358,13 +358,9 @@ int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
>>	if (!chip)
>>		return -ENODEV;
>>
>>-	rc = tpm_buf_init(&buf, 0, 0);
>>-	if (rc)
>>-		goto out;
>>-
>>-	memcpy(buf.data, cmd, buflen);
>>+	buf.data = cmd;
>>	rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to a send a command");
>>-	tpm_buf_destroy(&buf);
>>+
>>out:
>>	tpm_put_ops(chip);
>>	return rc;
>>-- 
>>2.20.1
>>
>
>Nothing uses the out label any longer so it should be dropped as well, but other than that...
>
>Acked-by: Jerry Snitselaar <jsnitsel@redhat.com>

sigh (wrong emacs macro hit), that should be:

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH] tpm: Wrap the buffer from the caller to tpm_buf in tpm_send()
  2019-09-16 21:04   ` Jerry Snitselaar
@ 2019-09-17 19:13     ` Jarkko Sakkinen
  0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2019-09-17 19:13 UTC (permalink / raw)
  To: linux-integrity, Mimi Zohar, stable, Peter Huewe,
	Jason Gunthorpe, Arnd Bergmann, Greg Kroah-Hartman, open list

On Mon, Sep 16, 2019 at 02:04:54PM -0700, Jerry Snitselaar wrote:
> On Mon Sep 16 19, Jerry Snitselaar wrote:
> > On Mon Sep 16 19, Jarkko Sakkinen wrote:
> > > tpm_send() does not give anymore the result back to the caller. This
> > > would require another memcpy(), which kind of tells that the whole
> > > approach is somewhat broken. Instead, as Mimi suggested, this commit
> > > just wraps the data to the tpm_buf, and thus the result will not go to
> > > the garbage.
> > > 
> > > Obviously this assumes from the caller that it passes large enough
> > > buffer, which makes the whole API somewhat broken because it could be
> > > different size than @buflen but since trusted keys is the only module
> > > using this API right now I think that this fix is sufficient for the
> > > moment.
> > > 
> > > In the near future the plan is to replace the parameters with a tpm_buf
> > > created by the caller.
> > > 
> > > Reported-by: Mimi Zohar <zohar@linux.ibm.com>
> > > Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
> > > Cc: stable@vger.kernel.org
> > > Fixes: 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter")
> > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > ---
> > > drivers/char/tpm/tpm-interface.c | 8 ++------
> > > 1 file changed, 2 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> > > index d9ace5480665..2459d36dd8cc 100644
> > > --- a/drivers/char/tpm/tpm-interface.c
> > > +++ b/drivers/char/tpm/tpm-interface.c
> > > @@ -358,13 +358,9 @@ int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
> > > 	if (!chip)
> > > 		return -ENODEV;
> > > 
> > > -	rc = tpm_buf_init(&buf, 0, 0);
> > > -	if (rc)
> > > -		goto out;
> > > -
> > > -	memcpy(buf.data, cmd, buflen);
> > > +	buf.data = cmd;
> > > 	rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to a send a command");
> > > -	tpm_buf_destroy(&buf);
> > > +
> > > out:
> > > 	tpm_put_ops(chip);
> > > 	return rc;
> > > -- 
> > > 2.20.1
> > > 
> > 
> > Nothing uses the out label any longer so it should be dropped as well, but other than that...
> > 
> > Acked-by: Jerry Snitselaar <jsnitsel@redhat.com>
> 
> sigh (wrong emacs macro hit), that should be:
> 
> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>

Thank you! I pushed the commit to master/next.

/Jarkko

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

end of thread, other threads:[~2019-09-17 19:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16  8:50 [PATCH] tpm: Wrap the buffer from the caller to tpm_buf in tpm_send() Jarkko Sakkinen
2019-09-16 21:03 ` Jerry Snitselaar
2019-09-16 21:04   ` Jerry Snitselaar
2019-09-17 19:13     ` 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).