Skip to content

Commit 5faafba

Browse files
author
Jarkko Sakkinen
committed
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: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Tested-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com> Tested-by: Alexander Steffen <Alexander.Steffen@infineon.com>
1 parent 29b47ce commit 5faafba

File tree

8 files changed

+43
-53
lines changed

8 files changed

+43
-53
lines changed

drivers/char/tpm/tpm-dev-common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
4848
if (ret)
4949
goto out_lock;
5050

51-
len = tpm_transmit(chip, space, buf, bufsiz, TPM_TRANSMIT_UNLOCKED);
51+
len = tpm_transmit(chip, buf, bufsiz, TPM_TRANSMIT_UNLOCKED);
5252
if (len < 0)
5353
ret = len;
5454

drivers/char/tpm/tpm-interface.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ static int tpm_go_idle(struct tpm_chip *chip, unsigned int flags)
120120
return chip->ops->go_idle(chip);
121121
}
122122

123-
static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
124-
void *buf, size_t bufsiz, unsigned int flags)
123+
static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz,
124+
unsigned int flags)
125125
{
126126
struct tpm_header *header = buf;
127127
int rc;
@@ -199,7 +199,6 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
199199
/**
200200
* tpm_transmit - Internal kernel interface to transmit TPM commands.
201201
* @chip: a TPM chip to use
202-
* @space: a TPM space
203202
* @buf: a TPM command buffer
204203
* @bufsiz: length of the TPM command buffer
205204
* @flags: TPM transmit flags
@@ -215,8 +214,8 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
215214
* * The response length - OK
216215
* * -errno - A system error
217216
*/
218-
ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
219-
u8 *buf, size_t bufsiz, unsigned int flags)
217+
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
218+
unsigned int flags)
220219
{
221220
struct tpm_header *header = (struct tpm_header *)buf;
222221
/* space for header and handles */
@@ -225,8 +224,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
225224
bool has_locality = false;
226225
u32 rc = 0;
227226
ssize_t ret;
228-
const size_t save_size = min(space ? sizeof(save) : TPM_HEADER_SIZE,
229-
bufsiz);
227+
const size_t save_size = min(sizeof(save), bufsiz);
230228
/* the command code is where the return code will be */
231229
u32 cc = be32_to_cpu(header->return_code);
232230

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

259-
ret = tpm_try_transmit(chip, space, buf, bufsiz, flags);
257+
ret = tpm_try_transmit(chip, buf, bufsiz, flags);
260258

261259
/* This may fail but do not override ret. */
262260
tpm_go_idle(chip, flags);
@@ -302,7 +300,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
302300
/**
303301
* tpm_transmit_cmd - send a tpm command to the device
304302
* @chip: a TPM chip to use
305-
* @space: a TPM space
306303
* @buf: a TPM command buffer
307304
* @min_rsp_body_length: minimum expected length of response body
308305
* @flags: TPM transmit flags
@@ -313,15 +310,15 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
313310
* * -errno - A system error
314311
* * TPM_RC - A TPM error
315312
*/
316-
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
317-
struct tpm_buf *buf, size_t min_rsp_body_length,
318-
unsigned int flags, const char *desc)
313+
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
314+
size_t min_rsp_body_length, unsigned int flags,
315+
const char *desc)
319316
{
320317
const struct tpm_header *header = (struct tpm_header *)buf->data;
321318
int err;
322319
ssize_t len;
323320

324-
len = tpm_transmit(chip, space, buf->data, PAGE_SIZE, flags);
321+
len = tpm_transmit(chip, buf->data, PAGE_SIZE, flags);
325322
if (len < 0)
326323
return len;
327324

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

472469
memcpy(buf.data, cmd, buflen);
473-
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0,
470+
rc = tpm_transmit_cmd(chip, &buf, 0, 0,
474471
"attempting to a send a command");
475472
tpm_buf_destroy(&buf);
476473
out:

drivers/char/tpm/tpm-sysfs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
5252

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

55-
rc = tpm_transmit_cmd(chip, NULL, &tpm_buf,
56-
READ_PUBEK_RESULT_MIN_BODY_SIZE, 0,
57-
"attempting to read the PUBEK");
55+
rc = tpm_transmit_cmd(chip, &tpm_buf, READ_PUBEK_RESULT_MIN_BODY_SIZE,
56+
0, "attempting to read the PUBEK");
5857
if (rc) {
5958
tpm_buf_destroy(&tpm_buf);
6059
return 0;

drivers/char/tpm/tpm.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,11 @@ enum tpm_transmit_flags {
498498
TPM_TRANSMIT_NESTED = BIT(1),
499499
};
500500

501-
ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
502-
u8 *buf, size_t bufsiz, unsigned int flags);
503-
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
504-
struct tpm_buf *buf, size_t min_rsp_body_length,
505-
unsigned int flags, const char *desc);
501+
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
502+
unsigned int flags);
503+
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
504+
size_t min_rsp_body_length, unsigned int flags,
505+
const char *desc);
506506
int tpm_get_timeouts(struct tpm_chip *);
507507
int tpm_auto_startup(struct tpm_chip *chip);
508508

drivers/char/tpm/tpm1-cmd.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ static int tpm1_startup(struct tpm_chip *chip)
334334

335335
tpm_buf_append_u16(&buf, TPM_ST_CLEAR);
336336

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

462-
rc = tpm_transmit_cmd(chip, NULL, &buf, TPM_DIGEST_SIZE, 0, log_msg);
461+
rc = tpm_transmit_cmd(chip, &buf, TPM_DIGEST_SIZE, 0, log_msg);
463462
tpm_buf_destroy(&buf);
464463
return rc;
465464
}
@@ -489,7 +488,7 @@ ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
489488
tpm_buf_append_u32(&buf, 4);
490489
tpm_buf_append_u32(&buf, subcap_id);
491490
}
492-
rc = tpm_transmit_cmd(chip, NULL, &buf, min_cap_length, 0, desc);
491+
rc = tpm_transmit_cmd(chip, &buf, min_cap_length, 0, desc);
493492
if (!rc)
494493
*cap = *(cap_t *)&buf.data[TPM_HEADER_SIZE + 4];
495494
tpm_buf_destroy(&buf);
@@ -530,8 +529,7 @@ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
530529
do {
531530
tpm_buf_append_u32(&buf, num_bytes);
532531

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

577575
tpm_buf_append_u32(&buf, pcr_idx);
578576

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

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

drivers/char/tpm/tpm2-cmd.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
197197
tpm_buf_append(&buf, (const unsigned char *)pcr_select,
198198
sizeof(pcr_select));
199199

200-
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0, res_buf ?
200+
rc = tpm_transmit_cmd(chip, &buf, 0, 0, res_buf ?
201201
"attempting to read a pcr value" : NULL);
202202
if (rc == 0 && res_buf) {
203203
out = (struct tpm2_pcr_read_out *)&buf.data[TPM_HEADER_SIZE];
@@ -264,7 +264,7 @@ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, u32 count,
264264
}
265265
}
266266

267-
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0,
267+
rc = tpm_transmit_cmd(chip, &buf, 0, 0,
268268
"attempting extend a PCR value");
269269

270270
tpm_buf_destroy(&buf);
@@ -309,7 +309,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
309309
do {
310310
tpm_buf_reset(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_RANDOM);
311311
tpm_buf_append_u16(&buf, num_bytes);
312-
err = tpm_transmit_cmd(chip, NULL, &buf,
312+
err = tpm_transmit_cmd(chip, &buf,
313313
offsetof(struct tpm2_get_random_out,
314314
buffer),
315315
0, "attempting get random");
@@ -362,7 +362,7 @@ void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle,
362362

363363
tpm_buf_append_u32(&buf, handle);
364364

365-
tpm_transmit_cmd(chip, NULL, &buf, 0, flags, "flushing context");
365+
tpm_transmit_cmd(chip, &buf, 0, flags, "flushing context");
366366
tpm_buf_destroy(&buf);
367367
}
368368

@@ -476,7 +476,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
476476
goto out;
477477
}
478478

479-
rc = tpm_transmit_cmd(chip, NULL, &buf, 4, 0, "sealing data");
479+
rc = tpm_transmit_cmd(chip, &buf, 4, 0, "sealing data");
480480
if (rc)
481481
goto out;
482482

@@ -558,7 +558,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
558558
goto out;
559559
}
560560

561-
rc = tpm_transmit_cmd(chip, NULL, &buf, 4, flags, "loading blob");
561+
rc = tpm_transmit_cmd(chip, &buf, 4, flags, "loading blob");
562562
if (!rc)
563563
*blob_handle = be32_to_cpup(
564564
(__be32 *) &buf.data[TPM_HEADER_SIZE]);
@@ -608,7 +608,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
608608
options->blobauth /* hmac */,
609609
TPM_DIGEST_SIZE);
610610

611-
rc = tpm_transmit_cmd(chip, NULL, &buf, 6, flags, "unsealing");
611+
rc = tpm_transmit_cmd(chip, &buf, 6, flags, "unsealing");
612612
if (rc > 0)
613613
rc = -EPERM;
614614

@@ -698,7 +698,7 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, u32 *value,
698698
tpm_buf_append_u32(&buf, TPM2_CAP_TPM_PROPERTIES);
699699
tpm_buf_append_u32(&buf, property_id);
700700
tpm_buf_append_u32(&buf, 1);
701-
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0, NULL);
701+
rc = tpm_transmit_cmd(chip, &buf, 0, 0, NULL);
702702
if (!rc) {
703703
out = (struct tpm2_get_cap_out *)
704704
&buf.data[TPM_HEADER_SIZE];
@@ -728,7 +728,7 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type)
728728
if (rc)
729729
return;
730730
tpm_buf_append_u16(&buf, shutdown_type);
731-
tpm_transmit_cmd(chip, NULL, &buf, 0, 0, "stopping the TPM");
731+
tpm_transmit_cmd(chip, &buf, 0, 0, "stopping the TPM");
732732
tpm_buf_destroy(&buf);
733733
}
734734

@@ -757,7 +757,7 @@ static int tpm2_do_selftest(struct tpm_chip *chip)
757757
return rc;
758758

759759
tpm_buf_append_u8(&buf, full);
760-
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0,
760+
rc = tpm_transmit_cmd(chip, &buf, 0, 0,
761761
"attempting the self test");
762762
tpm_buf_destroy(&buf);
763763

@@ -794,7 +794,7 @@ int tpm2_probe(struct tpm_chip *chip)
794794
tpm_buf_append_u32(&buf, TPM2_CAP_TPM_PROPERTIES);
795795
tpm_buf_append_u32(&buf, TPM_PT_TOTAL_COMMANDS);
796796
tpm_buf_append_u32(&buf, 1);
797-
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0, NULL);
797+
rc = tpm_transmit_cmd(chip, &buf, 0, 0, NULL);
798798
/* We ignore TPM return codes on purpose. */
799799
if (rc >= 0) {
800800
out = (struct tpm_header *)buf.data;
@@ -833,8 +833,7 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
833833
tpm_buf_append_u32(&buf, 0);
834834
tpm_buf_append_u32(&buf, 1);
835835

836-
rc = tpm_transmit_cmd(chip, NULL, &buf, 9, 0,
837-
"get tpm pcr allocation");
836+
rc = tpm_transmit_cmd(chip, &buf, 9, 0, "get tpm pcr allocation");
838837
if (rc)
839838
goto out;
840839

@@ -905,7 +904,7 @@ static int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip)
905904
tpm_buf_append_u32(&buf, TPM2_CC_FIRST);
906905
tpm_buf_append_u32(&buf, nr_commands);
907906

908-
rc = tpm_transmit_cmd(chip, NULL, &buf, 9 + 4 * nr_commands, 0, NULL);
907+
rc = tpm_transmit_cmd(chip, &buf, 9 + 4 * nr_commands, 0, NULL);
909908
if (rc) {
910909
tpm_buf_destroy(&buf);
911910
goto out;
@@ -962,8 +961,7 @@ static int tpm2_startup(struct tpm_chip *chip)
962961
return rc;
963962

964963
tpm_buf_append_u16(&buf, TPM2_SU_CLEAR);
965-
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0,
966-
"attempting to start the TPM");
964+
rc = tpm_transmit_cmd(chip, &buf, 0, 0, "attempting to start the TPM");
967965
tpm_buf_destroy(&buf);
968966

969967
return rc;

drivers/char/tpm/tpm2-space.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ static int tpm2_load_context(struct tpm_chip *chip, u8 *buf,
8383
body_size = sizeof(*ctx) + be16_to_cpu(ctx->blob_size);
8484
tpm_buf_append(&tbuf, &buf[*offset], body_size);
8585

86-
rc = tpm_transmit_cmd(chip, NULL, &tbuf, 4,
87-
TPM_TRANSMIT_UNLOCKED, NULL);
86+
rc = tpm_transmit_cmd(chip, &tbuf, 4, TPM_TRANSMIT_UNLOCKED, NULL);
8887
if (rc < 0) {
8988
dev_warn(&chip->dev, "%s: failed with a system error %d\n",
9089
__func__, rc);
@@ -132,8 +131,7 @@ static int tpm2_save_context(struct tpm_chip *chip, u32 handle, u8 *buf,
132131

133132
tpm_buf_append_u32(&tbuf, handle);
134133

135-
rc = tpm_transmit_cmd(chip, NULL, &tbuf, 0,
136-
TPM_TRANSMIT_UNLOCKED, NULL);
134+
rc = tpm_transmit_cmd(chip, &tbuf, 0, TPM_TRANSMIT_UNLOCKED, NULL);
137135
if (rc < 0) {
138136
dev_warn(&chip->dev, "%s: failed with a system error %d\n",
139137
__func__, rc);

drivers/char/tpm/tpm_vtpm_proxy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality)
416416

417417
proxy_dev->state |= STATE_DRIVER_COMMAND;
418418

419-
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, TPM_TRANSMIT_NESTED,
419+
rc = tpm_transmit_cmd(chip, &buf, 0, TPM_TRANSMIT_NESTED,
420420
"attempting to set locality");
421421

422422
proxy_dev->state &= ~STATE_DRIVER_COMMAND;

0 commit comments

Comments
 (0)