diff options
| -rw-r--r-- | security/integrity/ima/ima_template.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c index d93a58e603df..65117ba06809 100644 --- a/security/integrity/ima/ima_template.c +++ b/security/integrity/ima/ima_template.c | |||
| @@ -117,8 +117,9 @@ static int template_desc_init_fields(const char *template_fmt, | |||
| 117 | int *num_fields) | 117 | int *num_fields) |
| 118 | { | 118 | { |
| 119 | const char *template_fmt_ptr; | 119 | const char *template_fmt_ptr; |
| 120 | struct ima_template_field *found_fields[IMA_TEMPLATE_NUM_FIELDS_MAX]; | ||
| 120 | int template_num_fields = template_fmt_size(template_fmt); | 121 | int template_num_fields = template_fmt_size(template_fmt); |
| 121 | int i, len, result = 0; | 122 | int i, len; |
| 122 | 123 | ||
| 123 | if (template_num_fields > IMA_TEMPLATE_NUM_FIELDS_MAX) { | 124 | if (template_num_fields > IMA_TEMPLATE_NUM_FIELDS_MAX) { |
| 124 | pr_err("format string '%s' contains too many fields\n", | 125 | pr_err("format string '%s' contains too many fields\n", |
| @@ -126,41 +127,32 @@ static int template_desc_init_fields(const char *template_fmt, | |||
| 126 | return -EINVAL; | 127 | return -EINVAL; |
| 127 | } | 128 | } |
| 128 | 129 | ||
| 129 | *fields = kzalloc(template_num_fields * sizeof(*fields), GFP_KERNEL); | ||
| 130 | if (*fields == NULL) { | ||
| 131 | result = -ENOMEM; | ||
| 132 | goto out; | ||
| 133 | } | ||
| 134 | |||
| 135 | for (i = 0, template_fmt_ptr = template_fmt; i < template_num_fields; | 130 | for (i = 0, template_fmt_ptr = template_fmt; i < template_num_fields; |
| 136 | i++, template_fmt_ptr += len + 1) { | 131 | i++, template_fmt_ptr += len + 1) { |
| 137 | char tmp_field_id[IMA_TEMPLATE_FIELD_ID_MAX_LEN + 1]; | 132 | char tmp_field_id[IMA_TEMPLATE_FIELD_ID_MAX_LEN + 1]; |
| 138 | struct ima_template_field *f; | ||
| 139 | 133 | ||
| 140 | len = strchrnul(template_fmt_ptr, '|') - template_fmt_ptr; | 134 | len = strchrnul(template_fmt_ptr, '|') - template_fmt_ptr; |
| 141 | if (len == 0 || len > IMA_TEMPLATE_FIELD_ID_MAX_LEN) { | 135 | if (len == 0 || len > IMA_TEMPLATE_FIELD_ID_MAX_LEN) { |
| 142 | pr_err("Invalid field with length %d\n", len); | 136 | pr_err("Invalid field with length %d\n", len); |
| 143 | result = -EINVAL; | 137 | return -EINVAL; |
| 144 | goto out; | ||
| 145 | } | 138 | } |
| 146 | 139 | ||
| 147 | memcpy(tmp_field_id, template_fmt_ptr, len); | 140 | memcpy(tmp_field_id, template_fmt_ptr, len); |
| 148 | tmp_field_id[len] = '\0'; | 141 | tmp_field_id[len] = '\0'; |
| 149 | f = lookup_template_field(tmp_field_id); | 142 | found_fields[i] = lookup_template_field(tmp_field_id); |
| 150 | if (!f) { | 143 | if (!found_fields[i]) { |
| 151 | pr_err("field '%s' not found\n", tmp_field_id); | 144 | pr_err("field '%s' not found\n", tmp_field_id); |
| 152 | result = -ENOENT; | 145 | return -ENOENT; |
| 153 | goto out; | ||
| 154 | } | 146 | } |
| 155 | (*fields)[i] = f; | ||
| 156 | } | 147 | } |
| 148 | |||
| 149 | *fields = kmalloc_array(i, sizeof(*fields), GFP_KERNEL); | ||
| 150 | if (*fields == NULL) | ||
| 151 | return -ENOMEM; | ||
| 152 | |||
| 153 | memcpy(*fields, found_fields, i * sizeof(*fields)); | ||
| 157 | *num_fields = i; | 154 | *num_fields = i; |
| 158 | out: | 155 | return 0; |
| 159 | if (result < 0) { | ||
| 160 | kfree(*fields); | ||
| 161 | *fields = NULL; | ||
| 162 | } | ||
| 163 | return result; | ||
| 164 | } | 156 | } |
| 165 | 157 | ||
| 166 | struct ima_template_desc *ima_template_desc_current(void) | 158 | struct ima_template_desc *ima_template_desc_current(void) |
