diff options
author | Dmitry Kasatkin <d.kasatkin@samsung.com> | 2013-06-07 06:16:24 -0400 |
---|---|---|
committer | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2013-10-25 17:17:01 -0400 |
commit | ea593993d361748e795f5eb783a5fb5144fb2df9 (patch) | |
tree | 387915941a654ae6b23199d372c73afede8d19e1 /security/integrity | |
parent | 723326b927b675daf4223fe31d7428eca68f194b (diff) |
ima: support arbitrary hash algorithms in ima_calc_buffer_hash
ima_calc_buffer_hash will be used with different hash algorithms.
This patch provides support for arbitrary hash algorithms in
ima_calc_buffer_hash.
Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Diffstat (limited to 'security/integrity')
-rw-r--r-- | security/integrity/ima/ima_api.c | 3 | ||||
-rw-r--r-- | security/integrity/ima/ima_crypto.c | 28 |
2 files changed, 25 insertions, 6 deletions
diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index 2cc5dcc6bdeb..bc1d1282a06f 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/fs.h> | 18 | #include <linux/fs.h> |
19 | #include <linux/xattr.h> | 19 | #include <linux/xattr.h> |
20 | #include <linux/evm.h> | 20 | #include <linux/evm.h> |
21 | #include <crypto/hash_info.h> | ||
21 | #include "ima.h" | 22 | #include "ima.h" |
22 | 23 | ||
23 | static const char *IMA_TEMPLATE_NAME = "ima"; | 24 | static const char *IMA_TEMPLATE_NAME = "ima"; |
@@ -54,6 +55,8 @@ int ima_store_template(struct ima_template_entry *entry, | |||
54 | entry->template_len = sizeof(entry->template); | 55 | entry->template_len = sizeof(entry->template); |
55 | 56 | ||
56 | if (!violation) { | 57 | if (!violation) { |
58 | /* this function uses default algo */ | ||
59 | hash.hdr.algo = HASH_ALGO_SHA1; | ||
57 | result = ima_calc_buffer_hash(&entry->template, | 60 | result = ima_calc_buffer_hash(&entry->template, |
58 | entry->template_len, &hash.hdr); | 61 | entry->template_len, &hash.hdr); |
59 | if (result < 0) { | 62 | if (result < 0) { |
diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index e5d3ebf18436..e2be2524a372 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c | |||
@@ -139,23 +139,39 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash) | |||
139 | /* | 139 | /* |
140 | * Calculate the hash of a given buffer | 140 | * Calculate the hash of a given buffer |
141 | */ | 141 | */ |
142 | int ima_calc_buffer_hash(const void *buf, int len, struct ima_digest_data *hash) | 142 | static int ima_calc_buffer_hash_tfm(const void *buf, int len, |
143 | struct ima_digest_data *hash, | ||
144 | struct crypto_shash *tfm) | ||
143 | { | 145 | { |
144 | struct { | 146 | struct { |
145 | struct shash_desc shash; | 147 | struct shash_desc shash; |
146 | char ctx[crypto_shash_descsize(ima_shash_tfm)]; | 148 | char ctx[crypto_shash_descsize(tfm)]; |
147 | } desc; | 149 | } desc; |
148 | 150 | ||
149 | desc.shash.tfm = ima_shash_tfm; | 151 | desc.shash.tfm = tfm; |
150 | desc.shash.flags = 0; | 152 | desc.shash.flags = 0; |
151 | 153 | ||
152 | /* this function uses default algo */ | 154 | hash->length = crypto_shash_digestsize(tfm); |
153 | hash->algo = ima_hash_algo; | ||
154 | hash->length = crypto_shash_digestsize(ima_shash_tfm); | ||
155 | 155 | ||
156 | return crypto_shash_digest(&desc.shash, buf, len, hash->digest); | 156 | return crypto_shash_digest(&desc.shash, buf, len, hash->digest); |
157 | } | 157 | } |
158 | 158 | ||
159 | int ima_calc_buffer_hash(const void *buf, int len, struct ima_digest_data *hash) | ||
160 | { | ||
161 | struct crypto_shash *tfm; | ||
162 | int rc; | ||
163 | |||
164 | tfm = ima_alloc_tfm(hash->algo); | ||
165 | if (IS_ERR(tfm)) | ||
166 | return PTR_ERR(tfm); | ||
167 | |||
168 | rc = ima_calc_buffer_hash_tfm(buf, len, hash, tfm); | ||
169 | |||
170 | ima_free_tfm(tfm); | ||
171 | |||
172 | return rc; | ||
173 | } | ||
174 | |||
159 | static void __init ima_pcrread(int idx, u8 *pcr) | 175 | static void __init ima_pcrread(int idx, u8 *pcr) |
160 | { | 176 | { |
161 | if (!ima_used_chip) | 177 | if (!ima_used_chip) |