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