blob: 17f1f060306ff3c2aca7c1364b36536d30c0c302 [file] [log] [blame]
Mimi Zohar3323eec92009-02-04 09:06:58 -05001/*
2 * Copyright (C) 2005,2006,2007,2008 IBM Corporation
3 *
4 * Authors:
5 * Reiner Sailer <sailer@watson.ibm.com>
6 * Leendert van Doorn <leendert@watson.ibm.com>
7 * Mimi Zohar <zohar@us.ibm.com>
8 *
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
12 * License.
13 *
14 * File: ima_init.c
15 * initialization and cleanup functions
16 */
17#include <linux/module.h>
18#include <linux/scatterlist.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Mimi Zohar3323eec92009-02-04 09:06:58 -050020#include <linux/err.h>
21#include "ima.h"
22
23/* name for boot aggregate entry */
Mimi Zohar523979a2009-02-11 11:12:28 -050024static const char *boot_aggregate_name = "boot_aggregate";
Mimi Zohar3323eec92009-02-04 09:06:58 -050025int ima_used_chip;
26
27/* Add the boot aggregate to the IMA measurement list and extend
28 * the PCR register.
29 *
30 * Calculate the boot aggregate, a SHA1 over tpm registers 0-7,
31 * assuming a TPM chip exists, and zeroes if the TPM chip does not
32 * exist. Add the boot aggregate measurement to the measurement
33 * list and extend the PCR register.
34 *
35 * If a tpm chip does not exist, indicate the core root of trust is
36 * not hardware based by invalidating the aggregate PCR value.
37 * (The aggregate PCR value is invalidated by adding one value to
38 * the measurement list and extending the aggregate PCR value with
39 * a different value.) Violations add a zero entry to the measurement
40 * list and extend the aggregate PCR value with ff...ff's.
41 */
Eric Paris932995f2009-05-21 15:43:32 -040042static void __init ima_add_boot_aggregate(void)
Mimi Zohar3323eec92009-02-04 09:06:58 -050043{
44 struct ima_template_entry *entry;
45 const char *op = "add_boot_aggregate";
46 const char *audit_cause = "ENOMEM";
47 int result = -ENOMEM;
48 int violation = 1;
49
50 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
51 if (!entry)
52 goto err_out;
53
54 memset(&entry->template, 0, sizeof(entry->template));
55 strncpy(entry->template.file_name, boot_aggregate_name,
56 IMA_EVENT_NAME_LEN_MAX);
57 if (ima_used_chip) {
58 violation = 0;
59 result = ima_calc_boot_aggregate(entry->template.digest);
60 if (result < 0) {
61 audit_cause = "hashing_error";
62 kfree(entry);
63 goto err_out;
64 }
65 }
66 result = ima_store_template(entry, violation, NULL);
67 if (result < 0)
68 kfree(entry);
69 return;
70err_out:
71 integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, boot_aggregate_name, op,
72 audit_cause, result, 0);
73}
74
Eric Paris932995f2009-05-21 15:43:32 -040075int __init ima_init(void)
Mimi Zohar3323eec92009-02-04 09:06:58 -050076{
77 u8 pcr_i[IMA_DIGEST_SIZE];
78 int rc;
79
80 ima_used_chip = 0;
81 rc = tpm_pcr_read(TPM_ANY_NUM, 0, pcr_i);
82 if (rc == 0)
83 ima_used_chip = 1;
84
85 if (!ima_used_chip)
Eric Pariseb8dae92010-04-22 10:49:36 -040086 pr_info("IMA: No TPM chip found, activating TPM-bypass!\n");
Mimi Zohar3323eec92009-02-04 09:06:58 -050087
88 ima_add_boot_aggregate(); /* boot aggregate must be first entry */
89 ima_init_policy();
Mimi Zoharbab73932009-02-04 09:06:59 -050090
91 return ima_fs_init();
92}
93
94void __exit ima_cleanup(void)
95{
96 ima_fs_cleanup();
Mimi Zohar3323eec92009-02-04 09:06:58 -050097}