1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/module.h>
18#include <linux/scatterlist.h>
19#include <linux/slab.h>
20#include <linux/err.h>
21#include "ima.h"
22
23
24static const char *boot_aggregate_name = "boot_aggregate";
25int ima_used_chip;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42static void __init ima_add_boot_aggregate(void)
43{
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
75int __init ima_init(void)
76{
77 u8 pcr_i[IMA_DIGEST_SIZE];
78 int rc;
79
80 ima_used_chip = 0;
81 rc = tpm_pcr_read(NULL, 0, pcr_i);
82 if (rc == 0)
83 ima_used_chip = 1;
84
85 if (!ima_used_chip)
86 pr_info("IMA: No TPM chip found, activating TPM-bypass! (rc=%d)\n",
87 rc);
88
89 rc = ima_init_crypto();
90 if (rc)
91 return rc;
92 ima_add_boot_aggregate();
93 ima_init_policy();
94
95 return ima_fs_init();
96}
97