Commit 5faafbab authored by Jarkko Sakkinen's avatar Jarkko Sakkinen
Browse files

tpm: remove @space from tpm_transmit()



Remove @space from tpm_transmit() API` in order to completely remove the
bound between low-level transmission functionality and TPM spaces. The
only real dependency existing is the amount of data saved before trying
to send a command to the TPM.

It doesn't really matter if we save always a bit more than needed so
this commit changes the amount saved always to be the size of the TPM
header and three handles.

Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Tested-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
Tested-by: default avatarAlexander Steffen <Alexander.Steffen@infineon.com>
parent 29b47ce9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
	if (ret)
		goto out_lock;

	len = tpm_transmit(chip, space, buf, bufsiz, TPM_TRANSMIT_UNLOCKED);
	len = tpm_transmit(chip, buf, bufsiz, TPM_TRANSMIT_UNLOCKED);
	if (len < 0)
		ret = len;

+11 −14
Original line number Diff line number Diff line
@@ -120,8 +120,8 @@ static int tpm_go_idle(struct tpm_chip *chip, unsigned int flags)
	return chip->ops->go_idle(chip);
}

static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
				void *buf, size_t bufsiz, unsigned int flags)
static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz,
				unsigned int flags)
{
	struct tpm_header *header = buf;
	int rc;
@@ -199,7 +199,6 @@ out_recv:
/**
 * tpm_transmit - Internal kernel interface to transmit TPM commands.
 * @chip:	a TPM chip to use
 * @space:	a TPM space
 * @buf:	a TPM command buffer
 * @bufsiz:	length of the TPM command buffer
 * @flags:	TPM transmit flags
@@ -215,8 +214,8 @@ out_recv:
 * * The response length	- OK
 * * -errno			- A system error
 */
ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
		     u8 *buf, size_t bufsiz, unsigned int flags)
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
		     unsigned int flags)
{
	struct tpm_header *header = (struct tpm_header *)buf;
	/* space for header and handles */
@@ -225,8 +224,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
	bool has_locality = false;
	u32 rc = 0;
	ssize_t ret;
	const size_t save_size = min(space ? sizeof(save) : TPM_HEADER_SIZE,
				     bufsiz);
	const size_t save_size = min(sizeof(save), bufsiz);
	/* the command code is where the return code will be */
	u32 cc = be32_to_cpu(header->return_code);

@@ -256,7 +254,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
		if (ret)
			goto out_locality;

		ret = tpm_try_transmit(chip, space, buf, bufsiz, flags);
		ret = tpm_try_transmit(chip, buf, bufsiz, flags);

		/* This may fail but do not override ret. */
		tpm_go_idle(chip, flags);
@@ -302,7 +300,6 @@ out_locality:
/**
 * tpm_transmit_cmd - send a tpm command to the device
 * @chip:			a TPM chip to use
 * @space:			a TPM space
 * @buf:			a TPM command buffer
 * @min_rsp_body_length:	minimum expected length of response body
 * @flags:			TPM transmit flags
@@ -313,15 +310,15 @@ out_locality:
 * * -errno	- A system error
 * * TPM_RC	- A TPM error
 */
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
			 struct tpm_buf *buf, size_t min_rsp_body_length,
			 unsigned int flags, const char *desc)
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
			 size_t min_rsp_body_length, unsigned int flags,
			 const char *desc)
{
	const struct tpm_header *header = (struct tpm_header *)buf->data;
	int err;
	ssize_t len;

	len = tpm_transmit(chip, space, buf->data, PAGE_SIZE, flags);
	len = tpm_transmit(chip, buf->data, PAGE_SIZE, flags);
	if (len <  0)
		return len;

@@ -470,7 +467,7 @@ int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
		goto out;

	memcpy(buf.data, cmd, buflen);
	rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0,
	rc = tpm_transmit_cmd(chip, &buf, 0, 0,
			      "attempting to a send a command");
	tpm_buf_destroy(&buf);
out:
+2 −3
Original line number Diff line number Diff line
@@ -52,9 +52,8 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,

	tpm_buf_append(&tpm_buf, anti_replay, sizeof(anti_replay));

	rc = tpm_transmit_cmd(chip, NULL, &tpm_buf,
			      READ_PUBEK_RESULT_MIN_BODY_SIZE, 0,
			      "attempting to read the PUBEK");
	rc = tpm_transmit_cmd(chip, &tpm_buf, READ_PUBEK_RESULT_MIN_BODY_SIZE,
			      0, "attempting to read the PUBEK");
	if (rc) {
		tpm_buf_destroy(&tpm_buf);
		return 0;
+5 −5
Original line number Diff line number Diff line
@@ -498,11 +498,11 @@ enum tpm_transmit_flags {
	TPM_TRANSMIT_NESTED      = BIT(1),
};

ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
		     u8 *buf, size_t bufsiz, unsigned int flags);
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
			 struct tpm_buf *buf, size_t min_rsp_body_length,
			 unsigned int flags, const char *desc);
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
		     unsigned int flags);
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
			 size_t min_rsp_body_length, unsigned int flags,
			 const char *desc);
int tpm_get_timeouts(struct tpm_chip *);
int tpm_auto_startup(struct tpm_chip *chip);

+7 −9
Original line number Diff line number Diff line
@@ -334,8 +334,7 @@ static int tpm1_startup(struct tpm_chip *chip)

	tpm_buf_append_u16(&buf, TPM_ST_CLEAR);

	rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0,
			      "attempting to start the TPM");
	rc = tpm_transmit_cmd(chip, &buf, 0, 0, "attempting to start the TPM");
	tpm_buf_destroy(&buf);
	return rc;
}
@@ -459,7 +458,7 @@ int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
	tpm_buf_append_u32(&buf, pcr_idx);
	tpm_buf_append(&buf, hash, TPM_DIGEST_SIZE);

	rc = tpm_transmit_cmd(chip, NULL, &buf, TPM_DIGEST_SIZE, 0, log_msg);
	rc = tpm_transmit_cmd(chip, &buf, TPM_DIGEST_SIZE, 0, log_msg);
	tpm_buf_destroy(&buf);
	return rc;
}
@@ -489,7 +488,7 @@ ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
		tpm_buf_append_u32(&buf, 4);
		tpm_buf_append_u32(&buf, subcap_id);
	}
	rc = tpm_transmit_cmd(chip, NULL, &buf, min_cap_length, 0, desc);
	rc = tpm_transmit_cmd(chip, &buf, min_cap_length, 0, desc);
	if (!rc)
		*cap = *(cap_t *)&buf.data[TPM_HEADER_SIZE + 4];
	tpm_buf_destroy(&buf);
@@ -530,8 +529,7 @@ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
	do {
		tpm_buf_append_u32(&buf, num_bytes);

		rc = tpm_transmit_cmd(chip, NULL, &buf,
				      sizeof(out->rng_data_len), 0,
		rc = tpm_transmit_cmd(chip, &buf, sizeof(out->rng_data_len), 0,
				      "attempting get random");
		if (rc)
			goto out;
@@ -576,7 +574,7 @@ int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)

	tpm_buf_append_u32(&buf, pcr_idx);

	rc = tpm_transmit_cmd(chip, NULL, &buf, TPM_DIGEST_SIZE, 0,
	rc = tpm_transmit_cmd(chip, &buf, TPM_DIGEST_SIZE, 0,
			      "attempting to read a pcr value");
	if (rc)
		goto out;
@@ -610,7 +608,7 @@ static int tpm1_continue_selftest(struct tpm_chip *chip)
	if (rc)
		return rc;

	rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0, "continue selftest");
	rc = tpm_transmit_cmd(chip, &buf, 0, 0, "continue selftest");
	tpm_buf_destroy(&buf);
	return rc;
}
@@ -736,7 +734,7 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr)
		return rc;
	/* now do the actual savestate */
	for (try = 0; try < TPM_RETRY; try++) {
		rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0, NULL);
		rc = tpm_transmit_cmd(chip, &buf, 0, 0, NULL);
		/*
		 * If the TPM indicates that it is too busy to respond to
		 * this command then retry before giving up.  It can take
Loading