ima_policy.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  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/fs.h>
  16. #include <linux/security.h>
  17. #include <linux/magic.h>
  18. #include <linux/parser.h>
  19. #include <linux/slab.h>
  20. #include <linux/rculist.h>
  21. #include <linux/genhd.h>
  22. #include <linux/seq_file.h>
  23. #include "ima.h"
  24. /* flags definitions */
  25. #define IMA_FUNC 0x0001
  26. #define IMA_MASK 0x0002
  27. #define IMA_FSMAGIC 0x0004
  28. #define IMA_UID 0x0008
  29. #define IMA_FOWNER 0x0010
  30. #define IMA_FSUUID 0x0020
  31. #define IMA_INMASK 0x0040
  32. #define IMA_EUID 0x0080
  33. #define IMA_PCR 0x0100
  34. #define UNKNOWN 0
  35. #define MEASURE 0x0001 /* same as IMA_MEASURE */
  36. #define DONT_MEASURE 0x0002
  37. #define APPRAISE 0x0004 /* same as IMA_APPRAISE */
  38. #define DONT_APPRAISE 0x0008
  39. #define AUDIT 0x0040
  40. #define INVALID_PCR(a) (((a) < 0) || \
  41. (a) >= (FIELD_SIZEOF(struct integrity_iint_cache, measured_pcrs) * 8))
  42. int ima_policy_flag;
  43. static int temp_ima_appraise;
  44. #define MAX_LSM_RULES 6
  45. enum lsm_rule_types { LSM_OBJ_USER, LSM_OBJ_ROLE, LSM_OBJ_TYPE,
  46. LSM_SUBJ_USER, LSM_SUBJ_ROLE, LSM_SUBJ_TYPE
  47. };
  48. enum policy_types { ORIGINAL_TCB = 1, DEFAULT_TCB };
  49. struct ima_rule_entry {
  50. struct list_head list;
  51. int action;
  52. unsigned int flags;
  53. enum ima_hooks func;
  54. int mask;
  55. unsigned long fsmagic;
  56. u8 fsuuid[16];
  57. kuid_t uid;
  58. kuid_t fowner;
  59. bool (*uid_op)(kuid_t, kuid_t); /* Handlers for operators */
  60. bool (*fowner_op)(kuid_t, kuid_t); /* uid_eq(), uid_gt(), uid_lt() */
  61. int pcr;
  62. struct {
  63. void *rule; /* LSM file metadata specific */
  64. void *args_p; /* audit value */
  65. int type; /* audit type */
  66. } lsm[MAX_LSM_RULES];
  67. };
  68. /*
  69. * Without LSM specific knowledge, the default policy can only be
  70. * written in terms of .action, .func, .mask, .fsmagic, .uid, and .fowner
  71. */
  72. /*
  73. * The minimum rule set to allow for full TCB coverage. Measures all files
  74. * opened or mmap for exec and everything read by root. Dangerous because
  75. * normal users can easily run the machine out of memory simply building
  76. * and running executables.
  77. */
  78. static struct ima_rule_entry dont_measure_rules[] __ro_after_init = {
  79. {.action = DONT_MEASURE, .fsmagic = PROC_SUPER_MAGIC, .flags = IMA_FSMAGIC},
  80. {.action = DONT_MEASURE, .fsmagic = SYSFS_MAGIC, .flags = IMA_FSMAGIC},
  81. {.action = DONT_MEASURE, .fsmagic = DEBUGFS_MAGIC, .flags = IMA_FSMAGIC},
  82. {.action = DONT_MEASURE, .fsmagic = TMPFS_MAGIC, .flags = IMA_FSMAGIC},
  83. {.action = DONT_MEASURE, .fsmagic = DEVPTS_SUPER_MAGIC, .flags = IMA_FSMAGIC},
  84. {.action = DONT_MEASURE, .fsmagic = BINFMTFS_MAGIC, .flags = IMA_FSMAGIC},
  85. {.action = DONT_MEASURE, .fsmagic = SECURITYFS_MAGIC, .flags = IMA_FSMAGIC},
  86. {.action = DONT_MEASURE, .fsmagic = SELINUX_MAGIC, .flags = IMA_FSMAGIC},
  87. {.action = DONT_MEASURE, .fsmagic = CGROUP_SUPER_MAGIC,
  88. .flags = IMA_FSMAGIC},
  89. {.action = DONT_MEASURE, .fsmagic = NSFS_MAGIC, .flags = IMA_FSMAGIC}
  90. };
  91. static struct ima_rule_entry original_measurement_rules[] __ro_after_init = {
  92. {.action = MEASURE, .func = MMAP_CHECK, .mask = MAY_EXEC,
  93. .flags = IMA_FUNC | IMA_MASK},
  94. {.action = MEASURE, .func = BPRM_CHECK, .mask = MAY_EXEC,
  95. .flags = IMA_FUNC | IMA_MASK},
  96. {.action = MEASURE, .func = FILE_CHECK, .mask = MAY_READ,
  97. .uid = GLOBAL_ROOT_UID, .uid_op = &uid_eq,
  98. .flags = IMA_FUNC | IMA_MASK | IMA_UID},
  99. {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC},
  100. {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC},
  101. };
  102. static struct ima_rule_entry default_measurement_rules[] __ro_after_init = {
  103. {.action = MEASURE, .func = MMAP_CHECK, .mask = MAY_EXEC,
  104. .flags = IMA_FUNC | IMA_MASK},
  105. {.action = MEASURE, .func = BPRM_CHECK, .mask = MAY_EXEC,
  106. .flags = IMA_FUNC | IMA_MASK},
  107. {.action = MEASURE, .func = FILE_CHECK, .mask = MAY_READ,
  108. .uid = GLOBAL_ROOT_UID, .uid_op = &uid_eq,
  109. .flags = IMA_FUNC | IMA_INMASK | IMA_EUID},
  110. {.action = MEASURE, .func = FILE_CHECK, .mask = MAY_READ,
  111. .uid = GLOBAL_ROOT_UID, .uid_op = &uid_eq,
  112. .flags = IMA_FUNC | IMA_INMASK | IMA_UID},
  113. {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC},
  114. {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC},
  115. {.action = MEASURE, .func = POLICY_CHECK, .flags = IMA_FUNC},
  116. };
  117. static struct ima_rule_entry default_appraise_rules[] __ro_after_init = {
  118. {.action = DONT_APPRAISE, .fsmagic = PROC_SUPER_MAGIC, .flags = IMA_FSMAGIC},
  119. {.action = DONT_APPRAISE, .fsmagic = SYSFS_MAGIC, .flags = IMA_FSMAGIC},
  120. {.action = DONT_APPRAISE, .fsmagic = DEBUGFS_MAGIC, .flags = IMA_FSMAGIC},
  121. {.action = DONT_APPRAISE, .fsmagic = TMPFS_MAGIC, .flags = IMA_FSMAGIC},
  122. {.action = DONT_APPRAISE, .fsmagic = RAMFS_MAGIC, .flags = IMA_FSMAGIC},
  123. {.action = DONT_APPRAISE, .fsmagic = DEVPTS_SUPER_MAGIC, .flags = IMA_FSMAGIC},
  124. {.action = DONT_APPRAISE, .fsmagic = BINFMTFS_MAGIC, .flags = IMA_FSMAGIC},
  125. {.action = DONT_APPRAISE, .fsmagic = SECURITYFS_MAGIC, .flags = IMA_FSMAGIC},
  126. {.action = DONT_APPRAISE, .fsmagic = SELINUX_MAGIC, .flags = IMA_FSMAGIC},
  127. {.action = DONT_APPRAISE, .fsmagic = NSFS_MAGIC, .flags = IMA_FSMAGIC},
  128. {.action = DONT_APPRAISE, .fsmagic = CGROUP_SUPER_MAGIC, .flags = IMA_FSMAGIC},
  129. #ifdef CONFIG_IMA_WRITE_POLICY
  130. {.action = APPRAISE, .func = POLICY_CHECK,
  131. .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},
  132. #endif
  133. #ifndef CONFIG_IMA_APPRAISE_SIGNED_INIT
  134. {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .fowner_op = &uid_eq,
  135. .flags = IMA_FOWNER},
  136. #else
  137. /* force signature */
  138. {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .fowner_op = &uid_eq,
  139. .flags = IMA_FOWNER | IMA_DIGSIG_REQUIRED},
  140. #endif
  141. };
  142. static LIST_HEAD(ima_default_rules);
  143. static LIST_HEAD(ima_policy_rules);
  144. static LIST_HEAD(ima_temp_rules);
  145. static struct list_head *ima_rules;
  146. static int ima_policy __initdata;
  147. static int __init default_measure_policy_setup(char *str)
  148. {
  149. if (ima_policy)
  150. return 1;
  151. ima_policy = ORIGINAL_TCB;
  152. return 1;
  153. }
  154. __setup("ima_tcb", default_measure_policy_setup);
  155. static int __init policy_setup(char *str)
  156. {
  157. if (ima_policy)
  158. return 1;
  159. if (strcmp(str, "tcb") == 0)
  160. ima_policy = DEFAULT_TCB;
  161. return 1;
  162. }
  163. __setup("ima_policy=", policy_setup);
  164. static bool ima_use_appraise_tcb __initdata;
  165. static int __init default_appraise_policy_setup(char *str)
  166. {
  167. ima_use_appraise_tcb = 1;
  168. return 1;
  169. }
  170. __setup("ima_appraise_tcb", default_appraise_policy_setup);
  171. /*
  172. * The LSM policy can be reloaded, leaving the IMA LSM based rules referring
  173. * to the old, stale LSM policy. Update the IMA LSM based rules to reflect
  174. * the reloaded LSM policy. We assume the rules still exist; and BUG_ON() if
  175. * they don't.
  176. */
  177. static void ima_lsm_update_rules(void)
  178. {
  179. struct ima_rule_entry *entry;
  180. int result;
  181. int i;
  182. list_for_each_entry(entry, &ima_policy_rules, list) {
  183. for (i = 0; i < MAX_LSM_RULES; i++) {
  184. if (!entry->lsm[i].rule)
  185. continue;
  186. result = security_filter_rule_init(entry->lsm[i].type,
  187. Audit_equal,
  188. entry->lsm[i].args_p,
  189. &entry->lsm[i].rule);
  190. BUG_ON(!entry->lsm[i].rule);
  191. }
  192. }
  193. }
  194. /**
  195. * ima_match_rules - determine whether an inode matches the measure rule.
  196. * @rule: a pointer to a rule
  197. * @inode: a pointer to an inode
  198. * @func: LIM hook identifier
  199. * @mask: requested action (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
  200. *
  201. * Returns true on rule match, false on failure.
  202. */
  203. static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode,
  204. enum ima_hooks func, int mask)
  205. {
  206. struct task_struct *tsk = current;
  207. const struct cred *cred = current_cred();
  208. int i;
  209. if ((rule->flags & IMA_FUNC) &&
  210. (rule->func != func && func != POST_SETATTR))
  211. return false;
  212. if ((rule->flags & IMA_MASK) &&
  213. (rule->mask != mask && func != POST_SETATTR))
  214. return false;
  215. if ((rule->flags & IMA_INMASK) &&
  216. (!(rule->mask & mask) && func != POST_SETATTR))
  217. return false;
  218. if ((rule->flags & IMA_FSMAGIC)
  219. && rule->fsmagic != inode->i_sb->s_magic)
  220. return false;
  221. if ((rule->flags & IMA_FSUUID) &&
  222. memcmp(rule->fsuuid, inode->i_sb->s_uuid, sizeof(rule->fsuuid)))
  223. return false;
  224. if ((rule->flags & IMA_UID) && !rule->uid_op(cred->uid, rule->uid))
  225. return false;
  226. if (rule->flags & IMA_EUID) {
  227. if (has_capability_noaudit(current, CAP_SETUID)) {
  228. if (!rule->uid_op(cred->euid, rule->uid)
  229. && !rule->uid_op(cred->suid, rule->uid)
  230. && !rule->uid_op(cred->uid, rule->uid))
  231. return false;
  232. } else if (!rule->uid_op(cred->euid, rule->uid))
  233. return false;
  234. }
  235. if ((rule->flags & IMA_FOWNER) &&
  236. !rule->fowner_op(inode->i_uid, rule->fowner))
  237. return false;
  238. for (i = 0; i < MAX_LSM_RULES; i++) {
  239. int rc = 0;
  240. u32 osid, sid;
  241. int retried = 0;
  242. if (!rule->lsm[i].rule)
  243. continue;
  244. retry:
  245. switch (i) {
  246. case LSM_OBJ_USER:
  247. case LSM_OBJ_ROLE:
  248. case LSM_OBJ_TYPE:
  249. security_inode_getsecid(inode, &osid);
  250. rc = security_filter_rule_match(osid,
  251. rule->lsm[i].type,
  252. Audit_equal,
  253. rule->lsm[i].rule,
  254. NULL);
  255. break;
  256. case LSM_SUBJ_USER:
  257. case LSM_SUBJ_ROLE:
  258. case LSM_SUBJ_TYPE:
  259. security_task_getsecid(tsk, &sid);
  260. rc = security_filter_rule_match(sid,
  261. rule->lsm[i].type,
  262. Audit_equal,
  263. rule->lsm[i].rule,
  264. NULL);
  265. default:
  266. break;
  267. }
  268. if ((rc < 0) && (!retried)) {
  269. retried = 1;
  270. ima_lsm_update_rules();
  271. goto retry;
  272. }
  273. if (!rc)
  274. return false;
  275. }
  276. return true;
  277. }
  278. /*
  279. * In addition to knowing that we need to appraise the file in general,
  280. * we need to differentiate between calling hooks, for hook specific rules.
  281. */
  282. static int get_subaction(struct ima_rule_entry *rule, enum ima_hooks func)
  283. {
  284. if (!(rule->flags & IMA_FUNC))
  285. return IMA_FILE_APPRAISE;
  286. switch (func) {
  287. case MMAP_CHECK:
  288. return IMA_MMAP_APPRAISE;
  289. case BPRM_CHECK:
  290. return IMA_BPRM_APPRAISE;
  291. case FILE_CHECK:
  292. case POST_SETATTR:
  293. return IMA_FILE_APPRAISE;
  294. case MODULE_CHECK ... MAX_CHECK - 1:
  295. default:
  296. return IMA_READ_APPRAISE;
  297. }
  298. }
  299. /**
  300. * ima_match_policy - decision based on LSM and other conditions
  301. * @inode: pointer to an inode for which the policy decision is being made
  302. * @func: IMA hook identifier
  303. * @mask: requested action (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC)
  304. * @pcr: set the pcr to extend
  305. *
  306. * Measure decision based on func/mask/fsmagic and LSM(subj/obj/type)
  307. * conditions.
  308. *
  309. * Since the IMA policy may be updated multiple times we need to lock the
  310. * list when walking it. Reads are many orders of magnitude more numerous
  311. * than writes so ima_match_policy() is classical RCU candidate.
  312. */
  313. int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
  314. int flags, int *pcr)
  315. {
  316. struct ima_rule_entry *entry;
  317. int action = 0, actmask = flags | (flags << 1);
  318. rcu_read_lock();
  319. list_for_each_entry_rcu(entry, ima_rules, list) {
  320. if (!(entry->action & actmask))
  321. continue;
  322. if (!ima_match_rules(entry, inode, func, mask))
  323. continue;
  324. action |= entry->flags & IMA_ACTION_FLAGS;
  325. action |= entry->action & IMA_DO_MASK;
  326. if (entry->action & IMA_APPRAISE)
  327. action |= get_subaction(entry, func);
  328. if (entry->action & IMA_DO_MASK)
  329. actmask &= ~(entry->action | entry->action << 1);
  330. else
  331. actmask &= ~(entry->action | entry->action >> 1);
  332. if ((pcr) && (entry->flags & IMA_PCR))
  333. *pcr = entry->pcr;
  334. if (!actmask)
  335. break;
  336. }
  337. rcu_read_unlock();
  338. return action;
  339. }
  340. /*
  341. * Initialize the ima_policy_flag variable based on the currently
  342. * loaded policy. Based on this flag, the decision to short circuit
  343. * out of a function or not call the function in the first place
  344. * can be made earlier.
  345. */
  346. void ima_update_policy_flag(void)
  347. {
  348. struct ima_rule_entry *entry;
  349. list_for_each_entry(entry, ima_rules, list) {
  350. if (entry->action & IMA_DO_MASK)
  351. ima_policy_flag |= entry->action;
  352. }
  353. ima_appraise |= temp_ima_appraise;
  354. if (!ima_appraise)
  355. ima_policy_flag &= ~IMA_APPRAISE;
  356. }
  357. /**
  358. * ima_init_policy - initialize the default measure rules.
  359. *
  360. * ima_rules points to either the ima_default_rules or the
  361. * the new ima_policy_rules.
  362. */
  363. void __init ima_init_policy(void)
  364. {
  365. int i, measure_entries, appraise_entries;
  366. /* if !ima_policy set entries = 0 so we load NO default rules */
  367. measure_entries = ima_policy ? ARRAY_SIZE(dont_measure_rules) : 0;
  368. appraise_entries = ima_use_appraise_tcb ?
  369. ARRAY_SIZE(default_appraise_rules) : 0;
  370. for (i = 0; i < measure_entries; i++)
  371. list_add_tail(&dont_measure_rules[i].list, &ima_default_rules);
  372. switch (ima_policy) {
  373. case ORIGINAL_TCB:
  374. for (i = 0; i < ARRAY_SIZE(original_measurement_rules); i++)
  375. list_add_tail(&original_measurement_rules[i].list,
  376. &ima_default_rules);
  377. break;
  378. case DEFAULT_TCB:
  379. for (i = 0; i < ARRAY_SIZE(default_measurement_rules); i++)
  380. list_add_tail(&default_measurement_rules[i].list,
  381. &ima_default_rules);
  382. default:
  383. break;
  384. }
  385. for (i = 0; i < appraise_entries; i++) {
  386. list_add_tail(&default_appraise_rules[i].list,
  387. &ima_default_rules);
  388. if (default_appraise_rules[i].func == POLICY_CHECK)
  389. temp_ima_appraise |= IMA_APPRAISE_POLICY;
  390. }
  391. ima_rules = &ima_default_rules;
  392. ima_update_policy_flag();
  393. }
  394. /* Make sure we have a valid policy, at least containing some rules. */
  395. int ima_check_policy(void)
  396. {
  397. if (list_empty(&ima_temp_rules))
  398. return -EINVAL;
  399. return 0;
  400. }
  401. /**
  402. * ima_update_policy - update default_rules with new measure rules
  403. *
  404. * Called on file .release to update the default rules with a complete new
  405. * policy. What we do here is to splice ima_policy_rules and ima_temp_rules so
  406. * they make a queue. The policy may be updated multiple times and this is the
  407. * RCU updater.
  408. *
  409. * Policy rules are never deleted so ima_policy_flag gets zeroed only once when
  410. * we switch from the default policy to user defined.
  411. */
  412. void ima_update_policy(void)
  413. {
  414. struct list_head *first, *last, *policy;
  415. /* append current policy with the new rules */
  416. first = (&ima_temp_rules)->next;
  417. last = (&ima_temp_rules)->prev;
  418. policy = &ima_policy_rules;
  419. synchronize_rcu();
  420. last->next = policy;
  421. rcu_assign_pointer(list_next_rcu(policy->prev), first);
  422. first->prev = policy->prev;
  423. policy->prev = last;
  424. /* prepare for the next policy rules addition */
  425. INIT_LIST_HEAD(&ima_temp_rules);
  426. if (ima_rules != policy) {
  427. ima_policy_flag = 0;
  428. ima_rules = policy;
  429. }
  430. ima_update_policy_flag();
  431. }
  432. enum {
  433. Opt_err = -1,
  434. Opt_measure = 1, Opt_dont_measure,
  435. Opt_appraise, Opt_dont_appraise,
  436. Opt_audit,
  437. Opt_obj_user, Opt_obj_role, Opt_obj_type,
  438. Opt_subj_user, Opt_subj_role, Opt_subj_type,
  439. Opt_func, Opt_mask, Opt_fsmagic,
  440. Opt_fsuuid, Opt_uid_eq, Opt_euid_eq, Opt_fowner_eq,
  441. Opt_uid_gt, Opt_euid_gt, Opt_fowner_gt,
  442. Opt_uid_lt, Opt_euid_lt, Opt_fowner_lt,
  443. Opt_appraise_type, Opt_permit_directio,
  444. Opt_pcr
  445. };
  446. static match_table_t policy_tokens = {
  447. {Opt_measure, "measure"},
  448. {Opt_dont_measure, "dont_measure"},
  449. {Opt_appraise, "appraise"},
  450. {Opt_dont_appraise, "dont_appraise"},
  451. {Opt_audit, "audit"},
  452. {Opt_obj_user, "obj_user=%s"},
  453. {Opt_obj_role, "obj_role=%s"},
  454. {Opt_obj_type, "obj_type=%s"},
  455. {Opt_subj_user, "subj_user=%s"},
  456. {Opt_subj_role, "subj_role=%s"},
  457. {Opt_subj_type, "subj_type=%s"},
  458. {Opt_func, "func=%s"},
  459. {Opt_mask, "mask=%s"},
  460. {Opt_fsmagic, "fsmagic=%s"},
  461. {Opt_fsuuid, "fsuuid=%s"},
  462. {Opt_uid_eq, "uid=%s"},
  463. {Opt_euid_eq, "euid=%s"},
  464. {Opt_fowner_eq, "fowner=%s"},
  465. {Opt_uid_gt, "uid>%s"},
  466. {Opt_euid_gt, "euid>%s"},
  467. {Opt_fowner_gt, "fowner>%s"},
  468. {Opt_uid_lt, "uid<%s"},
  469. {Opt_euid_lt, "euid<%s"},
  470. {Opt_fowner_lt, "fowner<%s"},
  471. {Opt_appraise_type, "appraise_type=%s"},
  472. {Opt_permit_directio, "permit_directio"},
  473. {Opt_pcr, "pcr=%s"},
  474. {Opt_err, NULL}
  475. };
  476. static int ima_lsm_rule_init(struct ima_rule_entry *entry,
  477. substring_t *args, int lsm_rule, int audit_type)
  478. {
  479. int result;
  480. if (entry->lsm[lsm_rule].rule)
  481. return -EINVAL;
  482. entry->lsm[lsm_rule].args_p = match_strdup(args);
  483. if (!entry->lsm[lsm_rule].args_p)
  484. return -ENOMEM;
  485. entry->lsm[lsm_rule].type = audit_type;
  486. result = security_filter_rule_init(entry->lsm[lsm_rule].type,
  487. Audit_equal,
  488. entry->lsm[lsm_rule].args_p,
  489. &entry->lsm[lsm_rule].rule);
  490. if (!entry->lsm[lsm_rule].rule) {
  491. kfree(entry->lsm[lsm_rule].args_p);
  492. return -EINVAL;
  493. }
  494. return result;
  495. }
  496. static void ima_log_string_op(struct audit_buffer *ab, char *key, char *value,
  497. bool (*rule_operator)(kuid_t, kuid_t))
  498. {
  499. if (rule_operator == &uid_gt)
  500. audit_log_format(ab, "%s>", key);
  501. else if (rule_operator == &uid_lt)
  502. audit_log_format(ab, "%s<", key);
  503. else
  504. audit_log_format(ab, "%s=", key);
  505. audit_log_untrustedstring(ab, value);
  506. audit_log_format(ab, " ");
  507. }
  508. static void ima_log_string(struct audit_buffer *ab, char *key, char *value)
  509. {
  510. ima_log_string_op(ab, key, value, NULL);
  511. }
  512. static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
  513. {
  514. struct audit_buffer *ab;
  515. char *from;
  516. char *p;
  517. bool uid_token;
  518. int result = 0;
  519. ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_INTEGRITY_RULE);
  520. entry->uid = INVALID_UID;
  521. entry->fowner = INVALID_UID;
  522. entry->uid_op = &uid_eq;
  523. entry->fowner_op = &uid_eq;
  524. entry->action = UNKNOWN;
  525. while ((p = strsep(&rule, " \t")) != NULL) {
  526. substring_t args[MAX_OPT_ARGS];
  527. int token;
  528. unsigned long lnum;
  529. if (result < 0)
  530. break;
  531. if ((*p == '\0') || (*p == ' ') || (*p == '\t'))
  532. continue;
  533. token = match_token(p, policy_tokens, args);
  534. switch (token) {
  535. case Opt_measure:
  536. ima_log_string(ab, "action", "measure");
  537. if (entry->action != UNKNOWN)
  538. result = -EINVAL;
  539. entry->action = MEASURE;
  540. break;
  541. case Opt_dont_measure:
  542. ima_log_string(ab, "action", "dont_measure");
  543. if (entry->action != UNKNOWN)
  544. result = -EINVAL;
  545. entry->action = DONT_MEASURE;
  546. break;
  547. case Opt_appraise:
  548. ima_log_string(ab, "action", "appraise");
  549. if (entry->action != UNKNOWN)
  550. result = -EINVAL;
  551. entry->action = APPRAISE;
  552. break;
  553. case Opt_dont_appraise:
  554. ima_log_string(ab, "action", "dont_appraise");
  555. if (entry->action != UNKNOWN)
  556. result = -EINVAL;
  557. entry->action = DONT_APPRAISE;
  558. break;
  559. case Opt_audit:
  560. ima_log_string(ab, "action", "audit");
  561. if (entry->action != UNKNOWN)
  562. result = -EINVAL;
  563. entry->action = AUDIT;
  564. break;
  565. case Opt_func:
  566. ima_log_string(ab, "func", args[0].from);
  567. if (entry->func)
  568. result = -EINVAL;
  569. if (strcmp(args[0].from, "FILE_CHECK") == 0)
  570. entry->func = FILE_CHECK;
  571. /* PATH_CHECK is for backwards compat */
  572. else if (strcmp(args[0].from, "PATH_CHECK") == 0)
  573. entry->func = FILE_CHECK;
  574. else if (strcmp(args[0].from, "MODULE_CHECK") == 0)
  575. entry->func = MODULE_CHECK;
  576. else if (strcmp(args[0].from, "FIRMWARE_CHECK") == 0)
  577. entry->func = FIRMWARE_CHECK;
  578. else if ((strcmp(args[0].from, "FILE_MMAP") == 0)
  579. || (strcmp(args[0].from, "MMAP_CHECK") == 0))
  580. entry->func = MMAP_CHECK;
  581. else if (strcmp(args[0].from, "BPRM_CHECK") == 0)
  582. entry->func = BPRM_CHECK;
  583. else if (strcmp(args[0].from, "KEXEC_KERNEL_CHECK") ==
  584. 0)
  585. entry->func = KEXEC_KERNEL_CHECK;
  586. else if (strcmp(args[0].from, "KEXEC_INITRAMFS_CHECK")
  587. == 0)
  588. entry->func = KEXEC_INITRAMFS_CHECK;
  589. else if (strcmp(args[0].from, "POLICY_CHECK") == 0)
  590. entry->func = POLICY_CHECK;
  591. else
  592. result = -EINVAL;
  593. if (!result)
  594. entry->flags |= IMA_FUNC;
  595. break;
  596. case Opt_mask:
  597. ima_log_string(ab, "mask", args[0].from);
  598. if (entry->mask)
  599. result = -EINVAL;
  600. from = args[0].from;
  601. if (*from == '^')
  602. from++;
  603. if ((strcmp(from, "MAY_EXEC")) == 0)
  604. entry->mask = MAY_EXEC;
  605. else if (strcmp(from, "MAY_WRITE") == 0)
  606. entry->mask = MAY_WRITE;
  607. else if (strcmp(from, "MAY_READ") == 0)
  608. entry->mask = MAY_READ;
  609. else if (strcmp(from, "MAY_APPEND") == 0)
  610. entry->mask = MAY_APPEND;
  611. else
  612. result = -EINVAL;
  613. if (!result)
  614. entry->flags |= (*args[0].from == '^')
  615. ? IMA_INMASK : IMA_MASK;
  616. break;
  617. case Opt_fsmagic:
  618. ima_log_string(ab, "fsmagic", args[0].from);
  619. if (entry->fsmagic) {
  620. result = -EINVAL;
  621. break;
  622. }
  623. result = kstrtoul(args[0].from, 16, &entry->fsmagic);
  624. if (!result)
  625. entry->flags |= IMA_FSMAGIC;
  626. break;
  627. case Opt_fsuuid:
  628. ima_log_string(ab, "fsuuid", args[0].from);
  629. if (memchr_inv(entry->fsuuid, 0x00,
  630. sizeof(entry->fsuuid))) {
  631. result = -EINVAL;
  632. break;
  633. }
  634. result = blk_part_pack_uuid(args[0].from,
  635. entry->fsuuid);
  636. if (!result)
  637. entry->flags |= IMA_FSUUID;
  638. break;
  639. case Opt_uid_gt:
  640. case Opt_euid_gt:
  641. entry->uid_op = &uid_gt;
  642. case Opt_uid_lt:
  643. case Opt_euid_lt:
  644. if ((token == Opt_uid_lt) || (token == Opt_euid_lt))
  645. entry->uid_op = &uid_lt;
  646. case Opt_uid_eq:
  647. case Opt_euid_eq:
  648. uid_token = (token == Opt_uid_eq) ||
  649. (token == Opt_uid_gt) ||
  650. (token == Opt_uid_lt);
  651. ima_log_string_op(ab, uid_token ? "uid" : "euid",
  652. args[0].from, entry->uid_op);
  653. if (uid_valid(entry->uid)) {
  654. result = -EINVAL;
  655. break;
  656. }
  657. result = kstrtoul(args[0].from, 10, &lnum);
  658. if (!result) {
  659. entry->uid = make_kuid(current_user_ns(),
  660. (uid_t) lnum);
  661. if (!uid_valid(entry->uid) ||
  662. (uid_t)lnum != lnum)
  663. result = -EINVAL;
  664. else
  665. entry->flags |= uid_token
  666. ? IMA_UID : IMA_EUID;
  667. }
  668. break;
  669. case Opt_fowner_gt:
  670. entry->fowner_op = &uid_gt;
  671. case Opt_fowner_lt:
  672. if (token == Opt_fowner_lt)
  673. entry->fowner_op = &uid_lt;
  674. case Opt_fowner_eq:
  675. ima_log_string_op(ab, "fowner", args[0].from,
  676. entry->fowner_op);
  677. if (uid_valid(entry->fowner)) {
  678. result = -EINVAL;
  679. break;
  680. }
  681. result = kstrtoul(args[0].from, 10, &lnum);
  682. if (!result) {
  683. entry->fowner = make_kuid(current_user_ns(), (uid_t)lnum);
  684. if (!uid_valid(entry->fowner) || (((uid_t)lnum) != lnum))
  685. result = -EINVAL;
  686. else
  687. entry->flags |= IMA_FOWNER;
  688. }
  689. break;
  690. case Opt_obj_user:
  691. ima_log_string(ab, "obj_user", args[0].from);
  692. result = ima_lsm_rule_init(entry, args,
  693. LSM_OBJ_USER,
  694. AUDIT_OBJ_USER);
  695. break;
  696. case Opt_obj_role:
  697. ima_log_string(ab, "obj_role", args[0].from);
  698. result = ima_lsm_rule_init(entry, args,
  699. LSM_OBJ_ROLE,
  700. AUDIT_OBJ_ROLE);
  701. break;
  702. case Opt_obj_type:
  703. ima_log_string(ab, "obj_type", args[0].from);
  704. result = ima_lsm_rule_init(entry, args,
  705. LSM_OBJ_TYPE,
  706. AUDIT_OBJ_TYPE);
  707. break;
  708. case Opt_subj_user:
  709. ima_log_string(ab, "subj_user", args[0].from);
  710. result = ima_lsm_rule_init(entry, args,
  711. LSM_SUBJ_USER,
  712. AUDIT_SUBJ_USER);
  713. break;
  714. case Opt_subj_role:
  715. ima_log_string(ab, "subj_role", args[0].from);
  716. result = ima_lsm_rule_init(entry, args,
  717. LSM_SUBJ_ROLE,
  718. AUDIT_SUBJ_ROLE);
  719. break;
  720. case Opt_subj_type:
  721. ima_log_string(ab, "subj_type", args[0].from);
  722. result = ima_lsm_rule_init(entry, args,
  723. LSM_SUBJ_TYPE,
  724. AUDIT_SUBJ_TYPE);
  725. break;
  726. case Opt_appraise_type:
  727. if (entry->action != APPRAISE) {
  728. result = -EINVAL;
  729. break;
  730. }
  731. ima_log_string(ab, "appraise_type", args[0].from);
  732. if ((strcmp(args[0].from, "imasig")) == 0)
  733. entry->flags |= IMA_DIGSIG_REQUIRED;
  734. else
  735. result = -EINVAL;
  736. break;
  737. case Opt_permit_directio:
  738. entry->flags |= IMA_PERMIT_DIRECTIO;
  739. break;
  740. case Opt_pcr:
  741. if (entry->action != MEASURE) {
  742. result = -EINVAL;
  743. break;
  744. }
  745. ima_log_string(ab, "pcr", args[0].from);
  746. result = kstrtoint(args[0].from, 10, &entry->pcr);
  747. if (result || INVALID_PCR(entry->pcr))
  748. result = -EINVAL;
  749. else
  750. entry->flags |= IMA_PCR;
  751. break;
  752. case Opt_err:
  753. ima_log_string(ab, "UNKNOWN", p);
  754. result = -EINVAL;
  755. break;
  756. }
  757. }
  758. if (!result && (entry->action == UNKNOWN))
  759. result = -EINVAL;
  760. else if (entry->func == MODULE_CHECK)
  761. temp_ima_appraise |= IMA_APPRAISE_MODULES;
  762. else if (entry->func == FIRMWARE_CHECK)
  763. temp_ima_appraise |= IMA_APPRAISE_FIRMWARE;
  764. else if (entry->func == POLICY_CHECK)
  765. temp_ima_appraise |= IMA_APPRAISE_POLICY;
  766. audit_log_format(ab, "res=%d", !result);
  767. audit_log_end(ab);
  768. return result;
  769. }
  770. /**
  771. * ima_parse_add_rule - add a rule to ima_policy_rules
  772. * @rule - ima measurement policy rule
  773. *
  774. * Avoid locking by allowing just one writer at a time in ima_write_policy()
  775. * Returns the length of the rule parsed, an error code on failure
  776. */
  777. ssize_t ima_parse_add_rule(char *rule)
  778. {
  779. static const char op[] = "update_policy";
  780. char *p;
  781. struct ima_rule_entry *entry;
  782. ssize_t result, len;
  783. int audit_info = 0;
  784. p = strsep(&rule, "\n");
  785. len = strlen(p) + 1;
  786. p += strspn(p, " \t");
  787. if (*p == '#' || *p == '\0')
  788. return len;
  789. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  790. if (!entry) {
  791. integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
  792. NULL, op, "-ENOMEM", -ENOMEM, audit_info);
  793. return -ENOMEM;
  794. }
  795. INIT_LIST_HEAD(&entry->list);
  796. result = ima_parse_rule(p, entry);
  797. if (result) {
  798. kfree(entry);
  799. integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
  800. NULL, op, "invalid-policy", result,
  801. audit_info);
  802. return result;
  803. }
  804. list_add_tail(&entry->list, &ima_temp_rules);
  805. return len;
  806. }
  807. /**
  808. * ima_delete_rules() called to cleanup invalid in-flight policy.
  809. * We don't need locking as we operate on the temp list, which is
  810. * different from the active one. There is also only one user of
  811. * ima_delete_rules() at a time.
  812. */
  813. void ima_delete_rules(void)
  814. {
  815. struct ima_rule_entry *entry, *tmp;
  816. int i;
  817. temp_ima_appraise = 0;
  818. list_for_each_entry_safe(entry, tmp, &ima_temp_rules, list) {
  819. for (i = 0; i < MAX_LSM_RULES; i++)
  820. kfree(entry->lsm[i].args_p);
  821. list_del(&entry->list);
  822. kfree(entry);
  823. }
  824. }
  825. #ifdef CONFIG_IMA_READ_POLICY
  826. enum {
  827. mask_exec = 0, mask_write, mask_read, mask_append
  828. };
  829. static char *mask_tokens[] = {
  830. "MAY_EXEC",
  831. "MAY_WRITE",
  832. "MAY_READ",
  833. "MAY_APPEND"
  834. };
  835. enum {
  836. func_file = 0, func_mmap, func_bprm,
  837. func_module, func_firmware, func_post,
  838. func_kexec_kernel, func_kexec_initramfs,
  839. func_policy
  840. };
  841. static char *func_tokens[] = {
  842. "FILE_CHECK",
  843. "MMAP_CHECK",
  844. "BPRM_CHECK",
  845. "MODULE_CHECK",
  846. "FIRMWARE_CHECK",
  847. "POST_SETATTR",
  848. "KEXEC_KERNEL_CHECK",
  849. "KEXEC_INITRAMFS_CHECK",
  850. "POLICY_CHECK"
  851. };
  852. void *ima_policy_start(struct seq_file *m, loff_t *pos)
  853. {
  854. loff_t l = *pos;
  855. struct ima_rule_entry *entry;
  856. rcu_read_lock();
  857. list_for_each_entry_rcu(entry, ima_rules, list) {
  858. if (!l--) {
  859. rcu_read_unlock();
  860. return entry;
  861. }
  862. }
  863. rcu_read_unlock();
  864. return NULL;
  865. }
  866. void *ima_policy_next(struct seq_file *m, void *v, loff_t *pos)
  867. {
  868. struct ima_rule_entry *entry = v;
  869. rcu_read_lock();
  870. entry = list_entry_rcu(entry->list.next, struct ima_rule_entry, list);
  871. rcu_read_unlock();
  872. (*pos)++;
  873. return (&entry->list == ima_rules) ? NULL : entry;
  874. }
  875. void ima_policy_stop(struct seq_file *m, void *v)
  876. {
  877. }
  878. #define pt(token) policy_tokens[token + Opt_err].pattern
  879. #define mt(token) mask_tokens[token]
  880. #define ft(token) func_tokens[token]
  881. /*
  882. * policy_func_show - display the ima_hooks policy rule
  883. */
  884. static void policy_func_show(struct seq_file *m, enum ima_hooks func)
  885. {
  886. char tbuf[64] = {0,};
  887. switch (func) {
  888. case FILE_CHECK:
  889. seq_printf(m, pt(Opt_func), ft(func_file));
  890. break;
  891. case MMAP_CHECK:
  892. seq_printf(m, pt(Opt_func), ft(func_mmap));
  893. break;
  894. case BPRM_CHECK:
  895. seq_printf(m, pt(Opt_func), ft(func_bprm));
  896. break;
  897. case MODULE_CHECK:
  898. seq_printf(m, pt(Opt_func), ft(func_module));
  899. break;
  900. case FIRMWARE_CHECK:
  901. seq_printf(m, pt(Opt_func), ft(func_firmware));
  902. break;
  903. case POST_SETATTR:
  904. seq_printf(m, pt(Opt_func), ft(func_post));
  905. break;
  906. case KEXEC_KERNEL_CHECK:
  907. seq_printf(m, pt(Opt_func), ft(func_kexec_kernel));
  908. break;
  909. case KEXEC_INITRAMFS_CHECK:
  910. seq_printf(m, pt(Opt_func), ft(func_kexec_initramfs));
  911. break;
  912. case POLICY_CHECK:
  913. seq_printf(m, pt(Opt_func), ft(func_policy));
  914. break;
  915. default:
  916. snprintf(tbuf, sizeof(tbuf), "%d", func);
  917. seq_printf(m, pt(Opt_func), tbuf);
  918. break;
  919. }
  920. seq_puts(m, " ");
  921. }
  922. int ima_policy_show(struct seq_file *m, void *v)
  923. {
  924. struct ima_rule_entry *entry = v;
  925. int i;
  926. char tbuf[64] = {0,};
  927. rcu_read_lock();
  928. if (entry->action & MEASURE)
  929. seq_puts(m, pt(Opt_measure));
  930. if (entry->action & DONT_MEASURE)
  931. seq_puts(m, pt(Opt_dont_measure));
  932. if (entry->action & APPRAISE)
  933. seq_puts(m, pt(Opt_appraise));
  934. if (entry->action & DONT_APPRAISE)
  935. seq_puts(m, pt(Opt_dont_appraise));
  936. if (entry->action & AUDIT)
  937. seq_puts(m, pt(Opt_audit));
  938. seq_puts(m, " ");
  939. if (entry->flags & IMA_FUNC)
  940. policy_func_show(m, entry->func);
  941. if (entry->flags & IMA_MASK) {
  942. if (entry->mask & MAY_EXEC)
  943. seq_printf(m, pt(Opt_mask), mt(mask_exec));
  944. if (entry->mask & MAY_WRITE)
  945. seq_printf(m, pt(Opt_mask), mt(mask_write));
  946. if (entry->mask & MAY_READ)
  947. seq_printf(m, pt(Opt_mask), mt(mask_read));
  948. if (entry->mask & MAY_APPEND)
  949. seq_printf(m, pt(Opt_mask), mt(mask_append));
  950. seq_puts(m, " ");
  951. }
  952. if (entry->flags & IMA_FSMAGIC) {
  953. snprintf(tbuf, sizeof(tbuf), "0x%lx", entry->fsmagic);
  954. seq_printf(m, pt(Opt_fsmagic), tbuf);
  955. seq_puts(m, " ");
  956. }
  957. if (entry->flags & IMA_PCR) {
  958. snprintf(tbuf, sizeof(tbuf), "%d", entry->pcr);
  959. seq_printf(m, pt(Opt_pcr), tbuf);
  960. seq_puts(m, " ");
  961. }
  962. if (entry->flags & IMA_FSUUID) {
  963. seq_printf(m, "fsuuid=%pU", entry->fsuuid);
  964. seq_puts(m, " ");
  965. }
  966. if (entry->flags & IMA_UID) {
  967. snprintf(tbuf, sizeof(tbuf), "%d", __kuid_val(entry->uid));
  968. if (entry->uid_op == &uid_gt)
  969. seq_printf(m, pt(Opt_uid_gt), tbuf);
  970. else if (entry->uid_op == &uid_lt)
  971. seq_printf(m, pt(Opt_uid_lt), tbuf);
  972. else
  973. seq_printf(m, pt(Opt_uid_eq), tbuf);
  974. seq_puts(m, " ");
  975. }
  976. if (entry->flags & IMA_EUID) {
  977. snprintf(tbuf, sizeof(tbuf), "%d", __kuid_val(entry->uid));
  978. if (entry->uid_op == &uid_gt)
  979. seq_printf(m, pt(Opt_euid_gt), tbuf);
  980. else if (entry->uid_op == &uid_lt)
  981. seq_printf(m, pt(Opt_euid_lt), tbuf);
  982. else
  983. seq_printf(m, pt(Opt_euid_eq), tbuf);
  984. seq_puts(m, " ");
  985. }
  986. if (entry->flags & IMA_FOWNER) {
  987. snprintf(tbuf, sizeof(tbuf), "%d", __kuid_val(entry->fowner));
  988. if (entry->fowner_op == &uid_gt)
  989. seq_printf(m, pt(Opt_fowner_gt), tbuf);
  990. else if (entry->fowner_op == &uid_lt)
  991. seq_printf(m, pt(Opt_fowner_lt), tbuf);
  992. else
  993. seq_printf(m, pt(Opt_fowner_eq), tbuf);
  994. seq_puts(m, " ");
  995. }
  996. for (i = 0; i < MAX_LSM_RULES; i++) {
  997. if (entry->lsm[i].rule) {
  998. switch (i) {
  999. case LSM_OBJ_USER:
  1000. seq_printf(m, pt(Opt_obj_user),
  1001. (char *)entry->lsm[i].args_p);
  1002. break;
  1003. case LSM_OBJ_ROLE:
  1004. seq_printf(m, pt(Opt_obj_role),
  1005. (char *)entry->lsm[i].args_p);
  1006. break;
  1007. case LSM_OBJ_TYPE:
  1008. seq_printf(m, pt(Opt_obj_type),
  1009. (char *)entry->lsm[i].args_p);
  1010. break;
  1011. case LSM_SUBJ_USER:
  1012. seq_printf(m, pt(Opt_subj_user),
  1013. (char *)entry->lsm[i].args_p);
  1014. break;
  1015. case LSM_SUBJ_ROLE:
  1016. seq_printf(m, pt(Opt_subj_role),
  1017. (char *)entry->lsm[i].args_p);
  1018. break;
  1019. case LSM_SUBJ_TYPE:
  1020. seq_printf(m, pt(Opt_subj_type),
  1021. (char *)entry->lsm[i].args_p);
  1022. break;
  1023. }
  1024. }
  1025. }
  1026. if (entry->flags & IMA_DIGSIG_REQUIRED)
  1027. seq_puts(m, "appraise_type=imasig ");
  1028. if (entry->flags & IMA_PERMIT_DIRECTIO)
  1029. seq_puts(m, "permit_directio ");
  1030. rcu_read_unlock();
  1031. seq_puts(m, "\n");
  1032. return 0;
  1033. }
  1034. #endif /* CONFIG_IMA_READ_POLICY */