2 * AppArmor security module
4 * This file contains AppArmor policy loading interface function definitions.
6 * Copyright 2013 Canonical Ltd.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, version 2 of the
13 * Fns to provide a checksum of policy that has been loaded this can be
14 * compared to userspace policy compiles to check loaded policy is what
18 #include <linux/crypto.h>
20 #include "include/apparmor.h"
21 #include "include/crypto.h"
23 static unsigned int apparmor_hash_size;
25 static struct crypto_hash *apparmor_tfm;
27 unsigned int aa_hash_size(void)
29 return apparmor_hash_size;
32 int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,
35 struct scatterlist sg[2];
36 struct hash_desc desc = {
41 u32 le32_version = cpu_to_le32(version);
47 sg_set_buf(&sg[0], &le32_version, 4);
48 sg_set_buf(&sg[1], (u8 *) start, len);
50 profile->hash = kzalloc(apparmor_hash_size, GFP_KERNEL);
54 error = crypto_hash_init(&desc);
57 error = crypto_hash_update(&desc, &sg[0], 4);
60 error = crypto_hash_update(&desc, &sg[1], len);
63 error = crypto_hash_final(&desc, profile->hash);
76 static int __init init_profile_hash(void)
78 struct crypto_hash *tfm;
80 if (!apparmor_initialized)
83 tfm = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
85 int error = PTR_ERR(tfm);
86 AA_ERROR("failed to setup profile sha1 hashing: %d\n", error);
90 apparmor_hash_size = crypto_hash_digestsize(apparmor_tfm);
92 aa_info_message("AppArmor sha1 policy hashing enabled");
97 late_initcall(init_profile_hash);