Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Politecnico di Torino, Italy |
| 3 | * TORSEC group -- http://security.polito.it |
| 4 | * |
| 5 | * Author: Roberto Sassu <roberto.sassu@polito.it> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation, version 2 of the |
| 10 | * License. |
| 11 | * |
| 12 | * File: ima_template_lib.c |
| 13 | * Library of supported template fields. |
| 14 | */ |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 15 | #include <crypto/hash_info.h> |
| 16 | |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 17 | #include "ima_template_lib.h" |
| 18 | |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 19 | static bool ima_template_hash_algo_allowed(u8 algo) |
| 20 | { |
| 21 | if (algo == HASH_ALGO_SHA1 || algo == HASH_ALGO_MD5) |
| 22 | return true; |
| 23 | |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | enum data_formats { |
| 28 | DATA_FMT_DIGEST = 0, |
| 29 | DATA_FMT_DIGEST_WITH_ALGO, |
Mimi Zohar | bcbc9b0c | 2013-07-23 11:15:00 -0400 | [diff] [blame] | 30 | DATA_FMT_STRING, |
| 31 | DATA_FMT_HEX |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 34 | static int ima_write_template_field_data(const void *data, const u32 datalen, |
| 35 | enum data_formats datafmt, |
| 36 | struct ima_field_data *field_data) |
| 37 | { |
| 38 | u8 *buf, *buf_ptr; |
Roberto Sassu | e3b64c2 | 2014-02-03 13:56:05 +0100 | [diff] [blame] | 39 | u32 buflen = datalen; |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 40 | |
Roberto Sassu | e3b64c2 | 2014-02-03 13:56:05 +0100 | [diff] [blame] | 41 | if (datafmt == DATA_FMT_STRING) |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 42 | buflen = datalen + 1; |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 43 | |
| 44 | buf = kzalloc(buflen, GFP_KERNEL); |
| 45 | if (!buf) |
| 46 | return -ENOMEM; |
| 47 | |
| 48 | memcpy(buf, data, datalen); |
| 49 | |
| 50 | /* |
| 51 | * Replace all space characters with underscore for event names and |
| 52 | * strings. This avoid that, during the parsing of a measurements list, |
| 53 | * filenames with spaces or that end with the suffix ' (deleted)' are |
| 54 | * split into multiple template fields (the space is the delimitator |
| 55 | * character for measurements lists in ASCII format). |
| 56 | */ |
Roberto Sassu | e3b64c2 | 2014-02-03 13:56:05 +0100 | [diff] [blame] | 57 | if (datafmt == DATA_FMT_STRING) { |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 58 | for (buf_ptr = buf; buf_ptr - buf < datalen; buf_ptr++) |
| 59 | if (*buf_ptr == ' ') |
| 60 | *buf_ptr = '_'; |
| 61 | } |
| 62 | |
| 63 | field_data->data = buf; |
| 64 | field_data->len = buflen; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static void ima_show_template_data_ascii(struct seq_file *m, |
| 69 | enum ima_show_type show, |
| 70 | enum data_formats datafmt, |
| 71 | struct ima_field_data *field_data) |
| 72 | { |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 73 | u8 *buf_ptr = field_data->data, buflen = field_data->len; |
| 74 | |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 75 | switch (datafmt) { |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 76 | case DATA_FMT_DIGEST_WITH_ALGO: |
| 77 | buf_ptr = strnchr(field_data->data, buflen, ':'); |
| 78 | if (buf_ptr != field_data->data) |
| 79 | seq_printf(m, "%s", field_data->data); |
| 80 | |
| 81 | /* skip ':' and '\0' */ |
| 82 | buf_ptr += 2; |
| 83 | buflen -= buf_ptr - field_data->data; |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 84 | case DATA_FMT_DIGEST: |
Mimi Zohar | bcbc9b0c | 2013-07-23 11:15:00 -0400 | [diff] [blame] | 85 | case DATA_FMT_HEX: |
| 86 | if (!buflen) |
| 87 | break; |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 88 | ima_print_digest(m, buf_ptr, buflen); |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 89 | break; |
| 90 | case DATA_FMT_STRING: |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 91 | seq_printf(m, "%s", buf_ptr); |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 92 | break; |
| 93 | default: |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | static void ima_show_template_data_binary(struct seq_file *m, |
| 99 | enum ima_show_type show, |
| 100 | enum data_formats datafmt, |
| 101 | struct ima_field_data *field_data) |
| 102 | { |
Roberto Sassu | c019e30 | 2014-02-03 13:56:04 +0100 | [diff] [blame] | 103 | u32 len = (show == IMA_SHOW_BINARY_OLD_STRING_FMT) ? |
| 104 | strlen(field_data->data) : field_data->len; |
Roberto Sassu | 3e8e550 | 2013-11-08 19:21:40 +0100 | [diff] [blame] | 105 | |
Roberto Sassu | c019e30 | 2014-02-03 13:56:04 +0100 | [diff] [blame] | 106 | if (show != IMA_SHOW_BINARY_NO_FIELD_LEN) |
| 107 | ima_putc(m, &len, sizeof(len)); |
| 108 | |
| 109 | if (!len) |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 110 | return; |
Roberto Sassu | 3e8e550 | 2013-11-08 19:21:40 +0100 | [diff] [blame] | 111 | |
Roberto Sassu | c019e30 | 2014-02-03 13:56:04 +0100 | [diff] [blame] | 112 | ima_putc(m, field_data->data, len); |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static void ima_show_template_field_data(struct seq_file *m, |
| 116 | enum ima_show_type show, |
| 117 | enum data_formats datafmt, |
| 118 | struct ima_field_data *field_data) |
| 119 | { |
| 120 | switch (show) { |
| 121 | case IMA_SHOW_ASCII: |
| 122 | ima_show_template_data_ascii(m, show, datafmt, field_data); |
| 123 | break; |
| 124 | case IMA_SHOW_BINARY: |
Roberto Sassu | 3e8e550 | 2013-11-08 19:21:40 +0100 | [diff] [blame] | 125 | case IMA_SHOW_BINARY_NO_FIELD_LEN: |
Roberto Sassu | c019e30 | 2014-02-03 13:56:04 +0100 | [diff] [blame] | 126 | case IMA_SHOW_BINARY_OLD_STRING_FMT: |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 127 | ima_show_template_data_binary(m, show, datafmt, field_data); |
| 128 | break; |
| 129 | default: |
| 130 | break; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void ima_show_template_digest(struct seq_file *m, enum ima_show_type show, |
| 135 | struct ima_field_data *field_data) |
| 136 | { |
| 137 | ima_show_template_field_data(m, show, DATA_FMT_DIGEST, field_data); |
| 138 | } |
| 139 | |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 140 | void ima_show_template_digest_ng(struct seq_file *m, enum ima_show_type show, |
| 141 | struct ima_field_data *field_data) |
| 142 | { |
| 143 | ima_show_template_field_data(m, show, DATA_FMT_DIGEST_WITH_ALGO, |
| 144 | field_data); |
| 145 | } |
| 146 | |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 147 | void ima_show_template_string(struct seq_file *m, enum ima_show_type show, |
| 148 | struct ima_field_data *field_data) |
| 149 | { |
| 150 | ima_show_template_field_data(m, show, DATA_FMT_STRING, field_data); |
| 151 | } |
| 152 | |
Mimi Zohar | bcbc9b0c | 2013-07-23 11:15:00 -0400 | [diff] [blame] | 153 | void ima_show_template_sig(struct seq_file *m, enum ima_show_type show, |
| 154 | struct ima_field_data *field_data) |
| 155 | { |
| 156 | ima_show_template_field_data(m, show, DATA_FMT_HEX, field_data); |
| 157 | } |
| 158 | |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 159 | static int ima_eventdigest_init_common(u8 *digest, u32 digestsize, u8 hash_algo, |
Roberto Sassu | dcf4e39 | 2013-11-08 19:21:37 +0100 | [diff] [blame] | 160 | struct ima_field_data *field_data) |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 161 | { |
| 162 | /* |
| 163 | * digest formats: |
| 164 | * - DATA_FMT_DIGEST: digest |
| 165 | * - DATA_FMT_DIGEST_WITH_ALGO: [<hash algo>] + ':' + '\0' + digest, |
| 166 | * where <hash algo> is provided if the hash algoritm is not |
| 167 | * SHA1 or MD5 |
| 168 | */ |
| 169 | u8 buffer[CRYPTO_MAX_ALG_NAME + 2 + IMA_MAX_DIGEST_SIZE] = { 0 }; |
| 170 | enum data_formats fmt = DATA_FMT_DIGEST; |
| 171 | u32 offset = 0; |
| 172 | |
Roberto Sassu | dcf4e39 | 2013-11-08 19:21:37 +0100 | [diff] [blame] | 173 | if (hash_algo < HASH_ALGO__LAST) { |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 174 | fmt = DATA_FMT_DIGEST_WITH_ALGO; |
Roberto Sassu | dcf4e39 | 2013-11-08 19:21:37 +0100 | [diff] [blame] | 175 | offset += snprintf(buffer, CRYPTO_MAX_ALG_NAME + 1, "%s", |
| 176 | hash_algo_name[hash_algo]); |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 177 | buffer[offset] = ':'; |
| 178 | offset += 2; |
| 179 | } |
| 180 | |
| 181 | if (digest) |
| 182 | memcpy(buffer + offset, digest, digestsize); |
| 183 | else |
| 184 | /* |
| 185 | * If digest is NULL, the event being recorded is a violation. |
| 186 | * Make room for the digest by increasing the offset of |
| 187 | * IMA_DIGEST_SIZE. |
| 188 | */ |
| 189 | offset += IMA_DIGEST_SIZE; |
| 190 | |
| 191 | return ima_write_template_field_data(buffer, offset + digestsize, |
| 192 | fmt, field_data); |
| 193 | } |
| 194 | |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 195 | /* |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 196 | * This function writes the digest of an event (with size limit). |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 197 | */ |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 198 | int ima_eventdigest_init(struct ima_event_data *event_data, |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 199 | struct ima_field_data *field_data) |
| 200 | { |
| 201 | struct { |
| 202 | struct ima_digest_data hdr; |
| 203 | char digest[IMA_MAX_DIGEST_SIZE]; |
| 204 | } hash; |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 205 | u8 *cur_digest = NULL; |
| 206 | u32 cur_digestsize = 0; |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 207 | struct inode *inode; |
| 208 | int result; |
| 209 | |
| 210 | memset(&hash, 0, sizeof(hash)); |
| 211 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 212 | if (!event_data->iint) /* recording a violation. */ |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 213 | goto out; |
| 214 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 215 | if (ima_template_hash_algo_allowed(event_data->iint->ima_hash->algo)) { |
| 216 | cur_digest = event_data->iint->ima_hash->digest; |
| 217 | cur_digestsize = event_data->iint->ima_hash->length; |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 218 | goto out; |
| 219 | } |
| 220 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 221 | if (!event_data->file) /* missing info to re-calculate the digest */ |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 222 | return -EINVAL; |
| 223 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 224 | inode = file_inode(event_data->file); |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 225 | hash.hdr.algo = ima_template_hash_algo_allowed(ima_hash_algo) ? |
| 226 | ima_hash_algo : HASH_ALGO_SHA1; |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 227 | result = ima_calc_file_hash(event_data->file, &hash.hdr); |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 228 | if (result) { |
| 229 | integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode, |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 230 | event_data->filename, "collect_data", |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 231 | "failed", result, 0); |
| 232 | return result; |
| 233 | } |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 234 | cur_digest = hash.hdr.digest; |
| 235 | cur_digestsize = hash.hdr.length; |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 236 | out: |
Roberto Sassu | 712a49b | 2013-11-08 19:21:36 +0100 | [diff] [blame] | 237 | return ima_eventdigest_init_common(cur_digest, cur_digestsize, |
Roberto Sassu | dcf4e39 | 2013-11-08 19:21:37 +0100 | [diff] [blame] | 238 | HASH_ALGO__LAST, field_data); |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 242 | * This function writes the digest of an event (without size limit). |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 243 | */ |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 244 | int ima_eventdigest_ng_init(struct ima_event_data *event_data, |
| 245 | struct ima_field_data *field_data) |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 246 | { |
Roberto Sassu | c502c78 | 2013-11-08 19:21:35 +0100 | [diff] [blame] | 247 | u8 *cur_digest = NULL, hash_algo = HASH_ALGO_SHA1; |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 248 | u32 cur_digestsize = 0; |
| 249 | |
| 250 | /* If iint is NULL, we are recording a violation. */ |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 251 | if (!event_data->iint) |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 252 | goto out; |
| 253 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 254 | cur_digest = event_data->iint->ima_hash->digest; |
| 255 | cur_digestsize = event_data->iint->ima_hash->length; |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 256 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 257 | hash_algo = event_data->iint->ima_hash->algo; |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 258 | out: |
| 259 | return ima_eventdigest_init_common(cur_digest, cur_digestsize, |
Roberto Sassu | dcf4e39 | 2013-11-08 19:21:37 +0100 | [diff] [blame] | 260 | hash_algo, field_data); |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 263 | static int ima_eventname_init_common(struct ima_event_data *event_data, |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 264 | struct ima_field_data *field_data, |
| 265 | bool size_limit) |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 266 | { |
| 267 | const char *cur_filename = NULL; |
| 268 | u32 cur_filename_len = 0; |
| 269 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 270 | BUG_ON(event_data->filename == NULL && event_data->file == NULL); |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 271 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 272 | if (event_data->filename) { |
| 273 | cur_filename = event_data->filename; |
| 274 | cur_filename_len = strlen(event_data->filename); |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 275 | |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 276 | if (!size_limit || cur_filename_len <= IMA_EVENT_NAME_LEN_MAX) |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 277 | goto out; |
| 278 | } |
| 279 | |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 280 | if (event_data->file) { |
| 281 | cur_filename = event_data->file->f_path.dentry->d_name.name; |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 282 | cur_filename_len = strlen(cur_filename); |
| 283 | } else |
| 284 | /* |
| 285 | * Truncate filename if the latter is too long and |
| 286 | * the file descriptor is not available. |
| 287 | */ |
| 288 | cur_filename_len = IMA_EVENT_NAME_LEN_MAX; |
| 289 | out: |
| 290 | return ima_write_template_field_data(cur_filename, cur_filename_len, |
Roberto Sassu | e3b64c2 | 2014-02-03 13:56:05 +0100 | [diff] [blame] | 291 | DATA_FMT_STRING, field_data); |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* |
| 295 | * This function writes the name of an event (with size limit). |
| 296 | */ |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 297 | int ima_eventname_init(struct ima_event_data *event_data, |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 298 | struct ima_field_data *field_data) |
| 299 | { |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 300 | return ima_eventname_init_common(event_data, field_data, true); |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /* |
| 304 | * This function writes the name of an event (without size limit). |
| 305 | */ |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 306 | int ima_eventname_ng_init(struct ima_event_data *event_data, |
Roberto Sassu | 4d7aeee7 | 2013-06-07 12:16:32 +0200 | [diff] [blame] | 307 | struct ima_field_data *field_data) |
| 308 | { |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 309 | return ima_eventname_init_common(event_data, field_data, false); |
Roberto Sassu | 3ce1217d | 2013-06-07 12:16:30 +0200 | [diff] [blame] | 310 | } |
Mimi Zohar | bcbc9b0c | 2013-07-23 11:15:00 -0400 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * ima_eventsig_init - include the file signature as part of the template data |
| 314 | */ |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 315 | int ima_eventsig_init(struct ima_event_data *event_data, |
Mimi Zohar | bcbc9b0c | 2013-07-23 11:15:00 -0400 | [diff] [blame] | 316 | struct ima_field_data *field_data) |
| 317 | { |
| 318 | enum data_formats fmt = DATA_FMT_HEX; |
Roberto Sassu | 23b5741 | 2015-04-11 17:09:50 +0200 | [diff] [blame^] | 319 | struct evm_ima_xattr_data *xattr_value = event_data->xattr_value; |
| 320 | int xattr_len = event_data->xattr_len; |
Mimi Zohar | bcbc9b0c | 2013-07-23 11:15:00 -0400 | [diff] [blame] | 321 | int rc = 0; |
| 322 | |
| 323 | if ((!xattr_value) || (xattr_value->type != EVM_IMA_XATTR_DIGSIG)) |
| 324 | goto out; |
| 325 | |
| 326 | rc = ima_write_template_field_data(xattr_value, xattr_len, fmt, |
| 327 | field_data); |
| 328 | out: |
| 329 | return rc; |
| 330 | } |