diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-26 14:03:39 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-26 14:03:39 -0400 |
| commit | 8d80ce80e1d58ba9cd3e3972b112cccd6b4008f4 (patch) | |
| tree | 16d3cca8d260c731d02a4e5e1ea5b9817c9c3626 /security/integrity/ima/ima_init.c | |
| parent | 1646df40bb111715a90ce0b86448dabbcc5b3f3d (diff) | |
| parent | 703a3cd72817e99201cef84a8a7aecc60b2b3581 (diff) | |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6: (71 commits)
SELinux: inode_doinit_with_dentry drop no dentry printk
SELinux: new permission between tty audit and audit socket
SELinux: open perm for sock files
smack: fixes for unlabeled host support
keys: make procfiles per-user-namespace
keys: skip keys from another user namespace
keys: consider user namespace in key_permission
keys: distinguish per-uid keys in different namespaces
integrity: ima iint radix_tree_lookup locking fix
TOMOYO: Do not call tomoyo_realpath_init unless registered.
integrity: ima scatterlist bug fix
smack: fix lots of kernel-doc notation
TOMOYO: Don't create securityfs entries unless registered.
TOMOYO: Fix exception policy read failure.
SELinux: convert the avc cache hash list to an hlist
SELinux: code readability with avc_cache
SELinux: remove unused av.decided field
SELinux: more careful use of avd in avc_has_perm_noaudit
SELinux: remove the unused ae.used
SELinux: check seqno when updating an avc_node
...
Diffstat (limited to 'security/integrity/ima/ima_init.c')
| -rw-r--r-- | security/integrity/ima/ima_init.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/security/integrity/ima/ima_init.c b/security/integrity/ima/ima_init.c new file mode 100644 index 000000000000..0b0bb8c978cc --- /dev/null +++ b/security/integrity/ima/ima_init.c | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | /* | ||
| 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> | ||
| 19 | #include <linux/err.h> | ||
| 20 | #include "ima.h" | ||
| 21 | |||
| 22 | /* name for boot aggregate entry */ | ||
| 23 | static const char *boot_aggregate_name = "boot_aggregate"; | ||
| 24 | int ima_used_chip; | ||
| 25 | |||
| 26 | /* Add the boot aggregate to the IMA measurement list and extend | ||
| 27 | * the PCR register. | ||
| 28 | * | ||
| 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. | ||
| 33 | * | ||
| 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. | ||
| 40 | */ | ||
| 41 | static void ima_add_boot_aggregate(void) | ||
| 42 | { | ||
| 43 | struct ima_template_entry *entry; | ||
| 44 | const char *op = "add_boot_aggregate"; | ||
| 45 | const char *audit_cause = "ENOMEM"; | ||
| 46 | int result = -ENOMEM; | ||
| 47 | int violation = 1; | ||
| 48 | |||
| 49 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); | ||
| 50 | if (!entry) | ||
| 51 | goto err_out; | ||
| 52 | |||
| 53 | memset(&entry->template, 0, sizeof(entry->template)); | ||
| 54 | strncpy(entry->template.file_name, boot_aggregate_name, | ||
| 55 | IMA_EVENT_NAME_LEN_MAX); | ||
| 56 | if (ima_used_chip) { | ||
| 57 | violation = 0; | ||
| 58 | result = ima_calc_boot_aggregate(entry->template.digest); | ||
| 59 | if (result < 0) { | ||
| 60 | audit_cause = "hashing_error"; | ||
| 61 | kfree(entry); | ||
| 62 | goto err_out; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | result = ima_store_template(entry, violation, NULL); | ||
| 66 | if (result < 0) | ||
| 67 | kfree(entry); | ||
| 68 | return; | ||
| 69 | err_out: | ||
| 70 | integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, boot_aggregate_name, op, | ||
| 71 | audit_cause, result, 0); | ||
| 72 | } | ||
| 73 | |||
| 74 | int ima_init(void) | ||
| 75 | { | ||
| 76 | u8 pcr_i[IMA_DIGEST_SIZE]; | ||
| 77 | int rc; | ||
| 78 | |||
| 79 | ima_used_chip = 0; | ||
| 80 | rc = tpm_pcr_read(TPM_ANY_NUM, 0, pcr_i); | ||
| 81 | if (rc == 0) | ||
| 82 | ima_used_chip = 1; | ||
| 83 | |||
| 84 | if (!ima_used_chip) | ||
| 85 | pr_info("No TPM chip found, activating TPM-bypass!\n"); | ||
| 86 | |||
| 87 | ima_add_boot_aggregate(); /* boot aggregate must be first entry */ | ||
| 88 | ima_init_policy(); | ||
| 89 | |||
| 90 | return ima_fs_init(); | ||
| 91 | } | ||
| 92 | |||
| 93 | void __exit ima_cleanup(void) | ||
| 94 | { | ||
| 95 | ima_fs_cleanup(); | ||
| 96 | } | ||
