blob: 4989fb65e6628b923a189a74736280612cc4088d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Jurgensd291f1a2017-05-19 15:48:52 +03007 * Copyright (C) 2016 Mellanox Technologies
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
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 Cook9b8c7c12018-10-10 17:18:25 -070015#define pr_fmt(fmt) "LSM: " fmt
16
Chenbo Fengafdb09c2017-10-18 13:00:24 -070017#include <linux/bpf.h>
Randy.Dunlapc59ede72006-01-11 12:17:46 -080018#include <linux/capability.h>
David Quigleyd47be3d2013-05-22 12:50:34 -040019#include <linux/dcache.h>
Paul Gortmaker876979c2018-12-09 15:36:29 -050020#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
22#include <linux/kernel.h>
Casey Schaufler3c4ed7b2015-05-02 15:10:46 -070023#include <linux/lsm_hooks.h>
Mimi Zoharf381c272011-03-09 14:13:22 -050024#include <linux/integrity.h>
Mimi Zohar6c21a7f2009-10-22 17:30:13 -040025#include <linux/ima.h>
Mimi Zohar3e1be522011-03-09 14:38:26 -050026#include <linux/evm.h>
Al Viro40401532012-02-13 03:58:52 +000027#include <linux/fsnotify.h>
Al Viro8b3ec682012-05-30 17:11:23 -040028#include <linux/mman.h>
29#include <linux/mount.h>
30#include <linux/personality.h>
Paul Mundt75331a52012-07-02 14:34:11 +090031#include <linux/backing-dev.h>
Mickaël Salaün3bb857e2017-05-10 22:48:48 +020032#include <linux/string.h>
Al Viro40401532012-02-13 03:58:52 +000033#include <net/flow.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Mimi Zohar823eb1c2011-06-15 21:19:10 -040035#define MAX_LSM_EVM_XATTR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Kees Cook2d4d5112018-09-19 16:58:31 -070037/* How many LSMs were built into the kernel? */
38#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
39
Tetsuo Handa3dfc9b02017-03-22 19:46:19 +090040struct security_hook_heads security_hook_heads __lsm_ro_after_init;
Daniel Jurgens8f408ab2017-05-19 15:48:53 +030041static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
42
Casey Schaufler33bf60c2018-11-12 12:02:49 -080043static struct kmem_cache *lsm_file_cache;
Casey Schauflerafb1cbe32018-09-21 17:19:29 -070044static struct kmem_cache *lsm_inode_cache;
Casey Schaufler33bf60c2018-11-12 12:02:49 -080045
Casey Schauflerd69dece52017-01-18 17:09:05 -080046char *lsm_names;
Casey Schauflerbbd36622018-11-12 09:30:56 -080047static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init;
48
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +020049/* Boot-time LSM user choice */
Kees Cook79f78652018-09-19 17:30:09 -070050static __initdata const char *chosen_lsm_order;
Kees Cook5ef4e412018-09-19 13:11:41 -070051static __initdata const char *chosen_major_lsm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Kees Cook13e735c2018-10-09 14:27:46 -070053static __initconst const char * const builtin_lsm_order = CONFIG_LSM;
54
Kees Cook2d4d5112018-09-19 16:58:31 -070055/* Ordered list of LSMs to initialize. */
56static __initdata struct lsm_info **ordered_lsms;
Kees Cook14bd99c2018-09-19 19:57:06 -070057static __initdata struct lsm_info *exclusive;
Kees Cook2d4d5112018-09-19 16:58:31 -070058
Kees Cook9b8c7c12018-10-10 17:18:25 -070059static __initdata bool debug;
60#define init_debug(...) \
61 do { \
62 if (debug) \
63 pr_info(__VA_ARGS__); \
64 } while (0)
Ard Biesheuvel1b1eeca2018-08-21 21:56:13 -070065
Kees Cookf4941d72018-09-13 23:17:50 -070066static bool __init is_enabled(struct lsm_info *lsm)
Kees Cook657d9102018-09-19 16:16:55 -070067{
Kees Cooka8027fb2018-10-09 14:42:57 -070068 if (!lsm->enabled)
69 return false;
Kees Cook657d9102018-09-19 16:16:55 -070070
Kees Cooka8027fb2018-10-09 14:42:57 -070071 return *lsm->enabled;
Kees Cookf4941d72018-09-13 23:17:50 -070072}
73
74/* Mark an LSM's enabled flag. */
75static int lsm_enabled_true __initdata = 1;
76static int lsm_enabled_false __initdata = 0;
77static void __init set_enabled(struct lsm_info *lsm, bool enabled)
78{
79 /*
80 * When an LSM hasn't configured an enable variable, we can use
81 * a hard-coded location for storing the default enabled state.
82 */
83 if (!lsm->enabled) {
84 if (enabled)
85 lsm->enabled = &lsm_enabled_true;
86 else
87 lsm->enabled = &lsm_enabled_false;
88 } else if (lsm->enabled == &lsm_enabled_true) {
89 if (!enabled)
90 lsm->enabled = &lsm_enabled_false;
91 } else if (lsm->enabled == &lsm_enabled_false) {
92 if (enabled)
93 lsm->enabled = &lsm_enabled_true;
94 } else {
95 *lsm->enabled = enabled;
96 }
97}
98
Kees Cook2d4d5112018-09-19 16:58:31 -070099/* Is an LSM already listed in the ordered LSMs list? */
100static bool __init exists_ordered_lsm(struct lsm_info *lsm)
101{
102 struct lsm_info **check;
103
104 for (check = ordered_lsms; *check; check++)
105 if (*check == lsm)
106 return true;
107
108 return false;
109}
110
111/* Append an LSM to the list of ordered LSMs to initialize. */
112static int last_lsm __initdata;
113static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
114{
115 /* Ignore duplicate selections. */
116 if (exists_ordered_lsm(lsm))
117 return;
118
119 if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from))
120 return;
121
Kees Cooka8027fb2018-10-09 14:42:57 -0700122 /* Enable this LSM, if it is not already set. */
123 if (!lsm->enabled)
124 lsm->enabled = &lsm_enabled_true;
Kees Cook2d4d5112018-09-19 16:58:31 -0700125 ordered_lsms[last_lsm++] = lsm;
Kees Cooka8027fb2018-10-09 14:42:57 -0700126
Kees Cook2d4d5112018-09-19 16:58:31 -0700127 init_debug("%s ordering: %s (%sabled)\n", from, lsm->name,
128 is_enabled(lsm) ? "en" : "dis");
129}
130
Kees Cookf4941d72018-09-13 23:17:50 -0700131/* Is an LSM allowed to be initialized? */
132static bool __init lsm_allowed(struct lsm_info *lsm)
133{
134 /* Skip if the LSM is disabled. */
135 if (!is_enabled(lsm))
136 return false;
137
Kees Cook14bd99c2018-09-19 19:57:06 -0700138 /* Not allowed if another exclusive LSM already initialized. */
139 if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && exclusive) {
140 init_debug("exclusive disabled: %s\n", lsm->name);
141 return false;
142 }
143
Kees Cookf4941d72018-09-13 23:17:50 -0700144 return true;
145}
146
Casey Schauflerbbd36622018-11-12 09:30:56 -0800147static void __init lsm_set_blob_size(int *need, int *lbs)
148{
149 int offset;
150
151 if (*need > 0) {
152 offset = *lbs;
153 *lbs += *need;
154 *need = offset;
155 }
156}
157
158static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
159{
160 if (!needed)
161 return;
162
163 lsm_set_blob_size(&needed->lbs_cred, &blob_sizes.lbs_cred);
Casey Schaufler33bf60c2018-11-12 12:02:49 -0800164 lsm_set_blob_size(&needed->lbs_file, &blob_sizes.lbs_file);
Casey Schauflerafb1cbe32018-09-21 17:19:29 -0700165 /*
166 * The inode blob gets an rcu_head in addition to
167 * what the modules might need.
168 */
169 if (needed->lbs_inode && blob_sizes.lbs_inode == 0)
170 blob_sizes.lbs_inode = sizeof(struct rcu_head);
171 lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode);
Casey Schauflerbbd36622018-11-12 09:30:56 -0800172}
173
Kees Cookd8e9bbd42018-10-10 15:45:22 -0700174/* Prepare LSM for initialization. */
175static void __init prepare_lsm(struct lsm_info *lsm)
Kees Cookf4941d72018-09-13 23:17:50 -0700176{
177 int enabled = lsm_allowed(lsm);
178
179 /* Record enablement (to handle any following exclusive LSMs). */
180 set_enabled(lsm, enabled);
181
Kees Cookd8e9bbd42018-10-10 15:45:22 -0700182 /* If enabled, do pre-initialization work. */
Kees Cookf4941d72018-09-13 23:17:50 -0700183 if (enabled) {
Kees Cook14bd99c2018-09-19 19:57:06 -0700184 if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
185 exclusive = lsm;
186 init_debug("exclusive chosen: %s\n", lsm->name);
187 }
Casey Schauflerbbd36622018-11-12 09:30:56 -0800188
189 lsm_set_blob_sizes(lsm->blobs);
Kees Cookd8e9bbd42018-10-10 15:45:22 -0700190 }
191}
192
193/* Initialize a given LSM, if it is enabled. */
194static void __init initialize_lsm(struct lsm_info *lsm)
195{
196 if (is_enabled(lsm)) {
197 int ret;
Kees Cook14bd99c2018-09-19 19:57:06 -0700198
Kees Cook657d9102018-09-19 16:16:55 -0700199 init_debug("initializing %s\n", lsm->name);
200 ret = lsm->init();
201 WARN(ret, "%s failed to initialize: %d\n", lsm->name, ret);
202 }
203}
204
Kees Cook13e735c2018-10-09 14:27:46 -0700205/* Populate ordered LSMs list from comma-separated LSM name list. */
Kees Cook2d4d5112018-09-19 16:58:31 -0700206static void __init ordered_lsm_parse(const char *order, const char *origin)
Kees Cookf4941d72018-09-13 23:17:50 -0700207{
208 struct lsm_info *lsm;
Kees Cook13e735c2018-10-09 14:27:46 -0700209 char *sep, *name, *next;
Kees Cookf4941d72018-09-13 23:17:50 -0700210
Kees Cooke2bc4452018-09-19 17:48:21 -0700211 /* LSM_ORDER_FIRST is always first. */
212 for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
213 if (lsm->order == LSM_ORDER_FIRST)
214 append_ordered_lsm(lsm, "first");
215 }
216
Kees Cook7e611482018-09-19 13:32:15 -0700217 /* Process "security=", if given. */
Kees Cook7e611482018-09-19 13:32:15 -0700218 if (chosen_major_lsm) {
219 struct lsm_info *major;
220
221 /*
222 * To match the original "security=" behavior, this
223 * explicitly does NOT fallback to another Legacy Major
224 * if the selected one was separately disabled: disable
225 * all non-matching Legacy Major LSMs.
226 */
227 for (major = __start_lsm_info; major < __end_lsm_info;
228 major++) {
229 if ((major->flags & LSM_FLAG_LEGACY_MAJOR) &&
230 strcmp(major->name, chosen_major_lsm) != 0) {
231 set_enabled(major, false);
232 init_debug("security=%s disabled: %s\n",
233 chosen_major_lsm, major->name);
234 }
235 }
236 }
Kees Cook5ef4e412018-09-19 13:11:41 -0700237
Kees Cook13e735c2018-10-09 14:27:46 -0700238 sep = kstrdup(order, GFP_KERNEL);
239 next = sep;
240 /* Walk the list, looking for matching LSMs. */
241 while ((name = strsep(&next, ",")) != NULL) {
242 bool found = false;
243
244 for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
Kees Cooke2bc4452018-09-19 17:48:21 -0700245 if (lsm->order == LSM_ORDER_MUTABLE &&
246 strcmp(lsm->name, name) == 0) {
Kees Cook13e735c2018-10-09 14:27:46 -0700247 append_ordered_lsm(lsm, origin);
248 found = true;
249 }
250 }
251
252 if (!found)
253 init_debug("%s ignored: %s\n", origin, name);
Kees Cookf4941d72018-09-13 23:17:50 -0700254 }
Casey Schauflerc91d8102018-11-19 18:04:32 -0800255
256 /* Process "security=", if given. */
257 if (chosen_major_lsm) {
258 for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
259 if (exists_ordered_lsm(lsm))
260 continue;
261 if (strcmp(lsm->name, chosen_major_lsm) == 0)
262 append_ordered_lsm(lsm, "security=");
263 }
264 }
265
266 /* Disable all LSMs not in the ordered list. */
267 for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
268 if (exists_ordered_lsm(lsm))
269 continue;
270 set_enabled(lsm, false);
271 init_debug("%s disabled: %s\n", origin, lsm->name);
272 }
273
Kees Cook13e735c2018-10-09 14:27:46 -0700274 kfree(sep);
Kees Cookf4941d72018-09-13 23:17:50 -0700275}
276
Kees Cook2d4d5112018-09-19 16:58:31 -0700277static void __init ordered_lsm_init(void)
278{
279 struct lsm_info **lsm;
280
281 ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms),
282 GFP_KERNEL);
283
Kees Cook79f78652018-09-19 17:30:09 -0700284 if (chosen_lsm_order)
285 ordered_lsm_parse(chosen_lsm_order, "cmdline");
286 else
287 ordered_lsm_parse(builtin_lsm_order, "builtin");
Kees Cook2d4d5112018-09-19 16:58:31 -0700288
289 for (lsm = ordered_lsms; *lsm; lsm++)
Kees Cookd8e9bbd42018-10-10 15:45:22 -0700290 prepare_lsm(*lsm);
291
Casey Schauflerbbd36622018-11-12 09:30:56 -0800292 init_debug("cred blob size = %d\n", blob_sizes.lbs_cred);
Casey Schaufler33bf60c2018-11-12 12:02:49 -0800293 init_debug("file blob size = %d\n", blob_sizes.lbs_file);
Casey Schauflerafb1cbe32018-09-21 17:19:29 -0700294 init_debug("inode blob size = %d\n", blob_sizes.lbs_inode);
Casey Schaufler33bf60c2018-11-12 12:02:49 -0800295
296 /*
297 * Create any kmem_caches needed for blobs
298 */
299 if (blob_sizes.lbs_file)
300 lsm_file_cache = kmem_cache_create("lsm_file_cache",
301 blob_sizes.lbs_file, 0,
302 SLAB_PANIC, NULL);
Casey Schauflerafb1cbe32018-09-21 17:19:29 -0700303 if (blob_sizes.lbs_inode)
304 lsm_inode_cache = kmem_cache_create("lsm_inode_cache",
305 blob_sizes.lbs_inode, 0,
306 SLAB_PANIC, NULL);
Casey Schauflerbbd36622018-11-12 09:30:56 -0800307
Kees Cookd8e9bbd42018-10-10 15:45:22 -0700308 for (lsm = ordered_lsms; *lsm; lsm++)
309 initialize_lsm(*lsm);
Kees Cook2d4d5112018-09-19 16:58:31 -0700310
311 kfree(ordered_lsms);
312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314/**
315 * security_init - initializes the security framework
316 *
317 * This should be called early in the kernel initialization sequence.
318 */
319int __init security_init(void)
320{
Tetsuo Handa3dfc9b02017-03-22 19:46:19 +0900321 int i;
Sargun Dhillondf0ce172018-03-29 01:28:23 +0000322 struct hlist_head *list = (struct hlist_head *) &security_hook_heads;
Tetsuo Handa3dfc9b02017-03-22 19:46:19 +0900323
Kees Cook98d29172018-10-10 17:18:17 -0700324 pr_info("Security Framework initializing\n");
325
Sargun Dhillondf0ce172018-03-29 01:28:23 +0000326 for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head);
Tetsuo Handa3dfc9b02017-03-22 19:46:19 +0900327 i++)
Sargun Dhillondf0ce172018-03-29 01:28:23 +0000328 INIT_HLIST_HEAD(&list[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Kees Cook657d9102018-09-19 16:16:55 -0700330 /* Load LSMs in specified order. */
331 ordered_lsm_init();
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 return 0;
334}
335
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +0200336/* Save user chosen LSM */
Kees Cook5ef4e412018-09-19 13:11:41 -0700337static int __init choose_major_lsm(char *str)
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +0200338{
Kees Cook5ef4e412018-09-19 13:11:41 -0700339 chosen_major_lsm = str;
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +0200340 return 1;
341}
Kees Cook5ef4e412018-09-19 13:11:41 -0700342__setup("security=", choose_major_lsm);
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +0200343
Kees Cook79f78652018-09-19 17:30:09 -0700344/* Explicitly choose LSM initialization order. */
345static int __init choose_lsm_order(char *str)
346{
347 chosen_lsm_order = str;
348 return 1;
349}
350__setup("lsm=", choose_lsm_order);
351
Kees Cook9b8c7c12018-10-10 17:18:25 -0700352/* Enable LSM order debugging. */
353static int __init enable_debug(char *str)
354{
355 debug = true;
356 return 1;
357}
358__setup("lsm.debug", enable_debug);
359
Mickaël Salaün3bb857e2017-05-10 22:48:48 +0200360static bool match_last_lsm(const char *list, const char *lsm)
361{
362 const char *last;
363
364 if (WARN_ON(!list || !lsm))
365 return false;
366 last = strrchr(list, ',');
367 if (last)
368 /* Pass the comma, strcmp() will check for '\0' */
369 last++;
370 else
371 last = list;
372 return !strcmp(last, lsm);
373}
374
Casey Schauflerd69dece52017-01-18 17:09:05 -0800375static int lsm_append(char *new, char **result)
376{
377 char *cp;
378
379 if (*result == NULL) {
380 *result = kstrdup(new, GFP_KERNEL);
Eric Biggers87ea5842018-07-17 10:36:04 -0700381 if (*result == NULL)
382 return -ENOMEM;
Casey Schauflerd69dece52017-01-18 17:09:05 -0800383 } else {
Mickaël Salaün3bb857e2017-05-10 22:48:48 +0200384 /* Check if it is the last registered name */
385 if (match_last_lsm(*result, new))
386 return 0;
Casey Schauflerd69dece52017-01-18 17:09:05 -0800387 cp = kasprintf(GFP_KERNEL, "%s,%s", *result, new);
388 if (cp == NULL)
389 return -ENOMEM;
390 kfree(*result);
391 *result = cp;
392 }
393 return 0;
394}
395
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +0200396/**
Casey Schauflerd69dece52017-01-18 17:09:05 -0800397 * security_add_hooks - Add a modules hooks to the hook lists.
398 * @hooks: the hooks to add
399 * @count: the number of hooks to add
400 * @lsm: the name of the security module
401 *
402 * Each LSM has to register its hooks with the infrastructure.
403 */
404void __init security_add_hooks(struct security_hook_list *hooks, int count,
405 char *lsm)
406{
407 int i;
408
409 for (i = 0; i < count; i++) {
410 hooks[i].lsm = lsm;
Sargun Dhillondf0ce172018-03-29 01:28:23 +0000411 hlist_add_tail_rcu(&hooks[i].list, hooks[i].head);
Casey Schauflerd69dece52017-01-18 17:09:05 -0800412 }
413 if (lsm_append(lsm, &lsm_names) < 0)
414 panic("%s - Cannot get early memory.\n", __func__);
415}
416
Daniel Jurgens8f408ab2017-05-19 15:48:53 +0300417int call_lsm_notifier(enum lsm_event event, void *data)
418{
419 return atomic_notifier_call_chain(&lsm_notifier_chain, event, data);
420}
421EXPORT_SYMBOL(call_lsm_notifier);
422
423int register_lsm_notifier(struct notifier_block *nb)
424{
425 return atomic_notifier_chain_register(&lsm_notifier_chain, nb);
426}
427EXPORT_SYMBOL(register_lsm_notifier);
428
429int unregister_lsm_notifier(struct notifier_block *nb)
430{
431 return atomic_notifier_chain_unregister(&lsm_notifier_chain, nb);
432}
433EXPORT_SYMBOL(unregister_lsm_notifier);
434
Casey Schauflerbbd36622018-11-12 09:30:56 -0800435/**
436 * lsm_cred_alloc - allocate a composite cred blob
437 * @cred: the cred that needs a blob
438 * @gfp: allocation type
439 *
440 * Allocate the cred blob for all the modules
441 *
442 * Returns 0, or -ENOMEM if memory can't be allocated.
443 */
444static int lsm_cred_alloc(struct cred *cred, gfp_t gfp)
445{
446 if (blob_sizes.lbs_cred == 0) {
447 cred->security = NULL;
448 return 0;
449 }
450
451 cred->security = kzalloc(blob_sizes.lbs_cred, gfp);
452 if (cred->security == NULL)
453 return -ENOMEM;
454 return 0;
455}
456
457/**
458 * lsm_early_cred - during initialization allocate a composite cred blob
459 * @cred: the cred that needs a blob
460 *
461 * Allocate the cred blob for all the modules if it's not already there
462 */
463void __init lsm_early_cred(struct cred *cred)
464{
465 int rc;
466
467 if (cred == NULL)
468 panic("%s: NULL cred.\n", __func__);
469 if (cred->security != NULL)
470 return;
471 rc = lsm_cred_alloc(cred, GFP_KERNEL);
472 if (rc)
473 panic("%s: Early cred alloc failed.\n", __func__);
474}
475
Casey Schaufler33bf60c2018-11-12 12:02:49 -0800476/**
477 * lsm_file_alloc - allocate a composite file blob
478 * @file: the file that needs a blob
479 *
480 * Allocate the file blob for all the modules
481 *
482 * Returns 0, or -ENOMEM if memory can't be allocated.
483 */
484static int lsm_file_alloc(struct file *file)
485{
486 if (!lsm_file_cache) {
487 file->f_security = NULL;
488 return 0;
489 }
490
491 file->f_security = kmem_cache_zalloc(lsm_file_cache, GFP_KERNEL);
492 if (file->f_security == NULL)
493 return -ENOMEM;
494 return 0;
495}
496
Casey Schauflerafb1cbe32018-09-21 17:19:29 -0700497/**
498 * lsm_inode_alloc - allocate a composite inode blob
499 * @inode: the inode that needs a blob
500 *
501 * Allocate the inode blob for all the modules
502 *
503 * Returns 0, or -ENOMEM if memory can't be allocated.
504 */
505int lsm_inode_alloc(struct inode *inode)
506{
507 if (!lsm_inode_cache) {
508 inode->i_security = NULL;
509 return 0;
510 }
511
512 inode->i_security = kmem_cache_zalloc(lsm_inode_cache, GFP_NOFS);
513 if (inode->i_security == NULL)
514 return -ENOMEM;
515 return 0;
516}
517
Casey Schauflerf25fce32015-05-02 15:11:29 -0700518/*
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700519 * Hook list operation macros.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 *
Casey Schauflerf25fce32015-05-02 15:11:29 -0700521 * call_void_hook:
522 * This is a hook that does not return a value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 *
Casey Schauflerf25fce32015-05-02 15:11:29 -0700524 * call_int_hook:
525 * This is a hook that returns a value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700528#define call_void_hook(FUNC, ...) \
529 do { \
530 struct security_hook_list *P; \
531 \
Sargun Dhillondf0ce172018-03-29 01:28:23 +0000532 hlist_for_each_entry(P, &security_hook_heads.FUNC, list) \
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700533 P->hook.FUNC(__VA_ARGS__); \
534 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700536#define call_int_hook(FUNC, IRC, ...) ({ \
537 int RC = IRC; \
538 do { \
539 struct security_hook_list *P; \
540 \
Sargun Dhillondf0ce172018-03-29 01:28:23 +0000541 hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700542 RC = P->hook.FUNC(__VA_ARGS__); \
543 if (RC != 0) \
544 break; \
545 } \
546 } while (0); \
547 RC; \
548})
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
James Morris20510f22007-10-16 23:31:32 -0700550/* Security operations */
551
Stephen Smalley79af7302015-01-21 10:54:10 -0500552int security_binder_set_context_mgr(struct task_struct *mgr)
553{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700554 return call_int_hook(binder_set_context_mgr, 0, mgr);
Stephen Smalley79af7302015-01-21 10:54:10 -0500555}
556
557int security_binder_transaction(struct task_struct *from,
558 struct task_struct *to)
559{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700560 return call_int_hook(binder_transaction, 0, from, to);
Stephen Smalley79af7302015-01-21 10:54:10 -0500561}
562
563int security_binder_transfer_binder(struct task_struct *from,
564 struct task_struct *to)
565{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700566 return call_int_hook(binder_transfer_binder, 0, from, to);
Stephen Smalley79af7302015-01-21 10:54:10 -0500567}
568
569int security_binder_transfer_file(struct task_struct *from,
570 struct task_struct *to, struct file *file)
571{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700572 return call_int_hook(binder_transfer_file, 0, from, to, file);
Stephen Smalley79af7302015-01-21 10:54:10 -0500573}
574
Ingo Molnar9e488582009-05-07 19:26:19 +1000575int security_ptrace_access_check(struct task_struct *child, unsigned int mode)
James Morris20510f22007-10-16 23:31:32 -0700576{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700577 return call_int_hook(ptrace_access_check, 0, child, mode);
David Howells5cd9c582008-08-14 11:37:28 +0100578}
579
580int security_ptrace_traceme(struct task_struct *parent)
581{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700582 return call_int_hook(ptrace_traceme, 0, parent);
James Morris20510f22007-10-16 23:31:32 -0700583}
584
585int security_capget(struct task_struct *target,
586 kernel_cap_t *effective,
587 kernel_cap_t *inheritable,
588 kernel_cap_t *permitted)
589{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700590 return call_int_hook(capget, 0, target,
591 effective, inheritable, permitted);
James Morris20510f22007-10-16 23:31:32 -0700592}
593
David Howellsd84f4f92008-11-14 10:39:23 +1100594int security_capset(struct cred *new, const struct cred *old,
595 const kernel_cap_t *effective,
596 const kernel_cap_t *inheritable,
597 const kernel_cap_t *permitted)
James Morris20510f22007-10-16 23:31:32 -0700598{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700599 return call_int_hook(capset, 0, new, old,
600 effective, inheritable, permitted);
James Morris20510f22007-10-16 23:31:32 -0700601}
602
Eric Parisb7e724d2012-01-03 12:25:15 -0500603int security_capable(const struct cred *cred, struct user_namespace *ns,
Serge E. Hallyn34867402011-03-23 16:43:17 -0700604 int cap)
James Morris20510f22007-10-16 23:31:32 -0700605{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700606 return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_AUDIT);
Eric Paris06112162008-11-11 22:02:50 +1100607}
608
Eric Parisc7eba4a2012-01-03 12:25:15 -0500609int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
610 int cap)
Eric Paris06112162008-11-11 22:02:50 +1100611{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700612 return call_int_hook(capable, 0, cred, ns, cap, SECURITY_CAP_NOAUDIT);
James Morris20510f22007-10-16 23:31:32 -0700613}
614
James Morris20510f22007-10-16 23:31:32 -0700615int security_quotactl(int cmds, int type, int id, struct super_block *sb)
616{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700617 return call_int_hook(quotactl, 0, cmds, type, id, sb);
James Morris20510f22007-10-16 23:31:32 -0700618}
619
620int security_quota_on(struct dentry *dentry)
621{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700622 return call_int_hook(quota_on, 0, dentry);
James Morris20510f22007-10-16 23:31:32 -0700623}
624
Eric Paris12b30522010-11-15 18:36:29 -0500625int security_syslog(int type)
James Morris20510f22007-10-16 23:31:32 -0700626{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700627 return call_int_hook(syslog, 0, type);
James Morris20510f22007-10-16 23:31:32 -0700628}
629
Baolin Wang457db292016-04-08 14:02:11 +0800630int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
James Morris20510f22007-10-16 23:31:32 -0700631{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700632 return call_int_hook(settime, 0, ts, tz);
James Morris20510f22007-10-16 23:31:32 -0700633}
634
James Morris20510f22007-10-16 23:31:32 -0700635int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
636{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700637 struct security_hook_list *hp;
638 int cap_sys_admin = 1;
639 int rc;
640
641 /*
642 * The module will respond with a positive value if
643 * it thinks the __vm_enough_memory() call should be
644 * made with the cap_sys_admin set. If all of the modules
645 * agree that it should be set it will. If any module
646 * thinks it should not be set it won't.
647 */
Sargun Dhillondf0ce172018-03-29 01:28:23 +0000648 hlist_for_each_entry(hp, &security_hook_heads.vm_enough_memory, list) {
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700649 rc = hp->hook.vm_enough_memory(mm, pages);
650 if (rc <= 0) {
651 cap_sys_admin = 0;
652 break;
653 }
654 }
655 return __vm_enough_memory(mm, pages, cap_sys_admin);
James Morris20510f22007-10-16 23:31:32 -0700656}
657
David Howellsa6f76f22008-11-14 10:39:24 +1100658int security_bprm_set_creds(struct linux_binprm *bprm)
James Morris20510f22007-10-16 23:31:32 -0700659{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700660 return call_int_hook(bprm_set_creds, 0, bprm);
James Morris20510f22007-10-16 23:31:32 -0700661}
662
663int security_bprm_check(struct linux_binprm *bprm)
664{
Mimi Zohar6c21a7f2009-10-22 17:30:13 -0400665 int ret;
666
Casey Schauflerf25fce32015-05-02 15:11:29 -0700667 ret = call_int_hook(bprm_check_security, 0, bprm);
Mimi Zohar6c21a7f2009-10-22 17:30:13 -0400668 if (ret)
669 return ret;
670 return ima_bprm_check(bprm);
James Morris20510f22007-10-16 23:31:32 -0700671}
672
David Howellsa6f76f22008-11-14 10:39:24 +1100673void security_bprm_committing_creds(struct linux_binprm *bprm)
674{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700675 call_void_hook(bprm_committing_creds, bprm);
David Howellsa6f76f22008-11-14 10:39:24 +1100676}
677
678void security_bprm_committed_creds(struct linux_binprm *bprm)
679{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700680 call_void_hook(bprm_committed_creds, bprm);
David Howellsa6f76f22008-11-14 10:39:24 +1100681}
682
James Morris20510f22007-10-16 23:31:32 -0700683int security_sb_alloc(struct super_block *sb)
684{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700685 return call_int_hook(sb_alloc_security, 0, sb);
James Morris20510f22007-10-16 23:31:32 -0700686}
687
688void security_sb_free(struct super_block *sb)
689{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700690 call_void_hook(sb_free_security, sb);
James Morris20510f22007-10-16 23:31:32 -0700691}
692
Al Viro204cc0c2018-12-13 13:41:47 -0500693void security_free_mnt_opts(void **mnt_opts)
James Morris20510f22007-10-16 23:31:32 -0700694{
Al Viro204cc0c2018-12-13 13:41:47 -0500695 if (!*mnt_opts)
696 return;
697 call_void_hook(sb_free_mnt_opts, *mnt_opts);
698 *mnt_opts = NULL;
James Morris20510f22007-10-16 23:31:32 -0700699}
Al Viro204cc0c2018-12-13 13:41:47 -0500700EXPORT_SYMBOL(security_free_mnt_opts);
James Morris20510f22007-10-16 23:31:32 -0700701
Al Viro204cc0c2018-12-13 13:41:47 -0500702int security_sb_eat_lsm_opts(char *options, void **mnt_opts)
Eric Parisff36fe22011-03-03 16:09:14 -0500703{
Al Viro204cc0c2018-12-13 13:41:47 -0500704 return call_int_hook(sb_eat_lsm_opts, 0, options, mnt_opts);
Eric Parisff36fe22011-03-03 16:09:14 -0500705}
Al Virof5c0c262018-11-17 12:09:18 -0500706EXPORT_SYMBOL(security_sb_eat_lsm_opts);
Eric Parisff36fe22011-03-03 16:09:14 -0500707
Al Viroc039bc32018-12-01 23:06:57 -0500708int security_sb_remount(struct super_block *sb,
Al Viro204cc0c2018-12-13 13:41:47 -0500709 void *mnt_opts)
James Morris20510f22007-10-16 23:31:32 -0700710{
Al Viro204cc0c2018-12-13 13:41:47 -0500711 return call_int_hook(sb_remount, 0, sb, mnt_opts);
James Morris20510f22007-10-16 23:31:32 -0700712}
Al Viroa65001e2018-12-10 17:19:21 -0500713EXPORT_SYMBOL(security_sb_remount);
James Morris20510f22007-10-16 23:31:32 -0700714
Al Viroa10d7c22018-12-05 11:58:35 -0500715int security_sb_kern_mount(struct super_block *sb)
James Morris20510f22007-10-16 23:31:32 -0700716{
Al Viroa10d7c22018-12-05 11:58:35 -0500717 return call_int_hook(sb_kern_mount, 0, sb);
James Morris20510f22007-10-16 23:31:32 -0700718}
719
Eric Paris2069f452008-07-04 09:47:13 +1000720int security_sb_show_options(struct seq_file *m, struct super_block *sb)
721{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700722 return call_int_hook(sb_show_options, 0, m, sb);
Eric Paris2069f452008-07-04 09:47:13 +1000723}
724
James Morris20510f22007-10-16 23:31:32 -0700725int security_sb_statfs(struct dentry *dentry)
726{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700727 return call_int_hook(sb_statfs, 0, dentry);
James Morris20510f22007-10-16 23:31:32 -0700728}
729
Al Viro8a04c432016-03-25 14:52:53 -0400730int security_sb_mount(const char *dev_name, const struct path *path,
Al Viro808d4e32012-10-11 11:42:01 -0400731 const char *type, unsigned long flags, void *data)
James Morris20510f22007-10-16 23:31:32 -0700732{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700733 return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data);
James Morris20510f22007-10-16 23:31:32 -0700734}
735
James Morris20510f22007-10-16 23:31:32 -0700736int security_sb_umount(struct vfsmount *mnt, int flags)
737{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700738 return call_int_hook(sb_umount, 0, mnt, flags);
James Morris20510f22007-10-16 23:31:32 -0700739}
740
Al Viro3b73b682016-03-25 15:31:19 -0400741int security_sb_pivotroot(const struct path *old_path, const struct path *new_path)
James Morris20510f22007-10-16 23:31:32 -0700742{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700743 return call_int_hook(sb_pivotroot, 0, old_path, new_path);
James Morris20510f22007-10-16 23:31:32 -0700744}
745
Eric Parisc9180a52007-11-30 13:00:35 -0500746int security_sb_set_mnt_opts(struct super_block *sb,
Al Viro204cc0c2018-12-13 13:41:47 -0500747 void *mnt_opts,
David Quigley649f6e72013-05-22 12:50:36 -0400748 unsigned long kern_flags,
749 unsigned long *set_kern_flags)
Eric Parisc9180a52007-11-30 13:00:35 -0500750{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700751 return call_int_hook(sb_set_mnt_opts,
Al Viro204cc0c2018-12-13 13:41:47 -0500752 mnt_opts ? -EOPNOTSUPP : 0, sb,
753 mnt_opts, kern_flags, set_kern_flags);
Eric Parisc9180a52007-11-30 13:00:35 -0500754}
Eric Parise0007522008-03-05 10:31:54 -0500755EXPORT_SYMBOL(security_sb_set_mnt_opts);
Eric Parisc9180a52007-11-30 13:00:35 -0500756
Jeff Layton094f7b62013-04-01 08:14:24 -0400757int security_sb_clone_mnt_opts(const struct super_block *oldsb,
Scott Mayhew0b4d3452017-06-05 11:45:04 -0400758 struct super_block *newsb,
759 unsigned long kern_flags,
760 unsigned long *set_kern_flags)
Eric Parisc9180a52007-11-30 13:00:35 -0500761{
Scott Mayhew0b4d3452017-06-05 11:45:04 -0400762 return call_int_hook(sb_clone_mnt_opts, 0, oldsb, newsb,
763 kern_flags, set_kern_flags);
Eric Parisc9180a52007-11-30 13:00:35 -0500764}
Eric Parise0007522008-03-05 10:31:54 -0500765EXPORT_SYMBOL(security_sb_clone_mnt_opts);
766
Al Viro757cbe52018-12-14 23:42:21 -0500767int security_add_mnt_opt(const char *option, const char *val, int len,
768 void **mnt_opts)
Eric Parise0007522008-03-05 10:31:54 -0500769{
Al Viro757cbe52018-12-14 23:42:21 -0500770 return call_int_hook(sb_add_mnt_opt, -EINVAL,
771 option, val, len, mnt_opts);
Eric Parise0007522008-03-05 10:31:54 -0500772}
Al Viro757cbe52018-12-14 23:42:21 -0500773EXPORT_SYMBOL(security_add_mnt_opt);
Eric Parisc9180a52007-11-30 13:00:35 -0500774
James Morris20510f22007-10-16 23:31:32 -0700775int security_inode_alloc(struct inode *inode)
776{
Casey Schauflerafb1cbe32018-09-21 17:19:29 -0700777 int rc = lsm_inode_alloc(inode);
778
779 if (unlikely(rc))
780 return rc;
781 rc = call_int_hook(inode_alloc_security, 0, inode);
782 if (unlikely(rc))
783 security_inode_free(inode);
784 return rc;
785}
786
787static void inode_free_by_rcu(struct rcu_head *head)
788{
789 /*
790 * The rcu head is at the start of the inode blob
791 */
792 kmem_cache_free(lsm_inode_cache, head);
James Morris20510f22007-10-16 23:31:32 -0700793}
794
795void security_inode_free(struct inode *inode)
796{
Mimi Zoharf381c272011-03-09 14:13:22 -0500797 integrity_inode_free(inode);
Casey Schauflerf25fce32015-05-02 15:11:29 -0700798 call_void_hook(inode_free_security, inode);
Casey Schauflerafb1cbe32018-09-21 17:19:29 -0700799 /*
800 * The inode may still be referenced in a path walk and
801 * a call to security_inode_permission() can be made
802 * after inode_free_security() is called. Ideally, the VFS
803 * wouldn't do this, but fixing that is a much harder
804 * job. For now, simply free the i_security via RCU, and
805 * leave the current inode->i_security pointer intact.
806 * The inode will be freed after the RCU grace period too.
807 */
808 if (inode->i_security)
809 call_rcu((struct rcu_head *)inode->i_security,
810 inode_free_by_rcu);
James Morris20510f22007-10-16 23:31:32 -0700811}
812
David Quigleyd47be3d2013-05-22 12:50:34 -0400813int security_dentry_init_security(struct dentry *dentry, int mode,
Al Viro4f3ccd72016-07-20 16:06:15 -0400814 const struct qstr *name, void **ctx,
David Quigleyd47be3d2013-05-22 12:50:34 -0400815 u32 *ctxlen)
816{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700817 return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode,
818 name, ctx, ctxlen);
David Quigleyd47be3d2013-05-22 12:50:34 -0400819}
820EXPORT_SYMBOL(security_dentry_init_security);
821
Vivek Goyal26026252016-07-13 10:44:52 -0400822int security_dentry_create_files_as(struct dentry *dentry, int mode,
823 struct qstr *name,
824 const struct cred *old, struct cred *new)
825{
826 return call_int_hook(dentry_create_files_as, 0, dentry, mode,
827 name, old, new);
828}
829EXPORT_SYMBOL(security_dentry_create_files_as);
830
James Morris20510f22007-10-16 23:31:32 -0700831int security_inode_init_security(struct inode *inode, struct inode *dir,
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400832 const struct qstr *qstr,
833 const initxattrs initxattrs, void *fs_data)
834{
Mimi Zohar823eb1c2011-06-15 21:19:10 -0400835 struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
836 struct xattr *lsm_xattr, *evm_xattr, *xattr;
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400837 int ret;
838
839 if (unlikely(IS_PRIVATE(inode)))
Mimi Zoharfb88c2b2011-08-15 10:13:18 -0400840 return 0;
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400841
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400842 if (!initxattrs)
Jan Beuliche308fd32015-08-24 06:22:25 -0600843 return call_int_hook(inode_init_security, -EOPNOTSUPP, inode,
844 dir, qstr, NULL, NULL, NULL);
Tetsuo Handa95489062013-07-25 05:44:02 +0900845 memset(new_xattrs, 0, sizeof(new_xattrs));
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400846 lsm_xattr = new_xattrs;
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -0700847 ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr,
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400848 &lsm_xattr->name,
849 &lsm_xattr->value,
850 &lsm_xattr->value_len);
851 if (ret)
852 goto out;
Mimi Zohar823eb1c2011-06-15 21:19:10 -0400853
854 evm_xattr = lsm_xattr + 1;
855 ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
856 if (ret)
857 goto out;
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400858 ret = initxattrs(inode, new_xattrs, fs_data);
859out:
Tetsuo Handa95489062013-07-25 05:44:02 +0900860 for (xattr = new_xattrs; xattr->value != NULL; xattr++)
Mimi Zohar823eb1c2011-06-15 21:19:10 -0400861 kfree(xattr->value);
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400862 return (ret == -EOPNOTSUPP) ? 0 : ret;
863}
864EXPORT_SYMBOL(security_inode_init_security);
865
866int security_old_inode_init_security(struct inode *inode, struct inode *dir,
Tetsuo Handa95489062013-07-25 05:44:02 +0900867 const struct qstr *qstr, const char **name,
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400868 void **value, size_t *len)
James Morris20510f22007-10-16 23:31:32 -0700869{
870 if (unlikely(IS_PRIVATE(inode)))
Jan Kara30e05322012-01-03 13:14:29 +0100871 return -EOPNOTSUPP;
Jan Beuliche308fd32015-08-24 06:22:25 -0600872 return call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir,
873 qstr, name, value, len);
James Morris20510f22007-10-16 23:31:32 -0700874}
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400875EXPORT_SYMBOL(security_old_inode_init_security);
James Morris20510f22007-10-16 23:31:32 -0700876
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900877#ifdef CONFIG_SECURITY_PATH
Al Virod3607752016-03-25 15:21:09 -0400878int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode,
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900879 unsigned int dev)
880{
David Howellsc6f493d2015-03-17 22:26:22 +0000881 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900882 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700883 return call_int_hook(path_mknod, 0, dir, dentry, mode, dev);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900884}
885EXPORT_SYMBOL(security_path_mknod);
886
Al Virod3607752016-03-25 15:21:09 -0400887int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900888{
David Howellsc6f493d2015-03-17 22:26:22 +0000889 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900890 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700891 return call_int_hook(path_mkdir, 0, dir, dentry, mode);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900892}
David Howells82140442010-12-24 14:48:35 +0000893EXPORT_SYMBOL(security_path_mkdir);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900894
Al Viro989f74e2016-03-25 15:13:39 -0400895int security_path_rmdir(const struct path *dir, struct dentry *dentry)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900896{
David Howellsc6f493d2015-03-17 22:26:22 +0000897 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900898 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700899 return call_int_hook(path_rmdir, 0, dir, dentry);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900900}
901
Al Viro989f74e2016-03-25 15:13:39 -0400902int security_path_unlink(const struct path *dir, struct dentry *dentry)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900903{
David Howellsc6f493d2015-03-17 22:26:22 +0000904 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900905 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700906 return call_int_hook(path_unlink, 0, dir, dentry);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900907}
David Howells82140442010-12-24 14:48:35 +0000908EXPORT_SYMBOL(security_path_unlink);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900909
Al Virod3607752016-03-25 15:21:09 -0400910int security_path_symlink(const struct path *dir, struct dentry *dentry,
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900911 const char *old_name)
912{
David Howellsc6f493d2015-03-17 22:26:22 +0000913 if (unlikely(IS_PRIVATE(d_backing_inode(dir->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900914 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700915 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900916}
917
Al Viro3ccee462016-03-25 15:27:45 -0400918int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900919 struct dentry *new_dentry)
920{
David Howellsc6f493d2015-03-17 22:26:22 +0000921 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900922 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700923 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900924}
925
Al Viro3ccee462016-03-25 15:27:45 -0400926int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
927 const struct path *new_dir, struct dentry *new_dentry,
Miklos Szeredi0b3974e2014-04-01 17:08:43 +0200928 unsigned int flags)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900929{
David Howellsc6f493d2015-03-17 22:26:22 +0000930 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
931 (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900932 return 0;
Miklos Szeredida1ce062014-04-01 17:08:43 +0200933
934 if (flags & RENAME_EXCHANGE) {
Casey Schauflerf25fce32015-05-02 15:11:29 -0700935 int err = call_int_hook(path_rename, 0, new_dir, new_dentry,
936 old_dir, old_dentry);
Miklos Szeredida1ce062014-04-01 17:08:43 +0200937 if (err)
938 return err;
939 }
940
Casey Schauflerf25fce32015-05-02 15:11:29 -0700941 return call_int_hook(path_rename, 0, old_dir, old_dentry, new_dir,
942 new_dentry);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900943}
David Howells82140442010-12-24 14:48:35 +0000944EXPORT_SYMBOL(security_path_rename);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900945
Al Viro81f4c502016-03-25 14:22:01 -0400946int security_path_truncate(const struct path *path)
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900947{
David Howellsc6f493d2015-03-17 22:26:22 +0000948 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900949 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700950 return call_int_hook(path_truncate, 0, path);
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900951}
Tetsuo Handa89eda062009-10-04 21:49:47 +0900952
Al Virobe01f9f2016-03-25 14:56:23 -0400953int security_path_chmod(const struct path *path, umode_t mode)
Tetsuo Handa89eda062009-10-04 21:49:47 +0900954{
David Howellsc6f493d2015-03-17 22:26:22 +0000955 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
Tetsuo Handa89eda062009-10-04 21:49:47 +0900956 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700957 return call_int_hook(path_chmod, 0, path, mode);
Tetsuo Handa89eda062009-10-04 21:49:47 +0900958}
959
Al Viro7fd25da2016-03-25 14:44:41 -0400960int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
Tetsuo Handa89eda062009-10-04 21:49:47 +0900961{
David Howellsc6f493d2015-03-17 22:26:22 +0000962 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
Tetsuo Handa89eda062009-10-04 21:49:47 +0900963 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700964 return call_int_hook(path_chown, 0, path, uid, gid);
Tetsuo Handa89eda062009-10-04 21:49:47 +0900965}
Tetsuo Handa8b8efb42009-10-04 21:49:48 +0900966
Al Viro77b286c2016-03-25 15:28:43 -0400967int security_path_chroot(const struct path *path)
Tetsuo Handa8b8efb42009-10-04 21:49:48 +0900968{
Casey Schauflerf25fce32015-05-02 15:11:29 -0700969 return call_int_hook(path_chroot, 0, path);
Tetsuo Handa8b8efb42009-10-04 21:49:48 +0900970}
Kentaro Takedabe6d3e52008-12-17 13:24:15 +0900971#endif
972
Al Viro4acdaf22011-07-26 01:42:34 -0400973int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode)
James Morris20510f22007-10-16 23:31:32 -0700974{
975 if (unlikely(IS_PRIVATE(dir)))
976 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700977 return call_int_hook(inode_create, 0, dir, dentry, mode);
James Morris20510f22007-10-16 23:31:32 -0700978}
David Howells800a9642009-04-03 16:42:40 +0100979EXPORT_SYMBOL_GPL(security_inode_create);
James Morris20510f22007-10-16 23:31:32 -0700980
981int security_inode_link(struct dentry *old_dentry, struct inode *dir,
982 struct dentry *new_dentry)
983{
David Howellsc6f493d2015-03-17 22:26:22 +0000984 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry))))
James Morris20510f22007-10-16 23:31:32 -0700985 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700986 return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry);
James Morris20510f22007-10-16 23:31:32 -0700987}
988
989int security_inode_unlink(struct inode *dir, struct dentry *dentry)
990{
David Howellsc6f493d2015-03-17 22:26:22 +0000991 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -0700992 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -0700993 return call_int_hook(inode_unlink, 0, dir, dentry);
James Morris20510f22007-10-16 23:31:32 -0700994}
995
996int security_inode_symlink(struct inode *dir, struct dentry *dentry,
997 const char *old_name)
998{
999 if (unlikely(IS_PRIVATE(dir)))
1000 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001001 return call_int_hook(inode_symlink, 0, dir, dentry, old_name);
James Morris20510f22007-10-16 23:31:32 -07001002}
1003
Al Viro18bb1db2011-07-26 01:41:39 -04001004int security_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
James Morris20510f22007-10-16 23:31:32 -07001005{
1006 if (unlikely(IS_PRIVATE(dir)))
1007 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001008 return call_int_hook(inode_mkdir, 0, dir, dentry, mode);
James Morris20510f22007-10-16 23:31:32 -07001009}
David Howells800a9642009-04-03 16:42:40 +01001010EXPORT_SYMBOL_GPL(security_inode_mkdir);
James Morris20510f22007-10-16 23:31:32 -07001011
1012int security_inode_rmdir(struct inode *dir, struct dentry *dentry)
1013{
David Howellsc6f493d2015-03-17 22:26:22 +00001014 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -07001015 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001016 return call_int_hook(inode_rmdir, 0, dir, dentry);
James Morris20510f22007-10-16 23:31:32 -07001017}
1018
Al Viro1a67aaf2011-07-26 01:52:52 -04001019int security_inode_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
James Morris20510f22007-10-16 23:31:32 -07001020{
1021 if (unlikely(IS_PRIVATE(dir)))
1022 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001023 return call_int_hook(inode_mknod, 0, dir, dentry, mode, dev);
James Morris20510f22007-10-16 23:31:32 -07001024}
1025
1026int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
Miklos Szeredi0b3974e2014-04-01 17:08:43 +02001027 struct inode *new_dir, struct dentry *new_dentry,
1028 unsigned int flags)
James Morris20510f22007-10-16 23:31:32 -07001029{
David Howellsc6f493d2015-03-17 22:26:22 +00001030 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)) ||
1031 (d_is_positive(new_dentry) && IS_PRIVATE(d_backing_inode(new_dentry)))))
James Morris20510f22007-10-16 23:31:32 -07001032 return 0;
Miklos Szeredida1ce062014-04-01 17:08:43 +02001033
1034 if (flags & RENAME_EXCHANGE) {
Casey Schauflerf25fce32015-05-02 15:11:29 -07001035 int err = call_int_hook(inode_rename, 0, new_dir, new_dentry,
Miklos Szeredida1ce062014-04-01 17:08:43 +02001036 old_dir, old_dentry);
1037 if (err)
1038 return err;
1039 }
1040
Casey Schauflerf25fce32015-05-02 15:11:29 -07001041 return call_int_hook(inode_rename, 0, old_dir, old_dentry,
James Morris20510f22007-10-16 23:31:32 -07001042 new_dir, new_dentry);
1043}
1044
1045int security_inode_readlink(struct dentry *dentry)
1046{
David Howellsc6f493d2015-03-17 22:26:22 +00001047 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -07001048 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001049 return call_int_hook(inode_readlink, 0, dentry);
James Morris20510f22007-10-16 23:31:32 -07001050}
1051
NeilBrownbda0be72015-03-23 13:37:39 +11001052int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1053 bool rcu)
James Morris20510f22007-10-16 23:31:32 -07001054{
NeilBrownbda0be72015-03-23 13:37:39 +11001055 if (unlikely(IS_PRIVATE(inode)))
James Morris20510f22007-10-16 23:31:32 -07001056 return 0;
Linus Torvaldse22619a2015-06-27 13:26:03 -07001057 return call_int_hook(inode_follow_link, 0, dentry, inode, rcu);
James Morris20510f22007-10-16 23:31:32 -07001058}
1059
Al Virob77b0642008-07-17 09:37:02 -04001060int security_inode_permission(struct inode *inode, int mask)
James Morris20510f22007-10-16 23:31:32 -07001061{
1062 if (unlikely(IS_PRIVATE(inode)))
1063 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001064 return call_int_hook(inode_permission, 0, inode, mask);
James Morris20510f22007-10-16 23:31:32 -07001065}
1066
1067int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1068{
Mimi Zohar817b54a2011-05-13 12:53:38 -04001069 int ret;
1070
David Howellsc6f493d2015-03-17 22:26:22 +00001071 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -07001072 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001073 ret = call_int_hook(inode_setattr, 0, dentry, attr);
Mimi Zohar817b54a2011-05-13 12:53:38 -04001074 if (ret)
1075 return ret;
1076 return evm_inode_setattr(dentry, attr);
James Morris20510f22007-10-16 23:31:32 -07001077}
Miklos Szeredib1da47e2008-07-01 15:01:28 +02001078EXPORT_SYMBOL_GPL(security_inode_setattr);
James Morris20510f22007-10-16 23:31:32 -07001079
Al Viro3f7036a2015-03-08 19:28:30 -04001080int security_inode_getattr(const struct path *path)
James Morris20510f22007-10-16 23:31:32 -07001081{
David Howellsc6f493d2015-03-17 22:26:22 +00001082 if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
James Morris20510f22007-10-16 23:31:32 -07001083 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001084 return call_int_hook(inode_getattr, 0, path);
James Morris20510f22007-10-16 23:31:32 -07001085}
1086
David Howells8f0cfa52008-04-29 00:59:41 -07001087int security_inode_setxattr(struct dentry *dentry, const char *name,
1088 const void *value, size_t size, int flags)
James Morris20510f22007-10-16 23:31:32 -07001089{
Mimi Zohar3e1be522011-03-09 14:38:26 -05001090 int ret;
1091
David Howellsc6f493d2015-03-17 22:26:22 +00001092 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -07001093 return 0;
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001094 /*
1095 * SELinux and Smack integrate the cap call,
1096 * so assume that all LSMs supplying this call do so.
1097 */
1098 ret = call_int_hook(inode_setxattr, 1, dentry, name, value, size,
Casey Schauflerf25fce32015-05-02 15:11:29 -07001099 flags);
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001100
1101 if (ret == 1)
1102 ret = cap_inode_setxattr(dentry, name, value, size, flags);
Mimi Zohar3e1be522011-03-09 14:38:26 -05001103 if (ret)
1104 return ret;
Mimi Zohar42c63332011-03-10 18:54:15 -05001105 ret = ima_inode_setxattr(dentry, name, value, size);
1106 if (ret)
1107 return ret;
Mimi Zohar3e1be522011-03-09 14:38:26 -05001108 return evm_inode_setxattr(dentry, name, value, size);
James Morris20510f22007-10-16 23:31:32 -07001109}
1110
David Howells8f0cfa52008-04-29 00:59:41 -07001111void security_inode_post_setxattr(struct dentry *dentry, const char *name,
1112 const void *value, size_t size, int flags)
James Morris20510f22007-10-16 23:31:32 -07001113{
David Howellsc6f493d2015-03-17 22:26:22 +00001114 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -07001115 return;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001116 call_void_hook(inode_post_setxattr, dentry, name, value, size, flags);
Mimi Zohar3e1be522011-03-09 14:38:26 -05001117 evm_inode_post_setxattr(dentry, name, value, size);
James Morris20510f22007-10-16 23:31:32 -07001118}
1119
David Howells8f0cfa52008-04-29 00:59:41 -07001120int security_inode_getxattr(struct dentry *dentry, const char *name)
James Morris20510f22007-10-16 23:31:32 -07001121{
David Howellsc6f493d2015-03-17 22:26:22 +00001122 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -07001123 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001124 return call_int_hook(inode_getxattr, 0, dentry, name);
James Morris20510f22007-10-16 23:31:32 -07001125}
1126
1127int security_inode_listxattr(struct dentry *dentry)
1128{
David Howellsc6f493d2015-03-17 22:26:22 +00001129 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -07001130 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001131 return call_int_hook(inode_listxattr, 0, dentry);
James Morris20510f22007-10-16 23:31:32 -07001132}
1133
David Howells8f0cfa52008-04-29 00:59:41 -07001134int security_inode_removexattr(struct dentry *dentry, const char *name)
James Morris20510f22007-10-16 23:31:32 -07001135{
Mimi Zohar3e1be522011-03-09 14:38:26 -05001136 int ret;
1137
David Howellsc6f493d2015-03-17 22:26:22 +00001138 if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
James Morris20510f22007-10-16 23:31:32 -07001139 return 0;
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001140 /*
1141 * SELinux and Smack integrate the cap call,
1142 * so assume that all LSMs supplying this call do so.
1143 */
1144 ret = call_int_hook(inode_removexattr, 1, dentry, name);
1145 if (ret == 1)
1146 ret = cap_inode_removexattr(dentry, name);
Mimi Zohar3e1be522011-03-09 14:38:26 -05001147 if (ret)
1148 return ret;
Mimi Zohar42c63332011-03-10 18:54:15 -05001149 ret = ima_inode_removexattr(dentry, name);
1150 if (ret)
1151 return ret;
Mimi Zohar3e1be522011-03-09 14:38:26 -05001152 return evm_inode_removexattr(dentry, name);
James Morris20510f22007-10-16 23:31:32 -07001153}
1154
Serge E. Hallynb5376772007-10-16 23:31:36 -07001155int security_inode_need_killpriv(struct dentry *dentry)
1156{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001157 return call_int_hook(inode_need_killpriv, 0, dentry);
Serge E. Hallynb5376772007-10-16 23:31:36 -07001158}
1159
1160int security_inode_killpriv(struct dentry *dentry)
1161{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001162 return call_int_hook(inode_killpriv, 0, dentry);
Serge E. Hallynb5376772007-10-16 23:31:36 -07001163}
1164
Andreas Gruenbacherea861df2015-12-24 11:09:39 -05001165int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
James Morris20510f22007-10-16 23:31:32 -07001166{
Casey Schaufler2885c1e2016-05-31 17:24:15 -07001167 struct security_hook_list *hp;
1168 int rc;
1169
James Morris20510f22007-10-16 23:31:32 -07001170 if (unlikely(IS_PRIVATE(inode)))
James Morris8d952502010-01-14 09:33:28 +11001171 return -EOPNOTSUPP;
Casey Schaufler2885c1e2016-05-31 17:24:15 -07001172 /*
1173 * Only one module will provide an attribute with a given name.
1174 */
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001175 hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) {
Casey Schaufler2885c1e2016-05-31 17:24:15 -07001176 rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc);
1177 if (rc != -EOPNOTSUPP)
1178 return rc;
1179 }
1180 return -EOPNOTSUPP;
James Morris20510f22007-10-16 23:31:32 -07001181}
1182
1183int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
1184{
Casey Schaufler2885c1e2016-05-31 17:24:15 -07001185 struct security_hook_list *hp;
1186 int rc;
1187
James Morris20510f22007-10-16 23:31:32 -07001188 if (unlikely(IS_PRIVATE(inode)))
James Morris8d952502010-01-14 09:33:28 +11001189 return -EOPNOTSUPP;
Casey Schaufler2885c1e2016-05-31 17:24:15 -07001190 /*
1191 * Only one module will provide an attribute with a given name.
1192 */
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001193 hlist_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) {
Casey Schaufler2885c1e2016-05-31 17:24:15 -07001194 rc = hp->hook.inode_setsecurity(inode, name, value, size,
1195 flags);
1196 if (rc != -EOPNOTSUPP)
1197 return rc;
1198 }
1199 return -EOPNOTSUPP;
James Morris20510f22007-10-16 23:31:32 -07001200}
1201
1202int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
1203{
1204 if (unlikely(IS_PRIVATE(inode)))
1205 return 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001206 return call_int_hook(inode_listsecurity, 0, inode, buffer, buffer_size);
James Morris20510f22007-10-16 23:31:32 -07001207}
David Quigleyc9bccef2013-05-22 12:50:45 -04001208EXPORT_SYMBOL(security_inode_listsecurity);
James Morris20510f22007-10-16 23:31:32 -07001209
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -05001210void security_inode_getsecid(struct inode *inode, u32 *secid)
Ahmed S. Darwish8a076192008-03-01 21:51:09 +02001211{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001212 call_void_hook(inode_getsecid, inode, secid);
Ahmed S. Darwish8a076192008-03-01 21:51:09 +02001213}
1214
Vivek Goyald8ad8b42016-07-13 11:13:56 -04001215int security_inode_copy_up(struct dentry *src, struct cred **new)
1216{
1217 return call_int_hook(inode_copy_up, 0, src, new);
1218}
1219EXPORT_SYMBOL(security_inode_copy_up);
1220
Vivek Goyal121ab822016-07-13 10:44:49 -04001221int security_inode_copy_up_xattr(const char *name)
1222{
1223 return call_int_hook(inode_copy_up_xattr, -EOPNOTSUPP, name);
1224}
1225EXPORT_SYMBOL(security_inode_copy_up_xattr);
1226
James Morris20510f22007-10-16 23:31:32 -07001227int security_file_permission(struct file *file, int mask)
1228{
Eric Parisc4ec54b2009-12-17 21:24:34 -05001229 int ret;
1230
Casey Schauflerf25fce32015-05-02 15:11:29 -07001231 ret = call_int_hook(file_permission, 0, file, mask);
Eric Parisc4ec54b2009-12-17 21:24:34 -05001232 if (ret)
1233 return ret;
1234
1235 return fsnotify_perm(file, mask);
James Morris20510f22007-10-16 23:31:32 -07001236}
1237
1238int security_file_alloc(struct file *file)
1239{
Casey Schaufler33bf60c2018-11-12 12:02:49 -08001240 int rc = lsm_file_alloc(file);
1241
1242 if (rc)
1243 return rc;
1244 rc = call_int_hook(file_alloc_security, 0, file);
1245 if (unlikely(rc))
1246 security_file_free(file);
1247 return rc;
James Morris20510f22007-10-16 23:31:32 -07001248}
1249
1250void security_file_free(struct file *file)
1251{
Casey Schaufler33bf60c2018-11-12 12:02:49 -08001252 void *blob;
1253
Casey Schauflerf25fce32015-05-02 15:11:29 -07001254 call_void_hook(file_free_security, file);
Casey Schaufler33bf60c2018-11-12 12:02:49 -08001255
1256 blob = file->f_security;
1257 if (blob) {
1258 file->f_security = NULL;
1259 kmem_cache_free(lsm_file_cache, blob);
1260 }
James Morris20510f22007-10-16 23:31:32 -07001261}
1262
1263int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1264{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001265 return call_int_hook(file_ioctl, 0, file, cmd, arg);
James Morris20510f22007-10-16 23:31:32 -07001266}
1267
Al Viro98de59b2012-05-30 19:58:30 -04001268static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
James Morris20510f22007-10-16 23:31:32 -07001269{
Al Viro8b3ec682012-05-30 17:11:23 -04001270 /*
Al Viro98de59b2012-05-30 19:58:30 -04001271 * Does we have PROT_READ and does the application expect
1272 * it to imply PROT_EXEC? If not, nothing to talk about...
Al Viro8b3ec682012-05-30 17:11:23 -04001273 */
Al Viro98de59b2012-05-30 19:58:30 -04001274 if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
1275 return prot;
Al Viro8b3ec682012-05-30 17:11:23 -04001276 if (!(current->personality & READ_IMPLIES_EXEC))
Al Viro98de59b2012-05-30 19:58:30 -04001277 return prot;
1278 /*
1279 * if that's an anonymous mapping, let it.
1280 */
1281 if (!file)
1282 return prot | PROT_EXEC;
1283 /*
1284 * ditto if it's not on noexec mount, except that on !MMU we need
Christoph Hellwigb4caecd2015-01-14 10:42:32 +01001285 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
Al Viro98de59b2012-05-30 19:58:30 -04001286 */
Eric W. Biederman90f85722015-06-29 14:42:03 -05001287 if (!path_noexec(&file->f_path)) {
Al Viro8b3ec682012-05-30 17:11:23 -04001288#ifndef CONFIG_MMU
Christoph Hellwigb4caecd2015-01-14 10:42:32 +01001289 if (file->f_op->mmap_capabilities) {
1290 unsigned caps = file->f_op->mmap_capabilities(file);
1291 if (!(caps & NOMMU_MAP_EXEC))
1292 return prot;
1293 }
Al Viro8b3ec682012-05-30 17:11:23 -04001294#endif
Al Viro98de59b2012-05-30 19:58:30 -04001295 return prot | PROT_EXEC;
Al Viro8b3ec682012-05-30 17:11:23 -04001296 }
Al Viro98de59b2012-05-30 19:58:30 -04001297 /* anything on noexec mount won't get PROT_EXEC */
1298 return prot;
1299}
1300
1301int security_mmap_file(struct file *file, unsigned long prot,
1302 unsigned long flags)
1303{
1304 int ret;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001305 ret = call_int_hook(mmap_file, 0, file, prot,
Al Viro98de59b2012-05-30 19:58:30 -04001306 mmap_prot(file, prot), flags);
Mimi Zohar6c21a7f2009-10-22 17:30:13 -04001307 if (ret)
1308 return ret;
1309 return ima_file_mmap(file, prot);
James Morris20510f22007-10-16 23:31:32 -07001310}
1311
Al Viroe5467852012-05-30 13:30:51 -04001312int security_mmap_addr(unsigned long addr)
1313{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001314 return call_int_hook(mmap_addr, 0, addr);
Al Viroe5467852012-05-30 13:30:51 -04001315}
1316
James Morris20510f22007-10-16 23:31:32 -07001317int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
1318 unsigned long prot)
1319{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001320 return call_int_hook(file_mprotect, 0, vma, reqprot, prot);
James Morris20510f22007-10-16 23:31:32 -07001321}
1322
1323int security_file_lock(struct file *file, unsigned int cmd)
1324{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001325 return call_int_hook(file_lock, 0, file, cmd);
James Morris20510f22007-10-16 23:31:32 -07001326}
1327
1328int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
1329{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001330 return call_int_hook(file_fcntl, 0, file, cmd, arg);
James Morris20510f22007-10-16 23:31:32 -07001331}
1332
Jeff Laytone0b93ed2014-08-22 11:27:32 -04001333void security_file_set_fowner(struct file *file)
James Morris20510f22007-10-16 23:31:32 -07001334{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001335 call_void_hook(file_set_fowner, file);
James Morris20510f22007-10-16 23:31:32 -07001336}
1337
1338int security_file_send_sigiotask(struct task_struct *tsk,
1339 struct fown_struct *fown, int sig)
1340{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001341 return call_int_hook(file_send_sigiotask, 0, tsk, fown, sig);
James Morris20510f22007-10-16 23:31:32 -07001342}
1343
1344int security_file_receive(struct file *file)
1345{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001346 return call_int_hook(file_receive, 0, file);
James Morris20510f22007-10-16 23:31:32 -07001347}
1348
Al Viroe3f20ae2018-07-10 13:25:29 -04001349int security_file_open(struct file *file)
James Morris20510f22007-10-16 23:31:32 -07001350{
Eric Parisc4ec54b2009-12-17 21:24:34 -05001351 int ret;
1352
Al Viro94817692018-07-10 14:13:18 -04001353 ret = call_int_hook(file_open, 0, file);
Eric Parisc4ec54b2009-12-17 21:24:34 -05001354 if (ret)
1355 return ret;
1356
1357 return fsnotify_perm(file, MAY_OPEN);
James Morris20510f22007-10-16 23:31:32 -07001358}
1359
Tetsuo Handae4e55b42017-03-24 20:46:33 +09001360int security_task_alloc(struct task_struct *task, unsigned long clone_flags)
1361{
1362 return call_int_hook(task_alloc, 0, task, clone_flags);
1363}
1364
Kees Cook1a2a4d02011-12-21 12:17:03 -08001365void security_task_free(struct task_struct *task)
1366{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001367 call_void_hook(task_free, task);
Kees Cook1a2a4d02011-12-21 12:17:03 -08001368}
1369
David Howellsee18d642009-09-02 09:14:21 +01001370int security_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1371{
Casey Schauflerbbd36622018-11-12 09:30:56 -08001372 int rc = lsm_cred_alloc(cred, gfp);
1373
1374 if (rc)
1375 return rc;
1376
1377 rc = call_int_hook(cred_alloc_blank, 0, cred, gfp);
Casey Schaufler33bf60c2018-11-12 12:02:49 -08001378 if (unlikely(rc))
Casey Schauflerbbd36622018-11-12 09:30:56 -08001379 security_cred_free(cred);
1380 return rc;
David Howellsee18d642009-09-02 09:14:21 +01001381}
1382
David Howellsf1752ee2008-11-14 10:39:17 +11001383void security_cred_free(struct cred *cred)
James Morris20510f22007-10-16 23:31:32 -07001384{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001385 call_void_hook(cred_free, cred);
Casey Schauflerbbd36622018-11-12 09:30:56 -08001386
1387 kfree(cred->security);
1388 cred->security = NULL;
James Morris20510f22007-10-16 23:31:32 -07001389}
1390
David Howellsd84f4f92008-11-14 10:39:23 +11001391int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
1392{
Casey Schauflerbbd36622018-11-12 09:30:56 -08001393 int rc = lsm_cred_alloc(new, gfp);
1394
1395 if (rc)
1396 return rc;
1397
1398 rc = call_int_hook(cred_prepare, 0, new, old, gfp);
Casey Schaufler33bf60c2018-11-12 12:02:49 -08001399 if (unlikely(rc))
Casey Schauflerbbd36622018-11-12 09:30:56 -08001400 security_cred_free(new);
1401 return rc;
David Howellsd84f4f92008-11-14 10:39:23 +11001402}
1403
David Howellsee18d642009-09-02 09:14:21 +01001404void security_transfer_creds(struct cred *new, const struct cred *old)
1405{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001406 call_void_hook(cred_transfer, new, old);
David Howellsee18d642009-09-02 09:14:21 +01001407}
1408
Matthew Garrett3ec30112018-01-08 13:36:19 -08001409void security_cred_getsecid(const struct cred *c, u32 *secid)
1410{
1411 *secid = 0;
1412 call_void_hook(cred_getsecid, c, secid);
1413}
1414EXPORT_SYMBOL(security_cred_getsecid);
1415
David Howells3a3b7ce2008-11-14 10:39:28 +11001416int security_kernel_act_as(struct cred *new, u32 secid)
1417{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001418 return call_int_hook(kernel_act_as, 0, new, secid);
David Howells3a3b7ce2008-11-14 10:39:28 +11001419}
1420
1421int security_kernel_create_files_as(struct cred *new, struct inode *inode)
1422{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001423 return call_int_hook(kernel_create_files_as, 0, new, inode);
David Howells3a3b7ce2008-11-14 10:39:28 +11001424}
1425
Eric Parisdd8dbf22009-11-03 16:35:32 +11001426int security_kernel_module_request(char *kmod_name)
Eric Paris91884992009-08-13 09:44:57 -04001427{
Mikhail Kurinnoi6eb864c2018-06-27 16:33:42 +03001428 int ret;
1429
1430 ret = call_int_hook(kernel_module_request, 0, kmod_name);
1431 if (ret)
1432 return ret;
1433 return integrity_kernel_module_request(kmod_name);
Eric Paris91884992009-08-13 09:44:57 -04001434}
1435
Mimi Zohar39eeb4f2016-01-30 22:23:26 -05001436int security_kernel_read_file(struct file *file, enum kernel_read_file_id id)
1437{
1438 int ret;
1439
1440 ret = call_int_hook(kernel_read_file, 0, file, id);
1441 if (ret)
1442 return ret;
1443 return ima_read_file(file, id);
1444}
1445EXPORT_SYMBOL_GPL(security_kernel_read_file);
1446
Mimi Zoharbc8ca5b2016-01-24 10:07:32 -05001447int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
1448 enum kernel_read_file_id id)
Mimi Zoharb44a7df2015-12-28 16:02:29 -05001449{
Mimi Zoharcf222212016-01-14 17:57:47 -05001450 int ret;
1451
1452 ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id);
1453 if (ret)
1454 return ret;
1455 return ima_post_read_file(file, buf, size, id);
Mimi Zoharb44a7df2015-12-28 16:02:29 -05001456}
1457EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
1458
Mimi Zohar377179c2018-07-13 14:05:56 -04001459int security_kernel_load_data(enum kernel_load_data_id id)
1460{
Mimi Zohar16c267a2018-07-13 14:05:58 -04001461 int ret;
1462
1463 ret = call_int_hook(kernel_load_data, 0, id);
1464 if (ret)
1465 return ret;
1466 return ima_load_data(id);
Mimi Zohar377179c2018-07-13 14:05:56 -04001467}
Arnd Bergmann83a68a02018-07-17 22:23:37 +02001468EXPORT_SYMBOL_GPL(security_kernel_load_data);
Mimi Zohar377179c2018-07-13 14:05:56 -04001469
David Howellsd84f4f92008-11-14 10:39:23 +11001470int security_task_fix_setuid(struct cred *new, const struct cred *old,
1471 int flags)
James Morris20510f22007-10-16 23:31:32 -07001472{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001473 return call_int_hook(task_fix_setuid, 0, new, old, flags);
James Morris20510f22007-10-16 23:31:32 -07001474}
1475
James Morris20510f22007-10-16 23:31:32 -07001476int security_task_setpgid(struct task_struct *p, pid_t pgid)
1477{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001478 return call_int_hook(task_setpgid, 0, p, pgid);
James Morris20510f22007-10-16 23:31:32 -07001479}
1480
1481int security_task_getpgid(struct task_struct *p)
1482{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001483 return call_int_hook(task_getpgid, 0, p);
James Morris20510f22007-10-16 23:31:32 -07001484}
1485
1486int security_task_getsid(struct task_struct *p)
1487{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001488 return call_int_hook(task_getsid, 0, p);
James Morris20510f22007-10-16 23:31:32 -07001489}
1490
1491void security_task_getsecid(struct task_struct *p, u32 *secid)
1492{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001493 *secid = 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001494 call_void_hook(task_getsecid, p, secid);
James Morris20510f22007-10-16 23:31:32 -07001495}
1496EXPORT_SYMBOL(security_task_getsecid);
1497
James Morris20510f22007-10-16 23:31:32 -07001498int security_task_setnice(struct task_struct *p, int nice)
1499{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001500 return call_int_hook(task_setnice, 0, p, nice);
James Morris20510f22007-10-16 23:31:32 -07001501}
1502
1503int security_task_setioprio(struct task_struct *p, int ioprio)
1504{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001505 return call_int_hook(task_setioprio, 0, p, ioprio);
James Morris20510f22007-10-16 23:31:32 -07001506}
1507
1508int security_task_getioprio(struct task_struct *p)
1509{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001510 return call_int_hook(task_getioprio, 0, p);
James Morris20510f22007-10-16 23:31:32 -07001511}
1512
Stephen Smalley791ec492017-02-17 07:57:00 -05001513int security_task_prlimit(const struct cred *cred, const struct cred *tcred,
1514 unsigned int flags)
1515{
1516 return call_int_hook(task_prlimit, 0, cred, tcred, flags);
1517}
1518
Jiri Slaby8fd00b42009-08-26 18:41:16 +02001519int security_task_setrlimit(struct task_struct *p, unsigned int resource,
1520 struct rlimit *new_rlim)
James Morris20510f22007-10-16 23:31:32 -07001521{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001522 return call_int_hook(task_setrlimit, 0, p, resource, new_rlim);
James Morris20510f22007-10-16 23:31:32 -07001523}
1524
KOSAKI Motohirob0ae1982010-10-15 04:21:18 +09001525int security_task_setscheduler(struct task_struct *p)
James Morris20510f22007-10-16 23:31:32 -07001526{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001527 return call_int_hook(task_setscheduler, 0, p);
James Morris20510f22007-10-16 23:31:32 -07001528}
1529
1530int security_task_getscheduler(struct task_struct *p)
1531{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001532 return call_int_hook(task_getscheduler, 0, p);
James Morris20510f22007-10-16 23:31:32 -07001533}
1534
1535int security_task_movememory(struct task_struct *p)
1536{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001537 return call_int_hook(task_movememory, 0, p);
James Morris20510f22007-10-16 23:31:32 -07001538}
1539
Eric W. Biedermanae7795b2018-09-25 11:27:20 +02001540int security_task_kill(struct task_struct *p, struct kernel_siginfo *info,
Stephen Smalley6b4f3d02017-09-08 12:40:01 -04001541 int sig, const struct cred *cred)
James Morris20510f22007-10-16 23:31:32 -07001542{
Stephen Smalley6b4f3d02017-09-08 12:40:01 -04001543 return call_int_hook(task_kill, 0, p, info, sig, cred);
James Morris20510f22007-10-16 23:31:32 -07001544}
1545
James Morris20510f22007-10-16 23:31:32 -07001546int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
David Howellsd84f4f92008-11-14 10:39:23 +11001547 unsigned long arg4, unsigned long arg5)
James Morris20510f22007-10-16 23:31:32 -07001548{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001549 int thisrc;
1550 int rc = -ENOSYS;
1551 struct security_hook_list *hp;
1552
Sargun Dhillondf0ce172018-03-29 01:28:23 +00001553 hlist_for_each_entry(hp, &security_hook_heads.task_prctl, list) {
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001554 thisrc = hp->hook.task_prctl(option, arg2, arg3, arg4, arg5);
1555 if (thisrc != -ENOSYS) {
1556 rc = thisrc;
1557 if (thisrc != 0)
1558 break;
1559 }
1560 }
1561 return rc;
James Morris20510f22007-10-16 23:31:32 -07001562}
1563
1564void security_task_to_inode(struct task_struct *p, struct inode *inode)
1565{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001566 call_void_hook(task_to_inode, p, inode);
James Morris20510f22007-10-16 23:31:32 -07001567}
1568
1569int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
1570{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001571 return call_int_hook(ipc_permission, 0, ipcp, flag);
James Morris20510f22007-10-16 23:31:32 -07001572}
1573
Ahmed S. Darwish8a076192008-03-01 21:51:09 +02001574void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
1575{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001576 *secid = 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001577 call_void_hook(ipc_getsecid, ipcp, secid);
Ahmed S. Darwish8a076192008-03-01 21:51:09 +02001578}
1579
James Morris20510f22007-10-16 23:31:32 -07001580int security_msg_msg_alloc(struct msg_msg *msg)
1581{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001582 return call_int_hook(msg_msg_alloc_security, 0, msg);
James Morris20510f22007-10-16 23:31:32 -07001583}
1584
1585void security_msg_msg_free(struct msg_msg *msg)
1586{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001587 call_void_hook(msg_msg_free_security, msg);
James Morris20510f22007-10-16 23:31:32 -07001588}
1589
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001590int security_msg_queue_alloc(struct kern_ipc_perm *msq)
James Morris20510f22007-10-16 23:31:32 -07001591{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001592 return call_int_hook(msg_queue_alloc_security, 0, msq);
James Morris20510f22007-10-16 23:31:32 -07001593}
1594
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001595void security_msg_queue_free(struct kern_ipc_perm *msq)
James Morris20510f22007-10-16 23:31:32 -07001596{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001597 call_void_hook(msg_queue_free_security, msq);
James Morris20510f22007-10-16 23:31:32 -07001598}
1599
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001600int security_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg)
James Morris20510f22007-10-16 23:31:32 -07001601{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001602 return call_int_hook(msg_queue_associate, 0, msq, msqflg);
James Morris20510f22007-10-16 23:31:32 -07001603}
1604
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001605int security_msg_queue_msgctl(struct kern_ipc_perm *msq, int cmd)
James Morris20510f22007-10-16 23:31:32 -07001606{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001607 return call_int_hook(msg_queue_msgctl, 0, msq, cmd);
James Morris20510f22007-10-16 23:31:32 -07001608}
1609
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001610int security_msg_queue_msgsnd(struct kern_ipc_perm *msq,
James Morris20510f22007-10-16 23:31:32 -07001611 struct msg_msg *msg, int msqflg)
1612{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001613 return call_int_hook(msg_queue_msgsnd, 0, msq, msg, msqflg);
James Morris20510f22007-10-16 23:31:32 -07001614}
1615
Eric W. Biedermand8c6e852018-03-22 21:22:26 -05001616int security_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *msg,
James Morris20510f22007-10-16 23:31:32 -07001617 struct task_struct *target, long type, int mode)
1618{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001619 return call_int_hook(msg_queue_msgrcv, 0, msq, msg, target, type, mode);
James Morris20510f22007-10-16 23:31:32 -07001620}
1621
Eric W. Biederman7191adf2018-03-22 21:08:27 -05001622int security_shm_alloc(struct kern_ipc_perm *shp)
James Morris20510f22007-10-16 23:31:32 -07001623{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001624 return call_int_hook(shm_alloc_security, 0, shp);
James Morris20510f22007-10-16 23:31:32 -07001625}
1626
Eric W. Biederman7191adf2018-03-22 21:08:27 -05001627void security_shm_free(struct kern_ipc_perm *shp)
James Morris20510f22007-10-16 23:31:32 -07001628{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001629 call_void_hook(shm_free_security, shp);
James Morris20510f22007-10-16 23:31:32 -07001630}
1631
Eric W. Biederman7191adf2018-03-22 21:08:27 -05001632int security_shm_associate(struct kern_ipc_perm *shp, int shmflg)
James Morris20510f22007-10-16 23:31:32 -07001633{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001634 return call_int_hook(shm_associate, 0, shp, shmflg);
James Morris20510f22007-10-16 23:31:32 -07001635}
1636
Eric W. Biederman7191adf2018-03-22 21:08:27 -05001637int security_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
James Morris20510f22007-10-16 23:31:32 -07001638{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001639 return call_int_hook(shm_shmctl, 0, shp, cmd);
James Morris20510f22007-10-16 23:31:32 -07001640}
1641
Eric W. Biederman7191adf2018-03-22 21:08:27 -05001642int security_shm_shmat(struct kern_ipc_perm *shp, char __user *shmaddr, int shmflg)
James Morris20510f22007-10-16 23:31:32 -07001643{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001644 return call_int_hook(shm_shmat, 0, shp, shmaddr, shmflg);
James Morris20510f22007-10-16 23:31:32 -07001645}
1646
Eric W. Biedermanaefad952018-03-22 20:52:43 -05001647int security_sem_alloc(struct kern_ipc_perm *sma)
James Morris20510f22007-10-16 23:31:32 -07001648{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001649 return call_int_hook(sem_alloc_security, 0, sma);
James Morris20510f22007-10-16 23:31:32 -07001650}
1651
Eric W. Biedermanaefad952018-03-22 20:52:43 -05001652void security_sem_free(struct kern_ipc_perm *sma)
James Morris20510f22007-10-16 23:31:32 -07001653{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001654 call_void_hook(sem_free_security, sma);
James Morris20510f22007-10-16 23:31:32 -07001655}
1656
Eric W. Biedermanaefad952018-03-22 20:52:43 -05001657int security_sem_associate(struct kern_ipc_perm *sma, int semflg)
James Morris20510f22007-10-16 23:31:32 -07001658{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001659 return call_int_hook(sem_associate, 0, sma, semflg);
James Morris20510f22007-10-16 23:31:32 -07001660}
1661
Eric W. Biedermanaefad952018-03-22 20:52:43 -05001662int security_sem_semctl(struct kern_ipc_perm *sma, int cmd)
James Morris20510f22007-10-16 23:31:32 -07001663{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001664 return call_int_hook(sem_semctl, 0, sma, cmd);
James Morris20510f22007-10-16 23:31:32 -07001665}
1666
Eric W. Biedermanaefad952018-03-22 20:52:43 -05001667int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops,
James Morris20510f22007-10-16 23:31:32 -07001668 unsigned nsops, int alter)
1669{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001670 return call_int_hook(sem_semop, 0, sma, sops, nsops, alter);
James Morris20510f22007-10-16 23:31:32 -07001671}
1672
1673void security_d_instantiate(struct dentry *dentry, struct inode *inode)
1674{
1675 if (unlikely(inode && IS_PRIVATE(inode)))
1676 return;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001677 call_void_hook(d_instantiate, dentry, inode);
James Morris20510f22007-10-16 23:31:32 -07001678}
1679EXPORT_SYMBOL(security_d_instantiate);
1680
Casey Schaufler6d9c9392018-09-21 17:16:59 -07001681int security_getprocattr(struct task_struct *p, const char *lsm, char *name,
1682 char **value)
James Morris20510f22007-10-16 23:31:32 -07001683{
Casey Schaufler6d9c9392018-09-21 17:16:59 -07001684 struct security_hook_list *hp;
1685
1686 hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) {
1687 if (lsm != NULL && strcmp(lsm, hp->lsm))
1688 continue;
1689 return hp->hook.getprocattr(p, name, value);
1690 }
1691 return -EINVAL;
James Morris20510f22007-10-16 23:31:32 -07001692}
1693
Casey Schaufler6d9c9392018-09-21 17:16:59 -07001694int security_setprocattr(const char *lsm, const char *name, void *value,
1695 size_t size)
James Morris20510f22007-10-16 23:31:32 -07001696{
Casey Schaufler6d9c9392018-09-21 17:16:59 -07001697 struct security_hook_list *hp;
1698
1699 hlist_for_each_entry(hp, &security_hook_heads.setprocattr, list) {
1700 if (lsm != NULL && strcmp(lsm, hp->lsm))
1701 continue;
1702 return hp->hook.setprocattr(name, value, size);
1703 }
1704 return -EINVAL;
James Morris20510f22007-10-16 23:31:32 -07001705}
1706
1707int security_netlink_send(struct sock *sk, struct sk_buff *skb)
1708{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001709 return call_int_hook(netlink_send, 0, sk, skb);
James Morris20510f22007-10-16 23:31:32 -07001710}
James Morris20510f22007-10-16 23:31:32 -07001711
David Quigley746df9b2013-05-22 12:50:35 -04001712int security_ismaclabel(const char *name)
1713{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001714 return call_int_hook(ismaclabel, 0, name);
David Quigley746df9b2013-05-22 12:50:35 -04001715}
1716EXPORT_SYMBOL(security_ismaclabel);
1717
James Morris20510f22007-10-16 23:31:32 -07001718int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
1719{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001720 return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata,
1721 seclen);
James Morris20510f22007-10-16 23:31:32 -07001722}
1723EXPORT_SYMBOL(security_secid_to_secctx);
1724
David Howells7bf570d2008-04-29 20:52:51 +01001725int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
David Howells63cb3442008-01-15 23:47:35 +00001726{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001727 *secid = 0;
Casey Schauflerf25fce32015-05-02 15:11:29 -07001728 return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid);
David Howells63cb3442008-01-15 23:47:35 +00001729}
1730EXPORT_SYMBOL(security_secctx_to_secid);
1731
James Morris20510f22007-10-16 23:31:32 -07001732void security_release_secctx(char *secdata, u32 seclen)
1733{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001734 call_void_hook(release_secctx, secdata, seclen);
James Morris20510f22007-10-16 23:31:32 -07001735}
1736EXPORT_SYMBOL(security_release_secctx);
1737
Andreas Gruenbacher6f3be9f2015-12-24 11:09:40 -05001738void security_inode_invalidate_secctx(struct inode *inode)
1739{
1740 call_void_hook(inode_invalidate_secctx, inode);
1741}
1742EXPORT_SYMBOL(security_inode_invalidate_secctx);
1743
David P. Quigley1ee65e32009-09-03 14:25:57 -04001744int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
1745{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001746 return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen);
David P. Quigley1ee65e32009-09-03 14:25:57 -04001747}
1748EXPORT_SYMBOL(security_inode_notifysecctx);
1749
1750int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
1751{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001752 return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen);
David P. Quigley1ee65e32009-09-03 14:25:57 -04001753}
1754EXPORT_SYMBOL(security_inode_setsecctx);
1755
1756int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
1757{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001758 return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen);
David P. Quigley1ee65e32009-09-03 14:25:57 -04001759}
1760EXPORT_SYMBOL(security_inode_getsecctx);
1761
James Morris20510f22007-10-16 23:31:32 -07001762#ifdef CONFIG_SECURITY_NETWORK
1763
David S. Miller3610cda2011-01-05 15:38:53 -08001764int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
James Morris20510f22007-10-16 23:31:32 -07001765{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001766 return call_int_hook(unix_stream_connect, 0, sock, other, newsk);
James Morris20510f22007-10-16 23:31:32 -07001767}
1768EXPORT_SYMBOL(security_unix_stream_connect);
1769
1770int security_unix_may_send(struct socket *sock, struct socket *other)
1771{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001772 return call_int_hook(unix_may_send, 0, sock, other);
James Morris20510f22007-10-16 23:31:32 -07001773}
1774EXPORT_SYMBOL(security_unix_may_send);
1775
1776int security_socket_create(int family, int type, int protocol, int kern)
1777{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001778 return call_int_hook(socket_create, 0, family, type, protocol, kern);
James Morris20510f22007-10-16 23:31:32 -07001779}
1780
1781int security_socket_post_create(struct socket *sock, int family,
1782 int type, int protocol, int kern)
1783{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001784 return call_int_hook(socket_post_create, 0, sock, family, type,
James Morris20510f22007-10-16 23:31:32 -07001785 protocol, kern);
1786}
1787
David Herrmannaae7cfc2018-05-04 16:28:19 +02001788int security_socket_socketpair(struct socket *socka, struct socket *sockb)
1789{
1790 return call_int_hook(socket_socketpair, 0, socka, sockb);
1791}
1792EXPORT_SYMBOL(security_socket_socketpair);
1793
James Morris20510f22007-10-16 23:31:32 -07001794int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
1795{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001796 return call_int_hook(socket_bind, 0, sock, address, addrlen);
James Morris20510f22007-10-16 23:31:32 -07001797}
1798
1799int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
1800{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001801 return call_int_hook(socket_connect, 0, sock, address, addrlen);
James Morris20510f22007-10-16 23:31:32 -07001802}
1803
1804int security_socket_listen(struct socket *sock, int backlog)
1805{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001806 return call_int_hook(socket_listen, 0, sock, backlog);
James Morris20510f22007-10-16 23:31:32 -07001807}
1808
1809int security_socket_accept(struct socket *sock, struct socket *newsock)
1810{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001811 return call_int_hook(socket_accept, 0, sock, newsock);
James Morris20510f22007-10-16 23:31:32 -07001812}
1813
James Morris20510f22007-10-16 23:31:32 -07001814int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
1815{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001816 return call_int_hook(socket_sendmsg, 0, sock, msg, size);
James Morris20510f22007-10-16 23:31:32 -07001817}
1818
1819int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
1820 int size, int flags)
1821{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001822 return call_int_hook(socket_recvmsg, 0, sock, msg, size, flags);
James Morris20510f22007-10-16 23:31:32 -07001823}
1824
1825int security_socket_getsockname(struct socket *sock)
1826{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001827 return call_int_hook(socket_getsockname, 0, sock);
James Morris20510f22007-10-16 23:31:32 -07001828}
1829
1830int security_socket_getpeername(struct socket *sock)
1831{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001832 return call_int_hook(socket_getpeername, 0, sock);
James Morris20510f22007-10-16 23:31:32 -07001833}
1834
1835int security_socket_getsockopt(struct socket *sock, int level, int optname)
1836{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001837 return call_int_hook(socket_getsockopt, 0, sock, level, optname);
James Morris20510f22007-10-16 23:31:32 -07001838}
1839
1840int security_socket_setsockopt(struct socket *sock, int level, int optname)
1841{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001842 return call_int_hook(socket_setsockopt, 0, sock, level, optname);
James Morris20510f22007-10-16 23:31:32 -07001843}
1844
1845int security_socket_shutdown(struct socket *sock, int how)
1846{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001847 return call_int_hook(socket_shutdown, 0, sock, how);
James Morris20510f22007-10-16 23:31:32 -07001848}
1849
1850int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
1851{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001852 return call_int_hook(socket_sock_rcv_skb, 0, sk, skb);
James Morris20510f22007-10-16 23:31:32 -07001853}
1854EXPORT_SYMBOL(security_sock_rcv_skb);
1855
1856int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
1857 int __user *optlen, unsigned len)
1858{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07001859 return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock,
1860 optval, optlen, len);
James Morris20510f22007-10-16 23:31:32 -07001861}
1862
1863int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
1864{
Jan Beuliche308fd32015-08-24 06:22:25 -06001865 return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock,
1866 skb, secid);
James Morris20510f22007-10-16 23:31:32 -07001867}
1868EXPORT_SYMBOL(security_socket_getpeersec_dgram);
1869
1870int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
1871{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001872 return call_int_hook(sk_alloc_security, 0, sk, family, priority);
James Morris20510f22007-10-16 23:31:32 -07001873}
1874
1875void security_sk_free(struct sock *sk)
1876{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001877 call_void_hook(sk_free_security, sk);
James Morris20510f22007-10-16 23:31:32 -07001878}
1879
1880void security_sk_clone(const struct sock *sk, struct sock *newsk)
1881{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001882 call_void_hook(sk_clone_security, sk, newsk);
James Morris20510f22007-10-16 23:31:32 -07001883}
Paul Moore6230c9b2011-10-07 09:40:59 +00001884EXPORT_SYMBOL(security_sk_clone);
James Morris20510f22007-10-16 23:31:32 -07001885
1886void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
1887{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001888 call_void_hook(sk_getsecid, sk, &fl->flowi_secid);
James Morris20510f22007-10-16 23:31:32 -07001889}
1890EXPORT_SYMBOL(security_sk_classify_flow);
1891
1892void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
1893{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001894 call_void_hook(req_classify_flow, req, fl);
James Morris20510f22007-10-16 23:31:32 -07001895}
1896EXPORT_SYMBOL(security_req_classify_flow);
1897
1898void security_sock_graft(struct sock *sk, struct socket *parent)
1899{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001900 call_void_hook(sock_graft, sk, parent);
James Morris20510f22007-10-16 23:31:32 -07001901}
1902EXPORT_SYMBOL(security_sock_graft);
1903
1904int security_inet_conn_request(struct sock *sk,
1905 struct sk_buff *skb, struct request_sock *req)
1906{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001907 return call_int_hook(inet_conn_request, 0, sk, skb, req);
James Morris20510f22007-10-16 23:31:32 -07001908}
1909EXPORT_SYMBOL(security_inet_conn_request);
1910
1911void security_inet_csk_clone(struct sock *newsk,
1912 const struct request_sock *req)
1913{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001914 call_void_hook(inet_csk_clone, newsk, req);
James Morris20510f22007-10-16 23:31:32 -07001915}
1916
1917void security_inet_conn_established(struct sock *sk,
1918 struct sk_buff *skb)
1919{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001920 call_void_hook(inet_conn_established, sk, skb);
James Morris20510f22007-10-16 23:31:32 -07001921}
Richard Haines72e89f52018-02-13 20:53:21 +00001922EXPORT_SYMBOL(security_inet_conn_established);
James Morris20510f22007-10-16 23:31:32 -07001923
Eric Paris2606fd12010-10-13 16:24:41 -04001924int security_secmark_relabel_packet(u32 secid)
1925{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001926 return call_int_hook(secmark_relabel_packet, 0, secid);
Eric Paris2606fd12010-10-13 16:24:41 -04001927}
1928EXPORT_SYMBOL(security_secmark_relabel_packet);
1929
1930void security_secmark_refcount_inc(void)
1931{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001932 call_void_hook(secmark_refcount_inc);
Eric Paris2606fd12010-10-13 16:24:41 -04001933}
1934EXPORT_SYMBOL(security_secmark_refcount_inc);
1935
1936void security_secmark_refcount_dec(void)
1937{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001938 call_void_hook(secmark_refcount_dec);
Eric Paris2606fd12010-10-13 16:24:41 -04001939}
1940EXPORT_SYMBOL(security_secmark_refcount_dec);
1941
Paul Moore5dbbaf22013-01-14 07:12:19 +00001942int security_tun_dev_alloc_security(void **security)
1943{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001944 return call_int_hook(tun_dev_alloc_security, 0, security);
Paul Moore5dbbaf22013-01-14 07:12:19 +00001945}
1946EXPORT_SYMBOL(security_tun_dev_alloc_security);
1947
1948void security_tun_dev_free_security(void *security)
1949{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001950 call_void_hook(tun_dev_free_security, security);
Paul Moore5dbbaf22013-01-14 07:12:19 +00001951}
1952EXPORT_SYMBOL(security_tun_dev_free_security);
1953
Paul Moore2b980db2009-08-28 18:12:43 -04001954int security_tun_dev_create(void)
1955{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001956 return call_int_hook(tun_dev_create, 0);
Paul Moore2b980db2009-08-28 18:12:43 -04001957}
1958EXPORT_SYMBOL(security_tun_dev_create);
1959
Paul Moore5dbbaf22013-01-14 07:12:19 +00001960int security_tun_dev_attach_queue(void *security)
Paul Moore2b980db2009-08-28 18:12:43 -04001961{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001962 return call_int_hook(tun_dev_attach_queue, 0, security);
Paul Moore2b980db2009-08-28 18:12:43 -04001963}
Paul Moore5dbbaf22013-01-14 07:12:19 +00001964EXPORT_SYMBOL(security_tun_dev_attach_queue);
Paul Moore2b980db2009-08-28 18:12:43 -04001965
Paul Moore5dbbaf22013-01-14 07:12:19 +00001966int security_tun_dev_attach(struct sock *sk, void *security)
Paul Moore2b980db2009-08-28 18:12:43 -04001967{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001968 return call_int_hook(tun_dev_attach, 0, sk, security);
Paul Moore2b980db2009-08-28 18:12:43 -04001969}
1970EXPORT_SYMBOL(security_tun_dev_attach);
1971
Paul Moore5dbbaf22013-01-14 07:12:19 +00001972int security_tun_dev_open(void *security)
1973{
Casey Schauflerf25fce32015-05-02 15:11:29 -07001974 return call_int_hook(tun_dev_open, 0, security);
Paul Moore5dbbaf22013-01-14 07:12:19 +00001975}
1976EXPORT_SYMBOL(security_tun_dev_open);
1977
Richard Haines72e89f52018-02-13 20:53:21 +00001978int security_sctp_assoc_request(struct sctp_endpoint *ep, struct sk_buff *skb)
1979{
1980 return call_int_hook(sctp_assoc_request, 0, ep, skb);
1981}
1982EXPORT_SYMBOL(security_sctp_assoc_request);
1983
1984int security_sctp_bind_connect(struct sock *sk, int optname,
1985 struct sockaddr *address, int addrlen)
1986{
1987 return call_int_hook(sctp_bind_connect, 0, sk, optname,
1988 address, addrlen);
1989}
1990EXPORT_SYMBOL(security_sctp_bind_connect);
1991
1992void security_sctp_sk_clone(struct sctp_endpoint *ep, struct sock *sk,
1993 struct sock *newsk)
1994{
1995 call_void_hook(sctp_sk_clone, ep, sk, newsk);
1996}
1997EXPORT_SYMBOL(security_sctp_sk_clone);
1998
James Morris20510f22007-10-16 23:31:32 -07001999#endif /* CONFIG_SECURITY_NETWORK */
2000
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03002001#ifdef CONFIG_SECURITY_INFINIBAND
2002
2003int security_ib_pkey_access(void *sec, u64 subnet_prefix, u16 pkey)
2004{
2005 return call_int_hook(ib_pkey_access, 0, sec, subnet_prefix, pkey);
2006}
2007EXPORT_SYMBOL(security_ib_pkey_access);
2008
Daniel Jurgens47a2b332017-05-19 15:48:54 +03002009int security_ib_endport_manage_subnet(void *sec, const char *dev_name, u8 port_num)
2010{
2011 return call_int_hook(ib_endport_manage_subnet, 0, sec, dev_name, port_num);
2012}
2013EXPORT_SYMBOL(security_ib_endport_manage_subnet);
2014
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03002015int security_ib_alloc_security(void **sec)
2016{
2017 return call_int_hook(ib_alloc_security, 0, sec);
2018}
2019EXPORT_SYMBOL(security_ib_alloc_security);
2020
2021void security_ib_free_security(void *sec)
2022{
2023 call_void_hook(ib_free_security, sec);
2024}
2025EXPORT_SYMBOL(security_ib_free_security);
2026#endif /* CONFIG_SECURITY_INFINIBAND */
2027
James Morris20510f22007-10-16 23:31:32 -07002028#ifdef CONFIG_SECURITY_NETWORK_XFRM
2029
Nikolay Aleksandrov52a4c642014-03-07 12:44:19 +01002030int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
2031 struct xfrm_user_sec_ctx *sec_ctx,
2032 gfp_t gfp)
James Morris20510f22007-10-16 23:31:32 -07002033{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002034 return call_int_hook(xfrm_policy_alloc_security, 0, ctxp, sec_ctx, gfp);
James Morris20510f22007-10-16 23:31:32 -07002035}
2036EXPORT_SYMBOL(security_xfrm_policy_alloc);
2037
Paul Moore03e1ad72008-04-12 19:07:52 -07002038int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
2039 struct xfrm_sec_ctx **new_ctxp)
James Morris20510f22007-10-16 23:31:32 -07002040{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002041 return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
James Morris20510f22007-10-16 23:31:32 -07002042}
2043
Paul Moore03e1ad72008-04-12 19:07:52 -07002044void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
James Morris20510f22007-10-16 23:31:32 -07002045{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002046 call_void_hook(xfrm_policy_free_security, ctx);
James Morris20510f22007-10-16 23:31:32 -07002047}
2048EXPORT_SYMBOL(security_xfrm_policy_free);
2049
Paul Moore03e1ad72008-04-12 19:07:52 -07002050int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
James Morris20510f22007-10-16 23:31:32 -07002051{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002052 return call_int_hook(xfrm_policy_delete_security, 0, ctx);
James Morris20510f22007-10-16 23:31:32 -07002053}
2054
Paul Moore2e5aa862013-07-23 17:38:38 -04002055int security_xfrm_state_alloc(struct xfrm_state *x,
2056 struct xfrm_user_sec_ctx *sec_ctx)
James Morris20510f22007-10-16 23:31:32 -07002057{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002058 return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
James Morris20510f22007-10-16 23:31:32 -07002059}
2060EXPORT_SYMBOL(security_xfrm_state_alloc);
2061
2062int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
2063 struct xfrm_sec_ctx *polsec, u32 secid)
2064{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002065 return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
James Morris20510f22007-10-16 23:31:32 -07002066}
2067
2068int security_xfrm_state_delete(struct xfrm_state *x)
2069{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002070 return call_int_hook(xfrm_state_delete_security, 0, x);
James Morris20510f22007-10-16 23:31:32 -07002071}
2072EXPORT_SYMBOL(security_xfrm_state_delete);
2073
2074void security_xfrm_state_free(struct xfrm_state *x)
2075{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002076 call_void_hook(xfrm_state_free_security, x);
James Morris20510f22007-10-16 23:31:32 -07002077}
2078
Paul Moore03e1ad72008-04-12 19:07:52 -07002079int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
James Morris20510f22007-10-16 23:31:32 -07002080{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002081 return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid, dir);
James Morris20510f22007-10-16 23:31:32 -07002082}
2083
2084int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
David S. Millere33f7702011-02-22 18:13:15 -08002085 struct xfrm_policy *xp,
2086 const struct flowi *fl)
James Morris20510f22007-10-16 23:31:32 -07002087{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002088 struct security_hook_list *hp;
2089 int rc = 1;
2090
2091 /*
2092 * Since this function is expected to return 0 or 1, the judgment
2093 * becomes difficult if multiple LSMs supply this call. Fortunately,
2094 * we can use the first LSM's judgment because currently only SELinux
2095 * supplies this call.
2096 *
2097 * For speed optimization, we explicitly break the loop rather than
2098 * using the macro
2099 */
Sargun Dhillondf0ce172018-03-29 01:28:23 +00002100 hlist_for_each_entry(hp, &security_hook_heads.xfrm_state_pol_flow_match,
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002101 list) {
2102 rc = hp->hook.xfrm_state_pol_flow_match(x, xp, fl);
2103 break;
2104 }
2105 return rc;
James Morris20510f22007-10-16 23:31:32 -07002106}
2107
2108int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
2109{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002110 return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);
James Morris20510f22007-10-16 23:31:32 -07002111}
2112
2113void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
2114{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002115 int rc = call_int_hook(xfrm_decode_session, 0, skb, &fl->flowi_secid,
2116 0);
James Morris20510f22007-10-16 23:31:32 -07002117
2118 BUG_ON(rc);
2119}
2120EXPORT_SYMBOL(security_skb_classify_flow);
2121
2122#endif /* CONFIG_SECURITY_NETWORK_XFRM */
2123
2124#ifdef CONFIG_KEYS
2125
David Howellsd84f4f92008-11-14 10:39:23 +11002126int security_key_alloc(struct key *key, const struct cred *cred,
2127 unsigned long flags)
James Morris20510f22007-10-16 23:31:32 -07002128{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002129 return call_int_hook(key_alloc, 0, key, cred, flags);
James Morris20510f22007-10-16 23:31:32 -07002130}
2131
2132void security_key_free(struct key *key)
2133{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002134 call_void_hook(key_free, key);
James Morris20510f22007-10-16 23:31:32 -07002135}
2136
2137int security_key_permission(key_ref_t key_ref,
David Howellsf5895942014-03-14 17:44:49 +00002138 const struct cred *cred, unsigned perm)
James Morris20510f22007-10-16 23:31:32 -07002139{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002140 return call_int_hook(key_permission, 0, key_ref, cred, perm);
James Morris20510f22007-10-16 23:31:32 -07002141}
2142
David Howells70a5bb72008-04-29 01:01:26 -07002143int security_key_getsecurity(struct key *key, char **_buffer)
2144{
Casey Schauflerb1d9e6b2015-05-02 15:11:42 -07002145 *_buffer = NULL;
Casey Schauflerf25fce32015-05-02 15:11:29 -07002146 return call_int_hook(key_getsecurity, 0, key, _buffer);
David Howells70a5bb72008-04-29 01:01:26 -07002147}
2148
James Morris20510f22007-10-16 23:31:32 -07002149#endif /* CONFIG_KEYS */
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02002150
2151#ifdef CONFIG_AUDIT
2152
2153int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
2154{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002155 return call_int_hook(audit_rule_init, 0, field, op, rulestr, lsmrule);
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02002156}
2157
2158int security_audit_rule_known(struct audit_krule *krule)
2159{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002160 return call_int_hook(audit_rule_known, 0, krule);
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02002161}
2162
2163void security_audit_rule_free(void *lsmrule)
2164{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002165 call_void_hook(audit_rule_free, lsmrule);
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02002166}
2167
2168int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
2169 struct audit_context *actx)
2170{
Casey Schauflerf25fce32015-05-02 15:11:29 -07002171 return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule,
2172 actx);
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02002173}
Ahmed S. Darwish03d37d22008-03-01 22:00:05 +02002174#endif /* CONFIG_AUDIT */
Chenbo Fengafdb09c2017-10-18 13:00:24 -07002175
2176#ifdef CONFIG_BPF_SYSCALL
2177int security_bpf(int cmd, union bpf_attr *attr, unsigned int size)
2178{
2179 return call_int_hook(bpf, 0, cmd, attr, size);
2180}
2181int security_bpf_map(struct bpf_map *map, fmode_t fmode)
2182{
2183 return call_int_hook(bpf_map, 0, map, fmode);
2184}
2185int security_bpf_prog(struct bpf_prog *prog)
2186{
2187 return call_int_hook(bpf_prog, 0, prog);
2188}
2189int security_bpf_map_alloc(struct bpf_map *map)
2190{
2191 return call_int_hook(bpf_map_alloc_security, 0, map);
2192}
2193int security_bpf_prog_alloc(struct bpf_prog_aux *aux)
2194{
2195 return call_int_hook(bpf_prog_alloc_security, 0, aux);
2196}
2197void security_bpf_map_free(struct bpf_map *map)
2198{
2199 call_void_hook(bpf_map_free_security, map);
2200}
2201void security_bpf_prog_free(struct bpf_prog_aux *aux)
2202{
2203 call_void_hook(bpf_prog_free_security, aux);
2204}
2205#endif /* CONFIG_BPF_SYSCALL */