diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-08-04 19:39:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-08-04 19:39:07 -0400 |
commit | a6831a89bcaf351cf41b3a5922640c89beaaf9eb (patch) | |
tree | fcc857ebdb5d4853c6ea58b84b1fbc11d86c1815 | |
parent | 62d1716304d1bb35ad9cdafe40efbbb6b3981cfe (diff) | |
parent | fa4f99c05320eb28bf6ba52a9adf64d888da1f9e (diff) |
Merge tag 'tpmdd-next-20190805' of git://git.infradead.org/users/jjs/linux-tpmdd
Pull tpm fixes from Jarkko Sakkinen:
"Two bug fixes that did not make into my first pull request"
* tag 'tpmdd-next-20190805' of git://git.infradead.org/users/jjs/linux-tpmdd:
tpm: tpm_ibm_vtpm: Fix unallocated banks
tpm: Fix null pointer dereference on chip register error path
-rw-r--r-- | drivers/char/tpm/tpm-chip.c | 43 | ||||
-rw-r--r-- | drivers/char/tpm/tpm.h | 2 | ||||
-rw-r--r-- | drivers/char/tpm/tpm1-cmd.c | 36 | ||||
-rw-r--r-- | drivers/char/tpm/tpm2-cmd.c | 6 |
4 files changed, 63 insertions, 24 deletions
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index d47ad10a35fe..4838c6a9f0f2 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c | |||
@@ -77,6 +77,18 @@ static int tpm_go_idle(struct tpm_chip *chip) | |||
77 | return chip->ops->go_idle(chip); | 77 | return chip->ops->go_idle(chip); |
78 | } | 78 | } |
79 | 79 | ||
80 | static void tpm_clk_enable(struct tpm_chip *chip) | ||
81 | { | ||
82 | if (chip->ops->clk_enable) | ||
83 | chip->ops->clk_enable(chip, true); | ||
84 | } | ||
85 | |||
86 | static void tpm_clk_disable(struct tpm_chip *chip) | ||
87 | { | ||
88 | if (chip->ops->clk_enable) | ||
89 | chip->ops->clk_enable(chip, false); | ||
90 | } | ||
91 | |||
80 | /** | 92 | /** |
81 | * tpm_chip_start() - power on the TPM | 93 | * tpm_chip_start() - power on the TPM |
82 | * @chip: a TPM chip to use | 94 | * @chip: a TPM chip to use |
@@ -89,13 +101,12 @@ int tpm_chip_start(struct tpm_chip *chip) | |||
89 | { | 101 | { |
90 | int ret; | 102 | int ret; |
91 | 103 | ||
92 | if (chip->ops->clk_enable) | 104 | tpm_clk_enable(chip); |
93 | chip->ops->clk_enable(chip, true); | ||
94 | 105 | ||
95 | if (chip->locality == -1) { | 106 | if (chip->locality == -1) { |
96 | ret = tpm_request_locality(chip); | 107 | ret = tpm_request_locality(chip); |
97 | if (ret) { | 108 | if (ret) { |
98 | chip->ops->clk_enable(chip, false); | 109 | tpm_clk_disable(chip); |
99 | return ret; | 110 | return ret; |
100 | } | 111 | } |
101 | } | 112 | } |
@@ -103,8 +114,7 @@ int tpm_chip_start(struct tpm_chip *chip) | |||
103 | ret = tpm_cmd_ready(chip); | 114 | ret = tpm_cmd_ready(chip); |
104 | if (ret) { | 115 | if (ret) { |
105 | tpm_relinquish_locality(chip); | 116 | tpm_relinquish_locality(chip); |
106 | if (chip->ops->clk_enable) | 117 | tpm_clk_disable(chip); |
107 | chip->ops->clk_enable(chip, false); | ||
108 | return ret; | 118 | return ret; |
109 | } | 119 | } |
110 | 120 | ||
@@ -124,8 +134,7 @@ void tpm_chip_stop(struct tpm_chip *chip) | |||
124 | { | 134 | { |
125 | tpm_go_idle(chip); | 135 | tpm_go_idle(chip); |
126 | tpm_relinquish_locality(chip); | 136 | tpm_relinquish_locality(chip); |
127 | if (chip->ops->clk_enable) | 137 | tpm_clk_disable(chip); |
128 | chip->ops->clk_enable(chip, false); | ||
129 | } | 138 | } |
130 | EXPORT_SYMBOL_GPL(tpm_chip_stop); | 139 | EXPORT_SYMBOL_GPL(tpm_chip_stop); |
131 | 140 | ||
@@ -545,6 +554,20 @@ static int tpm_add_hwrng(struct tpm_chip *chip) | |||
545 | return hwrng_register(&chip->hwrng); | 554 | return hwrng_register(&chip->hwrng); |
546 | } | 555 | } |
547 | 556 | ||
557 | static int tpm_get_pcr_allocation(struct tpm_chip *chip) | ||
558 | { | ||
559 | int rc; | ||
560 | |||
561 | rc = (chip->flags & TPM_CHIP_FLAG_TPM2) ? | ||
562 | tpm2_get_pcr_allocation(chip) : | ||
563 | tpm1_get_pcr_allocation(chip); | ||
564 | |||
565 | if (rc > 0) | ||
566 | return -ENODEV; | ||
567 | |||
568 | return rc; | ||
569 | } | ||
570 | |||
548 | /* | 571 | /* |
549 | * tpm_chip_register() - create a character device for the TPM chip | 572 | * tpm_chip_register() - create a character device for the TPM chip |
550 | * @chip: TPM chip to use. | 573 | * @chip: TPM chip to use. |
@@ -564,6 +587,12 @@ int tpm_chip_register(struct tpm_chip *chip) | |||
564 | if (rc) | 587 | if (rc) |
565 | return rc; | 588 | return rc; |
566 | rc = tpm_auto_startup(chip); | 589 | rc = tpm_auto_startup(chip); |
590 | if (rc) { | ||
591 | tpm_chip_stop(chip); | ||
592 | return rc; | ||
593 | } | ||
594 | |||
595 | rc = tpm_get_pcr_allocation(chip); | ||
567 | tpm_chip_stop(chip); | 596 | tpm_chip_stop(chip); |
568 | if (rc) | 597 | if (rc) |
569 | return rc; | 598 | return rc; |
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index e503ffc3aa39..a7fea3e0ca86 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h | |||
@@ -394,6 +394,7 @@ int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf); | |||
394 | ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, | 394 | ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, |
395 | const char *desc, size_t min_cap_length); | 395 | const char *desc, size_t min_cap_length); |
396 | int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max); | 396 | int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max); |
397 | int tpm1_get_pcr_allocation(struct tpm_chip *chip); | ||
397 | unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); | 398 | unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); |
398 | int tpm_pm_suspend(struct device *dev); | 399 | int tpm_pm_suspend(struct device *dev); |
399 | int tpm_pm_resume(struct device *dev); | 400 | int tpm_pm_resume(struct device *dev); |
@@ -449,6 +450,7 @@ int tpm2_unseal_trusted(struct tpm_chip *chip, | |||
449 | ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, | 450 | ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, |
450 | u32 *value, const char *desc); | 451 | u32 *value, const char *desc); |
451 | 452 | ||
453 | ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip); | ||
452 | int tpm2_auto_startup(struct tpm_chip *chip); | 454 | int tpm2_auto_startup(struct tpm_chip *chip); |
453 | void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); | 455 | void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); |
454 | unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); | 456 | unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); |
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c index faacbe1ffa1a..149e953ca369 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c | |||
@@ -699,18 +699,6 @@ int tpm1_auto_startup(struct tpm_chip *chip) | |||
699 | goto out; | 699 | goto out; |
700 | } | 700 | } |
701 | 701 | ||
702 | chip->allocated_banks = kcalloc(1, sizeof(*chip->allocated_banks), | ||
703 | GFP_KERNEL); | ||
704 | if (!chip->allocated_banks) { | ||
705 | rc = -ENOMEM; | ||
706 | goto out; | ||
707 | } | ||
708 | |||
709 | chip->allocated_banks[0].alg_id = TPM_ALG_SHA1; | ||
710 | chip->allocated_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1]; | ||
711 | chip->allocated_banks[0].crypto_id = HASH_ALGO_SHA1; | ||
712 | chip->nr_allocated_banks = 1; | ||
713 | |||
714 | return rc; | 702 | return rc; |
715 | out: | 703 | out: |
716 | if (rc > 0) | 704 | if (rc > 0) |
@@ -779,3 +767,27 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr) | |||
779 | return rc; | 767 | return rc; |
780 | } | 768 | } |
781 | 769 | ||
770 | /** | ||
771 | * tpm1_get_pcr_allocation() - initialize the allocated bank | ||
772 | * @chip: TPM chip to use. | ||
773 | * | ||
774 | * The function initializes the SHA1 allocated bank to extend PCR | ||
775 | * | ||
776 | * Return: | ||
777 | * * 0 on success, | ||
778 | * * < 0 on error. | ||
779 | */ | ||
780 | int tpm1_get_pcr_allocation(struct tpm_chip *chip) | ||
781 | { | ||
782 | chip->allocated_banks = kcalloc(1, sizeof(*chip->allocated_banks), | ||
783 | GFP_KERNEL); | ||
784 | if (!chip->allocated_banks) | ||
785 | return -ENOMEM; | ||
786 | |||
787 | chip->allocated_banks[0].alg_id = TPM_ALG_SHA1; | ||
788 | chip->allocated_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1]; | ||
789 | chip->allocated_banks[0].crypto_id = HASH_ALGO_SHA1; | ||
790 | chip->nr_allocated_banks = 1; | ||
791 | |||
792 | return 0; | ||
793 | } | ||
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index d103545e4055..ba9acae83bff 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c | |||
@@ -840,7 +840,7 @@ struct tpm2_pcr_selection { | |||
840 | u8 pcr_select[3]; | 840 | u8 pcr_select[3]; |
841 | } __packed; | 841 | } __packed; |
842 | 842 | ||
843 | static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) | 843 | ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) |
844 | { | 844 | { |
845 | struct tpm2_pcr_selection pcr_selection; | 845 | struct tpm2_pcr_selection pcr_selection; |
846 | struct tpm_buf buf; | 846 | struct tpm_buf buf; |
@@ -1040,10 +1040,6 @@ int tpm2_auto_startup(struct tpm_chip *chip) | |||
1040 | goto out; | 1040 | goto out; |
1041 | } | 1041 | } |
1042 | 1042 | ||
1043 | rc = tpm2_get_pcr_allocation(chip); | ||
1044 | if (rc) | ||
1045 | goto out; | ||
1046 | |||
1047 | rc = tpm2_get_cc_attrs_tbl(chip); | 1043 | rc = tpm2_get_cc_attrs_tbl(chip); |
1048 | 1044 | ||
1049 | out: | 1045 | out: |