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