diff options
author | Stefan Berger <stefanb@linux.vnet.ibm.com> | 2018-06-26 15:09:32 -0400 |
---|---|---|
committer | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> | 2018-07-28 10:03:11 -0400 |
commit | 5c2a640aff73914e11ac0db310b32d3b7a1b87ad (patch) | |
tree | 26ab375331cfdd09aabc85709bd3c23c7afa04d3 | |
parent | 58bac8cc3010ccb845572a3512fc16c9aaa5e50e (diff) |
ima: Use tpm_default_chip() and call TPM functions with a tpm_chip
Rather than accessing the TPM functions by passing a NULL pointer for
the tpm_chip, which causes a lookup for a suitable chip every time, get a
hold of a tpm_chip and access the TPM functions using it.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
-rw-r--r-- | security/integrity/ima/ima.h | 1 | ||||
-rw-r--r-- | security/integrity/ima/ima_crypto.c | 2 | ||||
-rw-r--r-- | security/integrity/ima/ima_init.c | 11 | ||||
-rw-r--r-- | security/integrity/ima/ima_queue.c | 2 |
4 files changed, 7 insertions, 9 deletions
diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 78c15264b17b..dc212c59d4d6 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h | |||
@@ -56,6 +56,7 @@ extern int ima_policy_flag; | |||
56 | extern int ima_used_chip; | 56 | extern int ima_used_chip; |
57 | extern int ima_hash_algo; | 57 | extern int ima_hash_algo; |
58 | extern int ima_appraise; | 58 | extern int ima_appraise; |
59 | extern struct tpm_chip *ima_tpm_chip; | ||
59 | 60 | ||
60 | /* IMA event related data */ | 61 | /* IMA event related data */ |
61 | struct ima_event_data { | 62 | struct ima_event_data { |
diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index 4e085a17124f..88082f35adb2 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c | |||
@@ -634,7 +634,7 @@ static void __init ima_pcrread(int idx, u8 *pcr) | |||
634 | if (!ima_used_chip) | 634 | if (!ima_used_chip) |
635 | return; | 635 | return; |
636 | 636 | ||
637 | if (tpm_pcr_read(NULL, idx, pcr) != 0) | 637 | if (tpm_pcr_read(ima_tpm_chip, idx, pcr) != 0) |
638 | pr_err("Error Communicating to TPM chip\n"); | 638 | pr_err("Error Communicating to TPM chip\n"); |
639 | } | 639 | } |
640 | 640 | ||
diff --git a/security/integrity/ima/ima_init.c b/security/integrity/ima/ima_init.c index 29b72cd2502e..1437ed3dbccc 100644 --- a/security/integrity/ima/ima_init.c +++ b/security/integrity/ima/ima_init.c | |||
@@ -27,6 +27,7 @@ | |||
27 | /* name for boot aggregate entry */ | 27 | /* name for boot aggregate entry */ |
28 | static const char *boot_aggregate_name = "boot_aggregate"; | 28 | static const char *boot_aggregate_name = "boot_aggregate"; |
29 | int ima_used_chip; | 29 | int ima_used_chip; |
30 | struct tpm_chip *ima_tpm_chip; | ||
30 | 31 | ||
31 | /* Add the boot aggregate to the IMA measurement list and extend | 32 | /* Add the boot aggregate to the IMA measurement list and extend |
32 | * the PCR register. | 33 | * the PCR register. |
@@ -106,17 +107,13 @@ void __init ima_load_x509(void) | |||
106 | 107 | ||
107 | int __init ima_init(void) | 108 | int __init ima_init(void) |
108 | { | 109 | { |
109 | u8 pcr_i[TPM_DIGEST_SIZE]; | ||
110 | int rc; | 110 | int rc; |
111 | 111 | ||
112 | ima_used_chip = 0; | 112 | ima_tpm_chip = tpm_default_chip(); |
113 | rc = tpm_pcr_read(NULL, 0, pcr_i); | ||
114 | if (rc == 0) | ||
115 | ima_used_chip = 1; | ||
116 | 113 | ||
114 | ima_used_chip = ima_tpm_chip != NULL; | ||
117 | if (!ima_used_chip) | 115 | if (!ima_used_chip) |
118 | pr_info("No TPM chip found, activating TPM-bypass! (rc=%d)\n", | 116 | pr_info("No TPM chip found, activating TPM-bypass!\n"); |
119 | rc); | ||
120 | 117 | ||
121 | rc = integrity_init_keyring(INTEGRITY_KEYRING_IMA); | 118 | rc = integrity_init_keyring(INTEGRITY_KEYRING_IMA); |
122 | if (rc) | 119 | if (rc) |
diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c index 418f35e38015..c6303fa19a49 100644 --- a/security/integrity/ima/ima_queue.c +++ b/security/integrity/ima/ima_queue.c | |||
@@ -145,7 +145,7 @@ static int ima_pcr_extend(const u8 *hash, int pcr) | |||
145 | if (!ima_used_chip) | 145 | if (!ima_used_chip) |
146 | return result; | 146 | return result; |
147 | 147 | ||
148 | result = tpm_pcr_extend(NULL, pcr, hash); | 148 | result = tpm_pcr_extend(ima_tpm_chip, pcr, hash); |
149 | if (result != 0) | 149 | if (result != 0) |
150 | pr_err("Error Communicating to TPM chip, result: %d\n", result); | 150 | pr_err("Error Communicating to TPM chip, result: %d\n", result); |
151 | return result; | 151 | return result; |