aboutsummaryrefslogtreecommitdiffstats
path: root/security/integrity/ima/ima_template_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/integrity/ima/ima_template_lib.c')
-rw-r--r--security/integrity/ima/ima_template_lib.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/security/integrity/ima/ima_template_lib.c b/security/integrity/ima/ima_template_lib.c
index 1683bbf289a4..1506f0248572 100644
--- a/security/integrity/ima/ima_template_lib.c
+++ b/security/integrity/ima/ima_template_lib.c
@@ -27,7 +27,6 @@ static bool ima_template_hash_algo_allowed(u8 algo)
27enum data_formats { 27enum 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,
31 DATA_FMT_STRING, 30 DATA_FMT_STRING,
32 DATA_FMT_HEX 31 DATA_FMT_HEX
33}; 32};
@@ -37,18 +36,10 @@ static int ima_write_template_field_data(const void *data, const u32 datalen,
37 struct ima_field_data *field_data) 36 struct ima_field_data *field_data)
38{ 37{
39 u8 *buf, *buf_ptr; 38 u8 *buf, *buf_ptr;
40 u32 buflen; 39 u32 buflen = datalen;
41 40
42 switch (datafmt) { 41 if (datafmt == DATA_FMT_STRING)
43 case DATA_FMT_EVENT_NAME:
44 buflen = IMA_EVENT_NAME_LEN_MAX + 1;
45 break;
46 case DATA_FMT_STRING:
47 buflen = datalen + 1; 42 buflen = datalen + 1;
48 break;
49 default:
50 buflen = datalen;
51 }
52 43
53 buf = kzalloc(buflen, GFP_KERNEL); 44 buf = kzalloc(buflen, GFP_KERNEL);
54 if (!buf) 45 if (!buf)
@@ -63,7 +54,7 @@ static int ima_write_template_field_data(const void *data, const u32 datalen,
63 * split into multiple template fields (the space is the delimitator 54 * split into multiple template fields (the space is the delimitator
64 * character for measurements lists in ASCII format). 55 * character for measurements lists in ASCII format).
65 */ 56 */
66 if (datafmt == DATA_FMT_EVENT_NAME || datafmt == DATA_FMT_STRING) { 57 if (datafmt == DATA_FMT_STRING) {
67 for (buf_ptr = buf; buf_ptr - buf < datalen; buf_ptr++) 58 for (buf_ptr = buf; buf_ptr - buf < datalen; buf_ptr++)
68 if (*buf_ptr == ' ') 59 if (*buf_ptr == ' ')
69 *buf_ptr = '_'; 60 *buf_ptr = '_';
@@ -109,13 +100,16 @@ static void ima_show_template_data_binary(struct seq_file *m,
109 enum data_formats datafmt, 100 enum data_formats datafmt,
110 struct ima_field_data *field_data) 101 struct ima_field_data *field_data)
111{ 102{
103 u32 len = (show == IMA_SHOW_BINARY_OLD_STRING_FMT) ?
104 strlen(field_data->data) : field_data->len;
105
112 if (show != IMA_SHOW_BINARY_NO_FIELD_LEN) 106 if (show != IMA_SHOW_BINARY_NO_FIELD_LEN)
113 ima_putc(m, &field_data->len, sizeof(u32)); 107 ima_putc(m, &len, sizeof(len));
114 108
115 if (!field_data->len) 109 if (!len)
116 return; 110 return;
117 111
118 ima_putc(m, field_data->data, field_data->len); 112 ima_putc(m, field_data->data, len);
119} 113}
120 114
121static void ima_show_template_field_data(struct seq_file *m, 115static void ima_show_template_field_data(struct seq_file *m,
@@ -129,6 +123,7 @@ static void ima_show_template_field_data(struct seq_file *m,
129 break; 123 break;
130 case IMA_SHOW_BINARY: 124 case IMA_SHOW_BINARY:
131 case IMA_SHOW_BINARY_NO_FIELD_LEN: 125 case IMA_SHOW_BINARY_NO_FIELD_LEN:
126 case IMA_SHOW_BINARY_OLD_STRING_FMT:
132 ima_show_template_data_binary(m, show, datafmt, field_data); 127 ima_show_template_data_binary(m, show, datafmt, field_data);
133 break; 128 break;
134 default: 129 default:
@@ -277,8 +272,6 @@ static int ima_eventname_init_common(struct integrity_iint_cache *iint,
277{ 272{
278 const char *cur_filename = NULL; 273 const char *cur_filename = NULL;
279 u32 cur_filename_len = 0; 274 u32 cur_filename_len = 0;
280 enum data_formats fmt = size_limit ?
281 DATA_FMT_EVENT_NAME : DATA_FMT_STRING;
282 275
283 BUG_ON(filename == NULL && file == NULL); 276 BUG_ON(filename == NULL && file == NULL);
284 277
@@ -301,7 +294,7 @@ static int ima_eventname_init_common(struct integrity_iint_cache *iint,
301 cur_filename_len = IMA_EVENT_NAME_LEN_MAX; 294 cur_filename_len = IMA_EVENT_NAME_LEN_MAX;
302out: 295out:
303 return ima_write_template_field_data(cur_filename, cur_filename_len, 296 return ima_write_template_field_data(cur_filename, cur_filename_len,
304 fmt, field_data); 297 DATA_FMT_STRING, field_data);
305} 298}
306 299
307/* 300/*