diff options
Diffstat (limited to 'security/integrity/ima/ima_fs.c')
-rw-r--r-- | security/integrity/ima/ima_fs.c | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c index 38477c9c3415..db01125926bd 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c | |||
@@ -88,8 +88,7 @@ static void *ima_measurements_next(struct seq_file *m, void *v, loff_t *pos) | |||
88 | * against concurrent list-extension | 88 | * against concurrent list-extension |
89 | */ | 89 | */ |
90 | rcu_read_lock(); | 90 | rcu_read_lock(); |
91 | qe = list_entry_rcu(qe->later.next, | 91 | qe = list_entry_rcu(qe->later.next, struct ima_queue_entry, later); |
92 | struct ima_queue_entry, later); | ||
93 | rcu_read_unlock(); | 92 | rcu_read_unlock(); |
94 | (*pos)++; | 93 | (*pos)++; |
95 | 94 | ||
@@ -100,7 +99,7 @@ static void ima_measurements_stop(struct seq_file *m, void *v) | |||
100 | { | 99 | { |
101 | } | 100 | } |
102 | 101 | ||
103 | static void ima_putc(struct seq_file *m, void *data, int datalen) | 102 | void ima_putc(struct seq_file *m, void *data, int datalen) |
104 | { | 103 | { |
105 | while (datalen--) | 104 | while (datalen--) |
106 | seq_putc(m, *(char *)data++); | 105 | seq_putc(m, *(char *)data++); |
@@ -111,6 +110,7 @@ static void ima_putc(struct seq_file *m, void *data, int datalen) | |||
111 | * char[20]=template digest | 110 | * char[20]=template digest |
112 | * 32bit-le=template name size | 111 | * 32bit-le=template name size |
113 | * char[n]=template name | 112 | * char[n]=template name |
113 | * [eventdata length] | ||
114 | * eventdata[n]=template specific data | 114 | * eventdata[n]=template specific data |
115 | */ | 115 | */ |
116 | static int ima_measurements_show(struct seq_file *m, void *v) | 116 | static int ima_measurements_show(struct seq_file *m, void *v) |
@@ -120,6 +120,8 @@ static int ima_measurements_show(struct seq_file *m, void *v) | |||
120 | struct ima_template_entry *e; | 120 | struct ima_template_entry *e; |
121 | int namelen; | 121 | int namelen; |
122 | u32 pcr = CONFIG_IMA_MEASURE_PCR_IDX; | 122 | u32 pcr = CONFIG_IMA_MEASURE_PCR_IDX; |
123 | bool is_ima_template = false; | ||
124 | int i; | ||
123 | 125 | ||
124 | /* get entry */ | 126 | /* get entry */ |
125 | e = qe->entry; | 127 | e = qe->entry; |
@@ -134,18 +136,32 @@ static int ima_measurements_show(struct seq_file *m, void *v) | |||
134 | ima_putc(m, &pcr, sizeof pcr); | 136 | ima_putc(m, &pcr, sizeof pcr); |
135 | 137 | ||
136 | /* 2nd: template digest */ | 138 | /* 2nd: template digest */ |
137 | ima_putc(m, e->digest, IMA_DIGEST_SIZE); | 139 | ima_putc(m, e->digest, TPM_DIGEST_SIZE); |
138 | 140 | ||
139 | /* 3rd: template name size */ | 141 | /* 3rd: template name size */ |
140 | namelen = strlen(e->template_name); | 142 | namelen = strlen(e->template_desc->name); |
141 | ima_putc(m, &namelen, sizeof namelen); | 143 | ima_putc(m, &namelen, sizeof namelen); |
142 | 144 | ||
143 | /* 4th: template name */ | 145 | /* 4th: template name */ |
144 | ima_putc(m, (void *)e->template_name, namelen); | 146 | ima_putc(m, e->template_desc->name, namelen); |
147 | |||
148 | /* 5th: template length (except for 'ima' template) */ | ||
149 | if (strcmp(e->template_desc->name, IMA_TEMPLATE_IMA_NAME) == 0) | ||
150 | is_ima_template = true; | ||
151 | |||
152 | if (!is_ima_template) | ||
153 | ima_putc(m, &e->template_data_len, | ||
154 | sizeof(e->template_data_len)); | ||
155 | |||
156 | /* 6th: template specific data */ | ||
157 | for (i = 0; i < e->template_desc->num_fields; i++) { | ||
158 | enum ima_show_type show = IMA_SHOW_BINARY; | ||
159 | struct ima_template_field *field = e->template_desc->fields[i]; | ||
145 | 160 | ||
146 | /* 5th: template specific data */ | 161 | if (is_ima_template && strcmp(field->field_id, "d") == 0) |
147 | ima_template_show(m, (struct ima_template_data *)&e->template, | 162 | show = IMA_SHOW_BINARY_NO_FIELD_LEN; |
148 | IMA_SHOW_BINARY); | 163 | field->field_show(m, show, &e->template_data[i]); |
164 | } | ||
149 | return 0; | 165 | return 0; |
150 | } | 166 | } |
151 | 167 | ||
@@ -168,41 +184,21 @@ static const struct file_operations ima_measurements_ops = { | |||
168 | .release = seq_release, | 184 | .release = seq_release, |
169 | }; | 185 | }; |
170 | 186 | ||
171 | static void ima_print_digest(struct seq_file *m, u8 *digest) | 187 | void ima_print_digest(struct seq_file *m, u8 *digest, int size) |
172 | { | 188 | { |
173 | int i; | 189 | int i; |
174 | 190 | ||
175 | for (i = 0; i < IMA_DIGEST_SIZE; i++) | 191 | for (i = 0; i < size; i++) |
176 | seq_printf(m, "%02x", *(digest + i)); | 192 | seq_printf(m, "%02x", *(digest + i)); |
177 | } | 193 | } |
178 | 194 | ||
179 | void ima_template_show(struct seq_file *m, void *e, enum ima_show_type show) | ||
180 | { | ||
181 | struct ima_template_data *entry = e; | ||
182 | int namelen; | ||
183 | |||
184 | switch (show) { | ||
185 | case IMA_SHOW_ASCII: | ||
186 | ima_print_digest(m, entry->digest); | ||
187 | seq_printf(m, " %s\n", entry->file_name); | ||
188 | break; | ||
189 | case IMA_SHOW_BINARY: | ||
190 | ima_putc(m, entry->digest, IMA_DIGEST_SIZE); | ||
191 | |||
192 | namelen = strlen(entry->file_name); | ||
193 | ima_putc(m, &namelen, sizeof namelen); | ||
194 | ima_putc(m, entry->file_name, namelen); | ||
195 | default: | ||
196 | break; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | /* print in ascii */ | 195 | /* print in ascii */ |
201 | static int ima_ascii_measurements_show(struct seq_file *m, void *v) | 196 | static int ima_ascii_measurements_show(struct seq_file *m, void *v) |
202 | { | 197 | { |
203 | /* the list never shrinks, so we don't need a lock here */ | 198 | /* the list never shrinks, so we don't need a lock here */ |
204 | struct ima_queue_entry *qe = v; | 199 | struct ima_queue_entry *qe = v; |
205 | struct ima_template_entry *e; | 200 | struct ima_template_entry *e; |
201 | int i; | ||
206 | 202 | ||
207 | /* get entry */ | 203 | /* get entry */ |
208 | e = qe->entry; | 204 | e = qe->entry; |
@@ -213,14 +209,21 @@ static int ima_ascii_measurements_show(struct seq_file *m, void *v) | |||
213 | seq_printf(m, "%2d ", CONFIG_IMA_MEASURE_PCR_IDX); | 209 | seq_printf(m, "%2d ", CONFIG_IMA_MEASURE_PCR_IDX); |
214 | 210 | ||
215 | /* 2nd: SHA1 template hash */ | 211 | /* 2nd: SHA1 template hash */ |
216 | ima_print_digest(m, e->digest); | 212 | ima_print_digest(m, e->digest, TPM_DIGEST_SIZE); |
217 | 213 | ||
218 | /* 3th: template name */ | 214 | /* 3th: template name */ |
219 | seq_printf(m, " %s ", e->template_name); | 215 | seq_printf(m, " %s", e->template_desc->name); |
220 | 216 | ||
221 | /* 4th: template specific data */ | 217 | /* 4th: template specific data */ |
222 | ima_template_show(m, (struct ima_template_data *)&e->template, | 218 | for (i = 0; i < e->template_desc->num_fields; i++) { |
223 | IMA_SHOW_ASCII); | 219 | seq_puts(m, " "); |
220 | if (e->template_data[i].len == 0) | ||
221 | continue; | ||
222 | |||
223 | e->template_desc->fields[i]->field_show(m, IMA_SHOW_ASCII, | ||
224 | &e->template_data[i]); | ||
225 | } | ||
226 | seq_puts(m, "\n"); | ||
224 | return 0; | 227 | return 0; |
225 | } | 228 | } |
226 | 229 | ||