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
17 #include <linux/module.h>
18 #include <linux/scatterlist.h>
19 #include <linux/err.h>
22 /* name for boot aggregate entry */
23 static const char *boot_aggregate_name = "boot_aggregate";
26 /* Add the boot aggregate to the IMA measurement list and extend
29 * Calculate the boot aggregate, a SHA1 over tpm registers 0-7,
30 * assuming a TPM chip exists, and zeroes if the TPM chip does not
31 * exist. Add the boot aggregate measurement to the measurement
32 * list and extend the PCR register.
34 * If a tpm chip does not exist, indicate the core root of trust is
35 * not hardware based by invalidating the aggregate PCR value.
36 * (The aggregate PCR value is invalidated by adding one value to
37 * the measurement list and extending the aggregate PCR value with
38 * a different value.) Violations add a zero entry to the measurement
39 * list and extend the aggregate PCR value with ff...ff's.
41 static void __init ima_add_boot_aggregate(void)
43 struct ima_template_entry *entry;
44 const char *op = "add_boot_aggregate";
45 const char *audit_cause = "ENOMEM";
49 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
53 memset(&entry->template, 0, sizeof(entry->template));
54 strncpy(entry->template.file_name, boot_aggregate_name,
55 IMA_EVENT_NAME_LEN_MAX);
58 result = ima_calc_boot_aggregate(entry->template.digest);
60 audit_cause = "hashing_error";
65 result = ima_store_template(entry, violation, NULL);
70 integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, boot_aggregate_name, op,
71 audit_cause, result, 0);
74 int __init ima_init(void)
76 u8 pcr_i[IMA_DIGEST_SIZE];
80 rc = tpm_pcr_read(TPM_ANY_NUM, 0, pcr_i);
85 pr_info("No TPM chip found, activating TPM-bypass!\n");
87 ima_add_boot_aggregate(); /* boot aggregate must be first entry */
93 void __exit ima_cleanup(void)