Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Security plug functions |
| 3 | * |
| 4 | * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com> |
| 5 | * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com> |
| 6 | * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com> |
Daniel Jurgens | d291f1a | 2017-05-19 15:48:52 +0300 | [diff] [blame] | 7 | * Copyright (C) 2016 Mellanox Technologies |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | */ |
| 14 | |
Kees Cook | 9b8c7c1 | 2018-10-10 17:18:25 -0700 | [diff] [blame] | 15 | #define pr_fmt(fmt) "LSM: " fmt |
| 16 | |
Chenbo Feng | afdb09c | 2017-10-18 13:00:24 -0700 | [diff] [blame] | 17 | #include <linux/bpf.h> |
Randy.Dunlap | c59ede7 | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 18 | #include <linux/capability.h> |
David Quigley | d47be3d | 2013-05-22 12:50:34 -0400 | [diff] [blame] | 19 | #include <linux/dcache.h> |
Paul Gortmaker | 876979c | 2018-12-09 15:36:29 -0500 | [diff] [blame] | 20 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/init.h> |
| 22 | #include <linux/kernel.h> |
Casey Schaufler | 3c4ed7b | 2015-05-02 15:10:46 -0700 | [diff] [blame] | 23 | #include <linux/lsm_hooks.h> |
Mimi Zohar | f381c27 | 2011-03-09 14:13:22 -0500 | [diff] [blame] | 24 | #include <linux/integrity.h> |
Mimi Zohar | 6c21a7f | 2009-10-22 17:30:13 -0400 | [diff] [blame] | 25 | #include <linux/ima.h> |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 26 | #include <linux/evm.h> |
Al Viro | 4040153 | 2012-02-13 03:58:52 +0000 | [diff] [blame] | 27 | #include <linux/fsnotify.h> |
Al Viro | 8b3ec68 | 2012-05-30 17:11:23 -0400 | [diff] [blame] | 28 | #include <linux/mman.h> |
| 29 | #include <linux/mount.h> |
| 30 | #include <linux/personality.h> |
Paul Mundt | 75331a5 | 2012-07-02 14:34:11 +0900 | [diff] [blame] | 31 | #include <linux/backing-dev.h> |
Mickaël Salaün | 3bb857e | 2017-05-10 22:48:48 +0200 | [diff] [blame] | 32 | #include <linux/string.h> |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 33 | #include <linux/msg.h> |
Al Viro | 4040153 | 2012-02-13 03:58:52 +0000 | [diff] [blame] | 34 | #include <net/flow.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Mimi Zohar | 823eb1c | 2011-06-15 21:19:10 -0400 | [diff] [blame] | 36 | #define MAX_LSM_EVM_XATTR 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 38 | /* How many LSMs were built into the kernel? */ |
| 39 | #define LSM_COUNT (__end_lsm_info - __start_lsm_info) |
| 40 | |
Tetsuo Handa | 3dfc9b0 | 2017-03-22 19:46:19 +0900 | [diff] [blame] | 41 | struct security_hook_heads security_hook_heads __lsm_ro_after_init; |
Daniel Jurgens | 8f408ab | 2017-05-19 15:48:53 +0300 | [diff] [blame] | 42 | static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain); |
| 43 | |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 44 | static struct kmem_cache *lsm_file_cache; |
Casey Schaufler | afb1cbe3 | 2018-09-21 17:19:29 -0700 | [diff] [blame] | 45 | static struct kmem_cache *lsm_inode_cache; |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 46 | |
Casey Schaufler | d69dece5 | 2017-01-18 17:09:05 -0800 | [diff] [blame] | 47 | char *lsm_names; |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 48 | static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init; |
| 49 | |
Ahmed S. Darwish | 076c54c | 2008-03-06 18:09:10 +0200 | [diff] [blame] | 50 | /* Boot-time LSM user choice */ |
Kees Cook | 79f7865 | 2018-09-19 17:30:09 -0700 | [diff] [blame] | 51 | static __initdata const char *chosen_lsm_order; |
Kees Cook | 5ef4e41 | 2018-09-19 13:11:41 -0700 | [diff] [blame] | 52 | static __initdata const char *chosen_major_lsm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Kees Cook | 13e735c | 2018-10-09 14:27:46 -0700 | [diff] [blame] | 54 | static __initconst const char * const builtin_lsm_order = CONFIG_LSM; |
| 55 | |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 56 | /* Ordered list of LSMs to initialize. */ |
| 57 | static __initdata struct lsm_info **ordered_lsms; |
Kees Cook | 14bd99c | 2018-09-19 19:57:06 -0700 | [diff] [blame] | 58 | static __initdata struct lsm_info *exclusive; |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 59 | |
Kees Cook | 9b8c7c1 | 2018-10-10 17:18:25 -0700 | [diff] [blame] | 60 | static __initdata bool debug; |
| 61 | #define init_debug(...) \ |
| 62 | do { \ |
| 63 | if (debug) \ |
| 64 | pr_info(__VA_ARGS__); \ |
| 65 | } while (0) |
Ard Biesheuvel | 1b1eeca | 2018-08-21 21:56:13 -0700 | [diff] [blame] | 66 | |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 67 | static bool __init is_enabled(struct lsm_info *lsm) |
Kees Cook | 657d910 | 2018-09-19 16:16:55 -0700 | [diff] [blame] | 68 | { |
Kees Cook | a8027fb | 2018-10-09 14:42:57 -0700 | [diff] [blame] | 69 | if (!lsm->enabled) |
| 70 | return false; |
Kees Cook | 657d910 | 2018-09-19 16:16:55 -0700 | [diff] [blame] | 71 | |
Kees Cook | a8027fb | 2018-10-09 14:42:57 -0700 | [diff] [blame] | 72 | return *lsm->enabled; |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /* Mark an LSM's enabled flag. */ |
| 76 | static int lsm_enabled_true __initdata = 1; |
| 77 | static int lsm_enabled_false __initdata = 0; |
| 78 | static void __init set_enabled(struct lsm_info *lsm, bool enabled) |
| 79 | { |
| 80 | /* |
| 81 | * When an LSM hasn't configured an enable variable, we can use |
| 82 | * a hard-coded location for storing the default enabled state. |
| 83 | */ |
| 84 | if (!lsm->enabled) { |
| 85 | if (enabled) |
| 86 | lsm->enabled = &lsm_enabled_true; |
| 87 | else |
| 88 | lsm->enabled = &lsm_enabled_false; |
| 89 | } else if (lsm->enabled == &lsm_enabled_true) { |
| 90 | if (!enabled) |
| 91 | lsm->enabled = &lsm_enabled_false; |
| 92 | } else if (lsm->enabled == &lsm_enabled_false) { |
| 93 | if (enabled) |
| 94 | lsm->enabled = &lsm_enabled_true; |
| 95 | } else { |
| 96 | *lsm->enabled = enabled; |
| 97 | } |
| 98 | } |
| 99 | |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 100 | /* Is an LSM already listed in the ordered LSMs list? */ |
| 101 | static bool __init exists_ordered_lsm(struct lsm_info *lsm) |
| 102 | { |
| 103 | struct lsm_info **check; |
| 104 | |
| 105 | for (check = ordered_lsms; *check; check++) |
| 106 | if (*check == lsm) |
| 107 | return true; |
| 108 | |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | /* Append an LSM to the list of ordered LSMs to initialize. */ |
| 113 | static int last_lsm __initdata; |
| 114 | static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from) |
| 115 | { |
| 116 | /* Ignore duplicate selections. */ |
| 117 | if (exists_ordered_lsm(lsm)) |
| 118 | return; |
| 119 | |
| 120 | if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from)) |
| 121 | return; |
| 122 | |
Kees Cook | a8027fb | 2018-10-09 14:42:57 -0700 | [diff] [blame] | 123 | /* Enable this LSM, if it is not already set. */ |
| 124 | if (!lsm->enabled) |
| 125 | lsm->enabled = &lsm_enabled_true; |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 126 | ordered_lsms[last_lsm++] = lsm; |
Kees Cook | a8027fb | 2018-10-09 14:42:57 -0700 | [diff] [blame] | 127 | |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 128 | init_debug("%s ordering: %s (%sabled)\n", from, lsm->name, |
| 129 | is_enabled(lsm) ? "en" : "dis"); |
| 130 | } |
| 131 | |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 132 | /* Is an LSM allowed to be initialized? */ |
| 133 | static bool __init lsm_allowed(struct lsm_info *lsm) |
| 134 | { |
| 135 | /* Skip if the LSM is disabled. */ |
| 136 | if (!is_enabled(lsm)) |
| 137 | return false; |
| 138 | |
Kees Cook | 14bd99c | 2018-09-19 19:57:06 -0700 | [diff] [blame] | 139 | /* Not allowed if another exclusive LSM already initialized. */ |
| 140 | if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) { |
| 141 | init_debug("exclusive disabled: %s\n", lsm->name); |
| 142 | return false; |
| 143 | } |
| 144 | |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 145 | return true; |
| 146 | } |
| 147 | |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 148 | static void __init lsm_set_blob_size(int *need, int *lbs) |
| 149 | { |
| 150 | int offset; |
| 151 | |
| 152 | if (*need > 0) { |
| 153 | offset = *lbs; |
| 154 | *lbs += *need; |
| 155 | *need = offset; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed) |
| 160 | { |
| 161 | if (!needed) |
| 162 | return; |
| 163 | |
| 164 | lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred); |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 165 | lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file); |
Casey Schaufler | afb1cbe3 | 2018-09-21 17:19:29 -0700 | [diff] [blame] | 166 | /* |
| 167 | * The inode blob gets an rcu_head in addition to |
| 168 | * what the modules might need. |
| 169 | */ |
| 170 | if (needed->lbs_inode && blob_sizes.lbs_inode == 0) |
| 171 | blob_sizes.lbs_inode = sizeof(struct rcu_head); |
| 172 | lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode); |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 173 | lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc); |
| 174 | lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg); |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 175 | lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task); |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Kees Cook | d8e9bbd4 | 2018-10-10 15:45:22 -0700 | [diff] [blame] | 178 | /* Prepare LSM for initialization. */ |
| 179 | static void __init prepare_lsm(struct lsm_info *lsm) |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 180 | { |
| 181 | int enabled = lsm_allowed(lsm); |
| 182 | |
| 183 | /* Record enablement (to handle any following exclusive LSMs). */ |
| 184 | set_enabled(lsm, enabled); |
| 185 | |
Kees Cook | d8e9bbd4 | 2018-10-10 15:45:22 -0700 | [diff] [blame] | 186 | /* If enabled, do pre-initialization work. */ |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 187 | if (enabled) { |
Kees Cook | 14bd99c | 2018-09-19 19:57:06 -0700 | [diff] [blame] | 188 | if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) { |
| 189 | exclusive = lsm; |
| 190 | init_debug("exclusive chosen: %s\n", lsm->name); |
| 191 | } |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 192 | |
| 193 | lsm_set_blob_sizes(lsm->blobs); |
Kees Cook | d8e9bbd4 | 2018-10-10 15:45:22 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
| 197 | /* Initialize a given LSM, if it is enabled. */ |
| 198 | static void __init initialize_lsm(struct lsm_info *lsm) |
| 199 | { |
| 200 | if (is_enabled(lsm)) { |
| 201 | int ret; |
Kees Cook | 14bd99c | 2018-09-19 19:57:06 -0700 | [diff] [blame] | 202 | |
Kees Cook | 657d910 | 2018-09-19 16:16:55 -0700 | [diff] [blame] | 203 | init_debug("initializing %s\n", lsm->name); |
| 204 | ret = lsm->init(); |
| 205 | WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret); |
| 206 | } |
| 207 | } |
| 208 | |
Kees Cook | 13e735c | 2018-10-09 14:27:46 -0700 | [diff] [blame] | 209 | /* Populate ordered LSMs list from comma-separated LSM name list. */ |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 210 | static void __init ordered_lsm_parse(const char *order, const char *origin) |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 211 | { |
| 212 | struct lsm_info *lsm; |
Kees Cook | 13e735c | 2018-10-09 14:27:46 -0700 | [diff] [blame] | 213 | char *sep, *name, *next; |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 214 | |
Kees Cook | e2bc445 | 2018-09-19 17:48:21 -0700 | [diff] [blame] | 215 | /* LSM_ORDER_FIRST is always first. */ |
| 216 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { |
| 217 | if (lsm->order == LSM_ORDER_FIRST) |
| 218 | append_ordered_lsm(lsm, "first"); |
| 219 | } |
| 220 | |
Kees Cook | 7e61148 | 2018-09-19 13:32:15 -0700 | [diff] [blame] | 221 | /* Process "security=", if given. */ |
Kees Cook | 7e61148 | 2018-09-19 13:32:15 -0700 | [diff] [blame] | 222 | if (chosen_major_lsm) { |
| 223 | struct lsm_info *major; |
| 224 | |
| 225 | /* |
| 226 | * To match the original "security=" behavior, this |
| 227 | * explicitly does NOT fallback to another Legacy Major |
| 228 | * if the selected one was separately disabled: disable |
| 229 | * all non-matching Legacy Major LSMs. |
| 230 | */ |
| 231 | for (major = __start_lsm_info; major < __end_lsm_info; |
| 232 | major++) { |
| 233 | if ((major->flags & LSM_FLAG_LEGACY_MAJOR) && |
| 234 | strcmp(major->name, chosen_major_lsm) != 0) { |
| 235 | set_enabled(major, false); |
| 236 | init_debug("security=%s disabled: %s\n", |
| 237 | chosen_major_lsm, major->name); |
| 238 | } |
| 239 | } |
| 240 | } |
Kees Cook | 5ef4e41 | 2018-09-19 13:11:41 -0700 | [diff] [blame] | 241 | |
Kees Cook | 13e735c | 2018-10-09 14:27:46 -0700 | [diff] [blame] | 242 | sep = kstrdup(order, GFP_KERNEL); |
| 243 | next = sep; |
| 244 | /* Walk the list, looking for matching LSMs. */ |
| 245 | while ((name = strsep(&next, ",")) != NULL) { |
| 246 | bool found = false; |
| 247 | |
| 248 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { |
Kees Cook | e2bc445 | 2018-09-19 17:48:21 -0700 | [diff] [blame] | 249 | if (lsm->order == LSM_ORDER_MUTABLE && |
| 250 | strcmp(lsm->name, name) == 0) { |
Kees Cook | 13e735c | 2018-10-09 14:27:46 -0700 | [diff] [blame] | 251 | append_ordered_lsm(lsm, origin); |
| 252 | found = true; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | if (!found) |
| 257 | init_debug("%s ignored: %s\n", origin, name); |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 258 | } |
Casey Schaufler | c91d810 | 2018-11-19 18:04:32 -0800 | [diff] [blame] | 259 | |
| 260 | /* Process "security=", if given. */ |
| 261 | if (chosen_major_lsm) { |
| 262 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { |
| 263 | if (exists_ordered_lsm(lsm)) |
| 264 | continue; |
| 265 | if (strcmp(lsm->name, chosen_major_lsm) == 0) |
| 266 | append_ordered_lsm(lsm, "security="); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /* Disable all LSMs not in the ordered list. */ |
| 271 | for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { |
| 272 | if (exists_ordered_lsm(lsm)) |
| 273 | continue; |
| 274 | set_enabled(lsm, false); |
| 275 | init_debug("%s disabled: %s\n", origin, lsm->name); |
| 276 | } |
| 277 | |
Kees Cook | 13e735c | 2018-10-09 14:27:46 -0700 | [diff] [blame] | 278 | kfree(sep); |
Kees Cook | f4941d7 | 2018-09-13 23:17:50 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Tetsuo Handa | 1cfb2a5 | 2019-01-18 19:15:59 +0900 | [diff] [blame] | 281 | static void __init lsm_early_cred(struct cred *cred); |
| 282 | static void __init lsm_early_task(struct task_struct *task); |
| 283 | |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 284 | static void __init ordered_lsm_init(void) |
| 285 | { |
| 286 | struct lsm_info **lsm; |
| 287 | |
| 288 | ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms), |
| 289 | GFP_KERNEL); |
| 290 | |
Kees Cook | 79f7865 | 2018-09-19 17:30:09 -0700 | [diff] [blame] | 291 | if (chosen_lsm_order) |
| 292 | ordered_lsm_parse(chosen_lsm_order, "cmdline"); |
| 293 | else |
| 294 | ordered_lsm_parse(builtin_lsm_order, "builtin"); |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 295 | |
| 296 | for (lsm = ordered_lsms; *lsm; lsm++) |
Kees Cook | d8e9bbd4 | 2018-10-10 15:45:22 -0700 | [diff] [blame] | 297 | prepare_lsm(*lsm); |
| 298 | |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 299 | init_debug("cred blob size = %d\n", blob_sizes.lbs_cred); |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 300 | init_debug("file blob size = %d\n", blob_sizes.lbs_file); |
Casey Schaufler | afb1cbe3 | 2018-09-21 17:19:29 -0700 | [diff] [blame] | 301 | init_debug("inode blob size = %d\n", blob_sizes.lbs_inode); |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 302 | init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc); |
| 303 | init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg); |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 304 | init_debug("task blob size = %d\n", blob_sizes.lbs_task); |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * Create any kmem_caches needed for blobs |
| 308 | */ |
| 309 | if (blob_sizes.lbs_file) |
| 310 | lsm_file_cache = kmem_cache_create("lsm_file_cache", |
| 311 | blob_sizes.lbs_file, 0, |
| 312 | SLAB_PANIC, NULL); |
Casey Schaufler | afb1cbe3 | 2018-09-21 17:19:29 -0700 | [diff] [blame] | 313 | if (blob_sizes.lbs_inode) |
| 314 | lsm_inode_cache = kmem_cache_create("lsm_inode_cache", |
| 315 | blob_sizes.lbs_inode, 0, |
| 316 | SLAB_PANIC, NULL); |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 317 | |
Tetsuo Handa | 1cfb2a5 | 2019-01-18 19:15:59 +0900 | [diff] [blame] | 318 | lsm_early_cred((struct cred *) current->cred); |
| 319 | lsm_early_task(current); |
Kees Cook | d8e9bbd4 | 2018-10-10 15:45:22 -0700 | [diff] [blame] | 320 | for (lsm = ordered_lsms; *lsm; lsm++) |
| 321 | initialize_lsm(*lsm); |
Kees Cook | 2d4d511 | 2018-09-19 16:58:31 -0700 | [diff] [blame] | 322 | |
| 323 | kfree(ordered_lsms); |
| 324 | } |
| 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | /** |
| 327 | * security_init - initializes the security framework |
| 328 | * |
| 329 | * This should be called early in the kernel initialization sequence. |
| 330 | */ |
| 331 | int __init security_init(void) |
| 332 | { |
Tetsuo Handa | 3dfc9b0 | 2017-03-22 19:46:19 +0900 | [diff] [blame] | 333 | int i; |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 334 | struct hlist_head *list = (struct hlist_head *) &security_hook_heads; |
Tetsuo Handa | 3dfc9b0 | 2017-03-22 19:46:19 +0900 | [diff] [blame] | 335 | |
Kees Cook | 98d2917 | 2018-10-10 17:18:17 -0700 | [diff] [blame] | 336 | pr_info("Security Framework initializing\n"); |
| 337 | |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 338 | for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head); |
Tetsuo Handa | 3dfc9b0 | 2017-03-22 19:46:19 +0900 | [diff] [blame] | 339 | i++) |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 340 | INIT_HLIST_HEAD(&list[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Kees Cook | 657d910 | 2018-09-19 16:16:55 -0700 | [diff] [blame] | 342 | /* Load LSMs in specified order. */ |
| 343 | ordered_lsm_init(); |
| 344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
Ahmed S. Darwish | 076c54c | 2008-03-06 18:09:10 +0200 | [diff] [blame] | 348 | /* Save user chosen LSM */ |
Kees Cook | 5ef4e41 | 2018-09-19 13:11:41 -0700 | [diff] [blame] | 349 | static int __init choose_major_lsm(char *str) |
Ahmed S. Darwish | 076c54c | 2008-03-06 18:09:10 +0200 | [diff] [blame] | 350 | { |
Kees Cook | 5ef4e41 | 2018-09-19 13:11:41 -0700 | [diff] [blame] | 351 | chosen_major_lsm = str; |
Ahmed S. Darwish | 076c54c | 2008-03-06 18:09:10 +0200 | [diff] [blame] | 352 | return 1; |
| 353 | } |
Kees Cook | 5ef4e41 | 2018-09-19 13:11:41 -0700 | [diff] [blame] | 354 | __setup("security=", choose_major_lsm); |
Ahmed S. Darwish | 076c54c | 2008-03-06 18:09:10 +0200 | [diff] [blame] | 355 | |
Kees Cook | 79f7865 | 2018-09-19 17:30:09 -0700 | [diff] [blame] | 356 | /* Explicitly choose LSM initialization order. */ |
| 357 | static int __init choose_lsm_order(char *str) |
| 358 | { |
| 359 | chosen_lsm_order = str; |
| 360 | return 1; |
| 361 | } |
| 362 | __setup("lsm=", choose_lsm_order); |
| 363 | |
Kees Cook | 9b8c7c1 | 2018-10-10 17:18:25 -0700 | [diff] [blame] | 364 | /* Enable LSM order debugging. */ |
| 365 | static int __init enable_debug(char *str) |
| 366 | { |
| 367 | debug = true; |
| 368 | return 1; |
| 369 | } |
| 370 | __setup("lsm.debug", enable_debug); |
| 371 | |
Mickaël Salaün | 3bb857e | 2017-05-10 22:48:48 +0200 | [diff] [blame] | 372 | static bool match_last_lsm(const char *list, const char *lsm) |
| 373 | { |
| 374 | const char *last; |
| 375 | |
| 376 | if (WARN_ON(!list || !lsm)) |
| 377 | return false; |
| 378 | last = strrchr(list, ','); |
| 379 | if (last) |
| 380 | /* Pass the comma, strcmp() will check for '\0' */ |
| 381 | last++; |
| 382 | else |
| 383 | last = list; |
| 384 | return !strcmp(last, lsm); |
| 385 | } |
| 386 | |
Casey Schaufler | d69dece5 | 2017-01-18 17:09:05 -0800 | [diff] [blame] | 387 | static int lsm_append(char *new, char **result) |
| 388 | { |
| 389 | char *cp; |
| 390 | |
| 391 | if (*result == NULL) { |
| 392 | *result = kstrdup(new, GFP_KERNEL); |
Eric Biggers | 87ea584 | 2018-07-17 10:36:04 -0700 | [diff] [blame] | 393 | if (*result == NULL) |
| 394 | return -ENOMEM; |
Casey Schaufler | d69dece5 | 2017-01-18 17:09:05 -0800 | [diff] [blame] | 395 | } else { |
Mickaël Salaün | 3bb857e | 2017-05-10 22:48:48 +0200 | [diff] [blame] | 396 | /* Check if it is the last registered name */ |
| 397 | if (match_last_lsm(*result, new)) |
| 398 | return 0; |
Casey Schaufler | d69dece5 | 2017-01-18 17:09:05 -0800 | [diff] [blame] | 399 | cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new); |
| 400 | if (cp == NULL) |
| 401 | return -ENOMEM; |
| 402 | kfree(*result); |
| 403 | *result = cp; |
| 404 | } |
| 405 | return 0; |
| 406 | } |
| 407 | |
Ahmed S. Darwish | 076c54c | 2008-03-06 18:09:10 +0200 | [diff] [blame] | 408 | /** |
Casey Schaufler | d69dece5 | 2017-01-18 17:09:05 -0800 | [diff] [blame] | 409 | * security_add_hooks - Add a modules hooks to the hook lists. |
| 410 | * @hooks: the hooks to add |
| 411 | * @count: the number of hooks to add |
| 412 | * @lsm: the name of the security module |
| 413 | * |
| 414 | * Each LSM has to register its hooks with the infrastructure. |
| 415 | */ |
| 416 | void __init security_add_hooks(struct security_hook_list *hooks, int count, |
| 417 | char *lsm) |
| 418 | { |
| 419 | int i; |
| 420 | |
| 421 | for (i = 0; i < count; i++) { |
| 422 | hooks[i].lsm = lsm; |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 423 | hlist_add_tail_rcu(&hooks[i].list, hooks[i].head); |
Casey Schaufler | d69dece5 | 2017-01-18 17:09:05 -0800 | [diff] [blame] | 424 | } |
| 425 | if (lsm_append(lsm, &lsm_names) < 0) |
| 426 | panic("%s - Cannot get early memory.\n", __func__); |
| 427 | } |
| 428 | |
Daniel Jurgens | 8f408ab | 2017-05-19 15:48:53 +0300 | [diff] [blame] | 429 | int call_lsm_notifier(enum lsm_event event, void *data) |
| 430 | { |
| 431 | return atomic_notifier_call_chain(&lsm_notifier_chain, event, data); |
| 432 | } |
| 433 | EXPORT_SYMBOL(call_lsm_notifier); |
| 434 | |
| 435 | int register_lsm_notifier(struct notifier_block *nb) |
| 436 | { |
| 437 | return atomic_notifier_chain_register(&lsm_notifier_chain, nb); |
| 438 | } |
| 439 | EXPORT_SYMBOL(register_lsm_notifier); |
| 440 | |
| 441 | int unregister_lsm_notifier(struct notifier_block *nb) |
| 442 | { |
| 443 | return atomic_notifier_chain_unregister(&lsm_notifier_chain, nb); |
| 444 | } |
| 445 | EXPORT_SYMBOL(unregister_lsm_notifier); |
| 446 | |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 447 | /** |
| 448 | * lsm_cred_alloc - allocate a composite cred blob |
| 449 | * @cred: the cred that needs a blob |
| 450 | * @gfp: allocation type |
| 451 | * |
| 452 | * Allocate the cred blob for all the modules |
| 453 | * |
| 454 | * Returns 0, or -ENOMEM if memory can't be allocated. |
| 455 | */ |
| 456 | static int lsm_cred_alloc(struct cred *cred, gfp_t gfp) |
| 457 | { |
| 458 | if (blob_sizes.lbs_cred == 0) { |
| 459 | cred->security = NULL; |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | cred->security = kzalloc(blob_sizes.lbs_cred, gfp); |
| 464 | if (cred->security == NULL) |
| 465 | return -ENOMEM; |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * lsm_early_cred - during initialization allocate a composite cred blob |
| 471 | * @cred: the cred that needs a blob |
| 472 | * |
Tetsuo Handa | 1cfb2a5 | 2019-01-18 19:15:59 +0900 | [diff] [blame] | 473 | * Allocate the cred blob for all the modules |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 474 | */ |
Tetsuo Handa | 1cfb2a5 | 2019-01-18 19:15:59 +0900 | [diff] [blame] | 475 | static void __init lsm_early_cred(struct cred *cred) |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 476 | { |
Tetsuo Handa | 1cfb2a5 | 2019-01-18 19:15:59 +0900 | [diff] [blame] | 477 | int rc = lsm_cred_alloc(cred, GFP_KERNEL); |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 478 | |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 479 | if (rc) |
| 480 | panic("%s: Early cred alloc failed.\n", __func__); |
| 481 | } |
| 482 | |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 483 | /** |
| 484 | * lsm_file_alloc - allocate a composite file blob |
| 485 | * @file: the file that needs a blob |
| 486 | * |
| 487 | * Allocate the file blob for all the modules |
| 488 | * |
| 489 | * Returns 0, or -ENOMEM if memory can't be allocated. |
| 490 | */ |
| 491 | static int lsm_file_alloc(struct file *file) |
| 492 | { |
| 493 | if (!lsm_file_cache) { |
| 494 | file->f_security = NULL; |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | file->f_security = kmem_cache_zalloc(lsm_file_cache, GFP_KERNEL); |
| 499 | if (file->f_security == NULL) |
| 500 | return -ENOMEM; |
| 501 | return 0; |
| 502 | } |
| 503 | |
Casey Schaufler | afb1cbe3 | 2018-09-21 17:19:29 -0700 | [diff] [blame] | 504 | /** |
| 505 | * lsm_inode_alloc - allocate a composite inode blob |
| 506 | * @inode: the inode that needs a blob |
| 507 | * |
| 508 | * Allocate the inode blob for all the modules |
| 509 | * |
| 510 | * Returns 0, or -ENOMEM if memory can't be allocated. |
| 511 | */ |
| 512 | int lsm_inode_alloc(struct inode *inode) |
| 513 | { |
| 514 | if (!lsm_inode_cache) { |
| 515 | inode->i_security = NULL; |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | inode->i_security = kmem_cache_zalloc(lsm_inode_cache, GFP_NOFS); |
| 520 | if (inode->i_security == NULL) |
| 521 | return -ENOMEM; |
| 522 | return 0; |
| 523 | } |
| 524 | |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 525 | /** |
| 526 | * lsm_task_alloc - allocate a composite task blob |
| 527 | * @task: the task that needs a blob |
| 528 | * |
| 529 | * Allocate the task blob for all the modules |
| 530 | * |
| 531 | * Returns 0, or -ENOMEM if memory can't be allocated. |
| 532 | */ |
Wei Yongjun | 3e8c736 | 2019-01-16 05:44:32 +0000 | [diff] [blame^] | 533 | static int lsm_task_alloc(struct task_struct *task) |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 534 | { |
| 535 | if (blob_sizes.lbs_task == 0) { |
| 536 | task->security = NULL; |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL); |
| 541 | if (task->security == NULL) |
| 542 | return -ENOMEM; |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | /** |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 547 | * lsm_ipc_alloc - allocate a composite ipc blob |
| 548 | * @kip: the ipc that needs a blob |
| 549 | * |
| 550 | * Allocate the ipc blob for all the modules |
| 551 | * |
| 552 | * Returns 0, or -ENOMEM if memory can't be allocated. |
| 553 | */ |
Wei Yongjun | 3e8c736 | 2019-01-16 05:44:32 +0000 | [diff] [blame^] | 554 | static int lsm_ipc_alloc(struct kern_ipc_perm *kip) |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 555 | { |
| 556 | if (blob_sizes.lbs_ipc == 0) { |
| 557 | kip->security = NULL; |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | kip->security = kzalloc(blob_sizes.lbs_ipc, GFP_KERNEL); |
| 562 | if (kip->security == NULL) |
| 563 | return -ENOMEM; |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * lsm_msg_msg_alloc - allocate a composite msg_msg blob |
| 569 | * @mp: the msg_msg that needs a blob |
| 570 | * |
| 571 | * Allocate the ipc blob for all the modules |
| 572 | * |
| 573 | * Returns 0, or -ENOMEM if memory can't be allocated. |
| 574 | */ |
Wei Yongjun | 3e8c736 | 2019-01-16 05:44:32 +0000 | [diff] [blame^] | 575 | static int lsm_msg_msg_alloc(struct msg_msg *mp) |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 576 | { |
| 577 | if (blob_sizes.lbs_msg_msg == 0) { |
| 578 | mp->security = NULL; |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | mp->security = kzalloc(blob_sizes.lbs_msg_msg, GFP_KERNEL); |
| 583 | if (mp->security == NULL) |
| 584 | return -ENOMEM; |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | /** |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 589 | * lsm_early_task - during initialization allocate a composite task blob |
| 590 | * @task: the task that needs a blob |
| 591 | * |
Tetsuo Handa | 1cfb2a5 | 2019-01-18 19:15:59 +0900 | [diff] [blame] | 592 | * Allocate the task blob for all the modules |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 593 | */ |
Tetsuo Handa | 1cfb2a5 | 2019-01-18 19:15:59 +0900 | [diff] [blame] | 594 | static void __init lsm_early_task(struct task_struct *task) |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 595 | { |
Tetsuo Handa | 1cfb2a5 | 2019-01-18 19:15:59 +0900 | [diff] [blame] | 596 | int rc = lsm_task_alloc(task); |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 597 | |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 598 | if (rc) |
| 599 | panic("%s: Early task alloc failed.\n", __func__); |
| 600 | } |
| 601 | |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 602 | /* |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 603 | * Hook list operation macros. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | * |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 605 | * call_void_hook: |
| 606 | * This is a hook that does not return a value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | * |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 608 | * call_int_hook: |
| 609 | * This is a hook that returns a value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 612 | #define call_void_hook(FUNC, ...) \ |
| 613 | do { \ |
| 614 | struct security_hook_list *P; \ |
| 615 | \ |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 616 | hlist_for_each_entry(P, &security_hook_heads.FUNC, list) \ |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 617 | P->hook.FUNC(__VA_ARGS__); \ |
| 618 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 620 | #define call_int_hook(FUNC, IRC, ...) ({ \ |
| 621 | int RC = IRC; \ |
| 622 | do { \ |
| 623 | struct security_hook_list *P; \ |
| 624 | \ |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 625 | hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \ |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 626 | RC = P->hook.FUNC(__VA_ARGS__); \ |
| 627 | if (RC != 0) \ |
| 628 | break; \ |
| 629 | } \ |
| 630 | } while (0); \ |
| 631 | RC; \ |
| 632 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 634 | /* Security operations */ |
| 635 | |
Stephen Smalley | 79af730 | 2015-01-21 10:54:10 -0500 | [diff] [blame] | 636 | int security_binder_set_context_mgr(struct task_struct *mgr) |
| 637 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 638 | return call_int_hook(binder_set_context_mgr, 0, mgr); |
Stephen Smalley | 79af730 | 2015-01-21 10:54:10 -0500 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | int security_binder_transaction(struct task_struct *from, |
| 642 | struct task_struct *to) |
| 643 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 644 | return call_int_hook(binder_transaction, 0, from, to); |
Stephen Smalley | 79af730 | 2015-01-21 10:54:10 -0500 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | int security_binder_transfer_binder(struct task_struct *from, |
| 648 | struct task_struct *to) |
| 649 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 650 | return call_int_hook(binder_transfer_binder, 0, from, to); |
Stephen Smalley | 79af730 | 2015-01-21 10:54:10 -0500 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | int security_binder_transfer_file(struct task_struct *from, |
| 654 | struct task_struct *to, struct file *file) |
| 655 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 656 | return call_int_hook(binder_transfer_file, 0, from, to, file); |
Stephen Smalley | 79af730 | 2015-01-21 10:54:10 -0500 | [diff] [blame] | 657 | } |
| 658 | |
Ingo Molnar | 9e48858 | 2009-05-07 19:26:19 +1000 | [diff] [blame] | 659 | int security_ptrace_access_check(struct task_struct *child, unsigned int mode) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 660 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 661 | return call_int_hook(ptrace_access_check, 0, child, mode); |
David Howells | 5cd9c58 | 2008-08-14 11:37:28 +0100 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | int security_ptrace_traceme(struct task_struct *parent) |
| 665 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 666 | return call_int_hook(ptrace_traceme, 0, parent); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | int security_capget(struct task_struct *target, |
| 670 | kernel_cap_t *effective, |
| 671 | kernel_cap_t *inheritable, |
| 672 | kernel_cap_t *permitted) |
| 673 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 674 | return call_int_hook(capget, 0, target, |
| 675 | effective, inheritable, permitted); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 676 | } |
| 677 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 678 | int security_capset(struct cred *new, const struct cred *old, |
| 679 | const kernel_cap_t *effective, |
| 680 | const kernel_cap_t *inheritable, |
| 681 | const kernel_cap_t *permitted) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 682 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 683 | return call_int_hook(capset, 0, new, old, |
| 684 | effective, inheritable, permitted); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Micah Morton | c1a85a0 | 2019-01-07 16:10:53 -0800 | [diff] [blame] | 687 | int security_capable(const struct cred *cred, |
| 688 | struct user_namespace *ns, |
| 689 | int cap, |
| 690 | unsigned int opts) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 691 | { |
Micah Morton | c1a85a0 | 2019-01-07 16:10:53 -0800 | [diff] [blame] | 692 | return call_int_hook(capable, 0, cred, ns, cap, opts); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 693 | } |
| 694 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 695 | int security_quotactl(int cmds, int type, int id, struct super_block *sb) |
| 696 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 697 | return call_int_hook(quotactl, 0, cmds, type, id, sb); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | int security_quota_on(struct dentry *dentry) |
| 701 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 702 | return call_int_hook(quota_on, 0, dentry); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Eric Paris | 12b3052 | 2010-11-15 18:36:29 -0500 | [diff] [blame] | 705 | int security_syslog(int type) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 706 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 707 | return call_int_hook(syslog, 0, type); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Baolin Wang | 457db29 | 2016-04-08 14:02:11 +0800 | [diff] [blame] | 710 | int security_settime64(const struct timespec64 *ts, const struct timezone *tz) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 711 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 712 | return call_int_hook(settime, 0, ts, tz); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 713 | } |
| 714 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 715 | int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) |
| 716 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 717 | struct security_hook_list *hp; |
| 718 | int cap_sys_admin = 1; |
| 719 | int rc; |
| 720 | |
| 721 | /* |
| 722 | * The module will respond with a positive value if |
| 723 | * it thinks the __vm_enough_memory() call should be |
| 724 | * made with the cap_sys_admin set. If all of the modules |
| 725 | * agree that it should be set it will. If any module |
| 726 | * thinks it should not be set it won't. |
| 727 | */ |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 728 | hlist_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 729 | rc = hp->hook.vm_enough_memory(mm, pages); |
| 730 | if (rc <= 0) { |
| 731 | cap_sys_admin = 0; |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | return __vm_enough_memory(mm, pages, cap_sys_admin); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 736 | } |
| 737 | |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 738 | int security_bprm_set_creds(struct linux_binprm *bprm) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 739 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 740 | return call_int_hook(bprm_set_creds, 0, bprm); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | int security_bprm_check(struct linux_binprm *bprm) |
| 744 | { |
Mimi Zohar | 6c21a7f | 2009-10-22 17:30:13 -0400 | [diff] [blame] | 745 | int ret; |
| 746 | |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 747 | ret = call_int_hook(bprm_check_security, 0, bprm); |
Mimi Zohar | 6c21a7f | 2009-10-22 17:30:13 -0400 | [diff] [blame] | 748 | if (ret) |
| 749 | return ret; |
| 750 | return ima_bprm_check(bprm); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 751 | } |
| 752 | |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 753 | void security_bprm_committing_creds(struct linux_binprm *bprm) |
| 754 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 755 | call_void_hook(bprm_committing_creds, bprm); |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | void security_bprm_committed_creds(struct linux_binprm *bprm) |
| 759 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 760 | call_void_hook(bprm_committed_creds, bprm); |
David Howells | a6f76f2 | 2008-11-14 10:39:24 +1100 | [diff] [blame] | 761 | } |
| 762 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 763 | int security_sb_alloc(struct super_block *sb) |
| 764 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 765 | return call_int_hook(sb_alloc_security, 0, sb); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | void security_sb_free(struct super_block *sb) |
| 769 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 770 | call_void_hook(sb_free_security, sb); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 773 | void security_free_mnt_opts(void **mnt_opts) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 774 | { |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 775 | if (!*mnt_opts) |
| 776 | return; |
| 777 | call_void_hook(sb_free_mnt_opts, *mnt_opts); |
| 778 | *mnt_opts = NULL; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 779 | } |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 780 | EXPORT_SYMBOL(security_free_mnt_opts); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 781 | |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 782 | int security_sb_eat_lsm_opts(char *options, void **mnt_opts) |
Eric Paris | ff36fe2 | 2011-03-03 16:09:14 -0500 | [diff] [blame] | 783 | { |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 784 | return call_int_hook(sb_eat_lsm_opts, 0, options, mnt_opts); |
Eric Paris | ff36fe2 | 2011-03-03 16:09:14 -0500 | [diff] [blame] | 785 | } |
Al Viro | f5c0c26 | 2018-11-17 12:09:18 -0500 | [diff] [blame] | 786 | EXPORT_SYMBOL(security_sb_eat_lsm_opts); |
Eric Paris | ff36fe2 | 2011-03-03 16:09:14 -0500 | [diff] [blame] | 787 | |
Al Viro | c039bc3 | 2018-12-01 23:06:57 -0500 | [diff] [blame] | 788 | int security_sb_remount(struct super_block *sb, |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 789 | void *mnt_opts) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 790 | { |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 791 | return call_int_hook(sb_remount, 0, sb, mnt_opts); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 792 | } |
Al Viro | a65001e | 2018-12-10 17:19:21 -0500 | [diff] [blame] | 793 | EXPORT_SYMBOL(security_sb_remount); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 794 | |
Al Viro | a10d7c2 | 2018-12-05 11:58:35 -0500 | [diff] [blame] | 795 | int security_sb_kern_mount(struct super_block *sb) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 796 | { |
Al Viro | a10d7c2 | 2018-12-05 11:58:35 -0500 | [diff] [blame] | 797 | return call_int_hook(sb_kern_mount, 0, sb); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Eric Paris | 2069f45 | 2008-07-04 09:47:13 +1000 | [diff] [blame] | 800 | int security_sb_show_options(struct seq_file *m, struct super_block *sb) |
| 801 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 802 | return call_int_hook(sb_show_options, 0, m, sb); |
Eric Paris | 2069f45 | 2008-07-04 09:47:13 +1000 | [diff] [blame] | 803 | } |
| 804 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 805 | int security_sb_statfs(struct dentry *dentry) |
| 806 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 807 | return call_int_hook(sb_statfs, 0, dentry); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Al Viro | 8a04c43 | 2016-03-25 14:52:53 -0400 | [diff] [blame] | 810 | int security_sb_mount(const char *dev_name, const struct path *path, |
Al Viro | 808d4e3 | 2012-10-11 11:42:01 -0400 | [diff] [blame] | 811 | const char *type, unsigned long flags, void *data) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 812 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 813 | return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 814 | } |
| 815 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 816 | int security_sb_umount(struct vfsmount *mnt, int flags) |
| 817 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 818 | return call_int_hook(sb_umount, 0, mnt, flags); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Al Viro | 3b73b68 | 2016-03-25 15:31:19 -0400 | [diff] [blame] | 821 | int security_sb_pivotroot(const struct path *old_path, const struct path *new_path) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 822 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 823 | return call_int_hook(sb_pivotroot, 0, old_path, new_path); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Eric Paris | c9180a5 | 2007-11-30 13:00:35 -0500 | [diff] [blame] | 826 | int security_sb_set_mnt_opts(struct super_block *sb, |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 827 | void *mnt_opts, |
David Quigley | 649f6e7 | 2013-05-22 12:50:36 -0400 | [diff] [blame] | 828 | unsigned long kern_flags, |
| 829 | unsigned long *set_kern_flags) |
Eric Paris | c9180a5 | 2007-11-30 13:00:35 -0500 | [diff] [blame] | 830 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 831 | return call_int_hook(sb_set_mnt_opts, |
Al Viro | 204cc0c | 2018-12-13 13:41:47 -0500 | [diff] [blame] | 832 | mnt_opts ? -EOPNOTSUPP : 0, sb, |
| 833 | mnt_opts, kern_flags, set_kern_flags); |
Eric Paris | c9180a5 | 2007-11-30 13:00:35 -0500 | [diff] [blame] | 834 | } |
Eric Paris | e000752 | 2008-03-05 10:31:54 -0500 | [diff] [blame] | 835 | EXPORT_SYMBOL(security_sb_set_mnt_opts); |
Eric Paris | c9180a5 | 2007-11-30 13:00:35 -0500 | [diff] [blame] | 836 | |
Jeff Layton | 094f7b6 | 2013-04-01 08:14:24 -0400 | [diff] [blame] | 837 | int security_sb_clone_mnt_opts(const struct super_block *oldsb, |
Scott Mayhew | 0b4d345 | 2017-06-05 11:45:04 -0400 | [diff] [blame] | 838 | struct super_block *newsb, |
| 839 | unsigned long kern_flags, |
| 840 | unsigned long *set_kern_flags) |
Eric Paris | c9180a5 | 2007-11-30 13:00:35 -0500 | [diff] [blame] | 841 | { |
Scott Mayhew | 0b4d345 | 2017-06-05 11:45:04 -0400 | [diff] [blame] | 842 | return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb, |
| 843 | kern_flags, set_kern_flags); |
Eric Paris | c9180a5 | 2007-11-30 13:00:35 -0500 | [diff] [blame] | 844 | } |
Eric Paris | e000752 | 2008-03-05 10:31:54 -0500 | [diff] [blame] | 845 | EXPORT_SYMBOL(security_sb_clone_mnt_opts); |
| 846 | |
Al Viro | 757cbe5 | 2018-12-14 23:42:21 -0500 | [diff] [blame] | 847 | int security_add_mnt_opt(const char *option, const char *val, int len, |
| 848 | void **mnt_opts) |
Eric Paris | e000752 | 2008-03-05 10:31:54 -0500 | [diff] [blame] | 849 | { |
Al Viro | 757cbe5 | 2018-12-14 23:42:21 -0500 | [diff] [blame] | 850 | return call_int_hook(sb_add_mnt_opt, -EINVAL, |
| 851 | option, val, len, mnt_opts); |
Eric Paris | e000752 | 2008-03-05 10:31:54 -0500 | [diff] [blame] | 852 | } |
Al Viro | 757cbe5 | 2018-12-14 23:42:21 -0500 | [diff] [blame] | 853 | EXPORT_SYMBOL(security_add_mnt_opt); |
Eric Paris | c9180a5 | 2007-11-30 13:00:35 -0500 | [diff] [blame] | 854 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 855 | int security_inode_alloc(struct inode *inode) |
| 856 | { |
Casey Schaufler | afb1cbe3 | 2018-09-21 17:19:29 -0700 | [diff] [blame] | 857 | int rc = lsm_inode_alloc(inode); |
| 858 | |
| 859 | if (unlikely(rc)) |
| 860 | return rc; |
| 861 | rc = call_int_hook(inode_alloc_security, 0, inode); |
| 862 | if (unlikely(rc)) |
| 863 | security_inode_free(inode); |
| 864 | return rc; |
| 865 | } |
| 866 | |
| 867 | static void inode_free_by_rcu(struct rcu_head *head) |
| 868 | { |
| 869 | /* |
| 870 | * The rcu head is at the start of the inode blob |
| 871 | */ |
| 872 | kmem_cache_free(lsm_inode_cache, head); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | void security_inode_free(struct inode *inode) |
| 876 | { |
Mimi Zohar | f381c27 | 2011-03-09 14:13:22 -0500 | [diff] [blame] | 877 | integrity_inode_free(inode); |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 878 | call_void_hook(inode_free_security, inode); |
Casey Schaufler | afb1cbe3 | 2018-09-21 17:19:29 -0700 | [diff] [blame] | 879 | /* |
| 880 | * The inode may still be referenced in a path walk and |
| 881 | * a call to security_inode_permission() can be made |
| 882 | * after inode_free_security() is called. Ideally, the VFS |
| 883 | * wouldn't do this, but fixing that is a much harder |
| 884 | * job. For now, simply free the i_security via RCU, and |
| 885 | * leave the current inode->i_security pointer intact. |
| 886 | * The inode will be freed after the RCU grace period too. |
| 887 | */ |
| 888 | if (inode->i_security) |
| 889 | call_rcu((struct rcu_head *)inode->i_security, |
| 890 | inode_free_by_rcu); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 891 | } |
| 892 | |
David Quigley | d47be3d | 2013-05-22 12:50:34 -0400 | [diff] [blame] | 893 | int security_dentry_init_security(struct dentry *dentry, int mode, |
Al Viro | 4f3ccd7 | 2016-07-20 16:06:15 -0400 | [diff] [blame] | 894 | const struct qstr *name, void **ctx, |
David Quigley | d47be3d | 2013-05-22 12:50:34 -0400 | [diff] [blame] | 895 | u32 *ctxlen) |
| 896 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 897 | return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode, |
| 898 | name, ctx, ctxlen); |
David Quigley | d47be3d | 2013-05-22 12:50:34 -0400 | [diff] [blame] | 899 | } |
| 900 | EXPORT_SYMBOL(security_dentry_init_security); |
| 901 | |
Vivek Goyal | 2602625 | 2016-07-13 10:44:52 -0400 | [diff] [blame] | 902 | int security_dentry_create_files_as(struct dentry *dentry, int mode, |
| 903 | struct qstr *name, |
| 904 | const struct cred *old, struct cred *new) |
| 905 | { |
| 906 | return call_int_hook(dentry_create_files_as, 0, dentry, mode, |
| 907 | name, old, new); |
| 908 | } |
| 909 | EXPORT_SYMBOL(security_dentry_create_files_as); |
| 910 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 911 | int security_inode_init_security(struct inode *inode, struct inode *dir, |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 912 | const struct qstr *qstr, |
| 913 | const initxattrs initxattrs, void *fs_data) |
| 914 | { |
Mimi Zohar | 823eb1c | 2011-06-15 21:19:10 -0400 | [diff] [blame] | 915 | struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1]; |
| 916 | struct xattr *lsm_xattr, *evm_xattr, *xattr; |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 917 | int ret; |
| 918 | |
| 919 | if (unlikely(IS_PRIVATE(inode))) |
Mimi Zohar | fb88c2b | 2011-08-15 10:13:18 -0400 | [diff] [blame] | 920 | return 0; |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 921 | |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 922 | if (!initxattrs) |
Jan Beulich | e308fd3 | 2015-08-24 06:22:25 -0600 | [diff] [blame] | 923 | return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, |
| 924 | dir, qstr, NULL, NULL, NULL); |
Tetsuo Handa | 9548906 | 2013-07-25 05:44:02 +0900 | [diff] [blame] | 925 | memset(new_xattrs, 0, sizeof(new_xattrs)); |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 926 | lsm_xattr = new_xattrs; |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 927 | ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr, |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 928 | &lsm_xattr->name, |
| 929 | &lsm_xattr->value, |
| 930 | &lsm_xattr->value_len); |
| 931 | if (ret) |
| 932 | goto out; |
Mimi Zohar | 823eb1c | 2011-06-15 21:19:10 -0400 | [diff] [blame] | 933 | |
| 934 | evm_xattr = lsm_xattr + 1; |
| 935 | ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr); |
| 936 | if (ret) |
| 937 | goto out; |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 938 | ret = initxattrs(inode, new_xattrs, fs_data); |
| 939 | out: |
Tetsuo Handa | 9548906 | 2013-07-25 05:44:02 +0900 | [diff] [blame] | 940 | for (xattr = new_xattrs; xattr->value != NULL; xattr++) |
Mimi Zohar | 823eb1c | 2011-06-15 21:19:10 -0400 | [diff] [blame] | 941 | kfree(xattr->value); |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 942 | return (ret == -EOPNOTSUPP) ? 0 : ret; |
| 943 | } |
| 944 | EXPORT_SYMBOL(security_inode_init_security); |
| 945 | |
| 946 | int security_old_inode_init_security(struct inode *inode, struct inode *dir, |
Tetsuo Handa | 9548906 | 2013-07-25 05:44:02 +0900 | [diff] [blame] | 947 | const struct qstr *qstr, const char **name, |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 948 | void **value, size_t *len) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 949 | { |
| 950 | if (unlikely(IS_PRIVATE(inode))) |
Jan Kara | 30e0532 | 2012-01-03 13:14:29 +0100 | [diff] [blame] | 951 | return -EOPNOTSUPP; |
Jan Beulich | e308fd3 | 2015-08-24 06:22:25 -0600 | [diff] [blame] | 952 | return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, |
| 953 | qstr, name, value, len); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 954 | } |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 955 | EXPORT_SYMBOL(security_old_inode_init_security); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 956 | |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 957 | #ifdef CONFIG_SECURITY_PATH |
Al Viro | d360775 | 2016-03-25 15:21:09 -0400 | [diff] [blame] | 958 | int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode, |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 959 | unsigned int dev) |
| 960 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 961 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 962 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 963 | return call_int_hook(path_mknod, 0, dir, dentry, mode, dev); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 964 | } |
| 965 | EXPORT_SYMBOL(security_path_mknod); |
| 966 | |
Al Viro | d360775 | 2016-03-25 15:21:09 -0400 | [diff] [blame] | 967 | int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 968 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 969 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 970 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 971 | return call_int_hook(path_mkdir, 0, dir, dentry, mode); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 972 | } |
David Howells | 8214044 | 2010-12-24 14:48:35 +0000 | [diff] [blame] | 973 | EXPORT_SYMBOL(security_path_mkdir); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 974 | |
Al Viro | 989f74e | 2016-03-25 15:13:39 -0400 | [diff] [blame] | 975 | int security_path_rmdir(const struct path *dir, struct dentry *dentry) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 976 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 977 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 978 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 979 | return call_int_hook(path_rmdir, 0, dir, dentry); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 980 | } |
| 981 | |
Al Viro | 989f74e | 2016-03-25 15:13:39 -0400 | [diff] [blame] | 982 | int security_path_unlink(const struct path *dir, struct dentry *dentry) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 983 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 984 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 985 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 986 | return call_int_hook(path_unlink, 0, dir, dentry); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 987 | } |
David Howells | 8214044 | 2010-12-24 14:48:35 +0000 | [diff] [blame] | 988 | EXPORT_SYMBOL(security_path_unlink); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 989 | |
Al Viro | d360775 | 2016-03-25 15:21:09 -0400 | [diff] [blame] | 990 | int security_path_symlink(const struct path *dir, struct dentry *dentry, |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 991 | const char *old_name) |
| 992 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 993 | if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry)))) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 994 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 995 | return call_int_hook(path_symlink, 0, dir, dentry, old_name); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 996 | } |
| 997 | |
Al Viro | 3ccee46 | 2016-03-25 15:27:45 -0400 | [diff] [blame] | 998 | int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 999 | struct dentry *new_dentry) |
| 1000 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1001 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)))) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1002 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1003 | return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1004 | } |
| 1005 | |
Al Viro | 3ccee46 | 2016-03-25 15:27:45 -0400 | [diff] [blame] | 1006 | int security_path_rename(const struct path *old_dir, struct dentry *old_dentry, |
| 1007 | const struct path *new_dir, struct dentry *new_dentry, |
Miklos Szeredi | 0b3974e | 2014-04-01 17:08:43 +0200 | [diff] [blame] | 1008 | unsigned int flags) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1009 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1010 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) || |
| 1011 | (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry))))) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1012 | return 0; |
Miklos Szeredi | da1ce06 | 2014-04-01 17:08:43 +0200 | [diff] [blame] | 1013 | |
| 1014 | if (flags & RENAME_EXCHANGE) { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1015 | int err = call_int_hook(path_rename, 0, new_dir, new_dentry, |
| 1016 | old_dir, old_dentry); |
Miklos Szeredi | da1ce06 | 2014-04-01 17:08:43 +0200 | [diff] [blame] | 1017 | if (err) |
| 1018 | return err; |
| 1019 | } |
| 1020 | |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1021 | return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir, |
| 1022 | new_dentry); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1023 | } |
David Howells | 8214044 | 2010-12-24 14:48:35 +0000 | [diff] [blame] | 1024 | EXPORT_SYMBOL(security_path_rename); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1025 | |
Al Viro | 81f4c50 | 2016-03-25 14:22:01 -0400 | [diff] [blame] | 1026 | int security_path_truncate(const struct path *path) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1027 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1028 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1029 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1030 | return call_int_hook(path_truncate, 0, path); |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1031 | } |
Tetsuo Handa | 89eda06 | 2009-10-04 21:49:47 +0900 | [diff] [blame] | 1032 | |
Al Viro | be01f9f | 2016-03-25 14:56:23 -0400 | [diff] [blame] | 1033 | int security_path_chmod(const struct path *path, umode_t mode) |
Tetsuo Handa | 89eda06 | 2009-10-04 21:49:47 +0900 | [diff] [blame] | 1034 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1035 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
Tetsuo Handa | 89eda06 | 2009-10-04 21:49:47 +0900 | [diff] [blame] | 1036 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1037 | return call_int_hook(path_chmod, 0, path, mode); |
Tetsuo Handa | 89eda06 | 2009-10-04 21:49:47 +0900 | [diff] [blame] | 1038 | } |
| 1039 | |
Al Viro | 7fd25da | 2016-03-25 14:44:41 -0400 | [diff] [blame] | 1040 | int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
Tetsuo Handa | 89eda06 | 2009-10-04 21:49:47 +0900 | [diff] [blame] | 1041 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1042 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
Tetsuo Handa | 89eda06 | 2009-10-04 21:49:47 +0900 | [diff] [blame] | 1043 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1044 | return call_int_hook(path_chown, 0, path, uid, gid); |
Tetsuo Handa | 89eda06 | 2009-10-04 21:49:47 +0900 | [diff] [blame] | 1045 | } |
Tetsuo Handa | 8b8efb4 | 2009-10-04 21:49:48 +0900 | [diff] [blame] | 1046 | |
Al Viro | 77b286c | 2016-03-25 15:28:43 -0400 | [diff] [blame] | 1047 | int security_path_chroot(const struct path *path) |
Tetsuo Handa | 8b8efb4 | 2009-10-04 21:49:48 +0900 | [diff] [blame] | 1048 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1049 | return call_int_hook(path_chroot, 0, path); |
Tetsuo Handa | 8b8efb4 | 2009-10-04 21:49:48 +0900 | [diff] [blame] | 1050 | } |
Kentaro Takeda | be6d3e5 | 2008-12-17 13:24:15 +0900 | [diff] [blame] | 1051 | #endif |
| 1052 | |
Al Viro | 4acdaf2 | 2011-07-26 01:42:34 -0400 | [diff] [blame] | 1053 | int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1054 | { |
| 1055 | if (unlikely(IS_PRIVATE(dir))) |
| 1056 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1057 | return call_int_hook(inode_create, 0, dir, dentry, mode); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1058 | } |
David Howells | 800a964 | 2009-04-03 16:42:40 +0100 | [diff] [blame] | 1059 | EXPORT_SYMBOL_GPL(security_inode_create); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1060 | |
| 1061 | int security_inode_link(struct dentry *old_dentry, struct inode *dir, |
| 1062 | struct dentry *new_dentry) |
| 1063 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1064 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1065 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1066 | return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | int security_inode_unlink(struct inode *dir, struct dentry *dentry) |
| 1070 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1071 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1072 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1073 | return call_int_hook(inode_unlink, 0, dir, dentry); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | int security_inode_symlink(struct inode *dir, struct dentry *dentry, |
| 1077 | const char *old_name) |
| 1078 | { |
| 1079 | if (unlikely(IS_PRIVATE(dir))) |
| 1080 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1081 | return call_int_hook(inode_symlink, 0, dir, dentry, old_name); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 1084 | int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1085 | { |
| 1086 | if (unlikely(IS_PRIVATE(dir))) |
| 1087 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1088 | return call_int_hook(inode_mkdir, 0, dir, dentry, mode); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1089 | } |
David Howells | 800a964 | 2009-04-03 16:42:40 +0100 | [diff] [blame] | 1090 | EXPORT_SYMBOL_GPL(security_inode_mkdir); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1091 | |
| 1092 | int security_inode_rmdir(struct inode *dir, struct dentry *dentry) |
| 1093 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1094 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1095 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1096 | return call_int_hook(inode_rmdir, 0, dir, dentry); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Al Viro | 1a67aaf | 2011-07-26 01:52:52 -0400 | [diff] [blame] | 1099 | int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1100 | { |
| 1101 | if (unlikely(IS_PRIVATE(dir))) |
| 1102 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1103 | return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry, |
Miklos Szeredi | 0b3974e | 2014-04-01 17:08:43 +0200 | [diff] [blame] | 1107 | struct inode *new_dir, struct dentry *new_dentry, |
| 1108 | unsigned int flags) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1109 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1110 | if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) || |
| 1111 | (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry))))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1112 | return 0; |
Miklos Szeredi | da1ce06 | 2014-04-01 17:08:43 +0200 | [diff] [blame] | 1113 | |
| 1114 | if (flags & RENAME_EXCHANGE) { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1115 | int err = call_int_hook(inode_rename, 0, new_dir, new_dentry, |
Miklos Szeredi | da1ce06 | 2014-04-01 17:08:43 +0200 | [diff] [blame] | 1116 | old_dir, old_dentry); |
| 1117 | if (err) |
| 1118 | return err; |
| 1119 | } |
| 1120 | |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1121 | return call_int_hook(inode_rename, 0, old_dir, old_dentry, |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1122 | new_dir, new_dentry); |
| 1123 | } |
| 1124 | |
| 1125 | int security_inode_readlink(struct dentry *dentry) |
| 1126 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1127 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1128 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1129 | return call_int_hook(inode_readlink, 0, dentry); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
NeilBrown | bda0be7 | 2015-03-23 13:37:39 +1100 | [diff] [blame] | 1132 | int security_inode_follow_link(struct dentry *dentry, struct inode *inode, |
| 1133 | bool rcu) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1134 | { |
NeilBrown | bda0be7 | 2015-03-23 13:37:39 +1100 | [diff] [blame] | 1135 | if (unlikely(IS_PRIVATE(inode))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1136 | return 0; |
Linus Torvalds | e22619a | 2015-06-27 13:26:03 -0700 | [diff] [blame] | 1137 | return call_int_hook(inode_follow_link, 0, dentry, inode, rcu); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Al Viro | b77b064 | 2008-07-17 09:37:02 -0400 | [diff] [blame] | 1140 | int security_inode_permission(struct inode *inode, int mask) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1141 | { |
| 1142 | if (unlikely(IS_PRIVATE(inode))) |
| 1143 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1144 | return call_int_hook(inode_permission, 0, inode, mask); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | int security_inode_setattr(struct dentry *dentry, struct iattr *attr) |
| 1148 | { |
Mimi Zohar | 817b54a | 2011-05-13 12:53:38 -0400 | [diff] [blame] | 1149 | int ret; |
| 1150 | |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1151 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1152 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1153 | ret = call_int_hook(inode_setattr, 0, dentry, attr); |
Mimi Zohar | 817b54a | 2011-05-13 12:53:38 -0400 | [diff] [blame] | 1154 | if (ret) |
| 1155 | return ret; |
| 1156 | return evm_inode_setattr(dentry, attr); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1157 | } |
Miklos Szeredi | b1da47e | 2008-07-01 15:01:28 +0200 | [diff] [blame] | 1158 | EXPORT_SYMBOL_GPL(security_inode_setattr); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1159 | |
Al Viro | 3f7036a | 2015-03-08 19:28:30 -0400 | [diff] [blame] | 1160 | int security_inode_getattr(const struct path *path) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1161 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1162 | if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1163 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1164 | return call_int_hook(inode_getattr, 0, path); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 1167 | int security_inode_setxattr(struct dentry *dentry, const char *name, |
| 1168 | const void *value, size_t size, int flags) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1169 | { |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 1170 | int ret; |
| 1171 | |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1172 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1173 | return 0; |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1174 | /* |
| 1175 | * SELinux and Smack integrate the cap call, |
| 1176 | * so assume that all LSMs supplying this call do so. |
| 1177 | */ |
| 1178 | ret = call_int_hook(inode_setxattr, 1, dentry, name, value, size, |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1179 | flags); |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1180 | |
| 1181 | if (ret == 1) |
| 1182 | ret = cap_inode_setxattr(dentry, name, value, size, flags); |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 1183 | if (ret) |
| 1184 | return ret; |
Mimi Zohar | 42c6333 | 2011-03-10 18:54:15 -0500 | [diff] [blame] | 1185 | ret = ima_inode_setxattr(dentry, name, value, size); |
| 1186 | if (ret) |
| 1187 | return ret; |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 1188 | return evm_inode_setxattr(dentry, name, value, size); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 1191 | void security_inode_post_setxattr(struct dentry *dentry, const char *name, |
| 1192 | const void *value, size_t size, int flags) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1193 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1194 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1195 | return; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1196 | call_void_hook(inode_post_setxattr, dentry, name, value, size, flags); |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 1197 | evm_inode_post_setxattr(dentry, name, value, size); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 1200 | int security_inode_getxattr(struct dentry *dentry, const char *name) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1201 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1202 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1203 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1204 | return call_int_hook(inode_getxattr, 0, dentry, name); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | int security_inode_listxattr(struct dentry *dentry) |
| 1208 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1209 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1210 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1211 | return call_int_hook(inode_listxattr, 0, dentry); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
David Howells | 8f0cfa5 | 2008-04-29 00:59:41 -0700 | [diff] [blame] | 1214 | int security_inode_removexattr(struct dentry *dentry, const char *name) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1215 | { |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 1216 | int ret; |
| 1217 | |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 1218 | if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1219 | return 0; |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1220 | /* |
| 1221 | * SELinux and Smack integrate the cap call, |
| 1222 | * so assume that all LSMs supplying this call do so. |
| 1223 | */ |
| 1224 | ret = call_int_hook(inode_removexattr, 1, dentry, name); |
| 1225 | if (ret == 1) |
| 1226 | ret = cap_inode_removexattr(dentry, name); |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 1227 | if (ret) |
| 1228 | return ret; |
Mimi Zohar | 42c6333 | 2011-03-10 18:54:15 -0500 | [diff] [blame] | 1229 | ret = ima_inode_removexattr(dentry, name); |
| 1230 | if (ret) |
| 1231 | return ret; |
Mimi Zohar | 3e1be52 | 2011-03-09 14:38:26 -0500 | [diff] [blame] | 1232 | return evm_inode_removexattr(dentry, name); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Serge E. Hallyn | b537677 | 2007-10-16 23:31:36 -0700 | [diff] [blame] | 1235 | int security_inode_need_killpriv(struct dentry *dentry) |
| 1236 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1237 | return call_int_hook(inode_need_killpriv, 0, dentry); |
Serge E. Hallyn | b537677 | 2007-10-16 23:31:36 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | int security_inode_killpriv(struct dentry *dentry) |
| 1241 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1242 | return call_int_hook(inode_killpriv, 0, dentry); |
Serge E. Hallyn | b537677 | 2007-10-16 23:31:36 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Andreas Gruenbacher | ea861df | 2015-12-24 11:09:39 -0500 | [diff] [blame] | 1245 | int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1246 | { |
Casey Schaufler | 2885c1e | 2016-05-31 17:24:15 -0700 | [diff] [blame] | 1247 | struct security_hook_list *hp; |
| 1248 | int rc; |
| 1249 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1250 | if (unlikely(IS_PRIVATE(inode))) |
James Morris | 8d95250 | 2010-01-14 09:33:28 +1100 | [diff] [blame] | 1251 | return -EOPNOTSUPP; |
Casey Schaufler | 2885c1e | 2016-05-31 17:24:15 -0700 | [diff] [blame] | 1252 | /* |
| 1253 | * Only one module will provide an attribute with a given name. |
| 1254 | */ |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 1255 | hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) { |
Casey Schaufler | 2885c1e | 2016-05-31 17:24:15 -0700 | [diff] [blame] | 1256 | rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc); |
| 1257 | if (rc != -EOPNOTSUPP) |
| 1258 | return rc; |
| 1259 | } |
| 1260 | return -EOPNOTSUPP; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) |
| 1264 | { |
Casey Schaufler | 2885c1e | 2016-05-31 17:24:15 -0700 | [diff] [blame] | 1265 | struct security_hook_list *hp; |
| 1266 | int rc; |
| 1267 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1268 | if (unlikely(IS_PRIVATE(inode))) |
James Morris | 8d95250 | 2010-01-14 09:33:28 +1100 | [diff] [blame] | 1269 | return -EOPNOTSUPP; |
Casey Schaufler | 2885c1e | 2016-05-31 17:24:15 -0700 | [diff] [blame] | 1270 | /* |
| 1271 | * Only one module will provide an attribute with a given name. |
| 1272 | */ |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 1273 | hlist_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) { |
Casey Schaufler | 2885c1e | 2016-05-31 17:24:15 -0700 | [diff] [blame] | 1274 | rc = hp->hook.inode_setsecurity(inode, name, value, size, |
| 1275 | flags); |
| 1276 | if (rc != -EOPNOTSUPP) |
| 1277 | return rc; |
| 1278 | } |
| 1279 | return -EOPNOTSUPP; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size) |
| 1283 | { |
| 1284 | if (unlikely(IS_PRIVATE(inode))) |
| 1285 | return 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1286 | return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1287 | } |
David Quigley | c9bccef | 2013-05-22 12:50:45 -0400 | [diff] [blame] | 1288 | EXPORT_SYMBOL(security_inode_listsecurity); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1289 | |
Andreas Gruenbacher | d6335d7 | 2015-12-24 11:09:39 -0500 | [diff] [blame] | 1290 | void security_inode_getsecid(struct inode *inode, u32 *secid) |
Ahmed S. Darwish | 8a07619 | 2008-03-01 21:51:09 +0200 | [diff] [blame] | 1291 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1292 | call_void_hook(inode_getsecid, inode, secid); |
Ahmed S. Darwish | 8a07619 | 2008-03-01 21:51:09 +0200 | [diff] [blame] | 1293 | } |
| 1294 | |
Vivek Goyal | d8ad8b4 | 2016-07-13 11:13:56 -0400 | [diff] [blame] | 1295 | int security_inode_copy_up(struct dentry *src, struct cred **new) |
| 1296 | { |
| 1297 | return call_int_hook(inode_copy_up, 0, src, new); |
| 1298 | } |
| 1299 | EXPORT_SYMBOL(security_inode_copy_up); |
| 1300 | |
Vivek Goyal | 121ab82 | 2016-07-13 10:44:49 -0400 | [diff] [blame] | 1301 | int security_inode_copy_up_xattr(const char *name) |
| 1302 | { |
| 1303 | return call_int_hook(inode_copy_up_xattr, -EOPNOTSUPP, name); |
| 1304 | } |
| 1305 | EXPORT_SYMBOL(security_inode_copy_up_xattr); |
| 1306 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1307 | int security_file_permission(struct file *file, int mask) |
| 1308 | { |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 1309 | int ret; |
| 1310 | |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1311 | ret = call_int_hook(file_permission, 0, file, mask); |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 1312 | if (ret) |
| 1313 | return ret; |
| 1314 | |
| 1315 | return fsnotify_perm(file, mask); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | int security_file_alloc(struct file *file) |
| 1319 | { |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 1320 | int rc = lsm_file_alloc(file); |
| 1321 | |
| 1322 | if (rc) |
| 1323 | return rc; |
| 1324 | rc = call_int_hook(file_alloc_security, 0, file); |
| 1325 | if (unlikely(rc)) |
| 1326 | security_file_free(file); |
| 1327 | return rc; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | void security_file_free(struct file *file) |
| 1331 | { |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 1332 | void *blob; |
| 1333 | |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1334 | call_void_hook(file_free_security, file); |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 1335 | |
| 1336 | blob = file->f_security; |
| 1337 | if (blob) { |
| 1338 | file->f_security = NULL; |
| 1339 | kmem_cache_free(lsm_file_cache, blob); |
| 1340 | } |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 1344 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1345 | return call_int_hook(file_ioctl, 0, file, cmd, arg); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
Al Viro | 98de59b | 2012-05-30 19:58:30 -0400 | [diff] [blame] | 1348 | static inline unsigned long mmap_prot(struct file *file, unsigned long prot) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1349 | { |
Al Viro | 8b3ec68 | 2012-05-30 17:11:23 -0400 | [diff] [blame] | 1350 | /* |
Al Viro | 98de59b | 2012-05-30 19:58:30 -0400 | [diff] [blame] | 1351 | * Does we have PROT_READ and does the application expect |
| 1352 | * it to imply PROT_EXEC? If not, nothing to talk about... |
Al Viro | 8b3ec68 | 2012-05-30 17:11:23 -0400 | [diff] [blame] | 1353 | */ |
Al Viro | 98de59b | 2012-05-30 19:58:30 -0400 | [diff] [blame] | 1354 | if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ) |
| 1355 | return prot; |
Al Viro | 8b3ec68 | 2012-05-30 17:11:23 -0400 | [diff] [blame] | 1356 | if (!(current->personality & READ_IMPLIES_EXEC)) |
Al Viro | 98de59b | 2012-05-30 19:58:30 -0400 | [diff] [blame] | 1357 | return prot; |
| 1358 | /* |
| 1359 | * if that's an anonymous mapping, let it. |
| 1360 | */ |
| 1361 | if (!file) |
| 1362 | return prot | PROT_EXEC; |
| 1363 | /* |
| 1364 | * ditto if it's not on noexec mount, except that on !MMU we need |
Christoph Hellwig | b4caecd | 2015-01-14 10:42:32 +0100 | [diff] [blame] | 1365 | * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case |
Al Viro | 98de59b | 2012-05-30 19:58:30 -0400 | [diff] [blame] | 1366 | */ |
Eric W. Biederman | 90f8572 | 2015-06-29 14:42:03 -0500 | [diff] [blame] | 1367 | if (!path_noexec(&file->f_path)) { |
Al Viro | 8b3ec68 | 2012-05-30 17:11:23 -0400 | [diff] [blame] | 1368 | #ifndef CONFIG_MMU |
Christoph Hellwig | b4caecd | 2015-01-14 10:42:32 +0100 | [diff] [blame] | 1369 | if (file->f_op->mmap_capabilities) { |
| 1370 | unsigned caps = file->f_op->mmap_capabilities(file); |
| 1371 | if (!(caps & NOMMU_MAP_EXEC)) |
| 1372 | return prot; |
| 1373 | } |
Al Viro | 8b3ec68 | 2012-05-30 17:11:23 -0400 | [diff] [blame] | 1374 | #endif |
Al Viro | 98de59b | 2012-05-30 19:58:30 -0400 | [diff] [blame] | 1375 | return prot | PROT_EXEC; |
Al Viro | 8b3ec68 | 2012-05-30 17:11:23 -0400 | [diff] [blame] | 1376 | } |
Al Viro | 98de59b | 2012-05-30 19:58:30 -0400 | [diff] [blame] | 1377 | /* anything on noexec mount won't get PROT_EXEC */ |
| 1378 | return prot; |
| 1379 | } |
| 1380 | |
| 1381 | int security_mmap_file(struct file *file, unsigned long prot, |
| 1382 | unsigned long flags) |
| 1383 | { |
| 1384 | int ret; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1385 | ret = call_int_hook(mmap_file, 0, file, prot, |
Al Viro | 98de59b | 2012-05-30 19:58:30 -0400 | [diff] [blame] | 1386 | mmap_prot(file, prot), flags); |
Mimi Zohar | 6c21a7f | 2009-10-22 17:30:13 -0400 | [diff] [blame] | 1387 | if (ret) |
| 1388 | return ret; |
| 1389 | return ima_file_mmap(file, prot); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Al Viro | e546785 | 2012-05-30 13:30:51 -0400 | [diff] [blame] | 1392 | int security_mmap_addr(unsigned long addr) |
| 1393 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1394 | return call_int_hook(mmap_addr, 0, addr); |
Al Viro | e546785 | 2012-05-30 13:30:51 -0400 | [diff] [blame] | 1395 | } |
| 1396 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1397 | int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, |
| 1398 | unsigned long prot) |
| 1399 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1400 | return call_int_hook(file_mprotect, 0, vma, reqprot, prot); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | int security_file_lock(struct file *file, unsigned int cmd) |
| 1404 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1405 | return call_int_hook(file_lock, 0, file, cmd); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg) |
| 1409 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1410 | return call_int_hook(file_fcntl, 0, file, cmd, arg); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Jeff Layton | e0b93ed | 2014-08-22 11:27:32 -0400 | [diff] [blame] | 1413 | void security_file_set_fowner(struct file *file) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1414 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1415 | call_void_hook(file_set_fowner, file); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | int security_file_send_sigiotask(struct task_struct *tsk, |
| 1419 | struct fown_struct *fown, int sig) |
| 1420 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1421 | return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | int security_file_receive(struct file *file) |
| 1425 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1426 | return call_int_hook(file_receive, 0, file); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
Al Viro | e3f20ae | 2018-07-10 13:25:29 -0400 | [diff] [blame] | 1429 | int security_file_open(struct file *file) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1430 | { |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 1431 | int ret; |
| 1432 | |
Al Viro | 9481769 | 2018-07-10 14:13:18 -0400 | [diff] [blame] | 1433 | ret = call_int_hook(file_open, 0, file); |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 1434 | if (ret) |
| 1435 | return ret; |
| 1436 | |
| 1437 | return fsnotify_perm(file, MAY_OPEN); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Tetsuo Handa | e4e55b4 | 2017-03-24 20:46:33 +0900 | [diff] [blame] | 1440 | int security_task_alloc(struct task_struct *task, unsigned long clone_flags) |
| 1441 | { |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 1442 | int rc = lsm_task_alloc(task); |
| 1443 | |
| 1444 | if (rc) |
| 1445 | return rc; |
| 1446 | rc = call_int_hook(task_alloc, 0, task, clone_flags); |
| 1447 | if (unlikely(rc)) |
| 1448 | security_task_free(task); |
| 1449 | return rc; |
Tetsuo Handa | e4e55b4 | 2017-03-24 20:46:33 +0900 | [diff] [blame] | 1450 | } |
| 1451 | |
Kees Cook | 1a2a4d0 | 2011-12-21 12:17:03 -0800 | [diff] [blame] | 1452 | void security_task_free(struct task_struct *task) |
| 1453 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1454 | call_void_hook(task_free, task); |
Casey Schaufler | f4ad8f2 | 2018-09-21 17:19:37 -0700 | [diff] [blame] | 1455 | |
| 1456 | kfree(task->security); |
| 1457 | task->security = NULL; |
Kees Cook | 1a2a4d0 | 2011-12-21 12:17:03 -0800 | [diff] [blame] | 1458 | } |
| 1459 | |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1460 | int security_cred_alloc_blank(struct cred *cred, gfp_t gfp) |
| 1461 | { |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 1462 | int rc = lsm_cred_alloc(cred, gfp); |
| 1463 | |
| 1464 | if (rc) |
| 1465 | return rc; |
| 1466 | |
| 1467 | rc = call_int_hook(cred_alloc_blank, 0, cred, gfp); |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 1468 | if (unlikely(rc)) |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 1469 | security_cred_free(cred); |
| 1470 | return rc; |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
David Howells | f1752ee | 2008-11-14 10:39:17 +1100 | [diff] [blame] | 1473 | void security_cred_free(struct cred *cred) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1474 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1475 | call_void_hook(cred_free, cred); |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 1476 | |
| 1477 | kfree(cred->security); |
| 1478 | cred->security = NULL; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1481 | int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp) |
| 1482 | { |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 1483 | int rc = lsm_cred_alloc(new, gfp); |
| 1484 | |
| 1485 | if (rc) |
| 1486 | return rc; |
| 1487 | |
| 1488 | rc = call_int_hook(cred_prepare, 0, new, old, gfp); |
Casey Schaufler | 33bf60c | 2018-11-12 12:02:49 -0800 | [diff] [blame] | 1489 | if (unlikely(rc)) |
Casey Schaufler | bbd3662 | 2018-11-12 09:30:56 -0800 | [diff] [blame] | 1490 | security_cred_free(new); |
| 1491 | return rc; |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1492 | } |
| 1493 | |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1494 | void security_transfer_creds(struct cred *new, const struct cred *old) |
| 1495 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1496 | call_void_hook(cred_transfer, new, old); |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 1497 | } |
| 1498 | |
Matthew Garrett | 3ec3011 | 2018-01-08 13:36:19 -0800 | [diff] [blame] | 1499 | void security_cred_getsecid(const struct cred *c, u32 *secid) |
| 1500 | { |
| 1501 | *secid = 0; |
| 1502 | call_void_hook(cred_getsecid, c, secid); |
| 1503 | } |
| 1504 | EXPORT_SYMBOL(security_cred_getsecid); |
| 1505 | |
David Howells | 3a3b7ce | 2008-11-14 10:39:28 +1100 | [diff] [blame] | 1506 | int security_kernel_act_as(struct cred *new, u32 secid) |
| 1507 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1508 | return call_int_hook(kernel_act_as, 0, new, secid); |
David Howells | 3a3b7ce | 2008-11-14 10:39:28 +1100 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | int security_kernel_create_files_as(struct cred *new, struct inode *inode) |
| 1512 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1513 | return call_int_hook(kernel_create_files_as, 0, new, inode); |
David Howells | 3a3b7ce | 2008-11-14 10:39:28 +1100 | [diff] [blame] | 1514 | } |
| 1515 | |
Eric Paris | dd8dbf2 | 2009-11-03 16:35:32 +1100 | [diff] [blame] | 1516 | int security_kernel_module_request(char *kmod_name) |
Eric Paris | 9188499 | 2009-08-13 09:44:57 -0400 | [diff] [blame] | 1517 | { |
Mikhail Kurinnoi | 6eb864c | 2018-06-27 16:33:42 +0300 | [diff] [blame] | 1518 | int ret; |
| 1519 | |
| 1520 | ret = call_int_hook(kernel_module_request, 0, kmod_name); |
| 1521 | if (ret) |
| 1522 | return ret; |
| 1523 | return integrity_kernel_module_request(kmod_name); |
Eric Paris | 9188499 | 2009-08-13 09:44:57 -0400 | [diff] [blame] | 1524 | } |
| 1525 | |
Mimi Zohar | 39eeb4f | 2016-01-30 22:23:26 -0500 | [diff] [blame] | 1526 | int security_kernel_read_file(struct file *file, enum kernel_read_file_id id) |
| 1527 | { |
| 1528 | int ret; |
| 1529 | |
| 1530 | ret = call_int_hook(kernel_read_file, 0, file, id); |
| 1531 | if (ret) |
| 1532 | return ret; |
| 1533 | return ima_read_file(file, id); |
| 1534 | } |
| 1535 | EXPORT_SYMBOL_GPL(security_kernel_read_file); |
| 1536 | |
Mimi Zohar | bc8ca5b | 2016-01-24 10:07:32 -0500 | [diff] [blame] | 1537 | int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, |
| 1538 | enum kernel_read_file_id id) |
Mimi Zohar | b44a7df | 2015-12-28 16:02:29 -0500 | [diff] [blame] | 1539 | { |
Mimi Zohar | cf22221 | 2016-01-14 17:57:47 -0500 | [diff] [blame] | 1540 | int ret; |
| 1541 | |
| 1542 | ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id); |
| 1543 | if (ret) |
| 1544 | return ret; |
| 1545 | return ima_post_read_file(file, buf, size, id); |
Mimi Zohar | b44a7df | 2015-12-28 16:02:29 -0500 | [diff] [blame] | 1546 | } |
| 1547 | EXPORT_SYMBOL_GPL(security_kernel_post_read_file); |
| 1548 | |
Mimi Zohar | 377179c | 2018-07-13 14:05:56 -0400 | [diff] [blame] | 1549 | int security_kernel_load_data(enum kernel_load_data_id id) |
| 1550 | { |
Mimi Zohar | 16c267a | 2018-07-13 14:05:58 -0400 | [diff] [blame] | 1551 | int ret; |
| 1552 | |
| 1553 | ret = call_int_hook(kernel_load_data, 0, id); |
| 1554 | if (ret) |
| 1555 | return ret; |
| 1556 | return ima_load_data(id); |
Mimi Zohar | 377179c | 2018-07-13 14:05:56 -0400 | [diff] [blame] | 1557 | } |
Arnd Bergmann | 83a68a0 | 2018-07-17 22:23:37 +0200 | [diff] [blame] | 1558 | EXPORT_SYMBOL_GPL(security_kernel_load_data); |
Mimi Zohar | 377179c | 2018-07-13 14:05:56 -0400 | [diff] [blame] | 1559 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1560 | int security_task_fix_setuid(struct cred *new, const struct cred *old, |
| 1561 | int flags) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1562 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1563 | return call_int_hook(task_fix_setuid, 0, new, old, flags); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1566 | int security_task_setpgid(struct task_struct *p, pid_t pgid) |
| 1567 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1568 | return call_int_hook(task_setpgid, 0, p, pgid); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | int security_task_getpgid(struct task_struct *p) |
| 1572 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1573 | return call_int_hook(task_getpgid, 0, p); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | int security_task_getsid(struct task_struct *p) |
| 1577 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1578 | return call_int_hook(task_getsid, 0, p); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | void security_task_getsecid(struct task_struct *p, u32 *secid) |
| 1582 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1583 | *secid = 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1584 | call_void_hook(task_getsecid, p, secid); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1585 | } |
| 1586 | EXPORT_SYMBOL(security_task_getsecid); |
| 1587 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1588 | int security_task_setnice(struct task_struct *p, int nice) |
| 1589 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1590 | return call_int_hook(task_setnice, 0, p, nice); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | int security_task_setioprio(struct task_struct *p, int ioprio) |
| 1594 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1595 | return call_int_hook(task_setioprio, 0, p, ioprio); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | int security_task_getioprio(struct task_struct *p) |
| 1599 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1600 | return call_int_hook(task_getioprio, 0, p); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
Stephen Smalley | 791ec49 | 2017-02-17 07:57:00 -0500 | [diff] [blame] | 1603 | int security_task_prlimit(const struct cred *cred, const struct cred *tcred, |
| 1604 | unsigned int flags) |
| 1605 | { |
| 1606 | return call_int_hook(task_prlimit, 0, cred, tcred, flags); |
| 1607 | } |
| 1608 | |
Jiri Slaby | 8fd00b4 | 2009-08-26 18:41:16 +0200 | [diff] [blame] | 1609 | int security_task_setrlimit(struct task_struct *p, unsigned int resource, |
| 1610 | struct rlimit *new_rlim) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1611 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1612 | return call_int_hook(task_setrlimit, 0, p, resource, new_rlim); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
KOSAKI Motohiro | b0ae198 | 2010-10-15 04:21:18 +0900 | [diff] [blame] | 1615 | int security_task_setscheduler(struct task_struct *p) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1616 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1617 | return call_int_hook(task_setscheduler, 0, p); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | int security_task_getscheduler(struct task_struct *p) |
| 1621 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1622 | return call_int_hook(task_getscheduler, 0, p); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | int security_task_movememory(struct task_struct *p) |
| 1626 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1627 | return call_int_hook(task_movememory, 0, p); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Eric W. Biederman | ae7795b | 2018-09-25 11:27:20 +0200 | [diff] [blame] | 1630 | int security_task_kill(struct task_struct *p, struct kernel_siginfo *info, |
Stephen Smalley | 6b4f3d0 | 2017-09-08 12:40:01 -0400 | [diff] [blame] | 1631 | int sig, const struct cred *cred) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1632 | { |
Stephen Smalley | 6b4f3d0 | 2017-09-08 12:40:01 -0400 | [diff] [blame] | 1633 | return call_int_hook(task_kill, 0, p, info, sig, cred); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1636 | int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 1637 | unsigned long arg4, unsigned long arg5) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1638 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1639 | int thisrc; |
| 1640 | int rc = -ENOSYS; |
| 1641 | struct security_hook_list *hp; |
| 1642 | |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 1643 | hlist_for_each_entry(hp, &security_hook_heads.task_prctl, list) { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1644 | thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5); |
| 1645 | if (thisrc != -ENOSYS) { |
| 1646 | rc = thisrc; |
| 1647 | if (thisrc != 0) |
| 1648 | break; |
| 1649 | } |
| 1650 | } |
| 1651 | return rc; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | void security_task_to_inode(struct task_struct *p, struct inode *inode) |
| 1655 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1656 | call_void_hook(task_to_inode, p, inode); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) |
| 1660 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1661 | return call_int_hook(ipc_permission, 0, ipcp, flag); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Ahmed S. Darwish | 8a07619 | 2008-03-01 21:51:09 +0200 | [diff] [blame] | 1664 | void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) |
| 1665 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1666 | *secid = 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1667 | call_void_hook(ipc_getsecid, ipcp, secid); |
Ahmed S. Darwish | 8a07619 | 2008-03-01 21:51:09 +0200 | [diff] [blame] | 1668 | } |
| 1669 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1670 | int security_msg_msg_alloc(struct msg_msg *msg) |
| 1671 | { |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 1672 | int rc = lsm_msg_msg_alloc(msg); |
| 1673 | |
| 1674 | if (unlikely(rc)) |
| 1675 | return rc; |
| 1676 | rc = call_int_hook(msg_msg_alloc_security, 0, msg); |
| 1677 | if (unlikely(rc)) |
| 1678 | security_msg_msg_free(msg); |
| 1679 | return rc; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | void security_msg_msg_free(struct msg_msg *msg) |
| 1683 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1684 | call_void_hook(msg_msg_free_security, msg); |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 1685 | kfree(msg->security); |
| 1686 | msg->security = NULL; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
Eric W. Biederman | d8c6e85 | 2018-03-22 21:22:26 -0500 | [diff] [blame] | 1689 | int security_msg_queue_alloc(struct kern_ipc_perm *msq) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1690 | { |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 1691 | int rc = lsm_ipc_alloc(msq); |
| 1692 | |
| 1693 | if (unlikely(rc)) |
| 1694 | return rc; |
| 1695 | rc = call_int_hook(msg_queue_alloc_security, 0, msq); |
| 1696 | if (unlikely(rc)) |
| 1697 | security_msg_queue_free(msq); |
| 1698 | return rc; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Eric W. Biederman | d8c6e85 | 2018-03-22 21:22:26 -0500 | [diff] [blame] | 1701 | void security_msg_queue_free(struct kern_ipc_perm *msq) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1702 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1703 | call_void_hook(msg_queue_free_security, msq); |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 1704 | kfree(msq->security); |
| 1705 | msq->security = NULL; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Eric W. Biederman | d8c6e85 | 2018-03-22 21:22:26 -0500 | [diff] [blame] | 1708 | int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1709 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1710 | return call_int_hook(msg_queue_associate, 0, msq, msqflg); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
Eric W. Biederman | d8c6e85 | 2018-03-22 21:22:26 -0500 | [diff] [blame] | 1713 | int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1714 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1715 | return call_int_hook(msg_queue_msgctl, 0, msq, cmd); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Eric W. Biederman | d8c6e85 | 2018-03-22 21:22:26 -0500 | [diff] [blame] | 1718 | int security_msg_queue_msgsnd(struct kern_ipc_perm *msq, |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1719 | struct msg_msg *msg, int msqflg) |
| 1720 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1721 | return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
Eric W. Biederman | d8c6e85 | 2018-03-22 21:22:26 -0500 | [diff] [blame] | 1724 | int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg, |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1725 | struct task_struct *target, long type, int mode) |
| 1726 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1727 | return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
Eric W. Biederman | 7191adf | 2018-03-22 21:08:27 -0500 | [diff] [blame] | 1730 | int security_shm_alloc(struct kern_ipc_perm *shp) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1731 | { |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 1732 | int rc = lsm_ipc_alloc(shp); |
| 1733 | |
| 1734 | if (unlikely(rc)) |
| 1735 | return rc; |
| 1736 | rc = call_int_hook(shm_alloc_security, 0, shp); |
| 1737 | if (unlikely(rc)) |
| 1738 | security_shm_free(shp); |
| 1739 | return rc; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Eric W. Biederman | 7191adf | 2018-03-22 21:08:27 -0500 | [diff] [blame] | 1742 | void security_shm_free(struct kern_ipc_perm *shp) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1743 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1744 | call_void_hook(shm_free_security, shp); |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 1745 | kfree(shp->security); |
| 1746 | shp->security = NULL; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
Eric W. Biederman | 7191adf | 2018-03-22 21:08:27 -0500 | [diff] [blame] | 1749 | int security_shm_associate(struct kern_ipc_perm *shp, int shmflg) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1750 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1751 | return call_int_hook(shm_associate, 0, shp, shmflg); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Eric W. Biederman | 7191adf | 2018-03-22 21:08:27 -0500 | [diff] [blame] | 1754 | int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1755 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1756 | return call_int_hook(shm_shmctl, 0, shp, cmd); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Eric W. Biederman | 7191adf | 2018-03-22 21:08:27 -0500 | [diff] [blame] | 1759 | int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1760 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1761 | return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Eric W. Biederman | aefad95 | 2018-03-22 20:52:43 -0500 | [diff] [blame] | 1764 | int security_sem_alloc(struct kern_ipc_perm *sma) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1765 | { |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 1766 | int rc = lsm_ipc_alloc(sma); |
| 1767 | |
| 1768 | if (unlikely(rc)) |
| 1769 | return rc; |
| 1770 | rc = call_int_hook(sem_alloc_security, 0, sma); |
| 1771 | if (unlikely(rc)) |
| 1772 | security_sem_free(sma); |
| 1773 | return rc; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
Eric W. Biederman | aefad95 | 2018-03-22 20:52:43 -0500 | [diff] [blame] | 1776 | void security_sem_free(struct kern_ipc_perm *sma) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1777 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1778 | call_void_hook(sem_free_security, sma); |
Casey Schaufler | ecd5f82 | 2018-11-20 11:55:02 -0800 | [diff] [blame] | 1779 | kfree(sma->security); |
| 1780 | sma->security = NULL; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Eric W. Biederman | aefad95 | 2018-03-22 20:52:43 -0500 | [diff] [blame] | 1783 | int security_sem_associate(struct kern_ipc_perm *sma, int semflg) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1784 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1785 | return call_int_hook(sem_associate, 0, sma, semflg); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Eric W. Biederman | aefad95 | 2018-03-22 20:52:43 -0500 | [diff] [blame] | 1788 | int security_sem_semctl(struct kern_ipc_perm *sma, int cmd) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1789 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1790 | return call_int_hook(sem_semctl, 0, sma, cmd); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Eric W. Biederman | aefad95 | 2018-03-22 20:52:43 -0500 | [diff] [blame] | 1793 | int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops, |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1794 | unsigned nsops, int alter) |
| 1795 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1796 | return call_int_hook(sem_semop, 0, sma, sops, nsops, alter); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void security_d_instantiate(struct dentry *dentry, struct inode *inode) |
| 1800 | { |
| 1801 | if (unlikely(inode && IS_PRIVATE(inode))) |
| 1802 | return; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1803 | call_void_hook(d_instantiate, dentry, inode); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1804 | } |
| 1805 | EXPORT_SYMBOL(security_d_instantiate); |
| 1806 | |
Casey Schaufler | 6d9c939 | 2018-09-21 17:16:59 -0700 | [diff] [blame] | 1807 | int security_getprocattr(struct task_struct *p, const char *lsm, char *name, |
| 1808 | char **value) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1809 | { |
Casey Schaufler | 6d9c939 | 2018-09-21 17:16:59 -0700 | [diff] [blame] | 1810 | struct security_hook_list *hp; |
| 1811 | |
| 1812 | hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) { |
| 1813 | if (lsm != NULL && strcmp(lsm, hp->lsm)) |
| 1814 | continue; |
| 1815 | return hp->hook.getprocattr(p, name, value); |
| 1816 | } |
| 1817 | return -EINVAL; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Casey Schaufler | 6d9c939 | 2018-09-21 17:16:59 -0700 | [diff] [blame] | 1820 | int security_setprocattr(const char *lsm, const char *name, void *value, |
| 1821 | size_t size) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1822 | { |
Casey Schaufler | 6d9c939 | 2018-09-21 17:16:59 -0700 | [diff] [blame] | 1823 | struct security_hook_list *hp; |
| 1824 | |
| 1825 | hlist_for_each_entry(hp, &security_hook_heads.setprocattr, list) { |
| 1826 | if (lsm != NULL && strcmp(lsm, hp->lsm)) |
| 1827 | continue; |
| 1828 | return hp->hook.setprocattr(name, value, size); |
| 1829 | } |
| 1830 | return -EINVAL; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | int security_netlink_send(struct sock *sk, struct sk_buff *skb) |
| 1834 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1835 | return call_int_hook(netlink_send, 0, sk, skb); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1836 | } |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1837 | |
David Quigley | 746df9b | 2013-05-22 12:50:35 -0400 | [diff] [blame] | 1838 | int security_ismaclabel(const char *name) |
| 1839 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1840 | return call_int_hook(ismaclabel, 0, name); |
David Quigley | 746df9b | 2013-05-22 12:50:35 -0400 | [diff] [blame] | 1841 | } |
| 1842 | EXPORT_SYMBOL(security_ismaclabel); |
| 1843 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1844 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) |
| 1845 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1846 | return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata, |
| 1847 | seclen); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1848 | } |
| 1849 | EXPORT_SYMBOL(security_secid_to_secctx); |
| 1850 | |
David Howells | 7bf570d | 2008-04-29 20:52:51 +0100 | [diff] [blame] | 1851 | int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) |
David Howells | 63cb344 | 2008-01-15 23:47:35 +0000 | [diff] [blame] | 1852 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1853 | *secid = 0; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1854 | return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid); |
David Howells | 63cb344 | 2008-01-15 23:47:35 +0000 | [diff] [blame] | 1855 | } |
| 1856 | EXPORT_SYMBOL(security_secctx_to_secid); |
| 1857 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1858 | void security_release_secctx(char *secdata, u32 seclen) |
| 1859 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1860 | call_void_hook(release_secctx, secdata, seclen); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1861 | } |
| 1862 | EXPORT_SYMBOL(security_release_secctx); |
| 1863 | |
Andreas Gruenbacher | 6f3be9f | 2015-12-24 11:09:40 -0500 | [diff] [blame] | 1864 | void security_inode_invalidate_secctx(struct inode *inode) |
| 1865 | { |
| 1866 | call_void_hook(inode_invalidate_secctx, inode); |
| 1867 | } |
| 1868 | EXPORT_SYMBOL(security_inode_invalidate_secctx); |
| 1869 | |
David P. Quigley | 1ee65e3 | 2009-09-03 14:25:57 -0400 | [diff] [blame] | 1870 | int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) |
| 1871 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1872 | return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen); |
David P. Quigley | 1ee65e3 | 2009-09-03 14:25:57 -0400 | [diff] [blame] | 1873 | } |
| 1874 | EXPORT_SYMBOL(security_inode_notifysecctx); |
| 1875 | |
| 1876 | int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) |
| 1877 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1878 | return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen); |
David P. Quigley | 1ee65e3 | 2009-09-03 14:25:57 -0400 | [diff] [blame] | 1879 | } |
| 1880 | EXPORT_SYMBOL(security_inode_setsecctx); |
| 1881 | |
| 1882 | int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) |
| 1883 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1884 | return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen); |
David P. Quigley | 1ee65e3 | 2009-09-03 14:25:57 -0400 | [diff] [blame] | 1885 | } |
| 1886 | EXPORT_SYMBOL(security_inode_getsecctx); |
| 1887 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1888 | #ifdef CONFIG_SECURITY_NETWORK |
| 1889 | |
David S. Miller | 3610cda | 2011-01-05 15:38:53 -0800 | [diff] [blame] | 1890 | int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1891 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1892 | return call_int_hook(unix_stream_connect, 0, sock, other, newsk); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1893 | } |
| 1894 | EXPORT_SYMBOL(security_unix_stream_connect); |
| 1895 | |
| 1896 | int security_unix_may_send(struct socket *sock, struct socket *other) |
| 1897 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1898 | return call_int_hook(unix_may_send, 0, sock, other); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1899 | } |
| 1900 | EXPORT_SYMBOL(security_unix_may_send); |
| 1901 | |
| 1902 | int security_socket_create(int family, int type, int protocol, int kern) |
| 1903 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1904 | return call_int_hook(socket_create, 0, family, type, protocol, kern); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | int security_socket_post_create(struct socket *sock, int family, |
| 1908 | int type, int protocol, int kern) |
| 1909 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1910 | return call_int_hook(socket_post_create, 0, sock, family, type, |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1911 | protocol, kern); |
| 1912 | } |
| 1913 | |
David Herrmann | aae7cfc | 2018-05-04 16:28:19 +0200 | [diff] [blame] | 1914 | int security_socket_socketpair(struct socket *socka, struct socket *sockb) |
| 1915 | { |
| 1916 | return call_int_hook(socket_socketpair, 0, socka, sockb); |
| 1917 | } |
| 1918 | EXPORT_SYMBOL(security_socket_socketpair); |
| 1919 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1920 | int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen) |
| 1921 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1922 | return call_int_hook(socket_bind, 0, sock, address, addrlen); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen) |
| 1926 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1927 | return call_int_hook(socket_connect, 0, sock, address, addrlen); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | int security_socket_listen(struct socket *sock, int backlog) |
| 1931 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1932 | return call_int_hook(socket_listen, 0, sock, backlog); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | int security_socket_accept(struct socket *sock, struct socket *newsock) |
| 1936 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1937 | return call_int_hook(socket_accept, 0, sock, newsock); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1940 | int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size) |
| 1941 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1942 | return call_int_hook(socket_sendmsg, 0, sock, msg, size); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | int security_socket_recvmsg(struct socket *sock, struct msghdr *msg, |
| 1946 | int size, int flags) |
| 1947 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1948 | return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | int security_socket_getsockname(struct socket *sock) |
| 1952 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1953 | return call_int_hook(socket_getsockname, 0, sock); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | int security_socket_getpeername(struct socket *sock) |
| 1957 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1958 | return call_int_hook(socket_getpeername, 0, sock); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | int security_socket_getsockopt(struct socket *sock, int level, int optname) |
| 1962 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1963 | return call_int_hook(socket_getsockopt, 0, sock, level, optname); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | int security_socket_setsockopt(struct socket *sock, int level, int optname) |
| 1967 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1968 | return call_int_hook(socket_setsockopt, 0, sock, level, optname); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | int security_socket_shutdown(struct socket *sock, int how) |
| 1972 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1973 | return call_int_hook(socket_shutdown, 0, sock, how); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) |
| 1977 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1978 | return call_int_hook(socket_sock_rcv_skb, 0, sk, skb); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1979 | } |
| 1980 | EXPORT_SYMBOL(security_sock_rcv_skb); |
| 1981 | |
| 1982 | int security_socket_getpeersec_stream(struct socket *sock, char __user *optval, |
| 1983 | int __user *optlen, unsigned len) |
| 1984 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 1985 | return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock, |
| 1986 | optval, optlen, len); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid) |
| 1990 | { |
Jan Beulich | e308fd3 | 2015-08-24 06:22:25 -0600 | [diff] [blame] | 1991 | return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock, |
| 1992 | skb, secid); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1993 | } |
| 1994 | EXPORT_SYMBOL(security_socket_getpeersec_dgram); |
| 1995 | |
| 1996 | int security_sk_alloc(struct sock *sk, int family, gfp_t priority) |
| 1997 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 1998 | return call_int_hook(sk_alloc_security, 0, sk, family, priority); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | void security_sk_free(struct sock *sk) |
| 2002 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2003 | call_void_hook(sk_free_security, sk); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | void security_sk_clone(const struct sock *sk, struct sock *newsk) |
| 2007 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2008 | call_void_hook(sk_clone_security, sk, newsk); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2009 | } |
Paul Moore | 6230c9b | 2011-10-07 09:40:59 +0000 | [diff] [blame] | 2010 | EXPORT_SYMBOL(security_sk_clone); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2011 | |
| 2012 | void security_sk_classify_flow(struct sock *sk, struct flowi *fl) |
| 2013 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2014 | call_void_hook(sk_getsecid, sk, &fl->flowi_secid); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2015 | } |
| 2016 | EXPORT_SYMBOL(security_sk_classify_flow); |
| 2017 | |
| 2018 | void security_req_classify_flow(const struct request_sock *req, struct flowi *fl) |
| 2019 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2020 | call_void_hook(req_classify_flow, req, fl); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2021 | } |
| 2022 | EXPORT_SYMBOL(security_req_classify_flow); |
| 2023 | |
| 2024 | void security_sock_graft(struct sock *sk, struct socket *parent) |
| 2025 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2026 | call_void_hook(sock_graft, sk, parent); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2027 | } |
| 2028 | EXPORT_SYMBOL(security_sock_graft); |
| 2029 | |
| 2030 | int security_inet_conn_request(struct sock *sk, |
| 2031 | struct sk_buff *skb, struct request_sock *req) |
| 2032 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2033 | return call_int_hook(inet_conn_request, 0, sk, skb, req); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2034 | } |
| 2035 | EXPORT_SYMBOL(security_inet_conn_request); |
| 2036 | |
| 2037 | void security_inet_csk_clone(struct sock *newsk, |
| 2038 | const struct request_sock *req) |
| 2039 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2040 | call_void_hook(inet_csk_clone, newsk, req); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | void security_inet_conn_established(struct sock *sk, |
| 2044 | struct sk_buff *skb) |
| 2045 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2046 | call_void_hook(inet_conn_established, sk, skb); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2047 | } |
Richard Haines | 72e89f5 | 2018-02-13 20:53:21 +0000 | [diff] [blame] | 2048 | EXPORT_SYMBOL(security_inet_conn_established); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2049 | |
Eric Paris | 2606fd1 | 2010-10-13 16:24:41 -0400 | [diff] [blame] | 2050 | int security_secmark_relabel_packet(u32 secid) |
| 2051 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2052 | return call_int_hook(secmark_relabel_packet, 0, secid); |
Eric Paris | 2606fd1 | 2010-10-13 16:24:41 -0400 | [diff] [blame] | 2053 | } |
| 2054 | EXPORT_SYMBOL(security_secmark_relabel_packet); |
| 2055 | |
| 2056 | void security_secmark_refcount_inc(void) |
| 2057 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2058 | call_void_hook(secmark_refcount_inc); |
Eric Paris | 2606fd1 | 2010-10-13 16:24:41 -0400 | [diff] [blame] | 2059 | } |
| 2060 | EXPORT_SYMBOL(security_secmark_refcount_inc); |
| 2061 | |
| 2062 | void security_secmark_refcount_dec(void) |
| 2063 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2064 | call_void_hook(secmark_refcount_dec); |
Eric Paris | 2606fd1 | 2010-10-13 16:24:41 -0400 | [diff] [blame] | 2065 | } |
| 2066 | EXPORT_SYMBOL(security_secmark_refcount_dec); |
| 2067 | |
Paul Moore | 5dbbaf2 | 2013-01-14 07:12:19 +0000 | [diff] [blame] | 2068 | int security_tun_dev_alloc_security(void **security) |
| 2069 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2070 | return call_int_hook(tun_dev_alloc_security, 0, security); |
Paul Moore | 5dbbaf2 | 2013-01-14 07:12:19 +0000 | [diff] [blame] | 2071 | } |
| 2072 | EXPORT_SYMBOL(security_tun_dev_alloc_security); |
| 2073 | |
| 2074 | void security_tun_dev_free_security(void *security) |
| 2075 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2076 | call_void_hook(tun_dev_free_security, security); |
Paul Moore | 5dbbaf2 | 2013-01-14 07:12:19 +0000 | [diff] [blame] | 2077 | } |
| 2078 | EXPORT_SYMBOL(security_tun_dev_free_security); |
| 2079 | |
Paul Moore | 2b980db | 2009-08-28 18:12:43 -0400 | [diff] [blame] | 2080 | int security_tun_dev_create(void) |
| 2081 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2082 | return call_int_hook(tun_dev_create, 0); |
Paul Moore | 2b980db | 2009-08-28 18:12:43 -0400 | [diff] [blame] | 2083 | } |
| 2084 | EXPORT_SYMBOL(security_tun_dev_create); |
| 2085 | |
Paul Moore | 5dbbaf2 | 2013-01-14 07:12:19 +0000 | [diff] [blame] | 2086 | int security_tun_dev_attach_queue(void *security) |
Paul Moore | 2b980db | 2009-08-28 18:12:43 -0400 | [diff] [blame] | 2087 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2088 | return call_int_hook(tun_dev_attach_queue, 0, security); |
Paul Moore | 2b980db | 2009-08-28 18:12:43 -0400 | [diff] [blame] | 2089 | } |
Paul Moore | 5dbbaf2 | 2013-01-14 07:12:19 +0000 | [diff] [blame] | 2090 | EXPORT_SYMBOL(security_tun_dev_attach_queue); |
Paul Moore | 2b980db | 2009-08-28 18:12:43 -0400 | [diff] [blame] | 2091 | |
Paul Moore | 5dbbaf2 | 2013-01-14 07:12:19 +0000 | [diff] [blame] | 2092 | int security_tun_dev_attach(struct sock *sk, void *security) |
Paul Moore | 2b980db | 2009-08-28 18:12:43 -0400 | [diff] [blame] | 2093 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2094 | return call_int_hook(tun_dev_attach, 0, sk, security); |
Paul Moore | 2b980db | 2009-08-28 18:12:43 -0400 | [diff] [blame] | 2095 | } |
| 2096 | EXPORT_SYMBOL(security_tun_dev_attach); |
| 2097 | |
Paul Moore | 5dbbaf2 | 2013-01-14 07:12:19 +0000 | [diff] [blame] | 2098 | int security_tun_dev_open(void *security) |
| 2099 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2100 | return call_int_hook(tun_dev_open, 0, security); |
Paul Moore | 5dbbaf2 | 2013-01-14 07:12:19 +0000 | [diff] [blame] | 2101 | } |
| 2102 | EXPORT_SYMBOL(security_tun_dev_open); |
| 2103 | |
Richard Haines | 72e89f5 | 2018-02-13 20:53:21 +0000 | [diff] [blame] | 2104 | int security_sctp_assoc_request(struct sctp_endpoint *ep, struct sk_buff *skb) |
| 2105 | { |
| 2106 | return call_int_hook(sctp_assoc_request, 0, ep, skb); |
| 2107 | } |
| 2108 | EXPORT_SYMBOL(security_sctp_assoc_request); |
| 2109 | |
| 2110 | int security_sctp_bind_connect(struct sock *sk, int optname, |
| 2111 | struct sockaddr *address, int addrlen) |
| 2112 | { |
| 2113 | return call_int_hook(sctp_bind_connect, 0, sk, optname, |
| 2114 | address, addrlen); |
| 2115 | } |
| 2116 | EXPORT_SYMBOL(security_sctp_bind_connect); |
| 2117 | |
| 2118 | void security_sctp_sk_clone(struct sctp_endpoint *ep, struct sock *sk, |
| 2119 | struct sock *newsk) |
| 2120 | { |
| 2121 | call_void_hook(sctp_sk_clone, ep, sk, newsk); |
| 2122 | } |
| 2123 | EXPORT_SYMBOL(security_sctp_sk_clone); |
| 2124 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2125 | #endif /* CONFIG_SECURITY_NETWORK */ |
| 2126 | |
Daniel Jurgens | d291f1a | 2017-05-19 15:48:52 +0300 | [diff] [blame] | 2127 | #ifdef CONFIG_SECURITY_INFINIBAND |
| 2128 | |
| 2129 | int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey) |
| 2130 | { |
| 2131 | return call_int_hook(ib_pkey_access, 0, sec, subnet_prefix, pkey); |
| 2132 | } |
| 2133 | EXPORT_SYMBOL(security_ib_pkey_access); |
| 2134 | |
Daniel Jurgens | 47a2b33 | 2017-05-19 15:48:54 +0300 | [diff] [blame] | 2135 | int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num) |
| 2136 | { |
| 2137 | return call_int_hook(ib_endport_manage_subnet, 0, sec, dev_name, port_num); |
| 2138 | } |
| 2139 | EXPORT_SYMBOL(security_ib_endport_manage_subnet); |
| 2140 | |
Daniel Jurgens | d291f1a | 2017-05-19 15:48:52 +0300 | [diff] [blame] | 2141 | int security_ib_alloc_security(void **sec) |
| 2142 | { |
| 2143 | return call_int_hook(ib_alloc_security, 0, sec); |
| 2144 | } |
| 2145 | EXPORT_SYMBOL(security_ib_alloc_security); |
| 2146 | |
| 2147 | void security_ib_free_security(void *sec) |
| 2148 | { |
| 2149 | call_void_hook(ib_free_security, sec); |
| 2150 | } |
| 2151 | EXPORT_SYMBOL(security_ib_free_security); |
| 2152 | #endif /* CONFIG_SECURITY_INFINIBAND */ |
| 2153 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2154 | #ifdef CONFIG_SECURITY_NETWORK_XFRM |
| 2155 | |
Nikolay Aleksandrov | 52a4c64 | 2014-03-07 12:44:19 +0100 | [diff] [blame] | 2156 | int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, |
| 2157 | struct xfrm_user_sec_ctx *sec_ctx, |
| 2158 | gfp_t gfp) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2159 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2160 | return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2161 | } |
| 2162 | EXPORT_SYMBOL(security_xfrm_policy_alloc); |
| 2163 | |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 2164 | int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, |
| 2165 | struct xfrm_sec_ctx **new_ctxp) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2166 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2167 | return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 2170 | void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2171 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2172 | call_void_hook(xfrm_policy_free_security, ctx); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2173 | } |
| 2174 | EXPORT_SYMBOL(security_xfrm_policy_free); |
| 2175 | |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 2176 | int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2177 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2178 | return call_int_hook(xfrm_policy_delete_security, 0, ctx); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Paul Moore | 2e5aa86 | 2013-07-23 17:38:38 -0400 | [diff] [blame] | 2181 | int security_xfrm_state_alloc(struct xfrm_state *x, |
| 2182 | struct xfrm_user_sec_ctx *sec_ctx) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2183 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2184 | return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2185 | } |
| 2186 | EXPORT_SYMBOL(security_xfrm_state_alloc); |
| 2187 | |
| 2188 | int security_xfrm_state_alloc_acquire(struct xfrm_state *x, |
| 2189 | struct xfrm_sec_ctx *polsec, u32 secid) |
| 2190 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2191 | return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | int security_xfrm_state_delete(struct xfrm_state *x) |
| 2195 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2196 | return call_int_hook(xfrm_state_delete_security, 0, x); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2197 | } |
| 2198 | EXPORT_SYMBOL(security_xfrm_state_delete); |
| 2199 | |
| 2200 | void security_xfrm_state_free(struct xfrm_state *x) |
| 2201 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2202 | call_void_hook(xfrm_state_free_security, x); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2203 | } |
| 2204 | |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 2205 | int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2206 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2207 | return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | int security_xfrm_state_pol_flow_match(struct xfrm_state *x, |
David S. Miller | e33f770 | 2011-02-22 18:13:15 -0800 | [diff] [blame] | 2211 | struct xfrm_policy *xp, |
| 2212 | const struct flowi *fl) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2213 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 2214 | struct security_hook_list *hp; |
| 2215 | int rc = 1; |
| 2216 | |
| 2217 | /* |
| 2218 | * Since this function is expected to return 0 or 1, the judgment |
| 2219 | * becomes difficult if multiple LSMs supply this call. Fortunately, |
| 2220 | * we can use the first LSM's judgment because currently only SELinux |
| 2221 | * supplies this call. |
| 2222 | * |
| 2223 | * For speed optimization, we explicitly break the loop rather than |
| 2224 | * using the macro |
| 2225 | */ |
Sargun Dhillon | df0ce17 | 2018-03-29 01:28:23 +0000 | [diff] [blame] | 2226 | hlist_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match, |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 2227 | list) { |
| 2228 | rc = hp->hook.xfrm_state_pol_flow_match(x, xp, fl); |
| 2229 | break; |
| 2230 | } |
| 2231 | return rc; |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid) |
| 2235 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2236 | return call_int_hook(xfrm_decode_session, 0, skb, secid, 1); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl) |
| 2240 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2241 | int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid, |
| 2242 | 0); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2243 | |
| 2244 | BUG_ON(rc); |
| 2245 | } |
| 2246 | EXPORT_SYMBOL(security_skb_classify_flow); |
| 2247 | |
| 2248 | #endif /* CONFIG_SECURITY_NETWORK_XFRM */ |
| 2249 | |
| 2250 | #ifdef CONFIG_KEYS |
| 2251 | |
David Howells | d84f4f9 | 2008-11-14 10:39:23 +1100 | [diff] [blame] | 2252 | int security_key_alloc(struct key *key, const struct cred *cred, |
| 2253 | unsigned long flags) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2254 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2255 | return call_int_hook(key_alloc, 0, key, cred, flags); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | void security_key_free(struct key *key) |
| 2259 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2260 | call_void_hook(key_free, key); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | int security_key_permission(key_ref_t key_ref, |
David Howells | f589594 | 2014-03-14 17:44:49 +0000 | [diff] [blame] | 2264 | const struct cred *cred, unsigned perm) |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2265 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2266 | return call_int_hook(key_permission, 0, key_ref, cred, perm); |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 2269 | int security_key_getsecurity(struct key *key, char **_buffer) |
| 2270 | { |
Casey Schaufler | b1d9e6b | 2015-05-02 15:11:42 -0700 | [diff] [blame] | 2271 | *_buffer = NULL; |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2272 | return call_int_hook(key_getsecurity, 0, key, _buffer); |
David Howells | 70a5bb7 | 2008-04-29 01:01:26 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
James Morris | 20510f2 | 2007-10-16 23:31:32 -0700 | [diff] [blame] | 2275 | #endif /* CONFIG_KEYS */ |
Ahmed S. Darwish | 03d37d2 | 2008-03-01 22:00:05 +0200 | [diff] [blame] | 2276 | |
| 2277 | #ifdef CONFIG_AUDIT |
| 2278 | |
| 2279 | int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule) |
| 2280 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2281 | return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule); |
Ahmed S. Darwish | 03d37d2 | 2008-03-01 22:00:05 +0200 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | int security_audit_rule_known(struct audit_krule *krule) |
| 2285 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2286 | return call_int_hook(audit_rule_known, 0, krule); |
Ahmed S. Darwish | 03d37d2 | 2008-03-01 22:00:05 +0200 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | void security_audit_rule_free(void *lsmrule) |
| 2290 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2291 | call_void_hook(audit_rule_free, lsmrule); |
Ahmed S. Darwish | 03d37d2 | 2008-03-01 22:00:05 +0200 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule, |
| 2295 | struct audit_context *actx) |
| 2296 | { |
Casey Schaufler | f25fce3 | 2015-05-02 15:11:29 -0700 | [diff] [blame] | 2297 | return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule, |
| 2298 | actx); |
Ahmed S. Darwish | 03d37d2 | 2008-03-01 22:00:05 +0200 | [diff] [blame] | 2299 | } |
Ahmed S. Darwish | 03d37d2 | 2008-03-01 22:00:05 +0200 | [diff] [blame] | 2300 | #endif /* CONFIG_AUDIT */ |
Chenbo Feng | afdb09c | 2017-10-18 13:00:24 -0700 | [diff] [blame] | 2301 | |
| 2302 | #ifdef CONFIG_BPF_SYSCALL |
| 2303 | int security_bpf(int cmd, union bpf_attr *attr, unsigned int size) |
| 2304 | { |
| 2305 | return call_int_hook(bpf, 0, cmd, attr, size); |
| 2306 | } |
| 2307 | int security_bpf_map(struct bpf_map *map, fmode_t fmode) |
| 2308 | { |
| 2309 | return call_int_hook(bpf_map, 0, map, fmode); |
| 2310 | } |
| 2311 | int security_bpf_prog(struct bpf_prog *prog) |
| 2312 | { |
| 2313 | return call_int_hook(bpf_prog, 0, prog); |
| 2314 | } |
| 2315 | int security_bpf_map_alloc(struct bpf_map *map) |
| 2316 | { |
| 2317 | return call_int_hook(bpf_map_alloc_security, 0, map); |
| 2318 | } |
| 2319 | int security_bpf_prog_alloc(struct bpf_prog_aux *aux) |
| 2320 | { |
| 2321 | return call_int_hook(bpf_prog_alloc_security, 0, aux); |
| 2322 | } |
| 2323 | void security_bpf_map_free(struct bpf_map *map) |
| 2324 | { |
| 2325 | call_void_hook(bpf_map_free_security, map); |
| 2326 | } |
| 2327 | void security_bpf_prog_free(struct bpf_prog_aux *aux) |
| 2328 | { |
| 2329 | call_void_hook(bpf_prog_free_security, aux); |
| 2330 | } |
| 2331 | #endif /* CONFIG_BPF_SYSCALL */ |