Path: blob/master/security/integrity/ima/ima_init.c
10817 views
/*1* Copyright (C) 2005,2006,2007,2008 IBM Corporation2*3* Authors:4* Reiner Sailer <[email protected]>5* Leendert van Doorn <[email protected]>6* Mimi Zohar <[email protected]>7*8* This program is free software; you can redistribute it and/or9* modify it under the terms of the GNU General Public License as10* published by the Free Software Foundation, version 2 of the11* License.12*13* File: ima_init.c14* initialization and cleanup functions15*/16#include <linux/module.h>17#include <linux/scatterlist.h>18#include <linux/slab.h>19#include <linux/err.h>20#include "ima.h"2122/* name for boot aggregate entry */23static const char *boot_aggregate_name = "boot_aggregate";24int ima_used_chip;2526/* Add the boot aggregate to the IMA measurement list and extend27* 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 not31* exist. Add the boot aggregate measurement to the measurement32* list and extend the PCR register.33*34* If a tpm chip does not exist, indicate the core root of trust is35* not hardware based by invalidating the aggregate PCR value.36* (The aggregate PCR value is invalidated by adding one value to37* the measurement list and extending the aggregate PCR value with38* a different value.) Violations add a zero entry to the measurement39* list and extend the aggregate PCR value with ff...ff's.40*/41static void __init ima_add_boot_aggregate(void)42{43struct ima_template_entry *entry;44const char *op = "add_boot_aggregate";45const char *audit_cause = "ENOMEM";46int result = -ENOMEM;47int violation = 1;4849entry = kmalloc(sizeof(*entry), GFP_KERNEL);50if (!entry)51goto err_out;5253memset(&entry->template, 0, sizeof(entry->template));54strncpy(entry->template.file_name, boot_aggregate_name,55IMA_EVENT_NAME_LEN_MAX);56if (ima_used_chip) {57violation = 0;58result = ima_calc_boot_aggregate(entry->template.digest);59if (result < 0) {60audit_cause = "hashing_error";61kfree(entry);62goto err_out;63}64}65result = ima_store_template(entry, violation, NULL);66if (result < 0)67kfree(entry);68return;69err_out:70integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, boot_aggregate_name, op,71audit_cause, result, 0);72}7374int __init ima_init(void)75{76u8 pcr_i[IMA_DIGEST_SIZE];77int rc;7879ima_used_chip = 0;80rc = tpm_pcr_read(TPM_ANY_NUM, 0, pcr_i);81if (rc == 0)82ima_used_chip = 1;8384if (!ima_used_chip)85pr_info("IMA: No TPM chip found, activating TPM-bypass!\n");8687ima_add_boot_aggregate(); /* boot aggregate must be first entry */88ima_init_policy();8990return ima_fs_init();91}9293void __exit ima_cleanup(void)94{95ima_fs_cleanup();96}979899