aboutsummaryrefslogtreecommitdiffstats
path: root/security/integrity/ima/ima_template_lib.c
diff options
context:
space:
mode:
authorMimi Zohar <zohar@linux.vnet.ibm.com>2013-07-23 11:15:00 -0400
committerMimi Zohar <zohar@linux.vnet.ibm.com>2013-10-31 20:19:35 -0400
commitbcbc9b0cf6d8f340a1d166e414f4612b353f7a9b (patch)
treecd728f166ccf86137a7a8a7847ce962488ff86e2 /security/integrity/ima/ima_template_lib.c
parent42a20ba5c90ded07f79992d222fa0814b8448cf6 (diff)
ima: extend the measurement list to include the file signature
This patch defines a new template called 'ima-sig', which includes the file signature in the template data, in addition to the file's digest and pathname. A template is composed of a set of fields. Associated with each field is an initialization and display function. This patch defines a new template field called 'sig', the initialization function ima_eventsig_init(), and the display function ima_show_template_sig(). This patch modifies the .field_init() function definition to include the 'security.ima' extended attribute and length. Changelog: - remove unused code (Dmitry Kasatkin) - avoid calling ima_write_template_field_data() unnecesarily (Roberto Sassu) - rename DATA_FMT_SIG to DATA_FMT_HEX - cleanup ima_eventsig_init() based on Roberto's comments Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com> Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com> Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Diffstat (limited to 'security/integrity/ima/ima_template_lib.c')
-rw-r--r--security/integrity/ima/ima_template_lib.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/security/integrity/ima/ima_template_lib.c b/security/integrity/ima/ima_template_lib.c
index 7d841448f246..6d66ad6ed265 100644
--- a/security/integrity/ima/ima_template_lib.c
+++ b/security/integrity/ima/ima_template_lib.c
@@ -28,7 +28,8 @@ enum data_formats {
28 DATA_FMT_DIGEST = 0, 28 DATA_FMT_DIGEST = 0,
29 DATA_FMT_DIGEST_WITH_ALGO, 29 DATA_FMT_DIGEST_WITH_ALGO,
30 DATA_FMT_EVENT_NAME, 30 DATA_FMT_EVENT_NAME,
31 DATA_FMT_STRING 31 DATA_FMT_STRING,
32 DATA_FMT_HEX
32}; 33};
33 34
34static int ima_write_template_field_data(const void *data, const u32 datalen, 35static int ima_write_template_field_data(const void *data, const u32 datalen,
@@ -90,6 +91,9 @@ static void ima_show_template_data_ascii(struct seq_file *m,
90 buf_ptr += 2; 91 buf_ptr += 2;
91 buflen -= buf_ptr - field_data->data; 92 buflen -= buf_ptr - field_data->data;
92 case DATA_FMT_DIGEST: 93 case DATA_FMT_DIGEST:
94 case DATA_FMT_HEX:
95 if (!buflen)
96 break;
93 ima_print_digest(m, buf_ptr, buflen); 97 ima_print_digest(m, buf_ptr, buflen);
94 break; 98 break;
95 case DATA_FMT_STRING: 99 case DATA_FMT_STRING:
@@ -147,6 +151,12 @@ void ima_show_template_string(struct seq_file *m, enum ima_show_type show,
147 ima_show_template_field_data(m, show, DATA_FMT_STRING, field_data); 151 ima_show_template_field_data(m, show, DATA_FMT_STRING, field_data);
148} 152}
149 153
154void ima_show_template_sig(struct seq_file *m, enum ima_show_type show,
155 struct ima_field_data *field_data)
156{
157 ima_show_template_field_data(m, show, DATA_FMT_HEX, field_data);
158}
159
150static int ima_eventdigest_init_common(u8 *digest, u32 digestsize, u8 hash_algo, 160static int ima_eventdigest_init_common(u8 *digest, u32 digestsize, u8 hash_algo,
151 struct ima_field_data *field_data, 161 struct ima_field_data *field_data,
152 bool size_limit) 162 bool size_limit)
@@ -190,6 +200,7 @@ static int ima_eventdigest_init_common(u8 *digest, u32 digestsize, u8 hash_algo,
190 */ 200 */
191int ima_eventdigest_init(struct integrity_iint_cache *iint, struct file *file, 201int ima_eventdigest_init(struct integrity_iint_cache *iint, struct file *file,
192 const unsigned char *filename, 202 const unsigned char *filename,
203 struct evm_ima_xattr_data *xattr_value, int xattr_len,
193 struct ima_field_data *field_data) 204 struct ima_field_data *field_data)
194{ 205{
195 struct { 206 struct {
@@ -237,7 +248,8 @@ out:
237 */ 248 */
238int ima_eventdigest_ng_init(struct integrity_iint_cache *iint, 249int ima_eventdigest_ng_init(struct integrity_iint_cache *iint,
239 struct file *file, const unsigned char *filename, 250 struct file *file, const unsigned char *filename,
240 struct ima_field_data *field_data) 251 struct evm_ima_xattr_data *xattr_value,
252 int xattr_len, struct ima_field_data *field_data)
241{ 253{
242 u8 *cur_digest = NULL, hash_algo = HASH_ALGO__LAST; 254 u8 *cur_digest = NULL, hash_algo = HASH_ALGO__LAST;
243 u32 cur_digestsize = 0; 255 u32 cur_digestsize = 0;
@@ -295,6 +307,7 @@ out:
295 */ 307 */
296int ima_eventname_init(struct integrity_iint_cache *iint, struct file *file, 308int ima_eventname_init(struct integrity_iint_cache *iint, struct file *file,
297 const unsigned char *filename, 309 const unsigned char *filename,
310 struct evm_ima_xattr_data *xattr_value, int xattr_len,
298 struct ima_field_data *field_data) 311 struct ima_field_data *field_data)
299{ 312{
300 return ima_eventname_init_common(iint, file, filename, 313 return ima_eventname_init_common(iint, file, filename,
@@ -306,8 +319,29 @@ int ima_eventname_init(struct integrity_iint_cache *iint, struct file *file,
306 */ 319 */
307int ima_eventname_ng_init(struct integrity_iint_cache *iint, struct file *file, 320int ima_eventname_ng_init(struct integrity_iint_cache *iint, struct file *file,
308 const unsigned char *filename, 321 const unsigned char *filename,
322 struct evm_ima_xattr_data *xattr_value, int xattr_len,
309 struct ima_field_data *field_data) 323 struct ima_field_data *field_data)
310{ 324{
311 return ima_eventname_init_common(iint, file, filename, 325 return ima_eventname_init_common(iint, file, filename,
312 field_data, false); 326 field_data, false);
313} 327}
328
329/*
330 * ima_eventsig_init - include the file signature as part of the template data
331 */
332int ima_eventsig_init(struct integrity_iint_cache *iint, struct file *file,
333 const unsigned char *filename,
334 struct evm_ima_xattr_data *xattr_value, int xattr_len,
335 struct ima_field_data *field_data)
336{
337 enum data_formats fmt = DATA_FMT_HEX;
338 int rc = 0;
339
340 if ((!xattr_value) || (xattr_value->type != EVM_IMA_XATTR_DIGSIG))
341 goto out;
342
343 rc = ima_write_template_field_data(xattr_value, xattr_len, fmt,
344 field_data);
345out:
346 return rc;
347}