Skip to content

Commit 6cc7c26

Browse files
robertosassumimizohar
authored andcommitted
ima: Call ima_calc_boot_aggregate() in ima_eventdigest_init()
If the template field 'd' is chosen and the digest to be added to the measurement entry was not calculated with SHA1 or MD5, it is recalculated with SHA1, by using the passed file descriptor. However, this cannot be done for boot_aggregate, because there is no file descriptor. This patch adds a call to ima_calc_boot_aggregate() in ima_eventdigest_init(), so that the digest can be recalculated also for the boot_aggregate entry. Cc: [email protected] # 3.13.x Fixes: 3ce1217 ("ima: define template fields library and new helpers") Reported-by: Takashi Iwai <[email protected]> Signed-off-by: Roberto Sassu <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 067a436 commit 6cc7c26

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

security/integrity/ima/ima.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extern int ima_hash_algo_idx __ro_after_init;
5757
extern int ima_extra_slots __ro_after_init;
5858
extern int ima_appraise;
5959
extern struct tpm_chip *ima_tpm_chip;
60+
extern const char boot_aggregate_name[];
6061

6162
/* IMA event related data */
6263
struct ima_event_data {
@@ -144,7 +145,7 @@ int ima_calc_buffer_hash(const void *buf, loff_t len,
144145
struct ima_digest_data *hash);
145146
int ima_calc_field_array_hash(struct ima_field_data *field_data,
146147
struct ima_template_entry *entry);
147-
int __init ima_calc_boot_aggregate(struct ima_digest_data *hash);
148+
int ima_calc_boot_aggregate(struct ima_digest_data *hash);
148149
void ima_add_violation(struct file *file, const unsigned char *filename,
149150
struct integrity_iint_cache *iint,
150151
const char *op, const char *cause);

security/integrity/ima/ima_crypto.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,8 @@ static void __init ima_pcrread(u32 idx, struct tpm_digest *d)
806806
* hash algorithm for reading the TPM PCRs as for calculating the boot
807807
* aggregate digest as stored in the measurement list.
808808
*/
809-
static int __init ima_calc_boot_aggregate_tfm(char *digest, u16 alg_id,
810-
struct crypto_shash *tfm)
809+
static int ima_calc_boot_aggregate_tfm(char *digest, u16 alg_id,
810+
struct crypto_shash *tfm)
811811
{
812812
struct tpm_digest d = { .alg_id = alg_id, .digest = {0} };
813813
int rc;
@@ -835,7 +835,7 @@ static int __init ima_calc_boot_aggregate_tfm(char *digest, u16 alg_id,
835835
return rc;
836836
}
837837

838-
int __init ima_calc_boot_aggregate(struct ima_digest_data *hash)
838+
int ima_calc_boot_aggregate(struct ima_digest_data *hash)
839839
{
840840
struct crypto_shash *tfm;
841841
u16 crypto_id, alg_id;

security/integrity/ima/ima_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "ima.h"
2020

2121
/* name for boot aggregate entry */
22-
static const char boot_aggregate_name[] = "boot_aggregate";
22+
const char boot_aggregate_name[] = "boot_aggregate";
2323
struct tpm_chip *ima_tpm_chip;
2424

2525
/* Add the boot aggregate to the IMA measurement list and extend

security/integrity/ima/ima_template_lib.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,24 @@ int ima_eventdigest_init(struct ima_event_data *event_data,
286286
goto out;
287287
}
288288

289+
if ((const char *)event_data->filename == boot_aggregate_name) {
290+
if (ima_tpm_chip) {
291+
hash.hdr.algo = HASH_ALGO_SHA1;
292+
result = ima_calc_boot_aggregate(&hash.hdr);
293+
294+
/* algo can change depending on available PCR banks */
295+
if (!result && hash.hdr.algo != HASH_ALGO_SHA1)
296+
result = -EINVAL;
297+
298+
if (result < 0)
299+
memset(&hash, 0, sizeof(hash));
300+
}
301+
302+
cur_digest = hash.hdr.digest;
303+
cur_digestsize = hash_digest_size[HASH_ALGO_SHA1];
304+
goto out;
305+
}
306+
289307
if (!event_data->file) /* missing info to re-calculate the digest */
290308
return -EINVAL;
291309

0 commit comments

Comments
 (0)