Skip to content

Commit a2b095e

Browse files
committed
Merge tag 'tpmdd-next-v5.12-rc1-v2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm updates from Jarkko Sakkinen: "New features: - Cr50 I2C TPM driver - sysfs exports of PCR registers in TPM 2.0 chips Bug fixes: - bug fixes for tpm_tis driver, which had a racy wait for hardware state change to be ready to send a command to the TPM chip. The bug has existed already since 2006, but has only made itself known in recent past. This is the same as the "last time" :-) - Otherwise there's bunch of fixes for not as alarming regressions. I think the list is about the same as last time, except I added fixes for some disjoint bugs in trusted keys that I found some time ago" * tag 'tpmdd-next-v5.12-rc1-v2' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: KEYS: trusted: Reserve TPM for seal and unseal operations KEYS: trusted: Fix migratable=1 failing KEYS: trusted: Fix incorrect handling of tpm_get_random() tpm/ppi: Constify static struct attribute_group ABI: add sysfs description for tpm exports of PCR registers tpm: add sysfs exports for all banks of PCR registers keys: Update comment for restrict_link_by_key_or_keyring_chain tpm: Remove tpm_dev_wq_lock char: tpm: add i2c driver for cr50 tpm: Fix fall-through warnings for Clang tpm_tis: Clean up locality release tpm_tis: Fix check_locality for correct locality acquisition
2 parents 177626c + 8c657a0 commit a2b095e

File tree

15 files changed

+1054
-66
lines changed

15 files changed

+1054
-66
lines changed

Documentation/ABI/stable/sysfs-class-tpm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,17 @@ Description: The "tpm_version_major" property shows the TCG spec major version
194194
Example output::
195195

196196
2
197+
198+
What: /sys/class/tpm/tpmX/pcr-H/N
199+
Date: March 2021
200+
KernelVersion: 5.12
201+
202+
Description: produces output in compact hex representation for PCR
203+
number N from hash bank H. N is the numeric value of
204+
the PCR number and H is the crypto string
205+
representation of the hash
206+
207+
Example output::
208+
209+
cat /sys/class/tpm/tpm0/pcr-sha256/7
210+
2ED93F199692DC6788EFA6A1FE74514AB9760B2A6CEEAEF6C808C13E4ABB0D42

crypto/asymmetric_keys/restrict.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ int restrict_link_by_key_or_keyring(struct key *dest_keyring,
244244
* @payload: The payload of the new key.
245245
* @trusted: A key or ring of keys that can be used to vouch for the new cert.
246246
*
247-
* Check the new certificate only against the key or keys passed in the data
248-
* parameter. If one of those is the signing key and validates the new
249-
* certificate, then mark the new certificate as being ok to link.
247+
* Check the new certificate against the key or keys passed in the data
248+
* parameter and against the keys already linked to the destination keyring. If
249+
* one of those is the signing key and validates the new certificate, then mark
250+
* the new certificate as being ok to link.
250251
*
251252
* Returns 0 if the new certificate was accepted, -ENOKEY if we
252253
* couldn't find a matching parent certificate in the trusted list,

drivers/char/tpm/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ config TCG_TIS_SYNQUACER
8686
To compile this driver as a module, choose M here;
8787
the module will be called tpm_tis_synquacer.
8888

89+
config TCG_TIS_I2C_CR50
90+
tristate "TPM Interface Specification 2.0 Interface (I2C - CR50)"
91+
depends on I2C
92+
select TCG_CR50
93+
help
94+
This is a driver for the Google cr50 I2C TPM interface which is a
95+
custom microcontroller and requires a custom i2c protocol interface
96+
to handle the limitations of the hardware. To compile this driver
97+
as a module, choose M here; the module will be called tcg_tis_i2c_cr50.
98+
8999
config TCG_TIS_I2C_ATMEL
90100
tristate "TPM Interface Specification 1.2 Interface (I2C - Atmel)"
91101
depends on I2C

drivers/char/tpm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o
2727
tpm_tis_spi-y := tpm_tis_spi_main.o
2828
tpm_tis_spi-$(CONFIG_TCG_TIS_SPI_CR50) += tpm_tis_spi_cr50.o
2929

30+
obj-$(CONFIG_TCG_TIS_I2C_CR50) += tpm_tis_i2c_cr50.o
31+
3032
obj-$(CONFIG_TCG_TIS_I2C_ATMEL) += tpm_i2c_atmel.o
3133
obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
3234
obj-$(CONFIG_TCG_TIS_I2C_NUVOTON) += tpm_i2c_nuvoton.o

drivers/char/tpm/eventlog/tpm1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ static int get_event_name(char *dest, struct tcpa_event *event,
210210
default:
211211
break;
212212
}
213+
break;
213214
default:
214215
break;
215216
}

drivers/char/tpm/tpm-chip.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ static void tpm_devs_release(struct device *dev)
278278
{
279279
struct tpm_chip *chip = container_of(dev, struct tpm_chip, devs);
280280

281+
dump_stack();
282+
281283
/* release the master device reference */
282284
put_device(&chip->dev);
283285
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "tpm-dev.h"
2121

2222
static struct workqueue_struct *tpm_dev_wq;
23-
static DEFINE_MUTEX(tpm_dev_wq_lock);
2423

2524
static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
2625
u8 *buf, size_t bufsiz)

drivers/char/tpm/tpm-sysfs.c

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,190 @@ static const struct attribute_group tpm2_dev_group = {
337337
.attrs = tpm2_dev_attrs,
338338
};
339339

340+
struct tpm_pcr_attr {
341+
int alg_id;
342+
int pcr;
343+
struct device_attribute attr;
344+
};
345+
346+
#define to_tpm_pcr_attr(a) container_of(a, struct tpm_pcr_attr, attr)
347+
348+
static ssize_t pcr_value_show(struct device *dev,
349+
struct device_attribute *attr,
350+
char *buf)
351+
{
352+
struct tpm_pcr_attr *ha = to_tpm_pcr_attr(attr);
353+
struct tpm_chip *chip = to_tpm_chip(dev);
354+
struct tpm_digest digest;
355+
int i;
356+
int digest_size = 0;
357+
int rc;
358+
char *str = buf;
359+
360+
for (i = 0; i < chip->nr_allocated_banks; i++)
361+
if (ha->alg_id == chip->allocated_banks[i].alg_id)
362+
digest_size = chip->allocated_banks[i].digest_size;
363+
/* should never happen */
364+
if (!digest_size)
365+
return -EINVAL;
366+
367+
digest.alg_id = ha->alg_id;
368+
rc = tpm_pcr_read(chip, ha->pcr, &digest);
369+
if (rc)
370+
return rc;
371+
for (i = 0; i < digest_size; i++)
372+
str += sprintf(str, "%02X", digest.digest[i]);
373+
str += sprintf(str, "\n");
374+
375+
return str - buf;
376+
}
377+
378+
/*
379+
* The following set of defines represents all the magic to build
380+
* the per hash attribute groups for displaying each bank of PCRs.
381+
* The only slight problem with this approach is that every PCR is
382+
* hard coded to be present, so you don't know if an PCR is missing
383+
* until a cat of the file returns -EINVAL
384+
*
385+
* Also note you must ignore checkpatch warnings in this macro
386+
* code. This is deep macro magic that checkpatch.pl doesn't
387+
* understand.
388+
*/
389+
390+
/* Note, this must match TPM2_PLATFORM_PCR which is fixed at 24. */
391+
#define _TPM_HELPER(_alg, _hash, F) \
392+
F(_alg, _hash, 0) \
393+
F(_alg, _hash, 1) \
394+
F(_alg, _hash, 2) \
395+
F(_alg, _hash, 3) \
396+
F(_alg, _hash, 4) \
397+
F(_alg, _hash, 5) \
398+
F(_alg, _hash, 6) \
399+
F(_alg, _hash, 7) \
400+
F(_alg, _hash, 8) \
401+
F(_alg, _hash, 9) \
402+
F(_alg, _hash, 10) \
403+
F(_alg, _hash, 11) \
404+
F(_alg, _hash, 12) \
405+
F(_alg, _hash, 13) \
406+
F(_alg, _hash, 14) \
407+
F(_alg, _hash, 15) \
408+
F(_alg, _hash, 16) \
409+
F(_alg, _hash, 17) \
410+
F(_alg, _hash, 18) \
411+
F(_alg, _hash, 19) \
412+
F(_alg, _hash, 20) \
413+
F(_alg, _hash, 21) \
414+
F(_alg, _hash, 22) \
415+
F(_alg, _hash, 23)
416+
417+
/* ignore checkpatch warning about trailing ; in macro. */
418+
#define PCR_ATTR(_alg, _hash, _pcr) \
419+
static struct tpm_pcr_attr dev_attr_pcr_##_hash##_##_pcr = { \
420+
.alg_id = _alg, \
421+
.pcr = _pcr, \
422+
.attr = { \
423+
.attr = { \
424+
.name = __stringify(_pcr), \
425+
.mode = 0444 \
426+
}, \
427+
.show = pcr_value_show \
428+
} \
429+
};
430+
431+
#define PCR_ATTRS(_alg, _hash) \
432+
_TPM_HELPER(_alg, _hash, PCR_ATTR)
433+
434+
/* ignore checkpatch warning about trailing , in macro. */
435+
#define PCR_ATTR_VAL(_alg, _hash, _pcr) \
436+
&dev_attr_pcr_##_hash##_##_pcr.attr.attr,
437+
438+
#define PCR_ATTR_GROUP_ARRAY(_alg, _hash) \
439+
static struct attribute *pcr_group_attrs_##_hash[] = { \
440+
_TPM_HELPER(_alg, _hash, PCR_ATTR_VAL) \
441+
NULL \
442+
}
443+
444+
#define PCR_ATTR_GROUP(_alg, _hash) \
445+
static struct attribute_group pcr_group_##_hash = { \
446+
.name = "pcr-" __stringify(_hash), \
447+
.attrs = pcr_group_attrs_##_hash \
448+
}
449+
450+
#define PCR_ATTR_BUILD(_alg, _hash) \
451+
PCR_ATTRS(_alg, _hash) \
452+
PCR_ATTR_GROUP_ARRAY(_alg, _hash); \
453+
PCR_ATTR_GROUP(_alg, _hash)
454+
/*
455+
* End of macro structure to build an attribute group containing 24
456+
* PCR value files for each supported hash algorithm
457+
*/
458+
459+
/*
460+
* The next set of macros implements the cleverness for each hash to
461+
* build a static attribute group called pcr_group_<hash> which can be
462+
* added to chip->groups[].
463+
*
464+
* The first argument is the TPM algorithm id and the second is the
465+
* hash used as both the suffix and the group name. Note: the group
466+
* name is a directory in the top level tpm class with the name
467+
* pcr-<hash>, so it must not clash with any other names already
468+
* in the sysfs directory.
469+
*/
470+
PCR_ATTR_BUILD(TPM_ALG_SHA1, sha1);
471+
PCR_ATTR_BUILD(TPM_ALG_SHA256, sha256);
472+
PCR_ATTR_BUILD(TPM_ALG_SHA384, sha384);
473+
PCR_ATTR_BUILD(TPM_ALG_SHA512, sha512);
474+
PCR_ATTR_BUILD(TPM_ALG_SM3_256, sm3);
475+
476+
340477
void tpm_sysfs_add_device(struct tpm_chip *chip)
341478
{
479+
int i;
480+
342481
WARN_ON(chip->groups_cnt != 0);
482+
343483
if (chip->flags & TPM_CHIP_FLAG_TPM2)
344484
chip->groups[chip->groups_cnt++] = &tpm2_dev_group;
345485
else
346486
chip->groups[chip->groups_cnt++] = &tpm1_dev_group;
487+
488+
/* add one group for each bank hash */
489+
for (i = 0; i < chip->nr_allocated_banks; i++) {
490+
switch (chip->allocated_banks[i].alg_id) {
491+
case TPM_ALG_SHA1:
492+
chip->groups[chip->groups_cnt++] = &pcr_group_sha1;
493+
break;
494+
case TPM_ALG_SHA256:
495+
chip->groups[chip->groups_cnt++] = &pcr_group_sha256;
496+
break;
497+
case TPM_ALG_SHA384:
498+
chip->groups[chip->groups_cnt++] = &pcr_group_sha384;
499+
break;
500+
case TPM_ALG_SHA512:
501+
chip->groups[chip->groups_cnt++] = &pcr_group_sha512;
502+
break;
503+
case TPM_ALG_SM3_256:
504+
chip->groups[chip->groups_cnt++] = &pcr_group_sm3;
505+
break;
506+
default:
507+
/*
508+
* If triggers, send a patch to add both a
509+
* PCR_ATTR_BUILD() macro above for the
510+
* missing algorithm as well as an additional
511+
* case in this switch statement.
512+
*/
513+
dev_err(&chip->dev,
514+
"TPM with unsupported bank algorithm 0x%04x",
515+
chip->allocated_banks[i].alg_id);
516+
break;
517+
}
518+
}
519+
520+
/*
521+
* This will only trigger if someone has added an additional
522+
* hash to the tpm_algorithms enum without incrementing
523+
* TPM_MAX_HASHES.
524+
*/
525+
WARN_ON(chip->groups_cnt > TPM_MAX_HASHES + 1);
347526
}

drivers/char/tpm/tpm.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ extern const struct file_operations tpmrm_fops;
164164
extern struct idr dev_nums_idr;
165165

166166
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz);
167-
ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
168-
size_t min_rsp_body_length, const char *desc);
169167
int tpm_get_timeouts(struct tpm_chip *);
170168
int tpm_auto_startup(struct tpm_chip *chip);
171169

@@ -194,8 +192,6 @@ static inline void tpm_msleep(unsigned int delay_msec)
194192
int tpm_chip_start(struct tpm_chip *chip);
195193
void tpm_chip_stop(struct tpm_chip *chip);
196194
struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
197-
__must_check int tpm_try_get_ops(struct tpm_chip *chip);
198-
void tpm_put_ops(struct tpm_chip *chip);
199195

200196
struct tpm_chip *tpm_chip_alloc(struct device *dev,
201197
const struct tpm_class_ops *ops);

drivers/char/tpm/tpm_ppi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ static struct attribute *ppi_attrs[] = {
358358
&dev_attr_tcg_operations.attr,
359359
&dev_attr_vs_operations.attr, NULL,
360360
};
361-
static struct attribute_group ppi_attr_grp = {
361+
static const struct attribute_group ppi_attr_grp = {
362362
.name = "ppi",
363363
.attrs = ppi_attrs
364364
};

0 commit comments

Comments
 (0)