blob: b3a2038ed4243ba5da5e887d4a26d1818c138589 [file] [log] [blame]
Mimi Zohar3323eec2009-02-04 09:06:58 -05001/*
2 * Copyright (C) 2008 IBM Corporation
3 * Author: Mimi Zohar <zohar@us.ibm.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
8 *
9 * ima_policy.c
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020010 * - initialize default measure policy rules
Mimi Zohar3323eec2009-02-04 09:06:58 -050011 *
12 */
13#include <linux/module.h>
14#include <linux/list.h>
Mimi Zohar3323eec2009-02-04 09:06:58 -050015#include <linux/security.h>
16#include <linux/magic.h>
Mimi Zohar4af46622009-02-04 09:07:00 -050017#include <linux/parser.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Dmitry Kasatkin85865c12012-09-03 23:23:13 +030019#include <linux/genhd.h>
Mimi Zohar3323eec2009-02-04 09:06:58 -050020
21#include "ima.h"
22
23/* flags definitions */
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020024#define IMA_FUNC 0x0001
25#define IMA_MASK 0x0002
Mimi Zohar3323eec2009-02-04 09:06:58 -050026#define IMA_FSMAGIC 0x0004
27#define IMA_UID 0x0008
Mimi Zohar07f6a792011-03-09 22:25:48 -050028#define IMA_FOWNER 0x0010
Dmitry Kasatkin85865c12012-09-03 23:23:13 +030029#define IMA_FSUUID 0x0020
Mimi Zohar4351c292014-11-05 07:53:55 -050030#define IMA_INMASK 0x0040
Mimi Zohar139069e2014-11-05 07:48:36 -050031#define IMA_EUID 0x0080
Mimi Zohar3323eec2009-02-04 09:06:58 -050032
Dmitry Kasatkin45e24722012-09-12 20:51:32 +030033#define UNKNOWN 0
34#define MEASURE 0x0001 /* same as IMA_MEASURE */
35#define DONT_MEASURE 0x0002
36#define APPRAISE 0x0004 /* same as IMA_APPRAISE */
37#define DONT_APPRAISE 0x0008
Peter Moodye7c568e2012-06-14 10:04:36 -070038#define AUDIT 0x0040
Mimi Zohar4af46622009-02-04 09:07:00 -050039
Roberto Sassua7560242014-09-12 19:35:54 +020040int ima_policy_flag;
41
Mimi Zohar4af46622009-02-04 09:07:00 -050042#define MAX_LSM_RULES 6
43enum lsm_rule_types { LSM_OBJ_USER, LSM_OBJ_ROLE, LSM_OBJ_TYPE,
44 LSM_SUBJ_USER, LSM_SUBJ_ROLE, LSM_SUBJ_TYPE
45};
Mimi Zohar3323eec2009-02-04 09:06:58 -050046
Mimi Zohar07f6a792011-03-09 22:25:48 -050047struct ima_rule_entry {
Mimi Zohar3323eec2009-02-04 09:06:58 -050048 struct list_head list;
Mimi Zohar2fe5d6d2012-02-13 10:15:05 -050049 int action;
Mimi Zohar3323eec2009-02-04 09:06:58 -050050 unsigned int flags;
51 enum ima_hooks func;
52 int mask;
53 unsigned long fsmagic;
Dmitry Kasatkin85865c12012-09-03 23:23:13 +030054 u8 fsuuid[16];
Eric W. Biederman8b94eea2012-05-25 18:24:12 -060055 kuid_t uid;
Linus Torvalds882653222012-10-02 21:38:48 -070056 kuid_t fowner;
Mimi Zohar4af46622009-02-04 09:07:00 -050057 struct {
58 void *rule; /* LSM file metadata specific */
Mimi Zohar7163a992013-01-03 14:19:09 -050059 void *args_p; /* audit value */
Mimi Zohar4af46622009-02-04 09:07:00 -050060 int type; /* audit type */
61 } lsm[MAX_LSM_RULES];
Mimi Zohar3323eec2009-02-04 09:06:58 -050062};
63
Eric Paris5789ba32009-05-21 15:47:06 -040064/*
65 * Without LSM specific knowledge, the default policy can only be
Mimi Zohar07f6a792011-03-09 22:25:48 -050066 * written in terms of .action, .func, .mask, .fsmagic, .uid, and .fowner
Mimi Zohar4af46622009-02-04 09:07:00 -050067 */
Eric Paris5789ba32009-05-21 15:47:06 -040068
69/*
70 * The minimum rule set to allow for full TCB coverage. Measures all files
71 * opened or mmap for exec and everything read by root. Dangerous because
72 * normal users can easily run the machine out of memory simply building
73 * and running executables.
74 */
Mimi Zohar07f6a792011-03-09 22:25:48 -050075static struct ima_rule_entry default_rules[] = {
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020076 {.action = DONT_MEASURE, .fsmagic = PROC_SUPER_MAGIC, .flags = IMA_FSMAGIC},
77 {.action = DONT_MEASURE, .fsmagic = SYSFS_MAGIC, .flags = IMA_FSMAGIC},
78 {.action = DONT_MEASURE, .fsmagic = DEBUGFS_MAGIC, .flags = IMA_FSMAGIC},
79 {.action = DONT_MEASURE, .fsmagic = TMPFS_MAGIC, .flags = IMA_FSMAGIC},
80 {.action = DONT_MEASURE, .fsmagic = DEVPTS_SUPER_MAGIC, .flags = IMA_FSMAGIC},
81 {.action = DONT_MEASURE, .fsmagic = BINFMTFS_MAGIC, .flags = IMA_FSMAGIC},
82 {.action = DONT_MEASURE, .fsmagic = SECURITYFS_MAGIC, .flags = IMA_FSMAGIC},
83 {.action = DONT_MEASURE, .fsmagic = SELINUX_MAGIC, .flags = IMA_FSMAGIC},
Roberto Sassu6438de92015-04-11 17:13:06 +020084 {.action = DONT_MEASURE, .fsmagic = CGROUP_SUPER_MAGIC,
85 .flags = IMA_FSMAGIC},
Mimi Zoharcd025f72015-04-21 16:54:24 -040086 {.action = DONT_MEASURE, .fsmagic = NSFS_MAGIC, .flags = IMA_FSMAGIC},
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020087 {.action = MEASURE, .func = MMAP_CHECK, .mask = MAY_EXEC,
Mimi Zohar3323eec2009-02-04 09:06:58 -050088 .flags = IMA_FUNC | IMA_MASK},
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020089 {.action = MEASURE, .func = BPRM_CHECK, .mask = MAY_EXEC,
Mimi Zohar3323eec2009-02-04 09:06:58 -050090 .flags = IMA_FUNC | IMA_MASK},
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020091 {.action = MEASURE, .func = FILE_CHECK, .mask = MAY_READ, .uid = GLOBAL_ROOT_UID,
Eric Paris5789ba32009-05-21 15:47:06 -040092 .flags = IMA_FUNC | IMA_MASK | IMA_UID},
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020093 {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC},
Mimi Zohar5a9196d2014-07-22 10:39:48 -040094 {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC},
Mimi Zohar3323eec2009-02-04 09:06:58 -050095};
96
Mimi Zohar07f6a792011-03-09 22:25:48 -050097static struct ima_rule_entry default_appraise_rules[] = {
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020098 {.action = DONT_APPRAISE, .fsmagic = PROC_SUPER_MAGIC, .flags = IMA_FSMAGIC},
99 {.action = DONT_APPRAISE, .fsmagic = SYSFS_MAGIC, .flags = IMA_FSMAGIC},
100 {.action = DONT_APPRAISE, .fsmagic = DEBUGFS_MAGIC, .flags = IMA_FSMAGIC},
101 {.action = DONT_APPRAISE, .fsmagic = TMPFS_MAGIC, .flags = IMA_FSMAGIC},
102 {.action = DONT_APPRAISE, .fsmagic = RAMFS_MAGIC, .flags = IMA_FSMAGIC},
103 {.action = DONT_APPRAISE, .fsmagic = DEVPTS_SUPER_MAGIC, .flags = IMA_FSMAGIC},
104 {.action = DONT_APPRAISE, .fsmagic = BINFMTFS_MAGIC, .flags = IMA_FSMAGIC},
105 {.action = DONT_APPRAISE, .fsmagic = SECURITYFS_MAGIC, .flags = IMA_FSMAGIC},
106 {.action = DONT_APPRAISE, .fsmagic = SELINUX_MAGIC, .flags = IMA_FSMAGIC},
Mimi Zoharcd025f72015-04-21 16:54:24 -0400107 {.action = DONT_APPRAISE, .fsmagic = NSFS_MAGIC, .flags = IMA_FSMAGIC},
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200108 {.action = DONT_APPRAISE, .fsmagic = CGROUP_SUPER_MAGIC, .flags = IMA_FSMAGIC},
Dmitry Kasatkinc57782c2014-11-05 17:01:16 +0200109#ifndef CONFIG_IMA_APPRAISE_SIGNED_INIT
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200110 {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .flags = IMA_FOWNER},
Dmitry Kasatkinc57782c2014-11-05 17:01:16 +0200111#else
112 /* force signature */
113 {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID,
114 .flags = IMA_FOWNER | IMA_DIGSIG_REQUIRED},
115#endif
Mimi Zohar07f6a792011-03-09 22:25:48 -0500116};
Mimi Zohar3323eec2009-02-04 09:06:58 -0500117
Mimi Zohar07f6a792011-03-09 22:25:48 -0500118static LIST_HEAD(ima_default_rules);
119static LIST_HEAD(ima_policy_rules);
120static struct list_head *ima_rules;
121
122static DEFINE_MUTEX(ima_rules_mutex);
Mimi Zohar4af46622009-02-04 09:07:00 -0500123
Eric Paris5789ba32009-05-21 15:47:06 -0400124static bool ima_use_tcb __initdata;
Mimi Zohar07f6a792011-03-09 22:25:48 -0500125static int __init default_measure_policy_setup(char *str)
Eric Paris5789ba32009-05-21 15:47:06 -0400126{
127 ima_use_tcb = 1;
128 return 1;
129}
Mimi Zohar07f6a792011-03-09 22:25:48 -0500130__setup("ima_tcb", default_measure_policy_setup);
131
132static bool ima_use_appraise_tcb __initdata;
133static int __init default_appraise_policy_setup(char *str)
134{
135 ima_use_appraise_tcb = 1;
136 return 1;
137}
138__setup("ima_appraise_tcb", default_appraise_policy_setup);
Eric Paris5789ba32009-05-21 15:47:06 -0400139
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200140/*
Mimi Zohar7163a992013-01-03 14:19:09 -0500141 * Although the IMA policy does not change, the LSM policy can be
142 * reloaded, leaving the IMA LSM based rules referring to the old,
143 * stale LSM policy.
144 *
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200145 * Update the IMA LSM based rules to reflect the reloaded LSM policy.
Mimi Zohar7163a992013-01-03 14:19:09 -0500146 * We assume the rules still exist; and BUG_ON() if they don't.
147 */
148static void ima_lsm_update_rules(void)
149{
150 struct ima_rule_entry *entry, *tmp;
151 int result;
152 int i;
153
154 mutex_lock(&ima_rules_mutex);
155 list_for_each_entry_safe(entry, tmp, &ima_policy_rules, list) {
156 for (i = 0; i < MAX_LSM_RULES; i++) {
157 if (!entry->lsm[i].rule)
158 continue;
159 result = security_filter_rule_init(entry->lsm[i].type,
160 Audit_equal,
161 entry->lsm[i].args_p,
162 &entry->lsm[i].rule);
163 BUG_ON(!entry->lsm[i].rule);
164 }
165 }
166 mutex_unlock(&ima_rules_mutex);
167}
168
Mimi Zohar3323eec2009-02-04 09:06:58 -0500169/**
170 * ima_match_rules - determine whether an inode matches the measure rule.
171 * @rule: a pointer to a rule
172 * @inode: a pointer to an inode
173 * @func: LIM hook identifier
174 * @mask: requested action (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
175 *
176 * Returns true on rule match, false on failure.
177 */
Mimi Zohar07f6a792011-03-09 22:25:48 -0500178static bool ima_match_rules(struct ima_rule_entry *rule,
Mimi Zohar3323eec2009-02-04 09:06:58 -0500179 struct inode *inode, enum ima_hooks func, int mask)
180{
181 struct task_struct *tsk = current;
Mimi Zohar3db59dd2012-01-17 22:11:28 -0500182 const struct cred *cred = current_cred();
Mimi Zohar4af46622009-02-04 09:07:00 -0500183 int i;
Mimi Zohar3323eec2009-02-04 09:06:58 -0500184
Dmitry Kasatkin09b11482013-11-13 23:42:39 +0200185 if ((rule->flags & IMA_FUNC) &&
186 (rule->func != func && func != POST_SETATTR))
Mimi Zohar3323eec2009-02-04 09:06:58 -0500187 return false;
Dmitry Kasatkin09b11482013-11-13 23:42:39 +0200188 if ((rule->flags & IMA_MASK) &&
189 (rule->mask != mask && func != POST_SETATTR))
Mimi Zohar3323eec2009-02-04 09:06:58 -0500190 return false;
Mimi Zohar4351c292014-11-05 07:53:55 -0500191 if ((rule->flags & IMA_INMASK) &&
192 (!(rule->mask & mask) && func != POST_SETATTR))
193 return false;
Mimi Zohar3323eec2009-02-04 09:06:58 -0500194 if ((rule->flags & IMA_FSMAGIC)
195 && rule->fsmagic != inode->i_sb->s_magic)
196 return false;
Dmitry Kasatkin85865c12012-09-03 23:23:13 +0300197 if ((rule->flags & IMA_FSUUID) &&
Mimi Zohar446d64e2013-02-24 23:42:37 -0500198 memcmp(rule->fsuuid, inode->i_sb->s_uuid, sizeof(rule->fsuuid)))
Dmitry Kasatkin85865c12012-09-03 23:23:13 +0300199 return false;
Eric W. Biederman8b94eea2012-05-25 18:24:12 -0600200 if ((rule->flags & IMA_UID) && !uid_eq(rule->uid, cred->uid))
Mimi Zohar3323eec2009-02-04 09:06:58 -0500201 return false;
Mimi Zohar139069e2014-11-05 07:48:36 -0500202 if (rule->flags & IMA_EUID) {
203 if (has_capability_noaudit(current, CAP_SETUID)) {
204 if (!uid_eq(rule->uid, cred->euid)
205 && !uid_eq(rule->uid, cred->suid)
206 && !uid_eq(rule->uid, cred->uid))
207 return false;
208 } else if (!uid_eq(rule->uid, cred->euid))
209 return false;
210 }
211
Linus Torvalds882653222012-10-02 21:38:48 -0700212 if ((rule->flags & IMA_FOWNER) && !uid_eq(rule->fowner, inode->i_uid))
Mimi Zohar07f6a792011-03-09 22:25:48 -0500213 return false;
Mimi Zohar4af46622009-02-04 09:07:00 -0500214 for (i = 0; i < MAX_LSM_RULES; i++) {
Mimi Zohar53fc0e22009-05-05 13:12:48 -0400215 int rc = 0;
Mimi Zohar4af46622009-02-04 09:07:00 -0500216 u32 osid, sid;
Mimi Zohar7163a992013-01-03 14:19:09 -0500217 int retried = 0;
Mimi Zohar4af46622009-02-04 09:07:00 -0500218
219 if (!rule->lsm[i].rule)
220 continue;
Mimi Zohar7163a992013-01-03 14:19:09 -0500221retry:
Mimi Zohar4af46622009-02-04 09:07:00 -0500222 switch (i) {
223 case LSM_OBJ_USER:
224 case LSM_OBJ_ROLE:
225 case LSM_OBJ_TYPE:
226 security_inode_getsecid(inode, &osid);
227 rc = security_filter_rule_match(osid,
228 rule->lsm[i].type,
Mimi Zohar53fc0e22009-05-05 13:12:48 -0400229 Audit_equal,
Mimi Zohar4af46622009-02-04 09:07:00 -0500230 rule->lsm[i].rule,
231 NULL);
232 break;
233 case LSM_SUBJ_USER:
234 case LSM_SUBJ_ROLE:
235 case LSM_SUBJ_TYPE:
236 security_task_getsecid(tsk, &sid);
237 rc = security_filter_rule_match(sid,
238 rule->lsm[i].type,
Mimi Zohar53fc0e22009-05-05 13:12:48 -0400239 Audit_equal,
Mimi Zohar4af46622009-02-04 09:07:00 -0500240 rule->lsm[i].rule,
241 NULL);
242 default:
243 break;
244 }
Mimi Zohar7163a992013-01-03 14:19:09 -0500245 if ((rc < 0) && (!retried)) {
246 retried = 1;
247 ima_lsm_update_rules();
248 goto retry;
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200249 }
Mimi Zohar4af46622009-02-04 09:07:00 -0500250 if (!rc)
251 return false;
252 }
Mimi Zohar3323eec2009-02-04 09:06:58 -0500253 return true;
254}
255
Mimi Zohard79d72e2012-12-03 17:08:11 -0500256/*
257 * In addition to knowing that we need to appraise the file in general,
Mimi Zohar5a73fcf2012-12-05 15:14:38 -0500258 * we need to differentiate between calling hooks, for hook specific rules.
Mimi Zohard79d72e2012-12-03 17:08:11 -0500259 */
Mimi Zohar5a73fcf2012-12-05 15:14:38 -0500260static int get_subaction(struct ima_rule_entry *rule, int func)
Mimi Zohard79d72e2012-12-03 17:08:11 -0500261{
Mimi Zohar5a73fcf2012-12-05 15:14:38 -0500262 if (!(rule->flags & IMA_FUNC))
263 return IMA_FILE_APPRAISE;
264
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200265 switch (func) {
Mimi Zohard79d72e2012-12-03 17:08:11 -0500266 case MMAP_CHECK:
267 return IMA_MMAP_APPRAISE;
268 case BPRM_CHECK:
269 return IMA_BPRM_APPRAISE;
270 case MODULE_CHECK:
271 return IMA_MODULE_APPRAISE;
Mimi Zohar5a9196d2014-07-22 10:39:48 -0400272 case FIRMWARE_CHECK:
273 return IMA_FIRMWARE_APPRAISE;
Mimi Zohard79d72e2012-12-03 17:08:11 -0500274 case FILE_CHECK:
275 default:
276 return IMA_FILE_APPRAISE;
277 }
278}
279
Mimi Zohar3323eec2009-02-04 09:06:58 -0500280/**
281 * ima_match_policy - decision based on LSM and other conditions
282 * @inode: pointer to an inode for which the policy decision is being made
283 * @func: IMA hook identifier
284 * @mask: requested action (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
285 *
286 * Measure decision based on func/mask/fsmagic and LSM(subj/obj/type)
287 * conditions.
288 *
289 * (There is no need for locking when walking the policy list,
290 * as elements in the list are never deleted, nor does the list
291 * change.)
292 */
Mimi Zohar2fe5d6d2012-02-13 10:15:05 -0500293int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
294 int flags)
Mimi Zohar3323eec2009-02-04 09:06:58 -0500295{
Mimi Zohar07f6a792011-03-09 22:25:48 -0500296 struct ima_rule_entry *entry;
Mimi Zohar2fe5d6d2012-02-13 10:15:05 -0500297 int action = 0, actmask = flags | (flags << 1);
Mimi Zohar3323eec2009-02-04 09:06:58 -0500298
Mimi Zohar07f6a792011-03-09 22:25:48 -0500299 list_for_each_entry(entry, ima_rules, list) {
Mimi Zohar3323eec2009-02-04 09:06:58 -0500300
Mimi Zohar2fe5d6d2012-02-13 10:15:05 -0500301 if (!(entry->action & actmask))
302 continue;
303
304 if (!ima_match_rules(entry, inode, func, mask))
305 continue;
306
Dmitry Kasatkin0e5a2472012-06-08 13:58:49 +0300307 action |= entry->flags & IMA_ACTION_FLAGS;
308
Dmitry Kasatkin45e24722012-09-12 20:51:32 +0300309 action |= entry->action & IMA_DO_MASK;
Mimi Zohard79d72e2012-12-03 17:08:11 -0500310 if (entry->action & IMA_APPRAISE)
Mimi Zohar5a73fcf2012-12-05 15:14:38 -0500311 action |= get_subaction(entry, func);
Mimi Zohard79d72e2012-12-03 17:08:11 -0500312
Dmitry Kasatkin45e24722012-09-12 20:51:32 +0300313 if (entry->action & IMA_DO_MASK)
314 actmask &= ~(entry->action | entry->action << 1);
315 else
316 actmask &= ~(entry->action | entry->action >> 1);
317
Mimi Zohar2fe5d6d2012-02-13 10:15:05 -0500318 if (!actmask)
319 break;
Mimi Zohar3323eec2009-02-04 09:06:58 -0500320 }
Mimi Zohar2fe5d6d2012-02-13 10:15:05 -0500321
322 return action;
Mimi Zohar3323eec2009-02-04 09:06:58 -0500323}
324
Roberto Sassua7560242014-09-12 19:35:54 +0200325/*
326 * Initialize the ima_policy_flag variable based on the currently
327 * loaded policy. Based on this flag, the decision to short circuit
328 * out of a function or not call the function in the first place
329 * can be made earlier.
330 */
331void ima_update_policy_flag(void)
332{
333 struct ima_rule_entry *entry;
334
335 ima_policy_flag = 0;
336 list_for_each_entry(entry, ima_rules, list) {
337 if (entry->action & IMA_DO_MASK)
338 ima_policy_flag |= entry->action;
339 }
340
341 if (!ima_appraise)
342 ima_policy_flag &= ~IMA_APPRAISE;
343}
344
Mimi Zohar3323eec2009-02-04 09:06:58 -0500345/**
346 * ima_init_policy - initialize the default measure rules.
347 *
Mimi Zohar07f6a792011-03-09 22:25:48 -0500348 * ima_rules points to either the ima_default_rules or the
349 * the new ima_policy_rules.
Mimi Zohar3323eec2009-02-04 09:06:58 -0500350 */
Eric Paris932995f2009-05-21 15:43:32 -0400351void __init ima_init_policy(void)
Mimi Zohar3323eec2009-02-04 09:06:58 -0500352{
Mimi Zohar07f6a792011-03-09 22:25:48 -0500353 int i, measure_entries, appraise_entries;
Mimi Zohar3323eec2009-02-04 09:06:58 -0500354
Eric Paris5789ba32009-05-21 15:47:06 -0400355 /* if !ima_use_tcb set entries = 0 so we load NO default rules */
Mimi Zohar07f6a792011-03-09 22:25:48 -0500356 measure_entries = ima_use_tcb ? ARRAY_SIZE(default_rules) : 0;
357 appraise_entries = ima_use_appraise_tcb ?
358 ARRAY_SIZE(default_appraise_rules) : 0;
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200359
Dan Carpenter55778572015-04-07 12:22:11 +0300360 for (i = 0; i < measure_entries; i++)
361 list_add_tail(&default_rules[i].list, &ima_default_rules);
Eric Paris5789ba32009-05-21 15:47:06 -0400362
Dan Carpenter55778572015-04-07 12:22:11 +0300363 for (i = 0; i < appraise_entries; i++) {
364 list_add_tail(&default_appraise_rules[i].list,
365 &ima_default_rules);
Mimi Zohar07f6a792011-03-09 22:25:48 -0500366 }
367
368 ima_rules = &ima_default_rules;
Mimi Zohar3323eec2009-02-04 09:06:58 -0500369}
Mimi Zohar4af46622009-02-04 09:07:00 -0500370
371/**
372 * ima_update_policy - update default_rules with new measure rules
373 *
374 * Called on file .release to update the default rules with a complete new
375 * policy. Once updated, the policy is locked, no additional rules can be
376 * added to the policy.
377 */
378void ima_update_policy(void)
379{
Dmitry Kasatkin0716abb2014-10-03 14:40:21 +0300380 ima_rules = &ima_policy_rules;
381 ima_update_policy_flag();
Mimi Zohar4af46622009-02-04 09:07:00 -0500382}
383
384enum {
385 Opt_err = -1,
386 Opt_measure = 1, Opt_dont_measure,
Mimi Zohar07f6a792011-03-09 22:25:48 -0500387 Opt_appraise, Opt_dont_appraise,
Peter Moodye7c568e2012-06-14 10:04:36 -0700388 Opt_audit,
Mimi Zohar4af46622009-02-04 09:07:00 -0500389 Opt_obj_user, Opt_obj_role, Opt_obj_type,
390 Opt_subj_user, Opt_subj_role, Opt_subj_type,
Mimi Zohar139069e2014-11-05 07:48:36 -0500391 Opt_func, Opt_mask, Opt_fsmagic,
392 Opt_uid, Opt_euid, Opt_fowner,
Mimi Zoharf9b2a732014-05-12 09:28:11 -0400393 Opt_appraise_type, Opt_fsuuid, Opt_permit_directio
Mimi Zohar4af46622009-02-04 09:07:00 -0500394};
395
396static match_table_t policy_tokens = {
397 {Opt_measure, "measure"},
398 {Opt_dont_measure, "dont_measure"},
Mimi Zohar07f6a792011-03-09 22:25:48 -0500399 {Opt_appraise, "appraise"},
400 {Opt_dont_appraise, "dont_appraise"},
Peter Moodye7c568e2012-06-14 10:04:36 -0700401 {Opt_audit, "audit"},
Mimi Zohar4af46622009-02-04 09:07:00 -0500402 {Opt_obj_user, "obj_user=%s"},
403 {Opt_obj_role, "obj_role=%s"},
404 {Opt_obj_type, "obj_type=%s"},
405 {Opt_subj_user, "subj_user=%s"},
406 {Opt_subj_role, "subj_role=%s"},
407 {Opt_subj_type, "subj_type=%s"},
408 {Opt_func, "func=%s"},
409 {Opt_mask, "mask=%s"},
410 {Opt_fsmagic, "fsmagic=%s"},
Dmitry Kasatkin85865c12012-09-03 23:23:13 +0300411 {Opt_fsuuid, "fsuuid=%s"},
Mimi Zohar4af46622009-02-04 09:07:00 -0500412 {Opt_uid, "uid=%s"},
Mimi Zohar139069e2014-11-05 07:48:36 -0500413 {Opt_euid, "euid=%s"},
Mimi Zohar07f6a792011-03-09 22:25:48 -0500414 {Opt_fowner, "fowner=%s"},
Dmitry Kasatkin0e5a2472012-06-08 13:58:49 +0300415 {Opt_appraise_type, "appraise_type=%s"},
Mimi Zoharf9b2a732014-05-12 09:28:11 -0400416 {Opt_permit_directio, "permit_directio"},
Mimi Zohar4af46622009-02-04 09:07:00 -0500417 {Opt_err, NULL}
418};
419
Mimi Zohar07f6a792011-03-09 22:25:48 -0500420static int ima_lsm_rule_init(struct ima_rule_entry *entry,
Mimi Zohar7163a992013-01-03 14:19:09 -0500421 substring_t *args, int lsm_rule, int audit_type)
Mimi Zohar4af46622009-02-04 09:07:00 -0500422{
423 int result;
424
Eric Paris7b62e162010-04-20 10:21:01 -0400425 if (entry->lsm[lsm_rule].rule)
426 return -EINVAL;
427
Mimi Zohar7163a992013-01-03 14:19:09 -0500428 entry->lsm[lsm_rule].args_p = match_strdup(args);
429 if (!entry->lsm[lsm_rule].args_p)
430 return -ENOMEM;
431
Mimi Zohar4af46622009-02-04 09:07:00 -0500432 entry->lsm[lsm_rule].type = audit_type;
433 result = security_filter_rule_init(entry->lsm[lsm_rule].type,
Mimi Zohar7163a992013-01-03 14:19:09 -0500434 Audit_equal,
435 entry->lsm[lsm_rule].args_p,
Mimi Zohar4af46622009-02-04 09:07:00 -0500436 &entry->lsm[lsm_rule].rule);
Mimi Zohar7163a992013-01-03 14:19:09 -0500437 if (!entry->lsm[lsm_rule].rule) {
438 kfree(entry->lsm[lsm_rule].args_p);
Mimi Zohar867c2022011-01-03 14:59:10 -0800439 return -EINVAL;
Mimi Zohar7163a992013-01-03 14:19:09 -0500440 }
441
Mimi Zohar4af46622009-02-04 09:07:00 -0500442 return result;
443}
444
Eric Paris2f1506c2010-04-20 10:21:30 -0400445static void ima_log_string(struct audit_buffer *ab, char *key, char *value)
446{
447 audit_log_format(ab, "%s=", key);
448 audit_log_untrustedstring(ab, value);
449 audit_log_format(ab, " ");
450}
451
Mimi Zohar07f6a792011-03-09 22:25:48 -0500452static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
Mimi Zohar4af46622009-02-04 09:07:00 -0500453{
454 struct audit_buffer *ab;
Mimi Zohar4351c292014-11-05 07:53:55 -0500455 char *from;
Mimi Zohar4af46622009-02-04 09:07:00 -0500456 char *p;
457 int result = 0;
458
Mimi Zohar523979a2009-02-11 11:12:28 -0500459 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_INTEGRITY_RULE);
Mimi Zohar4af46622009-02-04 09:07:00 -0500460
Eric W. Biederman8b94eea2012-05-25 18:24:12 -0600461 entry->uid = INVALID_UID;
Linus Torvalds882653222012-10-02 21:38:48 -0700462 entry->fowner = INVALID_UID;
Eric Parisb9035b12010-04-20 10:21:07 -0400463 entry->action = UNKNOWN;
Eric Paris28ef4002010-04-20 10:21:18 -0400464 while ((p = strsep(&rule, " \t")) != NULL) {
Mimi Zohar4af46622009-02-04 09:07:00 -0500465 substring_t args[MAX_OPT_ARGS];
466 int token;
467 unsigned long lnum;
468
469 if (result < 0)
470 break;
Eric Paris28ef4002010-04-20 10:21:18 -0400471 if ((*p == '\0') || (*p == ' ') || (*p == '\t'))
472 continue;
Mimi Zohar4af46622009-02-04 09:07:00 -0500473 token = match_token(p, policy_tokens, args);
474 switch (token) {
475 case Opt_measure:
Eric Paris2f1506c2010-04-20 10:21:30 -0400476 ima_log_string(ab, "action", "measure");
Eric Paris7b62e162010-04-20 10:21:01 -0400477
478 if (entry->action != UNKNOWN)
479 result = -EINVAL;
480
Mimi Zohar4af46622009-02-04 09:07:00 -0500481 entry->action = MEASURE;
482 break;
483 case Opt_dont_measure:
Eric Paris2f1506c2010-04-20 10:21:30 -0400484 ima_log_string(ab, "action", "dont_measure");
Eric Paris7b62e162010-04-20 10:21:01 -0400485
486 if (entry->action != UNKNOWN)
487 result = -EINVAL;
488
Mimi Zohar4af46622009-02-04 09:07:00 -0500489 entry->action = DONT_MEASURE;
490 break;
Mimi Zohar07f6a792011-03-09 22:25:48 -0500491 case Opt_appraise:
492 ima_log_string(ab, "action", "appraise");
493
494 if (entry->action != UNKNOWN)
495 result = -EINVAL;
496
497 entry->action = APPRAISE;
498 break;
499 case Opt_dont_appraise:
500 ima_log_string(ab, "action", "dont_appraise");
501
502 if (entry->action != UNKNOWN)
503 result = -EINVAL;
504
505 entry->action = DONT_APPRAISE;
506 break;
Peter Moodye7c568e2012-06-14 10:04:36 -0700507 case Opt_audit:
508 ima_log_string(ab, "action", "audit");
509
510 if (entry->action != UNKNOWN)
511 result = -EINVAL;
512
513 entry->action = AUDIT;
514 break;
Mimi Zohar4af46622009-02-04 09:07:00 -0500515 case Opt_func:
Eric Paris2f1506c2010-04-20 10:21:30 -0400516 ima_log_string(ab, "func", args[0].from);
Eric Paris7b62e162010-04-20 10:21:01 -0400517
518 if (entry->func)
Mimi Zohar07f6a792011-03-09 22:25:48 -0500519 result = -EINVAL;
Eric Paris7b62e162010-04-20 10:21:01 -0400520
Mimi Zohar1e93d002010-01-26 17:02:41 -0500521 if (strcmp(args[0].from, "FILE_CHECK") == 0)
522 entry->func = FILE_CHECK;
523 /* PATH_CHECK is for backwards compat */
524 else if (strcmp(args[0].from, "PATH_CHECK") == 0)
525 entry->func = FILE_CHECK;
Mimi Zoharfdf90722012-10-16 12:40:08 +1030526 else if (strcmp(args[0].from, "MODULE_CHECK") == 0)
527 entry->func = MODULE_CHECK;
Mimi Zohar5a9196d2014-07-22 10:39:48 -0400528 else if (strcmp(args[0].from, "FIRMWARE_CHECK") == 0)
529 entry->func = FIRMWARE_CHECK;
Mimi Zohar16cac492012-12-13 11:15:04 -0500530 else if ((strcmp(args[0].from, "FILE_MMAP") == 0)
531 || (strcmp(args[0].from, "MMAP_CHECK") == 0))
532 entry->func = MMAP_CHECK;
Mimi Zohar4af46622009-02-04 09:07:00 -0500533 else if (strcmp(args[0].from, "BPRM_CHECK") == 0)
534 entry->func = BPRM_CHECK;
535 else
536 result = -EINVAL;
537 if (!result)
538 entry->flags |= IMA_FUNC;
539 break;
540 case Opt_mask:
Eric Paris2f1506c2010-04-20 10:21:30 -0400541 ima_log_string(ab, "mask", args[0].from);
Eric Paris7b62e162010-04-20 10:21:01 -0400542
543 if (entry->mask)
544 result = -EINVAL;
545
Mimi Zohar4351c292014-11-05 07:53:55 -0500546 from = args[0].from;
547 if (*from == '^')
548 from++;
549
550 if ((strcmp(from, "MAY_EXEC")) == 0)
Mimi Zohar4af46622009-02-04 09:07:00 -0500551 entry->mask = MAY_EXEC;
Mimi Zohar4351c292014-11-05 07:53:55 -0500552 else if (strcmp(from, "MAY_WRITE") == 0)
Mimi Zohar4af46622009-02-04 09:07:00 -0500553 entry->mask = MAY_WRITE;
Mimi Zohar4351c292014-11-05 07:53:55 -0500554 else if (strcmp(from, "MAY_READ") == 0)
Mimi Zohar4af46622009-02-04 09:07:00 -0500555 entry->mask = MAY_READ;
Mimi Zohar4351c292014-11-05 07:53:55 -0500556 else if (strcmp(from, "MAY_APPEND") == 0)
Mimi Zohar4af46622009-02-04 09:07:00 -0500557 entry->mask = MAY_APPEND;
558 else
559 result = -EINVAL;
560 if (!result)
Mimi Zohar4351c292014-11-05 07:53:55 -0500561 entry->flags |= (*args[0].from == '^')
562 ? IMA_INMASK : IMA_MASK;
Mimi Zohar4af46622009-02-04 09:07:00 -0500563 break;
564 case Opt_fsmagic:
Eric Paris2f1506c2010-04-20 10:21:30 -0400565 ima_log_string(ab, "fsmagic", args[0].from);
Eric Paris7b62e162010-04-20 10:21:01 -0400566
567 if (entry->fsmagic) {
568 result = -EINVAL;
569 break;
570 }
571
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +0200572 result = kstrtoul(args[0].from, 16, &entry->fsmagic);
Mimi Zohar4af46622009-02-04 09:07:00 -0500573 if (!result)
574 entry->flags |= IMA_FSMAGIC;
575 break;
Dmitry Kasatkin85865c12012-09-03 23:23:13 +0300576 case Opt_fsuuid:
577 ima_log_string(ab, "fsuuid", args[0].from);
578
579 if (memchr_inv(entry->fsuuid, 0x00,
Mimi Zohar446d64e2013-02-24 23:42:37 -0500580 sizeof(entry->fsuuid))) {
Dmitry Kasatkin85865c12012-09-03 23:23:13 +0300581 result = -EINVAL;
582 break;
583 }
584
Mimi Zohar446d64e2013-02-24 23:42:37 -0500585 result = blk_part_pack_uuid(args[0].from,
586 entry->fsuuid);
587 if (!result)
588 entry->flags |= IMA_FSUUID;
Dmitry Kasatkin85865c12012-09-03 23:23:13 +0300589 break;
Mimi Zohar4af46622009-02-04 09:07:00 -0500590 case Opt_uid:
Eric Paris2f1506c2010-04-20 10:21:30 -0400591 ima_log_string(ab, "uid", args[0].from);
Mimi Zohar139069e2014-11-05 07:48:36 -0500592 case Opt_euid:
593 if (token == Opt_euid)
594 ima_log_string(ab, "euid", args[0].from);
Eric Paris7b62e162010-04-20 10:21:01 -0400595
Eric W. Biederman8b94eea2012-05-25 18:24:12 -0600596 if (uid_valid(entry->uid)) {
Eric Paris7b62e162010-04-20 10:21:01 -0400597 result = -EINVAL;
598 break;
599 }
600
Jingoo Han29707b22014-02-05 15:13:14 +0900601 result = kstrtoul(args[0].from, 10, &lnum);
Mimi Zohar4af46622009-02-04 09:07:00 -0500602 if (!result) {
Mimi Zohar139069e2014-11-05 07:48:36 -0500603 entry->uid = make_kuid(current_user_ns(),
604 (uid_t) lnum);
605 if (!uid_valid(entry->uid) ||
606 (uid_t)lnum != lnum)
Mimi Zohar4af46622009-02-04 09:07:00 -0500607 result = -EINVAL;
608 else
Mimi Zohar139069e2014-11-05 07:48:36 -0500609 entry->flags |= (token == Opt_uid)
610 ? IMA_UID : IMA_EUID;
Mimi Zohar4af46622009-02-04 09:07:00 -0500611 }
612 break;
Mimi Zohar07f6a792011-03-09 22:25:48 -0500613 case Opt_fowner:
614 ima_log_string(ab, "fowner", args[0].from);
615
Linus Torvalds882653222012-10-02 21:38:48 -0700616 if (uid_valid(entry->fowner)) {
Mimi Zohar07f6a792011-03-09 22:25:48 -0500617 result = -EINVAL;
618 break;
619 }
620
Jingoo Han29707b22014-02-05 15:13:14 +0900621 result = kstrtoul(args[0].from, 10, &lnum);
Mimi Zohar07f6a792011-03-09 22:25:48 -0500622 if (!result) {
Linus Torvalds882653222012-10-02 21:38:48 -0700623 entry->fowner = make_kuid(current_user_ns(), (uid_t)lnum);
624 if (!uid_valid(entry->fowner) || (((uid_t)lnum) != lnum))
Mimi Zohar07f6a792011-03-09 22:25:48 -0500625 result = -EINVAL;
626 else
627 entry->flags |= IMA_FOWNER;
628 }
629 break;
Mimi Zohar4af46622009-02-04 09:07:00 -0500630 case Opt_obj_user:
Eric Paris2f1506c2010-04-20 10:21:30 -0400631 ima_log_string(ab, "obj_user", args[0].from);
Mimi Zohar7163a992013-01-03 14:19:09 -0500632 result = ima_lsm_rule_init(entry, args,
Mimi Zohar4af46622009-02-04 09:07:00 -0500633 LSM_OBJ_USER,
634 AUDIT_OBJ_USER);
635 break;
636 case Opt_obj_role:
Eric Paris2f1506c2010-04-20 10:21:30 -0400637 ima_log_string(ab, "obj_role", args[0].from);
Mimi Zohar7163a992013-01-03 14:19:09 -0500638 result = ima_lsm_rule_init(entry, args,
Mimi Zohar4af46622009-02-04 09:07:00 -0500639 LSM_OBJ_ROLE,
640 AUDIT_OBJ_ROLE);
641 break;
642 case Opt_obj_type:
Eric Paris2f1506c2010-04-20 10:21:30 -0400643 ima_log_string(ab, "obj_type", args[0].from);
Mimi Zohar7163a992013-01-03 14:19:09 -0500644 result = ima_lsm_rule_init(entry, args,
Mimi Zohar4af46622009-02-04 09:07:00 -0500645 LSM_OBJ_TYPE,
646 AUDIT_OBJ_TYPE);
647 break;
648 case Opt_subj_user:
Eric Paris2f1506c2010-04-20 10:21:30 -0400649 ima_log_string(ab, "subj_user", args[0].from);
Mimi Zohar7163a992013-01-03 14:19:09 -0500650 result = ima_lsm_rule_init(entry, args,
Mimi Zohar4af46622009-02-04 09:07:00 -0500651 LSM_SUBJ_USER,
652 AUDIT_SUBJ_USER);
653 break;
654 case Opt_subj_role:
Eric Paris2f1506c2010-04-20 10:21:30 -0400655 ima_log_string(ab, "subj_role", args[0].from);
Mimi Zohar7163a992013-01-03 14:19:09 -0500656 result = ima_lsm_rule_init(entry, args,
Mimi Zohar4af46622009-02-04 09:07:00 -0500657 LSM_SUBJ_ROLE,
658 AUDIT_SUBJ_ROLE);
659 break;
660 case Opt_subj_type:
Eric Paris2f1506c2010-04-20 10:21:30 -0400661 ima_log_string(ab, "subj_type", args[0].from);
Mimi Zohar7163a992013-01-03 14:19:09 -0500662 result = ima_lsm_rule_init(entry, args,
Mimi Zohar4af46622009-02-04 09:07:00 -0500663 LSM_SUBJ_TYPE,
664 AUDIT_SUBJ_TYPE);
665 break;
Dmitry Kasatkin0e5a2472012-06-08 13:58:49 +0300666 case Opt_appraise_type:
667 if (entry->action != APPRAISE) {
668 result = -EINVAL;
669 break;
670 }
671
672 ima_log_string(ab, "appraise_type", args[0].from);
673 if ((strcmp(args[0].from, "imasig")) == 0)
674 entry->flags |= IMA_DIGSIG_REQUIRED;
675 else
676 result = -EINVAL;
677 break;
Mimi Zoharf9b2a732014-05-12 09:28:11 -0400678 case Opt_permit_directio:
679 entry->flags |= IMA_PERMIT_DIRECTIO;
680 break;
Mimi Zohar4af46622009-02-04 09:07:00 -0500681 case Opt_err:
Eric Paris2f1506c2010-04-20 10:21:30 -0400682 ima_log_string(ab, "UNKNOWN", p);
Eric Parise9d393b2010-04-20 10:21:13 -0400683 result = -EINVAL;
Mimi Zohar4af46622009-02-04 09:07:00 -0500684 break;
685 }
686 }
Eric Paris7b62e162010-04-20 10:21:01 -0400687 if (!result && (entry->action == UNKNOWN))
Mimi Zohar4af46622009-02-04 09:07:00 -0500688 result = -EINVAL;
Mimi Zohara7f2a362012-12-21 08:34:21 -0500689 else if (entry->func == MODULE_CHECK)
690 ima_appraise |= IMA_APPRAISE_MODULES;
Mimi Zohar5a9196d2014-07-22 10:39:48 -0400691 else if (entry->func == FIRMWARE_CHECK)
692 ima_appraise |= IMA_APPRAISE_FIRMWARE;
Eric Parisb0d5de42012-02-14 17:11:07 -0500693 audit_log_format(ab, "res=%d", !result);
Mimi Zohar4af46622009-02-04 09:07:00 -0500694 audit_log_end(ab);
695 return result;
696}
697
698/**
Mimi Zohar07f6a792011-03-09 22:25:48 -0500699 * ima_parse_add_rule - add a rule to ima_policy_rules
Mimi Zohar4af46622009-02-04 09:07:00 -0500700 * @rule - ima measurement policy rule
701 *
702 * Uses a mutex to protect the policy list from multiple concurrent writers.
Eric Paris6ccd0452010-04-20 10:20:54 -0400703 * Returns the length of the rule parsed, an error code on failure
Mimi Zohar4af46622009-02-04 09:07:00 -0500704 */
Eric Paris6ccd0452010-04-20 10:20:54 -0400705ssize_t ima_parse_add_rule(char *rule)
Mimi Zohar4af46622009-02-04 09:07:00 -0500706{
Mimi Zohar52a13282013-12-11 14:44:04 -0500707 static const char op[] = "update_policy";
Eric Paris6ccd0452010-04-20 10:20:54 -0400708 char *p;
Mimi Zohar07f6a792011-03-09 22:25:48 -0500709 struct ima_rule_entry *entry;
Eric Paris6ccd0452010-04-20 10:20:54 -0400710 ssize_t result, len;
Mimi Zohar4af46622009-02-04 09:07:00 -0500711 int audit_info = 0;
712
Dmitry Kasatkin272a6e92014-10-03 14:40:19 +0300713 p = strsep(&rule, "\n");
714 len = strlen(p) + 1;
Dmitry Kasatkin71787842014-10-03 14:40:20 +0300715 p += strspn(p, " \t");
Dmitry Kasatkin272a6e92014-10-03 14:40:19 +0300716
Dmitry Kasatkin71787842014-10-03 14:40:20 +0300717 if (*p == '#' || *p == '\0')
Dmitry Kasatkin272a6e92014-10-03 14:40:19 +0300718 return len;
719
Mimi Zohar4af46622009-02-04 09:07:00 -0500720 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
721 if (!entry) {
722 integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
723 NULL, op, "-ENOMEM", -ENOMEM, audit_info);
724 return -ENOMEM;
725 }
726
727 INIT_LIST_HEAD(&entry->list);
728
Eric Paris6ccd0452010-04-20 10:20:54 -0400729 result = ima_parse_rule(p, entry);
Eric Paris7233e3e2010-04-20 10:21:24 -0400730 if (result) {
Mimi Zohar4af46622009-02-04 09:07:00 -0500731 kfree(entry);
Mimi Zohar523979a2009-02-11 11:12:28 -0500732 integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
Richard Guy Briggs7e9001f2014-06-16 15:52:07 -0400733 NULL, op, "invalid-policy", result,
Mimi Zohar523979a2009-02-11 11:12:28 -0500734 audit_info);
Eric Paris7233e3e2010-04-20 10:21:24 -0400735 return result;
Mimi Zohar523979a2009-02-11 11:12:28 -0500736 }
Eric Paris7233e3e2010-04-20 10:21:24 -0400737
Mimi Zohar07f6a792011-03-09 22:25:48 -0500738 mutex_lock(&ima_rules_mutex);
739 list_add_tail(&entry->list, &ima_policy_rules);
740 mutex_unlock(&ima_rules_mutex);
Eric Paris7233e3e2010-04-20 10:21:24 -0400741
742 return len;
Mimi Zohar4af46622009-02-04 09:07:00 -0500743}
744
745/* ima_delete_rules called to cleanup invalid policy */
James Morris64c61d82009-02-05 09:28:26 +1100746void ima_delete_rules(void)
Mimi Zohar4af46622009-02-04 09:07:00 -0500747{
Mimi Zohar07f6a792011-03-09 22:25:48 -0500748 struct ima_rule_entry *entry, *tmp;
Mimi Zohar7163a992013-01-03 14:19:09 -0500749 int i;
Mimi Zohar4af46622009-02-04 09:07:00 -0500750
Mimi Zohar07f6a792011-03-09 22:25:48 -0500751 mutex_lock(&ima_rules_mutex);
752 list_for_each_entry_safe(entry, tmp, &ima_policy_rules, list) {
Mimi Zohar7163a992013-01-03 14:19:09 -0500753 for (i = 0; i < MAX_LSM_RULES; i++)
754 kfree(entry->lsm[i].args_p);
755
Mimi Zohar4af46622009-02-04 09:07:00 -0500756 list_del(&entry->list);
757 kfree(entry);
758 }
Mimi Zohar07f6a792011-03-09 22:25:48 -0500759 mutex_unlock(&ima_rules_mutex);
Mimi Zohar4af46622009-02-04 09:07:00 -0500760}