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