Skip to contentSkip to conversation

tpm: Wrap the buffer from the caller to tpm_buf in tpm_send()

PATCH In review Jarkko Sakkinen 2 participants 4 messages Sep 16, 2019 – Sep 17, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: Wrap the buffer from the caller to tpm_buf in tpm_send()

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.

Fixes 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter")
---
 drivers/char/tpm/tpm-interface.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm-interface.c +2 -6
index d9ace5480665..2459d36dd8cc 100644
@@ -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;
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 42 lines · Jarkko Sakkinen

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.

Fixes 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter")

---
drivers/char/tpm/tpm-interface.c | 8 ++------

1 file changed, 2 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm-interface.c +2 -6
index d9ace5480665..2459d36dd8cc 100644
@@ -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:

Quoted 5 lines
	tpm_put_ops(chip);
	return rc;
Signature · 1 line
2.20.1

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

Reviewed-by
#2 lore raw
Quoted 51 lines · Jerry Snitselaar
Quoted 42 lines · Jarkko Sakkinen

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.

Fixes 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter")

---
drivers/char/tpm/tpm-interface.c | 8 ++------

1 file changed, 2 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm-interface.c +2 -6
index d9ace5480665..2459d36dd8cc 100644
@@ -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:

Quoted 5 lines
	tpm_put_ops(chip);
	return rc;
Signature · 1 line
2.20.1

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

Quoted 1 line

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

#3 lore raw
Quoted 52 lines · Jerry Snitselaar
Quoted 51 lines · Jerry Snitselaar
Quoted 42 lines · Jarkko Sakkinen

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.

Fixes 412eb585587a ("use tpm_buf in tpm_transmit_cmd() as the IO parameter")

---
drivers/char/tpm/tpm-interface.c | 8 ++------

1 file changed, 2 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm-interface.c +2 -6
index d9ace5480665..2459d36dd8cc 100644
@@ -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:

Quoted 5 lines
	tpm_put_ops(chip);
	return rc;
Signature · 1 line
2.20.1

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

Quoted 5 lines
Quoted 1 line

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

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

/Jarkko