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

tpm: use tpm2_pcr_read() in tpm2_do_selftest()

tpm2_do_selftest() performs a PCR read during the TPM initialization phase.
This patch replaces the PCR read code with a call to tpm2_pcr_read().

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkine@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>

authored by

Roberto Sassu and committed by
James Morris
28707bf2 91f7f3d7

+1 -30
+1 -30
drivers/char/tpm/tpm2-cmd.c
··· 35 35 u8 full_test; 36 36 } __packed; 37 37 38 - struct tpm2_pcr_read_in { 39 - __be32 pcr_selects_cnt; 40 - __be16 hash_alg; 41 - u8 pcr_select_size; 42 - u8 pcr_select[TPM2_PCR_SELECT_MIN]; 43 - } __packed; 44 - 45 38 struct tpm2_get_tpm_pt_in { 46 39 __be32 cap_id; 47 40 __be32 property_id; ··· 61 68 union tpm2_cmd_params { 62 69 struct tpm2_startup_in startup_in; 63 70 struct tpm2_self_test_in selftest_in; 64 - struct tpm2_pcr_read_in pcrread_in; 65 71 struct tpm2_get_tpm_pt_in get_tpm_pt_in; 66 72 struct tpm2_get_tpm_pt_out get_tpm_pt_out; 67 73 struct tpm2_get_random_in getrandom_in; ··· 205 213 TPM_UNDEFINED, /* 18d */ 206 214 TPM_UNDEFINED, /* 18e */ 207 215 TPM_UNDEFINED /* 18f */ 208 - }; 209 - 210 - #define TPM2_PCR_READ_IN_SIZE \ 211 - (sizeof(struct tpm_input_header) + \ 212 - sizeof(struct tpm2_pcr_read_in)) 213 - 214 - static const struct tpm_input_header tpm2_pcrread_header = { 215 - .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS), 216 - .length = cpu_to_be32(TPM2_PCR_READ_IN_SIZE), 217 - .ordinal = cpu_to_be32(TPM2_CC_PCR_READ) 218 216 }; 219 217 220 218 struct tpm2_pcr_read_out { ··· 880 898 unsigned int loops; 881 899 unsigned int delay_msec = 100; 882 900 unsigned long duration; 883 - struct tpm2_cmd cmd; 884 901 int i; 885 902 886 903 duration = tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST); ··· 892 911 893 912 for (i = 0; i < loops; i++) { 894 913 /* Attempt to read a PCR value */ 895 - cmd.header.in = tpm2_pcrread_header; 896 - cmd.params.pcrread_in.pcr_selects_cnt = cpu_to_be32(1); 897 - cmd.params.pcrread_in.hash_alg = cpu_to_be16(TPM2_ALG_SHA1); 898 - cmd.params.pcrread_in.pcr_select_size = TPM2_PCR_SELECT_MIN; 899 - cmd.params.pcrread_in.pcr_select[0] = 0x01; 900 - cmd.params.pcrread_in.pcr_select[1] = 0x00; 901 - cmd.params.pcrread_in.pcr_select[2] = 0x00; 902 - 903 - rc = tpm_transmit_cmd(chip, NULL, &cmd, sizeof(cmd), 0, 0, 904 - NULL); 914 + rc = tpm2_pcr_read(chip, 0, NULL); 905 915 if (rc < 0) 906 916 break; 907 917 908 - rc = be32_to_cpu(cmd.header.out.return_code); 909 918 if (rc != TPM2_RC_TESTING) 910 919 break; 911 920