ima_policy.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /*
  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
  10. * - initialize default measure policy rules
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/list.h>
  15. #include <linux/security.h>
  16. #include <linux/magic.h>
  17. #include <linux/parser.h>
  18. #include <linux/slab.h>
  19. #include "ima.h"
  20. /* flags definitions */
  21. #define IMA_FUNC 0x0001
  22. #define IMA_MASK 0x0002
  23. #define IMA_FSMAGIC 0x0004
  24. #define IMA_UID 0x0008
  25. #define IMA_FOWNER 0x0010
  26. #define UNKNOWN 0
  27. #define MEASURE 0x0001 /* same as IMA_MEASURE */
  28. #define DONT_MEASURE 0x0002
  29. #define APPRAISE 0x0004 /* same as IMA_APPRAISE */
  30. #define DONT_APPRAISE 0x0008
  31. #define AUDIT 0x0040
  32. #define MAX_LSM_RULES 6
  33. enum lsm_rule_types { LSM_OBJ_USER, LSM_OBJ_ROLE, LSM_OBJ_TYPE,
  34. LSM_SUBJ_USER, LSM_SUBJ_ROLE, LSM_SUBJ_TYPE
  35. };
  36. struct ima_rule_entry {
  37. struct list_head list;
  38. int action;
  39. unsigned int flags;
  40. enum ima_hooks func;
  41. int mask;
  42. unsigned long fsmagic;
  43. kuid_t uid;
  44. kuid_t fowner;
  45. struct {
  46. void *rule; /* LSM file metadata specific */
  47. int type; /* audit type */
  48. } lsm[MAX_LSM_RULES];
  49. };
  50. /*
  51. * Without LSM specific knowledge, the default policy can only be
  52. * written in terms of .action, .func, .mask, .fsmagic, .uid, and .fowner
  53. */
  54. /*
  55. * The minimum rule set to allow for full TCB coverage. Measures all files
  56. * opened or mmap for exec and everything read by root. Dangerous because
  57. * normal users can easily run the machine out of memory simply building
  58. * and running executables.
  59. */
  60. static struct ima_rule_entry default_rules[] = {
  61. {.action = DONT_MEASURE,.fsmagic = PROC_SUPER_MAGIC,.flags = IMA_FSMAGIC},
  62. {.action = DONT_MEASURE,.fsmagic = SYSFS_MAGIC,.flags = IMA_FSMAGIC},
  63. {.action = DONT_MEASURE,.fsmagic = DEBUGFS_MAGIC,.flags = IMA_FSMAGIC},
  64. {.action = DONT_MEASURE,.fsmagic = TMPFS_MAGIC,.flags = IMA_FSMAGIC},
  65. {.action = DONT_MEASURE,.fsmagic = RAMFS_MAGIC,.flags = IMA_FSMAGIC},
  66. {.action = DONT_MEASURE,.fsmagic = DEVPTS_SUPER_MAGIC,.flags = IMA_FSMAGIC},
  67. {.action = DONT_MEASURE,.fsmagic = BINFMTFS_MAGIC,.flags = IMA_FSMAGIC},
  68. {.action = DONT_MEASURE,.fsmagic = SECURITYFS_MAGIC,.flags = IMA_FSMAGIC},
  69. {.action = DONT_MEASURE,.fsmagic = SELINUX_MAGIC,.flags = IMA_FSMAGIC},
  70. {.action = MEASURE,.func = FILE_MMAP,.mask = MAY_EXEC,
  71. .flags = IMA_FUNC | IMA_MASK},
  72. {.action = MEASURE,.func = BPRM_CHECK,.mask = MAY_EXEC,
  73. .flags = IMA_FUNC | IMA_MASK},
  74. {.action = MEASURE,.func = FILE_CHECK,.mask = MAY_READ,.uid = GLOBAL_ROOT_UID,
  75. .flags = IMA_FUNC | IMA_MASK | IMA_UID},
  76. {.action = MEASURE,.func = MODULE_CHECK, .flags = IMA_FUNC},
  77. };
  78. static struct ima_rule_entry default_appraise_rules[] = {
  79. {.action = DONT_APPRAISE,.fsmagic = PROC_SUPER_MAGIC,.flags = IMA_FSMAGIC},
  80. {.action = DONT_APPRAISE,.fsmagic = SYSFS_MAGIC,.flags = IMA_FSMAGIC},
  81. {.action = DONT_APPRAISE,.fsmagic = DEBUGFS_MAGIC,.flags = IMA_FSMAGIC},
  82. {.action = DONT_APPRAISE,.fsmagic = TMPFS_MAGIC,.flags = IMA_FSMAGIC},
  83. {.action = DONT_APPRAISE,.fsmagic = RAMFS_MAGIC,.flags = IMA_FSMAGIC},
  84. {.action = DONT_APPRAISE,.fsmagic = DEVPTS_SUPER_MAGIC,.flags = IMA_FSMAGIC},
  85. {.action = DONT_APPRAISE,.fsmagic = BINFMTFS_MAGIC,.flags = IMA_FSMAGIC},
  86. {.action = DONT_APPRAISE,.fsmagic = SECURITYFS_MAGIC,.flags = IMA_FSMAGIC},
  87. {.action = DONT_APPRAISE,.fsmagic = SELINUX_MAGIC,.flags = IMA_FSMAGIC},
  88. {.action = DONT_APPRAISE,.fsmagic = CGROUP_SUPER_MAGIC,.flags = IMA_FSMAGIC},
  89. {.action = APPRAISE,.fowner = GLOBAL_ROOT_UID,.flags = IMA_FOWNER},
  90. };
  91. static LIST_HEAD(ima_default_rules);
  92. static LIST_HEAD(ima_policy_rules);
  93. static struct list_head *ima_rules;
  94. static DEFINE_MUTEX(ima_rules_mutex);
  95. static bool ima_use_tcb __initdata;
  96. static int __init default_measure_policy_setup(char *str)
  97. {
  98. ima_use_tcb = 1;
  99. return 1;
  100. }
  101. __setup("ima_tcb", default_measure_policy_setup);
  102. static bool ima_use_appraise_tcb __initdata;
  103. static int __init default_appraise_policy_setup(char *str)
  104. {
  105. ima_use_appraise_tcb = 1;
  106. return 1;
  107. }
  108. __setup("ima_appraise_tcb", default_appraise_policy_setup);
  109. /**
  110. * ima_match_rules - determine whether an inode matches the measure rule.
  111. * @rule: a pointer to a rule
  112. * @inode: a pointer to an inode
  113. * @func: LIM hook identifier
  114. * @mask: requested action (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
  115. *
  116. * Returns true on rule match, false on failure.
  117. */
  118. static bool ima_match_rules(struct ima_rule_entry *rule,
  119. struct inode *inode, enum ima_hooks func, int mask)
  120. {
  121. struct task_struct *tsk = current;
  122. const struct cred *cred = current_cred();
  123. int i;
  124. if ((rule->flags & IMA_FUNC) && rule->func != func)
  125. return false;
  126. if ((rule->flags & IMA_MASK) && rule->mask != mask)
  127. return false;
  128. if ((rule->flags & IMA_FSMAGIC)
  129. && rule->fsmagic != inode->i_sb->s_magic)
  130. return false;
  131. if ((rule->flags & IMA_UID) && !uid_eq(rule->uid, cred->uid))
  132. return false;
  133. if ((rule->flags & IMA_FOWNER) && !uid_eq(rule->fowner, inode->i_uid))
  134. return false;
  135. for (i = 0; i < MAX_LSM_RULES; i++) {
  136. int rc = 0;
  137. u32 osid, sid;
  138. if (!rule->lsm[i].rule)
  139. continue;
  140. switch (i) {
  141. case LSM_OBJ_USER:
  142. case LSM_OBJ_ROLE:
  143. case LSM_OBJ_TYPE:
  144. security_inode_getsecid(inode, &osid);
  145. rc = security_filter_rule_match(osid,
  146. rule->lsm[i].type,
  147. Audit_equal,
  148. rule->lsm[i].rule,
  149. NULL);
  150. break;
  151. case LSM_SUBJ_USER:
  152. case LSM_SUBJ_ROLE:
  153. case LSM_SUBJ_TYPE:
  154. security_task_getsecid(tsk, &sid);
  155. rc = security_filter_rule_match(sid,
  156. rule->lsm[i].type,
  157. Audit_equal,
  158. rule->lsm[i].rule,
  159. NULL);
  160. default:
  161. break;
  162. }
  163. if (!rc)
  164. return false;
  165. }
  166. return true;
  167. }
  168. /**
  169. * ima_match_policy - decision based on LSM and other conditions
  170. * @inode: pointer to an inode for which the policy decision is being made
  171. * @func: IMA hook identifier
  172. * @mask: requested action (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
  173. *
  174. * Measure decision based on func/mask/fsmagic and LSM(subj/obj/type)
  175. * conditions.
  176. *
  177. * (There is no need for locking when walking the policy list,
  178. * as elements in the list are never deleted, nor does the list
  179. * change.)
  180. */
  181. int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
  182. int flags)
  183. {
  184. struct ima_rule_entry *entry;
  185. int action = 0, actmask = flags | (flags << 1);
  186. list_for_each_entry(entry, ima_rules, list) {
  187. if (!(entry->action & actmask))
  188. continue;
  189. if (!ima_match_rules(entry, inode, func, mask))
  190. continue;
  191. action |= entry->action & IMA_DO_MASK;
  192. if (entry->action & IMA_DO_MASK)
  193. actmask &= ~(entry->action | entry->action << 1);
  194. else
  195. actmask &= ~(entry->action | entry->action >> 1);
  196. if (!actmask)
  197. break;
  198. }
  199. return action;
  200. }
  201. /**
  202. * ima_init_policy - initialize the default measure rules.
  203. *
  204. * ima_rules points to either the ima_default_rules or the
  205. * the new ima_policy_rules.
  206. */
  207. void __init ima_init_policy(void)
  208. {
  209. int i, measure_entries, appraise_entries;
  210. /* if !ima_use_tcb set entries = 0 so we load NO default rules */
  211. measure_entries = ima_use_tcb ? ARRAY_SIZE(default_rules) : 0;
  212. appraise_entries = ima_use_appraise_tcb ?
  213. ARRAY_SIZE(default_appraise_rules) : 0;
  214. for (i = 0; i < measure_entries + appraise_entries; i++) {
  215. if (i < measure_entries)
  216. list_add_tail(&default_rules[i].list,
  217. &ima_default_rules);
  218. else {
  219. int j = i - measure_entries;
  220. list_add_tail(&default_appraise_rules[j].list,
  221. &ima_default_rules);
  222. }
  223. }
  224. ima_rules = &ima_default_rules;
  225. }
  226. /**
  227. * ima_update_policy - update default_rules with new measure rules
  228. *
  229. * Called on file .release to update the default rules with a complete new
  230. * policy. Once updated, the policy is locked, no additional rules can be
  231. * added to the policy.
  232. */
  233. void ima_update_policy(void)
  234. {
  235. const char *op = "policy_update";
  236. const char *cause = "already exists";
  237. int result = 1;
  238. int audit_info = 0;
  239. if (ima_rules == &ima_default_rules) {
  240. ima_rules = &ima_policy_rules;
  241. cause = "complete";
  242. result = 0;
  243. }
  244. integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
  245. NULL, op, cause, result, audit_info);
  246. }
  247. enum {
  248. Opt_err = -1,
  249. Opt_measure = 1, Opt_dont_measure,
  250. Opt_appraise, Opt_dont_appraise,
  251. Opt_audit,
  252. Opt_obj_user, Opt_obj_role, Opt_obj_type,
  253. Opt_subj_user, Opt_subj_role, Opt_subj_type,
  254. Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner
  255. };
  256. static match_table_t policy_tokens = {
  257. {Opt_measure, "measure"},
  258. {Opt_dont_measure, "dont_measure"},
  259. {Opt_appraise, "appraise"},
  260. {Opt_dont_appraise, "dont_appraise"},
  261. {Opt_audit, "audit"},
  262. {Opt_obj_user, "obj_user=%s"},
  263. {Opt_obj_role, "obj_role=%s"},
  264. {Opt_obj_type, "obj_type=%s"},
  265. {Opt_subj_user, "subj_user=%s"},
  266. {Opt_subj_role, "subj_role=%s"},
  267. {Opt_subj_type, "subj_type=%s"},
  268. {Opt_func, "func=%s"},
  269. {Opt_mask, "mask=%s"},
  270. {Opt_fsmagic, "fsmagic=%s"},
  271. {Opt_uid, "uid=%s"},
  272. {Opt_fowner, "fowner=%s"},
  273. {Opt_err, NULL}
  274. };
  275. static int ima_lsm_rule_init(struct ima_rule_entry *entry,
  276. char *args, int lsm_rule, int audit_type)
  277. {
  278. int result;
  279. if (entry->lsm[lsm_rule].rule)
  280. return -EINVAL;
  281. entry->lsm[lsm_rule].type = audit_type;
  282. result = security_filter_rule_init(entry->lsm[lsm_rule].type,
  283. Audit_equal, args,
  284. &entry->lsm[lsm_rule].rule);
  285. if (!entry->lsm[lsm_rule].rule)
  286. return -EINVAL;
  287. return result;
  288. }
  289. static void ima_log_string(struct audit_buffer *ab, char *key, char *value)
  290. {
  291. audit_log_format(ab, "%s=", key);
  292. audit_log_untrustedstring(ab, value);
  293. audit_log_format(ab, " ");
  294. }
  295. static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
  296. {
  297. struct audit_buffer *ab;
  298. char *p;
  299. int result = 0;
  300. ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_INTEGRITY_RULE);
  301. entry->uid = INVALID_UID;
  302. entry->fowner = INVALID_UID;
  303. entry->action = UNKNOWN;
  304. while ((p = strsep(&rule, " \t")) != NULL) {
  305. substring_t args[MAX_OPT_ARGS];
  306. int token;
  307. unsigned long lnum;
  308. if (result < 0)
  309. break;
  310. if ((*p == '\0') || (*p == ' ') || (*p == '\t'))
  311. continue;
  312. token = match_token(p, policy_tokens, args);
  313. switch (token) {
  314. case Opt_measure:
  315. ima_log_string(ab, "action", "measure");
  316. if (entry->action != UNKNOWN)
  317. result = -EINVAL;
  318. entry->action = MEASURE;
  319. break;
  320. case Opt_dont_measure:
  321. ima_log_string(ab, "action", "dont_measure");
  322. if (entry->action != UNKNOWN)
  323. result = -EINVAL;
  324. entry->action = DONT_MEASURE;
  325. break;
  326. case Opt_appraise:
  327. ima_log_string(ab, "action", "appraise");
  328. if (entry->action != UNKNOWN)
  329. result = -EINVAL;
  330. entry->action = APPRAISE;
  331. break;
  332. case Opt_dont_appraise:
  333. ima_log_string(ab, "action", "dont_appraise");
  334. if (entry->action != UNKNOWN)
  335. result = -EINVAL;
  336. entry->action = DONT_APPRAISE;
  337. break;
  338. case Opt_audit:
  339. ima_log_string(ab, "action", "audit");
  340. if (entry->action != UNKNOWN)
  341. result = -EINVAL;
  342. entry->action = AUDIT;
  343. break;
  344. case Opt_func:
  345. ima_log_string(ab, "func", args[0].from);
  346. if (entry->func)
  347. result = -EINVAL;
  348. if (strcmp(args[0].from, "FILE_CHECK") == 0)
  349. entry->func = FILE_CHECK;
  350. /* PATH_CHECK is for backwards compat */
  351. else if (strcmp(args[0].from, "PATH_CHECK") == 0)
  352. entry->func = FILE_CHECK;
  353. else if (strcmp(args[0].from, "MODULE_CHECK") == 0)
  354. entry->func = MODULE_CHECK;
  355. else if (strcmp(args[0].from, "FILE_MMAP") == 0)
  356. entry->func = FILE_MMAP;
  357. else if (strcmp(args[0].from, "BPRM_CHECK") == 0)
  358. entry->func = BPRM_CHECK;
  359. else
  360. result = -EINVAL;
  361. if (!result)
  362. entry->flags |= IMA_FUNC;
  363. break;
  364. case Opt_mask:
  365. ima_log_string(ab, "mask", args[0].from);
  366. if (entry->mask)
  367. result = -EINVAL;
  368. if ((strcmp(args[0].from, "MAY_EXEC")) == 0)
  369. entry->mask = MAY_EXEC;
  370. else if (strcmp(args[0].from, "MAY_WRITE") == 0)
  371. entry->mask = MAY_WRITE;
  372. else if (strcmp(args[0].from, "MAY_READ") == 0)
  373. entry->mask = MAY_READ;
  374. else if (strcmp(args[0].from, "MAY_APPEND") == 0)
  375. entry->mask = MAY_APPEND;
  376. else
  377. result = -EINVAL;
  378. if (!result)
  379. entry->flags |= IMA_MASK;
  380. break;
  381. case Opt_fsmagic:
  382. ima_log_string(ab, "fsmagic", args[0].from);
  383. if (entry->fsmagic) {
  384. result = -EINVAL;
  385. break;
  386. }
  387. result = strict_strtoul(args[0].from, 16,
  388. &entry->fsmagic);
  389. if (!result)
  390. entry->flags |= IMA_FSMAGIC;
  391. break;
  392. case Opt_uid:
  393. ima_log_string(ab, "uid", args[0].from);
  394. if (uid_valid(entry->uid)) {
  395. result = -EINVAL;
  396. break;
  397. }
  398. result = strict_strtoul(args[0].from, 10, &lnum);
  399. if (!result) {
  400. entry->uid = make_kuid(current_user_ns(), (uid_t)lnum);
  401. if (!uid_valid(entry->uid) || (((uid_t)lnum) != lnum))
  402. result = -EINVAL;
  403. else
  404. entry->flags |= IMA_UID;
  405. }
  406. break;
  407. case Opt_fowner:
  408. ima_log_string(ab, "fowner", args[0].from);
  409. if (uid_valid(entry->fowner)) {
  410. result = -EINVAL;
  411. break;
  412. }
  413. result = strict_strtoul(args[0].from, 10, &lnum);
  414. if (!result) {
  415. entry->fowner = make_kuid(current_user_ns(), (uid_t)lnum);
  416. if (!uid_valid(entry->fowner) || (((uid_t)lnum) != lnum))
  417. result = -EINVAL;
  418. else
  419. entry->flags |= IMA_FOWNER;
  420. }
  421. break;
  422. case Opt_obj_user:
  423. ima_log_string(ab, "obj_user", args[0].from);
  424. result = ima_lsm_rule_init(entry, args[0].from,
  425. LSM_OBJ_USER,
  426. AUDIT_OBJ_USER);
  427. break;
  428. case Opt_obj_role:
  429. ima_log_string(ab, "obj_role", args[0].from);
  430. result = ima_lsm_rule_init(entry, args[0].from,
  431. LSM_OBJ_ROLE,
  432. AUDIT_OBJ_ROLE);
  433. break;
  434. case Opt_obj_type:
  435. ima_log_string(ab, "obj_type", args[0].from);
  436. result = ima_lsm_rule_init(entry, args[0].from,
  437. LSM_OBJ_TYPE,
  438. AUDIT_OBJ_TYPE);
  439. break;
  440. case Opt_subj_user:
  441. ima_log_string(ab, "subj_user", args[0].from);
  442. result = ima_lsm_rule_init(entry, args[0].from,
  443. LSM_SUBJ_USER,
  444. AUDIT_SUBJ_USER);
  445. break;
  446. case Opt_subj_role:
  447. ima_log_string(ab, "subj_role", args[0].from);
  448. result = ima_lsm_rule_init(entry, args[0].from,
  449. LSM_SUBJ_ROLE,
  450. AUDIT_SUBJ_ROLE);
  451. break;
  452. case Opt_subj_type:
  453. ima_log_string(ab, "subj_type", args[0].from);
  454. result = ima_lsm_rule_init(entry, args[0].from,
  455. LSM_SUBJ_TYPE,
  456. AUDIT_SUBJ_TYPE);
  457. break;
  458. case Opt_err:
  459. ima_log_string(ab, "UNKNOWN", p);
  460. result = -EINVAL;
  461. break;
  462. }
  463. }
  464. if (!result && (entry->action == UNKNOWN))
  465. result = -EINVAL;
  466. else if (entry->func == MODULE_CHECK)
  467. ima_appraise |= IMA_APPRAISE_MODULES;
  468. audit_log_format(ab, "res=%d", !result);
  469. audit_log_end(ab);
  470. return result;
  471. }
  472. /**
  473. * ima_parse_add_rule - add a rule to ima_policy_rules
  474. * @rule - ima measurement policy rule
  475. *
  476. * Uses a mutex to protect the policy list from multiple concurrent writers.
  477. * Returns the length of the rule parsed, an error code on failure
  478. */
  479. ssize_t ima_parse_add_rule(char *rule)
  480. {
  481. const char *op = "update_policy";
  482. char *p;
  483. struct ima_rule_entry *entry;
  484. ssize_t result, len;
  485. int audit_info = 0;
  486. /* Prevent installed policy from changing */
  487. if (ima_rules != &ima_default_rules) {
  488. integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
  489. NULL, op, "already exists",
  490. -EACCES, audit_info);
  491. return -EACCES;
  492. }
  493. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  494. if (!entry) {
  495. integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
  496. NULL, op, "-ENOMEM", -ENOMEM, audit_info);
  497. return -ENOMEM;
  498. }
  499. INIT_LIST_HEAD(&entry->list);
  500. p = strsep(&rule, "\n");
  501. len = strlen(p) + 1;
  502. if (*p == '#') {
  503. kfree(entry);
  504. return len;
  505. }
  506. result = ima_parse_rule(p, entry);
  507. if (result) {
  508. kfree(entry);
  509. integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
  510. NULL, op, "invalid policy", result,
  511. audit_info);
  512. return result;
  513. }
  514. mutex_lock(&ima_rules_mutex);
  515. list_add_tail(&entry->list, &ima_policy_rules);
  516. mutex_unlock(&ima_rules_mutex);
  517. return len;
  518. }
  519. /* ima_delete_rules called to cleanup invalid policy */
  520. void ima_delete_rules(void)
  521. {
  522. struct ima_rule_entry *entry, *tmp;
  523. mutex_lock(&ima_rules_mutex);
  524. list_for_each_entry_safe(entry, tmp, &ima_policy_rules, list) {
  525. list_del(&entry->list);
  526. kfree(entry);
  527. }
  528. mutex_unlock(&ima_rules_mutex);
  529. }