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