2 * Copyright (C) 2005,2006,2007,2008 IBM Corporation
5 * Reiner Sailer <sailer@watson.ibm.com>
6 * Leendert van Doorn <leendert@watson.ibm.com>
7 * Mimi Zohar <zohar@us.ibm.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2 of the
15 * initialization and cleanup functions
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/module.h>
21 #include <linux/scatterlist.h>
22 #include <linux/slab.h>
23 #include <linux/err.h>
24 #include <crypto/hash_info.h>
27 /* name for boot aggregate entry */
28 static const char *boot_aggregate_name
= "boot_aggregate";
31 /* Add the boot aggregate to the IMA measurement list and extend
34 * Calculate the boot aggregate, a SHA1 over tpm registers 0-7,
35 * assuming a TPM chip exists, and zeroes if the TPM chip does not
36 * exist. Add the boot aggregate measurement to the measurement
37 * list and extend the PCR register.
39 * If a tpm chip does not exist, indicate the core root of trust is
40 * not hardware based by invalidating the aggregate PCR value.
41 * (The aggregate PCR value is invalidated by adding one value to
42 * the measurement list and extending the aggregate PCR value with
43 * a different value.) Violations add a zero entry to the measurement
44 * list and extend the aggregate PCR value with ff...ff's.
46 static void __init
ima_add_boot_aggregate(void)
48 static const char op
[] = "add_boot_aggregate";
49 const char *audit_cause
= "ENOMEM";
50 struct ima_template_entry
*entry
;
51 struct integrity_iint_cache tmp_iint
, *iint
= &tmp_iint
;
55 struct ima_digest_data hdr
;
56 char digest
[TPM_DIGEST_SIZE
];
59 memset(iint
, 0, sizeof(*iint
));
60 memset(&hash
, 0, sizeof(hash
));
61 iint
->ima_hash
= &hash
.hdr
;
62 iint
->ima_hash
->algo
= HASH_ALGO_SHA1
;
63 iint
->ima_hash
->length
= SHA1_DIGEST_SIZE
;
66 result
= ima_calc_boot_aggregate(&hash
.hdr
);
68 audit_cause
= "hashing_error";
73 result
= ima_alloc_init_template(iint
, NULL
, boot_aggregate_name
,
78 result
= ima_store_template(entry
, violation
, NULL
,
81 ima_free_template_entry(entry
);
84 integrity_audit_msg(AUDIT_INTEGRITY_PCR
, NULL
, boot_aggregate_name
, op
,
85 audit_cause
, result
, 0);
88 int __init
ima_init(void)
90 u8 pcr_i
[TPM_DIGEST_SIZE
];
94 rc
= tpm_pcr_read(TPM_ANY_NUM
, 0, pcr_i
);
99 pr_info("No TPM chip found, activating TPM-bypass!\n");
101 rc
= ima_init_crypto();
104 rc
= ima_init_template();
108 ima_add_boot_aggregate(); /* boot aggregate must be first entry */
111 return ima_fs_init();