blob: ca303e5d2b9403d858c9df8f5512c80040b0f3f7 [file] [log] [blame]
Mimi Zoharbab73932009-02-04 09:06:59 -05001/*
2 * Copyright (C) 2005,2006,2007,2008 IBM Corporation
3 *
4 * Authors:
5 * Kylene Hall <kjhall@us.ibm.com>
6 * Reiner Sailer <sailer@us.ibm.com>
7 * Mimi Zohar <zohar@us.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2 of the
12 * License.
13 *
14 * File: ima_fs.c
15 * implemenents security file system for reporting
16 * current measurement list and IMA statistics
17 */
Eric Parisf850a7c2009-05-12 15:13:55 -040018#include <linux/fcntl.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Mimi Zoharbab73932009-02-04 09:06:59 -050020#include <linux/module.h>
21#include <linux/seq_file.h>
22#include <linux/rculist.h>
23#include <linux/rcupdate.h>
Mimi Zohar4af46622009-02-04 09:07:00 -050024#include <linux/parser.h>
Dmitry Kasatkin7429b092014-04-11 17:47:01 +030025#include <linux/vmalloc.h>
Mimi Zoharbab73932009-02-04 09:06:59 -050026
27#include "ima.h"
28
Petko Manolov38d859f2015-12-02 17:47:54 +020029static DEFINE_MUTEX(ima_write_mutex);
30
Mimi Zohard68a6fe2016-12-19 16:22:57 -080031bool ima_canonical_fmt;
32static int __init default_canonical_fmt_setup(char *str)
33{
34#ifdef __BIG_ENDIAN
35 ima_canonical_fmt = 1;
36#endif
37 return 1;
38}
39__setup("ima_canonical_fmt", default_canonical_fmt_setup);
40
Mimi Zohar4af46622009-02-04 09:07:00 -050041static int valid_policy = 1;
Mimi Zoharbab73932009-02-04 09:06:59 -050042#define TMPBUFLEN 12
43static ssize_t ima_show_htable_value(char __user *buf, size_t count,
44 loff_t *ppos, atomic_long_t *val)
45{
46 char tmpbuf[TMPBUFLEN];
47 ssize_t len;
48
49 len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
50 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
51}
52
53static ssize_t ima_show_htable_violations(struct file *filp,
54 char __user *buf,
55 size_t count, loff_t *ppos)
56{
57 return ima_show_htable_value(buf, count, ppos, &ima_htable.violations);
58}
59
Alexey Dobriyan828c0952009-10-01 15:43:56 -070060static const struct file_operations ima_htable_violations_ops = {
Arnd Bergmanncdcd90f2010-07-07 23:40:15 +020061 .read = ima_show_htable_violations,
62 .llseek = generic_file_llseek,
Mimi Zoharbab73932009-02-04 09:06:59 -050063};
64
65static ssize_t ima_show_measurements_count(struct file *filp,
66 char __user *buf,
67 size_t count, loff_t *ppos)
68{
69 return ima_show_htable_value(buf, count, ppos, &ima_htable.len);
70
71}
72
Alexey Dobriyan828c0952009-10-01 15:43:56 -070073static const struct file_operations ima_measurements_count_ops = {
Arnd Bergmanncdcd90f2010-07-07 23:40:15 +020074 .read = ima_show_measurements_count,
75 .llseek = generic_file_llseek,
Mimi Zoharbab73932009-02-04 09:06:59 -050076};
77
78/* returns pointer to hlist_node */
79static void *ima_measurements_start(struct seq_file *m, loff_t *pos)
80{
81 loff_t l = *pos;
82 struct ima_queue_entry *qe;
83
84 /* we need a lock since pos could point beyond last element */
85 rcu_read_lock();
86 list_for_each_entry_rcu(qe, &ima_measurements, later) {
87 if (!l--) {
88 rcu_read_unlock();
89 return qe;
90 }
91 }
92 rcu_read_unlock();
93 return NULL;
94}
95
96static void *ima_measurements_next(struct seq_file *m, void *v, loff_t *pos)
97{
98 struct ima_queue_entry *qe = v;
99
100 /* lock protects when reading beyond last element
101 * against concurrent list-extension
102 */
103 rcu_read_lock();
Dmitry Kasatkin089bc8e2013-10-10 15:56:13 +0900104 qe = list_entry_rcu(qe->later.next, struct ima_queue_entry, later);
Mimi Zoharbab73932009-02-04 09:06:59 -0500105 rcu_read_unlock();
106 (*pos)++;
107
108 return (&qe->later == &ima_measurements) ? NULL : qe;
109}
110
111static void ima_measurements_stop(struct seq_file *m, void *v)
112{
113}
114
Roberto Sassu3ce1217d2013-06-07 12:16:30 +0200115void ima_putc(struct seq_file *m, void *data, int datalen)
Mimi Zoharbab73932009-02-04 09:06:59 -0500116{
117 while (datalen--)
118 seq_putc(m, *(char *)data++);
119}
120
121/* print format:
122 * 32bit-le=pcr#
123 * char[20]=template digest
124 * 32bit-le=template name size
125 * char[n]=template name
Roberto Sassua71dc652013-06-07 12:16:33 +0200126 * [eventdata length]
Mimi Zoharbab73932009-02-04 09:06:59 -0500127 * eventdata[n]=template specific data
128 */
Mimi Zohar7b8589c2016-12-19 16:22:48 -0800129int ima_measurements_show(struct seq_file *m, void *v)
Mimi Zoharbab73932009-02-04 09:06:59 -0500130{
131 /* the list never shrinks, so we don't need a lock here */
132 struct ima_queue_entry *qe = v;
133 struct ima_template_entry *e;
Roberto Sassu7dbdb422014-10-13 14:08:39 +0200134 char *template_name;
Mimi Zohard68a6fe2016-12-19 16:22:57 -0800135 u32 pcr, namelen, template_data_len; /* temporary fields */
Roberto Sassu3e8e5502013-11-08 19:21:40 +0100136 bool is_ima_template = false;
Roberto Sassua71dc652013-06-07 12:16:33 +0200137 int i;
Mimi Zoharbab73932009-02-04 09:06:59 -0500138
139 /* get entry */
140 e = qe->entry;
141 if (e == NULL)
142 return -1;
143
Roberto Sassu7dbdb422014-10-13 14:08:39 +0200144 template_name = (e->template_desc->name[0] != '\0') ?
145 e->template_desc->name : e->template_desc->fmt;
146
Mimi Zoharbab73932009-02-04 09:06:59 -0500147 /*
148 * 1st: PCRIndex
Eric Richter5f6f0272016-06-01 13:14:04 -0500149 * PCR used defaults to the same (config option) in
150 * little-endian format, unless set in policy
Mimi Zoharbab73932009-02-04 09:06:59 -0500151 */
Mimi Zohard68a6fe2016-12-19 16:22:57 -0800152 pcr = !ima_canonical_fmt ? e->pcr : cpu_to_le32(e->pcr);
153 ima_putc(m, &pcr, sizeof(e->pcr));
Mimi Zoharbab73932009-02-04 09:06:59 -0500154
155 /* 2nd: template digest */
Mimi Zohar140d8022013-03-11 20:29:47 -0400156 ima_putc(m, e->digest, TPM_DIGEST_SIZE);
Mimi Zoharbab73932009-02-04 09:06:59 -0500157
158 /* 3rd: template name size */
Mimi Zohard68a6fe2016-12-19 16:22:57 -0800159 namelen = !ima_canonical_fmt ? strlen(template_name) :
160 cpu_to_le32(strlen(template_name));
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200161 ima_putc(m, &namelen, sizeof(namelen));
Mimi Zoharbab73932009-02-04 09:06:59 -0500162
163 /* 4th: template name */
Mimi Zohard68a6fe2016-12-19 16:22:57 -0800164 ima_putc(m, template_name, strlen(template_name));
Mimi Zoharbab73932009-02-04 09:06:59 -0500165
Roberto Sassua71dc652013-06-07 12:16:33 +0200166 /* 5th: template length (except for 'ima' template) */
Roberto Sassu7dbdb422014-10-13 14:08:39 +0200167 if (strcmp(template_name, IMA_TEMPLATE_IMA_NAME) == 0)
Roberto Sassu3e8e5502013-11-08 19:21:40 +0100168 is_ima_template = true;
169
Mimi Zohard68a6fe2016-12-19 16:22:57 -0800170 if (!is_ima_template) {
171 template_data_len = !ima_canonical_fmt ? e->template_data_len :
172 cpu_to_le32(e->template_data_len);
173 ima_putc(m, &template_data_len, sizeof(e->template_data_len));
174 }
Roberto Sassua71dc652013-06-07 12:16:33 +0200175
176 /* 6th: template specific data */
177 for (i = 0; i < e->template_desc->num_fields; i++) {
Roberto Sassu3e8e5502013-11-08 19:21:40 +0100178 enum ima_show_type show = IMA_SHOW_BINARY;
179 struct ima_template_field *field = e->template_desc->fields[i];
180
181 if (is_ima_template && strcmp(field->field_id, "d") == 0)
182 show = IMA_SHOW_BINARY_NO_FIELD_LEN;
Roberto Sassuc019e302014-02-03 13:56:04 +0100183 if (is_ima_template && strcmp(field->field_id, "n") == 0)
184 show = IMA_SHOW_BINARY_OLD_STRING_FMT;
Roberto Sassu3e8e5502013-11-08 19:21:40 +0100185 field->field_show(m, show, &e->template_data[i]);
Roberto Sassua71dc652013-06-07 12:16:33 +0200186 }
Mimi Zoharbab73932009-02-04 09:06:59 -0500187 return 0;
188}
189
James Morris88e9d342009-09-22 16:43:43 -0700190static const struct seq_operations ima_measurments_seqops = {
Mimi Zoharbab73932009-02-04 09:06:59 -0500191 .start = ima_measurements_start,
192 .next = ima_measurements_next,
193 .stop = ima_measurements_stop,
194 .show = ima_measurements_show
195};
196
197static int ima_measurements_open(struct inode *inode, struct file *file)
198{
199 return seq_open(file, &ima_measurments_seqops);
200}
201
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700202static const struct file_operations ima_measurements_ops = {
Mimi Zoharbab73932009-02-04 09:06:59 -0500203 .open = ima_measurements_open,
204 .read = seq_read,
205 .llseek = seq_lseek,
206 .release = seq_release,
207};
208
Mimi Zohar45b26132015-06-11 11:54:42 -0400209void ima_print_digest(struct seq_file *m, u8 *digest, u32 size)
Mimi Zoharbab73932009-02-04 09:06:59 -0500210{
Mimi Zohar45b26132015-06-11 11:54:42 -0400211 u32 i;
Mimi Zoharbab73932009-02-04 09:06:59 -0500212
Mimi Zohar140d8022013-03-11 20:29:47 -0400213 for (i = 0; i < size; i++)
Mimi Zoharbab73932009-02-04 09:06:59 -0500214 seq_printf(m, "%02x", *(digest + i));
215}
216
Mimi Zoharbab73932009-02-04 09:06:59 -0500217/* print in ascii */
218static int ima_ascii_measurements_show(struct seq_file *m, void *v)
219{
220 /* the list never shrinks, so we don't need a lock here */
221 struct ima_queue_entry *qe = v;
222 struct ima_template_entry *e;
Roberto Sassu7dbdb422014-10-13 14:08:39 +0200223 char *template_name;
Roberto Sassua71dc652013-06-07 12:16:33 +0200224 int i;
Mimi Zoharbab73932009-02-04 09:06:59 -0500225
226 /* get entry */
227 e = qe->entry;
228 if (e == NULL)
229 return -1;
230
Roberto Sassu7dbdb422014-10-13 14:08:39 +0200231 template_name = (e->template_desc->name[0] != '\0') ?
232 e->template_desc->name : e->template_desc->fmt;
233
Mimi Zoharbab73932009-02-04 09:06:59 -0500234 /* 1st: PCR used (config option) */
Eric Richter5f6f0272016-06-01 13:14:04 -0500235 seq_printf(m, "%2d ", e->pcr);
Mimi Zoharbab73932009-02-04 09:06:59 -0500236
237 /* 2nd: SHA1 template hash */
Mimi Zohar140d8022013-03-11 20:29:47 -0400238 ima_print_digest(m, e->digest, TPM_DIGEST_SIZE);
Mimi Zoharbab73932009-02-04 09:06:59 -0500239
240 /* 3th: template name */
Roberto Sassu7dbdb422014-10-13 14:08:39 +0200241 seq_printf(m, " %s", template_name);
Mimi Zoharbab73932009-02-04 09:06:59 -0500242
243 /* 4th: template specific data */
Roberto Sassua71dc652013-06-07 12:16:33 +0200244 for (i = 0; i < e->template_desc->num_fields; i++) {
245 seq_puts(m, " ");
246 if (e->template_data[i].len == 0)
247 continue;
248
249 e->template_desc->fields[i]->field_show(m, IMA_SHOW_ASCII,
250 &e->template_data[i]);
251 }
252 seq_puts(m, "\n");
Mimi Zoharbab73932009-02-04 09:06:59 -0500253 return 0;
254}
255
James Morris88e9d342009-09-22 16:43:43 -0700256static const struct seq_operations ima_ascii_measurements_seqops = {
Mimi Zoharbab73932009-02-04 09:06:59 -0500257 .start = ima_measurements_start,
258 .next = ima_measurements_next,
259 .stop = ima_measurements_stop,
260 .show = ima_ascii_measurements_show
261};
262
263static int ima_ascii_measurements_open(struct inode *inode, struct file *file)
264{
265 return seq_open(file, &ima_ascii_measurements_seqops);
266}
267
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700268static const struct file_operations ima_ascii_measurements_ops = {
Mimi Zoharbab73932009-02-04 09:06:59 -0500269 .open = ima_ascii_measurements_open,
270 .read = seq_read,
271 .llseek = seq_lseek,
272 .release = seq_release,
273};
274
Dmitry Kasatkin7429b092014-04-11 17:47:01 +0300275static ssize_t ima_read_policy(char *path)
276{
277 void *data;
278 char *datap;
279 loff_t size;
280 int rc, pathlen = strlen(path);
281
282 char *p;
283
284 /* remove \n */
285 datap = path;
286 strsep(&datap, "\n");
287
288 rc = kernel_read_file_from_path(path, &data, &size, 0, READING_POLICY);
289 if (rc < 0) {
290 pr_err("Unable to open file: %s (%d)", path, rc);
291 return rc;
292 }
293
294 datap = data;
295 while (size > 0 && (p = strsep(&datap, "\n"))) {
296 pr_debug("rule: %s\n", p);
297 rc = ima_parse_add_rule(p);
298 if (rc < 0)
299 break;
300 size -= rc;
301 }
302
303 vfree(data);
304 if (rc < 0)
305 return rc;
306 else if (size)
307 return -EINVAL;
308 else
309 return pathlen;
310}
311
Mimi Zohar4af46622009-02-04 09:07:00 -0500312static ssize_t ima_write_policy(struct file *file, const char __user *buf,
313 size_t datalen, loff_t *ppos)
314{
Petko Manolov6427e6c2016-01-03 17:36:38 +0200315 char *data;
Eric Paris6ccd0452010-04-20 10:20:54 -0400316 ssize_t result;
Mimi Zohar4af46622009-02-04 09:07:00 -0500317
318 if (datalen >= PAGE_SIZE)
Eric Paris6ccd0452010-04-20 10:20:54 -0400319 datalen = PAGE_SIZE - 1;
320
321 /* No partial writes. */
322 result = -EINVAL;
323 if (*ppos != 0)
324 goto out;
325
326 result = -ENOMEM;
Mimi Zohar4af46622009-02-04 09:07:00 -0500327 data = kmalloc(datalen + 1, GFP_KERNEL);
328 if (!data)
Eric Paris6ccd0452010-04-20 10:20:54 -0400329 goto out;
Mimi Zohar4af46622009-02-04 09:07:00 -0500330
Mimi Zohar4af46622009-02-04 09:07:00 -0500331 *(data + datalen) = '\0';
Mimi Zohar4af46622009-02-04 09:07:00 -0500332
Eric Paris6ccd0452010-04-20 10:20:54 -0400333 result = -EFAULT;
334 if (copy_from_user(data, buf, datalen))
Petko Manolov6427e6c2016-01-03 17:36:38 +0200335 goto out_free;
Eric Paris6ccd0452010-04-20 10:20:54 -0400336
Petko Manolov6427e6c2016-01-03 17:36:38 +0200337 result = mutex_lock_interruptible(&ima_write_mutex);
338 if (result < 0)
339 goto out_free;
Petko Manolov6427e6c2016-01-03 17:36:38 +0200340
Mimi Zohar19f8a842016-01-15 10:17:12 -0500341 if (data[0] == '/') {
Dmitry Kasatkin7429b092014-04-11 17:47:01 +0300342 result = ima_read_policy(data);
Mimi Zohar19f8a842016-01-15 10:17:12 -0500343 } else if (ima_appraise & IMA_APPRAISE_POLICY) {
344 pr_err("IMA: signed policy file (specified as an absolute pathname) required\n");
345 integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL, NULL,
346 "policy_update", "signed policy required",
347 1, 0);
348 if (ima_appraise & IMA_APPRAISE_ENFORCE)
349 result = -EACCES;
350 } else {
Dmitry Kasatkin7429b092014-04-11 17:47:01 +0300351 result = ima_parse_add_rule(data);
Mimi Zohar19f8a842016-01-15 10:17:12 -0500352 }
Dmitry Kasatkin7429b092014-04-11 17:47:01 +0300353 mutex_unlock(&ima_write_mutex);
Petko Manolov6427e6c2016-01-03 17:36:38 +0200354out_free:
355 kfree(data);
Eric Paris6ccd0452010-04-20 10:20:54 -0400356out:
357 if (result < 0)
358 valid_policy = 0;
Petko Manolov38d859f2015-12-02 17:47:54 +0200359
Eric Paris6ccd0452010-04-20 10:20:54 -0400360 return result;
Mimi Zohar4af46622009-02-04 09:07:00 -0500361}
362
Mimi Zoharbab73932009-02-04 09:06:59 -0500363static struct dentry *ima_dir;
364static struct dentry *binary_runtime_measurements;
365static struct dentry *ascii_runtime_measurements;
366static struct dentry *runtime_measurements_count;
367static struct dentry *violations;
Mimi Zohar4af46622009-02-04 09:07:00 -0500368static struct dentry *ima_policy;
369
Dmitry Kasatkin0716abb2014-10-03 14:40:21 +0300370enum ima_fs_flags {
371 IMA_FS_BUSY,
372};
373
374static unsigned long ima_fs_flags;
375
Petko Manolov80eae202015-12-02 17:47:56 +0200376#ifdef CONFIG_IMA_READ_POLICY
377static const struct seq_operations ima_policy_seqops = {
378 .start = ima_policy_start,
379 .next = ima_policy_next,
380 .stop = ima_policy_stop,
381 .show = ima_policy_show,
382};
383#endif
384
Mimi Zoharf4bd8572009-02-04 09:07:01 -0500385/*
386 * ima_open_policy: sequentialize access to the policy file
387 */
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200388static int ima_open_policy(struct inode *inode, struct file *filp)
Mimi Zoharf4bd8572009-02-04 09:07:01 -0500389{
Petko Manolov80eae202015-12-02 17:47:56 +0200390 if (!(filp->f_flags & O_WRONLY)) {
391#ifndef CONFIG_IMA_READ_POLICY
Eric Parisf850a7c2009-05-12 15:13:55 -0400392 return -EACCES;
Petko Manolov80eae202015-12-02 17:47:56 +0200393#else
394 if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
395 return -EACCES;
396 if (!capable(CAP_SYS_ADMIN))
397 return -EPERM;
398 return seq_open(filp, &ima_policy_seqops);
399#endif
400 }
Dmitry Kasatkin0716abb2014-10-03 14:40:21 +0300401 if (test_and_set_bit(IMA_FS_BUSY, &ima_fs_flags))
402 return -EBUSY;
403 return 0;
Mimi Zoharf4bd8572009-02-04 09:07:01 -0500404}
405
Mimi Zohar4af46622009-02-04 09:07:00 -0500406/*
407 * ima_release_policy - start using the new measure policy rules.
408 *
409 * Initially, ima_measure points to the default policy rules, now
Mimi Zoharf4bd8572009-02-04 09:07:01 -0500410 * point to the new policy rules, and remove the securityfs policy file,
411 * assuming a valid policy.
Mimi Zohar4af46622009-02-04 09:07:00 -0500412 */
413static int ima_release_policy(struct inode *inode, struct file *file)
414{
Dmitry Kasatkin0716abb2014-10-03 14:40:21 +0300415 const char *cause = valid_policy ? "completed" : "failed";
416
Petko Manolov80eae202015-12-02 17:47:56 +0200417 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
Eric Richter9a11a182016-10-13 17:47:36 -0500418 return seq_release(inode, file);
Petko Manolov80eae202015-12-02 17:47:56 +0200419
Sasha Levin01127212015-12-22 08:51:23 -0500420 if (valid_policy && ima_check_policy() < 0) {
421 cause = "failed";
422 valid_policy = 0;
423 }
424
Dmitry Kasatkin0716abb2014-10-03 14:40:21 +0300425 pr_info("IMA: policy update %s\n", cause);
426 integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL, NULL,
427 "policy_update", cause, !valid_policy, 0);
428
Mimi Zohar4af46622009-02-04 09:07:00 -0500429 if (!valid_policy) {
430 ima_delete_rules();
Mimi Zoharf4bd8572009-02-04 09:07:01 -0500431 valid_policy = 1;
Dmitry Kasatkin0716abb2014-10-03 14:40:21 +0300432 clear_bit(IMA_FS_BUSY, &ima_fs_flags);
Mimi Zohar4af46622009-02-04 09:07:00 -0500433 return 0;
434 }
Petko Manolov80eae202015-12-02 17:47:56 +0200435
Mimi Zohar4af46622009-02-04 09:07:00 -0500436 ima_update_policy();
Petko Manolov38d859f2015-12-02 17:47:54 +0200437#ifndef CONFIG_IMA_WRITE_POLICY
Mimi Zohar4af46622009-02-04 09:07:00 -0500438 securityfs_remove(ima_policy);
439 ima_policy = NULL;
Petko Manolov38d859f2015-12-02 17:47:54 +0200440#else
441 clear_bit(IMA_FS_BUSY, &ima_fs_flags);
442#endif
Mimi Zohar4af46622009-02-04 09:07:00 -0500443 return 0;
444}
445
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700446static const struct file_operations ima_measure_policy_ops = {
Mimi Zoharf4bd8572009-02-04 09:07:01 -0500447 .open = ima_open_policy,
Mimi Zohar4af46622009-02-04 09:07:00 -0500448 .write = ima_write_policy,
Petko Manolov80eae202015-12-02 17:47:56 +0200449 .read = seq_read,
Arnd Bergmanncdcd90f2010-07-07 23:40:15 +0200450 .release = ima_release_policy,
451 .llseek = generic_file_llseek,
Mimi Zohar4af46622009-02-04 09:07:00 -0500452};
Mimi Zoharbab73932009-02-04 09:06:59 -0500453
Eric Paris932995f2009-05-21 15:43:32 -0400454int __init ima_fs_init(void)
Mimi Zoharbab73932009-02-04 09:06:59 -0500455{
456 ima_dir = securityfs_create_dir("ima", NULL);
457 if (IS_ERR(ima_dir))
458 return -1;
459
460 binary_runtime_measurements =
461 securityfs_create_file("binary_runtime_measurements",
462 S_IRUSR | S_IRGRP, ima_dir, NULL,
463 &ima_measurements_ops);
464 if (IS_ERR(binary_runtime_measurements))
465 goto out;
466
467 ascii_runtime_measurements =
468 securityfs_create_file("ascii_runtime_measurements",
469 S_IRUSR | S_IRGRP, ima_dir, NULL,
470 &ima_ascii_measurements_ops);
471 if (IS_ERR(ascii_runtime_measurements))
472 goto out;
473
474 runtime_measurements_count =
475 securityfs_create_file("runtime_measurements_count",
476 S_IRUSR | S_IRGRP, ima_dir, NULL,
477 &ima_measurements_count_ops);
478 if (IS_ERR(runtime_measurements_count))
479 goto out;
480
481 violations =
482 securityfs_create_file("violations", S_IRUSR | S_IRGRP,
483 ima_dir, NULL, &ima_htable_violations_ops);
484 if (IS_ERR(violations))
485 goto out;
486
Petko Manolov80eae202015-12-02 17:47:56 +0200487 ima_policy = securityfs_create_file("policy", POLICY_FILE_FLAGS,
Mimi Zohar4af46622009-02-04 09:07:00 -0500488 ima_dir, NULL,
489 &ima_measure_policy_ops);
490 if (IS_ERR(ima_policy))
491 goto out;
Mimi Zoharbab73932009-02-04 09:06:59 -0500492
Mimi Zohar4af46622009-02-04 09:07:00 -0500493 return 0;
Mimi Zoharbab73932009-02-04 09:06:59 -0500494out:
Dmitry Kasatkin0ea4f8a2012-01-29 19:19:08 -0500495 securityfs_remove(violations);
Mimi Zoharbab73932009-02-04 09:06:59 -0500496 securityfs_remove(runtime_measurements_count);
497 securityfs_remove(ascii_runtime_measurements);
498 securityfs_remove(binary_runtime_measurements);
499 securityfs_remove(ima_dir);
Mimi Zohar4af46622009-02-04 09:07:00 -0500500 securityfs_remove(ima_policy);
Mimi Zoharbab73932009-02-04 09:06:59 -0500501 return -1;
502}