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.

tpm: tpm_ibm_vtpm: Fix unallocated banks

The nr_allocated_banks and allocated banks are initialized as part of
tpm_chip_register. Currently, this is done as part of auto startup
function. However, some drivers, like the ibm vtpm driver, do not run
auto startup during initialization. This results in uninitialized memory
issue and causes a kernel panic during boot.

This patch moves the pcr allocation outside the auto startup function
into tpm_chip_register. This ensures that allocated banks are initialized
in any case.

Fixes: 879b589210a9 ("tpm: retrieve digest size of unknown algorithms with PCR read")
Reported-by: Michal Suchanek <msuchanek@suse.de>
Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Tested-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
Tested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

authored by

Nayna Jain and committed by
Jarkko Sakkinen
fa4f99c0 1e5ac630

+47 -17
+20
drivers/char/tpm/tpm-chip.c
··· 554 return hwrng_register(&chip->hwrng); 555 } 556 557 /* 558 * tpm_chip_register() - create a character device for the TPM chip 559 * @chip: TPM chip to use. ··· 587 if (rc) 588 return rc; 589 rc = tpm_auto_startup(chip); 590 tpm_chip_stop(chip); 591 if (rc) 592 return rc;
··· 554 return hwrng_register(&chip->hwrng); 555 } 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 + 571 /* 572 * tpm_chip_register() - create a character device for the TPM chip 573 * @chip: TPM chip to use. ··· 573 if (rc) 574 return rc; 575 rc = tpm_auto_startup(chip); 576 + if (rc) { 577 + tpm_chip_stop(chip); 578 + return rc; 579 + } 580 + 581 + rc = tpm_get_pcr_allocation(chip); 582 tpm_chip_stop(chip); 583 if (rc) 584 return rc;
+2
drivers/char/tpm/tpm.h
··· 394 ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, 395 const char *desc, size_t min_cap_length); 396 int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max); 397 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); 398 int tpm_pm_suspend(struct device *dev); 399 int tpm_pm_resume(struct device *dev); ··· 450 ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, 451 u32 *value, const char *desc); 452 453 int tpm2_auto_startup(struct tpm_chip *chip); 454 void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); 455 unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
··· 394 ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, 395 const char *desc, size_t min_cap_length); 396 int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max); 397 + int tpm1_get_pcr_allocation(struct tpm_chip *chip); 398 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); 399 int tpm_pm_suspend(struct device *dev); 400 int tpm_pm_resume(struct device *dev); ··· 449 ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, 450 u32 *value, const char *desc); 451 452 + ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip); 453 int tpm2_auto_startup(struct tpm_chip *chip); 454 void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); 455 unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
+24 -12
drivers/char/tpm/tpm1-cmd.c
··· 699 goto out; 700 } 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; 715 out: 716 if (rc > 0) ··· 767 return rc; 768 } 769
··· 699 goto out; 700 } 701 702 return rc; 703 out: 704 if (rc > 0) ··· 779 return rc; 780 } 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 u8 pcr_select[3]; 841 } __packed; 842 843 - static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) 844 { 845 struct tpm2_pcr_selection pcr_selection; 846 struct tpm_buf buf; ··· 1039 if (rc) 1040 goto out; 1041 } 1042 - 1043 - rc = tpm2_get_pcr_allocation(chip); 1044 - if (rc) 1045 - goto out; 1046 1047 rc = tpm2_get_cc_attrs_tbl(chip); 1048
··· 840 u8 pcr_select[3]; 841 } __packed; 842 843 + ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) 844 { 845 struct tpm2_pcr_selection pcr_selection; 846 struct tpm_buf buf; ··· 1039 if (rc) 1040 goto out; 1041 } 1042 1043 rc = tpm2_get_cc_attrs_tbl(chip); 1044