Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+63 -24
+36 -7
drivers/char/tpm/tpm-chip.c
··· 77 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 93 * tpm_chip_start() - power on the TPM 82 94 * @chip: a TPM chip to use ··· 101 89 { 102 90 int ret; 103 91 104 - if (chip->ops->clk_enable) 105 - chip->ops->clk_enable(chip, true); 92 + tpm_clk_enable(chip); 106 93 107 94 if (chip->locality == -1) { 108 95 ret = tpm_request_locality(chip); 109 96 if (ret) { 110 - chip->ops->clk_enable(chip, false); 97 + tpm_clk_disable(chip); 111 98 return ret; 112 99 } 113 100 } ··· 114 103 ret = tpm_cmd_ready(chip); 115 104 if (ret) { 116 105 tpm_relinquish_locality(chip); 117 - if (chip->ops->clk_enable) 118 - chip->ops->clk_enable(chip, false); 106 + tpm_clk_disable(chip); 119 107 return ret; 120 108 } 121 109 ··· 134 124 { 135 125 tpm_go_idle(chip); 136 126 tpm_relinquish_locality(chip); 137 - if (chip->ops->clk_enable) 138 - chip->ops->clk_enable(chip, false); 127 + tpm_clk_disable(chip); 139 128 } 140 129 EXPORT_SYMBOL_GPL(tpm_chip_stop); 141 130 ··· 554 545 return hwrng_register(&chip->hwrng); 555 546 } 556 547 548 + static int tpm_get_pcr_allocation(struct tpm_chip *chip) 549 + { 550 + int rc; 551 + 552 + rc = (chip->flags & TPM_CHIP_FLAG_TPM2) ? 553 + tpm2_get_pcr_allocation(chip) : 554 + tpm1_get_pcr_allocation(chip); 555 + 556 + if (rc > 0) 557 + return -ENODEV; 558 + 559 + return rc; 560 + } 561 + 557 562 /* 558 563 * tpm_chip_register() - create a character device for the TPM chip 559 564 * @chip: TPM chip to use. ··· 587 564 if (rc) 588 565 return rc; 589 566 rc = tpm_auto_startup(chip); 567 + if (rc) { 568 + tpm_chip_stop(chip); 569 + return rc; 570 + } 571 + 572 + rc = tpm_get_pcr_allocation(chip); 590 573 tpm_chip_stop(chip); 591 574 if (rc) 592 575 return rc;
+2
drivers/char/tpm/tpm.h
··· 394 394 ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, 395 395 const char *desc, size_t min_cap_length); 396 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 398 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); 398 399 int tpm_pm_suspend(struct device *dev); 399 400 int tpm_pm_resume(struct device *dev); ··· 450 449 ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, 451 450 u32 *value, const char *desc); 452 451 452 + ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip); 453 453 int tpm2_auto_startup(struct tpm_chip *chip); 454 454 void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); 455 455 unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
+24 -12
drivers/char/tpm/tpm1-cmd.c
··· 699 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 702 return rc; 715 703 out: 716 704 if (rc > 0) ··· 767 779 return rc; 768 780 } 769 781 782 + /** 783 + * tpm1_get_pcr_allocation() - initialize the allocated bank 784 + * @chip: TPM chip to use. 785 + * 786 + * The function initializes the SHA1 allocated bank to extend PCR 787 + * 788 + * Return: 789 + * * 0 on success, 790 + * * < 0 on error. 791 + */ 792 + int tpm1_get_pcr_allocation(struct tpm_chip *chip) 793 + { 794 + chip->allocated_banks = kcalloc(1, sizeof(*chip->allocated_banks), 795 + GFP_KERNEL); 796 + if (!chip->allocated_banks) 797 + return -ENOMEM; 798 + 799 + chip->allocated_banks[0].alg_id = TPM_ALG_SHA1; 800 + chip->allocated_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1]; 801 + chip->allocated_banks[0].crypto_id = HASH_ALGO_SHA1; 802 + chip->nr_allocated_banks = 1; 803 + 804 + return 0; 805 + }
+1 -5
drivers/char/tpm/tpm2-cmd.c
··· 840 840 u8 pcr_select[3]; 841 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 845 struct tpm2_pcr_selection pcr_selection; 846 846 struct tpm_buf buf; ··· 1039 1039 if (rc) 1040 1040 goto out; 1041 1041 } 1042 - 1043 - rc = tpm2_get_pcr_allocation(chip); 1044 - if (rc) 1045 - goto out; 1046 1042 1047 1043 rc = tpm2_get_cc_attrs_tbl(chip); 1048 1044