2 * Security plug functions
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>
7 * Copyright (C) 2016 Mellanox Technologies
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.
15 #include <linux/capability.h>
16 #include <linux/dcache.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/lsm_hooks.h>
21 #include <linux/integrity.h>
22 #include <linux/ima.h>
23 #include <linux/evm.h>
24 #include <linux/fsnotify.h>
25 #include <linux/mman.h>
26 #include <linux/mount.h>
27 #include <linux/personality.h>
28 #include <linux/backing-dev.h>
29 #include <linux/string.h>
30 #include <linux/msg.h>
31 #include <linux/prctl.h>
35 #define MAX_LSM_EVM_XATTR 2
37 /* Maximum number of letters for an LSM name string */
38 #define SECURITY_NAME_MAX 10
39 #define SECURITY_CHOSEN_NAMES_MAX (SECURITY_NAME_MAX * LSM_MAX_MAJOR)
40 #define MODULE_STACK "(stacking)"
42 struct security_hook_heads security_hook_heads __lsm_ro_after_init
;
43 static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain
);
48 * If stacking is enabled the task blob will always
49 * include an indicator of what security module data
50 * should be displayed. This is set with PR_SET_DISPLAY_LSM.
52 static struct lsm_blob_sizes blob_sizes
= {
53 #ifdef CONFIG_SECURITY_STACKING
54 .lbs_task
= SECURITY_NAME_MAX
+ 6,
58 /* Boot-time LSM user choice */
59 static __initdata
char chosen_lsms
[SECURITY_CHOSEN_NAMES_MAX
+ 1] =
60 #ifdef CONFIG_SECURITY_STACKING
63 CONFIG_DEFAULT_SECURITY
;
65 static __initdata
char chosen_display_lsm
[SECURITY_NAME_MAX
+ 1];
66 static char default_display_lsm
[SECURITY_NAME_MAX
+ 1];
68 static void __init
do_security_initcalls(void)
71 call
= __security_initcall_start
;
72 while (call
< __security_initcall_end
) {
79 * security_init - initializes the security framework
81 * This should be called early in the kernel initialization sequence.
83 int __init
security_init(void)
86 struct list_head
*list
= (struct list_head
*) &security_hook_heads
;
88 for (i
= 0; i
< sizeof(security_hook_heads
) / sizeof(struct list_head
);
90 INIT_LIST_HEAD(&list
[i
]);
91 pr_info("Security Framework initialized\n");
94 * Load minor LSMs, with the capability module always first.
96 capability_add_hooks();
101 * The first call to a module specific init function
102 * updates the blob size requirements.
104 do_security_initcalls();
107 * The second call to a module specific init function
108 * adds hooks to the hook lists and does any other early
109 * initializations required.
111 do_security_initcalls();
113 #ifdef CONFIG_SECURITY_LSM_DEBUG
114 pr_info("LSM: cred blob size = %d\n", blob_sizes
.lbs_cred
);
115 pr_info("LSM: file blob size = %d\n", blob_sizes
.lbs_file
);
116 pr_info("LSM: inode blob size = %d\n", blob_sizes
.lbs_inode
);
117 pr_info("LSM: ipc blob size = %d\n", blob_sizes
.lbs_ipc
);
119 pr_info("LSM: key blob size = %d\n", blob_sizes
.lbs_key
);
120 #endif /* CONFIG_KEYS */
121 pr_info("LSM: msg_msg blob size = %d\n", blob_sizes
.lbs_msg_msg
);
122 pr_info("LSM: sock blob size = %d\n", blob_sizes
.lbs_sock
);
123 pr_info("LSM: superblock blob size = %d\n", blob_sizes
.lbs_superblock
);
124 pr_info("LSM: task blob size = %d\n", blob_sizes
.lbs_task
);
125 #endif /* CONFIG_SECURITY_LSM_DEBUG */
130 /* Save user chosen LSM */
131 static int __init
choose_lsm(char *str
)
133 strncpy(chosen_lsms
, str
, SECURITY_CHOSEN_NAMES_MAX
);
134 pr_info("LSM: command line set '%s' security module(s).\n",
138 __setup("security=", choose_lsm
);
140 static int __init
choose_display_lsm(char *str
)
142 strncpy(chosen_display_lsm
, str
, SECURITY_NAME_MAX
);
143 pr_info("LSM: command line set default display lsm %s'\n",
147 __setup("security.display=", choose_display_lsm
);
149 static bool match_last_lsm(const char *list
, const char *lsm
)
153 if (WARN_ON(!list
|| !lsm
))
155 last
= strrchr(list
, ',');
157 /* Pass the comma, strcmp() will check for '\0' */
161 return !strcmp(last
, lsm
);
164 static int lsm_append(char *new, char **result
)
168 if (*result
== NULL
) {
169 *result
= kstrdup(new, GFP_KERNEL
);
171 /* Check if it is the last registered name */
172 if (match_last_lsm(*result
, new))
174 cp
= kasprintf(GFP_KERNEL
, "%s,%s", *result
, new);
184 * security_module_enable - Load given security module on boot ?
185 * @module: the name of the module
186 * @stacked: indicates that the module wants to be stacked
188 * Each LSM must pass this method before registering its own operations
189 * to avoid security registration races. This method may also be used
190 * to check if your LSM is currently loaded during kernel initialization.
196 * - The passed LSM is the one chosen by user at boot time,
197 * - or the passed LSM is configured as the default and the user did not
198 * choose an alternate LSM at boot time.
200 * Otherwise, return false.
202 #ifdef CONFIG_SECURITY_STACKING
203 static bool __init
cmp_lsms(const char *lsm
)
205 const char *str
= chosen_lsms
;
207 int len
= strlen(lsm
);
209 if (len
> SECURITY_NAME_MAX
) {
210 pr_info("LSM: security module name '%s' exceeds limit\n", lsm
);
213 for (split
= strchr(str
, ','); split
; split
= strchr(str
, ',')) {
214 if ((len
== split
- str
) && !strncmp(lsm
, str
, split
- str
))
218 if ((len
== strlen(str
)) && !strncmp(lsm
, str
, strlen(str
)))
224 bool __init
security_module_enable(const char *lsm
, const bool stacked
)
226 #ifdef CONFIG_SECURITY_STACKING
228 * Module defined on the command line security=XXXX
230 if (strcmp(chosen_lsms
, MODULE_STACK
)) {
232 /* set to first LSM registered and then override */
233 if (!*default_display_lsm
)
234 strcpy(default_display_lsm
, lsm
);
235 else if (*chosen_display_lsm
&& !strcmp(chosen_display_lsm
, lsm
)) {
236 strcpy(default_display_lsm
, lsm
);
237 pr_info("LSM: default display lsm '%s'\n", default_display_lsm
);
244 * Module configured as stacked.
246 if (stacked
&& !*default_display_lsm
)
247 strcpy(default_display_lsm
, lsm
);
248 else if (stacked
&& *chosen_display_lsm
&& !strcmp(chosen_display_lsm
, lsm
)) {
249 strcpy(default_display_lsm
, lsm
);
250 pr_info("LSM: default display lsm '%s'\n", default_display_lsm
);
255 if (strcmp(lsm
, chosen_lsms
) == 0) {
256 strcpy(default_display_lsm
, lsm
);
264 * Keep the order of major modules for mapping secids.
266 static int lsm_next_major
;
269 * security_add_hooks - Add a modules hooks to the hook lists.
270 * @hooks: the hooks to add
271 * @count: the number of hooks to add
272 * @lsm: the name of the security module
274 * Each LSM has to register its hooks with the infrastructure.
276 void __init
security_add_hooks(struct security_hook_list
*hooks
, int count
,
280 int lsm_index
= lsm_next_major
++;
282 #ifdef CONFIG_SECURITY_LSM_DEBUG
283 pr_info("LSM: Security module %s gets index %d\n", lsm
, lsm_index
);
285 for (i
= 0; i
< count
; i
++) {
287 hooks
[i
].lsm_index
= lsm_index
;
288 list_add_tail_rcu(&hooks
[i
].list
, hooks
[i
].head
);
290 if (lsm_append(lsm
, &lsm_names
) < 0)
291 panic("%s - Cannot get early memory.\n", __func__
);
294 int call_lsm_notifier(enum lsm_event event
, void *data
)
296 return atomic_notifier_call_chain(&lsm_notifier_chain
, event
, data
);
298 EXPORT_SYMBOL(call_lsm_notifier
);
300 int register_lsm_notifier(struct notifier_block
*nb
)
302 return atomic_notifier_chain_register(&lsm_notifier_chain
, nb
);
304 EXPORT_SYMBOL(register_lsm_notifier
);
306 int unregister_lsm_notifier(struct notifier_block
*nb
)
308 return atomic_notifier_chain_unregister(&lsm_notifier_chain
, nb
);
310 EXPORT_SYMBOL(unregister_lsm_notifier
);
313 * lsm_cred_alloc - allocate a composite cred blob
314 * @cred: the cred that needs a blob
315 * @gfp: allocation type
317 * Allocate the cred blob for all the modules
319 * Returns 0, or -ENOMEM if memory can't be allocated.
321 int lsm_cred_alloc(struct cred
*cred
, gfp_t gfp
)
323 #ifdef CONFIG_SECURITY_LSM_DEBUG
325 pr_info("%s: Inbound cred blob is not NULL.\n", __func__
);
327 if (blob_sizes
.lbs_cred
== 0)
330 cred
->security
= kzalloc(blob_sizes
.lbs_cred
, gfp
);
331 if (cred
->security
== NULL
)
337 * lsm_early_cred - during initialization allocate a composite cred blob
338 * @cred: the cred that needs a blob
340 * Allocate the cred blob for all the modules if it's not already there
342 void lsm_early_cred(struct cred
*cred
)
347 panic("%s: NULL cred.\n", __func__
);
348 if (cred
->security
!= NULL
)
350 rc
= lsm_cred_alloc(cred
, GFP_KERNEL
);
352 panic("%s: Early cred alloc failed.\n", __func__
);
355 static void __init
lsm_set_size(int *need
, int *lbs
)
367 * security_add_blobs - Report blob sizes
368 * @needed: the size of blobs needed by the module
370 * Each LSM has to register its blobs with the infrastructure.
371 * The "needed" data tells the infrastructure how much memory
372 * the module requires for each of its blobs. On return the
373 * structure is filled with the offset that module should use
374 * from the blob pointer.
376 void __init
security_add_blobs(struct lsm_blob_sizes
*needed
)
378 lsm_set_size(&needed
->lbs_cred
, &blob_sizes
.lbs_cred
);
379 lsm_set_size(&needed
->lbs_file
, &blob_sizes
.lbs_file
);
380 lsm_set_size(&needed
->lbs_ipc
, &blob_sizes
.lbs_ipc
);
381 lsm_set_size(&needed
->lbs_key
, &blob_sizes
.lbs_key
);
382 lsm_set_size(&needed
->lbs_msg_msg
, &blob_sizes
.lbs_msg_msg
);
383 lsm_set_size(&needed
->lbs_sock
, &blob_sizes
.lbs_sock
);
384 lsm_set_size(&needed
->lbs_superblock
, &blob_sizes
.lbs_superblock
);
385 lsm_set_size(&needed
->lbs_task
, &blob_sizes
.lbs_task
);
387 * The inode blob gets an rcu_head in addition to
388 * what the modules might need.
390 if (needed
->lbs_inode
&& blob_sizes
.lbs_inode
== 0)
391 blob_sizes
.lbs_inode
= sizeof(struct rcu_head
);
392 lsm_set_size(&needed
->lbs_inode
, &blob_sizes
.lbs_inode
);
396 * lsm_file_alloc - allocate a composite file blob
397 * @file: the file that needs a blob
399 * Allocate the file blob for all the modules
401 * Returns 0, or -ENOMEM if memory can't be allocated.
403 int lsm_file_alloc(struct file
*file
)
405 #ifdef CONFIG_SECURITY_LSM_DEBUG
406 if (file
->f_security
)
407 pr_info("%s: Inbound file blob is not NULL.\n", __func__
);
409 if (blob_sizes
.lbs_file
== 0)
412 file
->f_security
= kzalloc(blob_sizes
.lbs_file
, GFP_KERNEL
);
413 if (file
->f_security
== NULL
)
418 #ifdef CONFIG_SECURITY_STACKING
419 static inline char *lsm_of_task(struct task_struct
*task
)
421 #ifdef CONFIG_SECURITY_LSM_DEBUG
422 if (task
->security
== NULL
)
423 pr_info("%s: task has no lsm name.\n", __func__
);
425 return task
->security
;
429 #ifdef CONFIG_SECURITY_STACKING
436 * lsm_parse_context - break a compound "context" into module data
437 * @cxt: the initial data, which will be modified
438 * @vlist: an array to receive the results
440 * Returns the number of entries, or -EINVAL if the cxt is unworkable.
442 static int lsm_parse_context(char *cxt
, struct lsm_value
*vlist
)
450 for (i
= 0; i
< LSM_MAX_MAJOR
; i
++) {
451 data
= strstr(lsm
, "='");
456 cp
= strchr(data
, '\'');
461 vlist
[i
].data
= data
;
474 #endif /* CONFIG_SECURITY_STACKING */
477 * lsm_task_alloc - allocate a composite task blob
478 * @task: the task that needs a blob
480 * Allocate the task blob for all the modules
482 * Returns 0, or -ENOMEM if memory can't be allocated.
484 int lsm_task_alloc(struct task_struct
*task
)
486 #ifdef CONFIG_SECURITY_LSM_DEBUG
488 pr_info("%s: Inbound task blob is not NULL.\n", __func__
);
490 if (blob_sizes
.lbs_task
== 0)
493 task
->security
= kzalloc(blob_sizes
.lbs_task
, GFP_KERNEL
);
494 if (task
->security
== NULL
)
497 /* inherit current display lsm */
498 #ifdef CONFIG_SECURITY_STACKING
499 if (current
->security
)
500 strcpy(task
->security
, lsm_of_task(current
));
502 strcpy(task
->security
, default_display_lsm
);
508 * lsm_inode_alloc - allocate a composite inode blob
509 * @inode: the inode that needs a blob
511 * Allocate the inode blob for all the modules
513 * Returns 0, or -ENOMEM if memory can't be allocated.
515 int lsm_inode_alloc(struct inode
*inode
)
517 #ifdef CONFIG_SECURITY_LSM_DEBUG
518 if (inode
->i_security
)
519 pr_info("%s: Inbound inode blob is not NULL.\n", __func__
);
521 if (blob_sizes
.lbs_inode
== 0)
524 inode
->i_security
= kzalloc(blob_sizes
.lbs_inode
, GFP_KERNEL
);
525 if (inode
->i_security
== NULL
)
531 * lsm_early_inode - during initialization allocate a composite inode blob
532 * @inode: the inode that needs a blob
534 * Allocate the inode blob for all the modules if it's not already there
536 void lsm_early_inode(struct inode
*inode
)
541 panic("%s: NULL inode.\n", __func__
);
542 if (inode
->i_security
!= NULL
)
544 rc
= lsm_inode_alloc(inode
);
546 panic("%s: Early inode alloc failed.\n", __func__
);
550 * lsm_ipc_alloc - allocate a composite ipc blob
551 * @kip: the ipc that needs a blob
553 * Allocate the ipc blob for all the modules
555 * Returns 0, or -ENOMEM if memory can't be allocated.
557 int lsm_ipc_alloc(struct kern_ipc_perm
*kip
)
559 #ifdef CONFIG_SECURITY_LSM_DEBUG
561 pr_info("%s: Inbound ipc blob is not NULL.\n", __func__
);
563 if (blob_sizes
.lbs_ipc
== 0)
566 kip
->security
= kzalloc(blob_sizes
.lbs_ipc
, GFP_KERNEL
);
567 if (kip
->security
== NULL
)
574 * lsm_key_alloc - allocate a composite key blob
575 * @key: the key that needs a blob
577 * Allocate the key blob for all the modules
579 * Returns 0, or -ENOMEM if memory can't be allocated.
581 int lsm_key_alloc(struct key
*key
)
583 #ifdef CONFIG_SECURITY_LSM_DEBUG
585 pr_info("%s: Inbound key blob is not NULL.\n", __func__
);
587 if (blob_sizes
.lbs_key
== 0)
590 key
->security
= kzalloc(blob_sizes
.lbs_key
, GFP_KERNEL
);
591 if (key
->security
== NULL
)
595 #endif /* CONFIG_KEYS */
598 * lsm_msg_msg_alloc - allocate a composite msg_msg blob
599 * @mp: the msg_msg that needs a blob
601 * Allocate the ipc blob for all the modules
603 * Returns 0, or -ENOMEM if memory can't be allocated.
605 int lsm_msg_msg_alloc(struct msg_msg
*mp
)
607 #ifdef CONFIG_SECURITY_LSM_DEBUG
609 pr_info("%s: Inbound msg_msg blob is not NULL.\n", __func__
);
611 if (blob_sizes
.lbs_msg_msg
== 0)
614 mp
->security
= kzalloc(blob_sizes
.lbs_msg_msg
, GFP_KERNEL
);
615 if (mp
->security
== NULL
)
621 * lsm_sock_alloc - allocate a composite sock blob
622 * @sock: the sock that needs a blob
623 * @priority: allocation mode
625 * Allocate the sock blob for all the modules
627 * Returns 0, or -ENOMEM if memory can't be allocated.
629 int lsm_sock_alloc(struct sock
*sock
, gfp_t priority
)
631 #ifdef CONFIG_SECURITY_LSM_DEBUG
632 if (sock
->sk_security
)
633 pr_info("%s: Inbound sock blob is not NULL.\n", __func__
);
635 if (blob_sizes
.lbs_sock
== 0)
638 sock
->sk_security
= kzalloc(blob_sizes
.lbs_sock
, priority
);
639 if (sock
->sk_security
== NULL
)
645 * lsm_superblock_alloc - allocate a composite superblock blob
646 * @sb: the superblock that needs a blob
648 * Allocate the superblock blob for all the modules
650 * Returns 0, or -ENOMEM if memory can't be allocated.
652 int lsm_superblock_alloc(struct super_block
*sb
)
654 #ifdef CONFIG_SECURITY_LSM_DEBUG
656 pr_info("%s: Inbound superblock blob is not NULL.\n", __func__
);
658 if (blob_sizes
.lbs_superblock
== 0)
661 sb
->s_security
= kzalloc(blob_sizes
.lbs_superblock
, GFP_KERNEL
);
662 if (sb
->s_security
== NULL
)
668 * Hook list operation macros.
671 * This is a hook that does not return a value.
674 * This is a hook that returns a value.
677 #define call_void_hook(FUNC, ...) \
679 struct security_hook_list *P; \
681 list_for_each_entry(P, &security_hook_heads.FUNC, list) \
682 P->hook.FUNC(__VA_ARGS__); \
685 #define call_int_hook(FUNC, IRC, ...) ({ \
688 struct security_hook_list *P; \
690 list_for_each_entry(P, &security_hook_heads.FUNC, list) { \
691 RC = P->hook.FUNC(__VA_ARGS__); \
699 /* Security operations */
701 int security_binder_set_context_mgr(struct task_struct
*mgr
)
703 return call_int_hook(binder_set_context_mgr
, 0, mgr
);
706 int security_binder_transaction(struct task_struct
*from
,
707 struct task_struct
*to
)
709 return call_int_hook(binder_transaction
, 0, from
, to
);
712 int security_binder_transfer_binder(struct task_struct
*from
,
713 struct task_struct
*to
)
715 return call_int_hook(binder_transfer_binder
, 0, from
, to
);
718 int security_binder_transfer_file(struct task_struct
*from
,
719 struct task_struct
*to
, struct file
*file
)
721 return call_int_hook(binder_transfer_file
, 0, from
, to
, file
);
724 int security_ptrace_access_check(struct task_struct
*child
, unsigned int mode
)
726 return call_int_hook(ptrace_access_check
, 0, child
, mode
);
729 int security_ptrace_traceme(struct task_struct
*parent
)
731 return call_int_hook(ptrace_traceme
, 0, parent
);
734 int security_capget(struct task_struct
*target
,
735 kernel_cap_t
*effective
,
736 kernel_cap_t
*inheritable
,
737 kernel_cap_t
*permitted
)
739 return call_int_hook(capget
, 0, target
,
740 effective
, inheritable
, permitted
);
743 int security_capset(struct cred
*new, const struct cred
*old
,
744 const kernel_cap_t
*effective
,
745 const kernel_cap_t
*inheritable
,
746 const kernel_cap_t
*permitted
)
748 return call_int_hook(capset
, 0, new, old
,
749 effective
, inheritable
, permitted
);
752 int security_capable(const struct cred
*cred
, struct user_namespace
*ns
,
755 return call_int_hook(capable
, 0, cred
, ns
, cap
, SECURITY_CAP_AUDIT
);
758 int security_capable_noaudit(const struct cred
*cred
, struct user_namespace
*ns
,
761 return call_int_hook(capable
, 0, cred
, ns
, cap
, SECURITY_CAP_NOAUDIT
);
764 int security_quotactl(int cmds
, int type
, int id
, struct super_block
*sb
)
766 return call_int_hook(quotactl
, 0, cmds
, type
, id
, sb
);
769 int security_quota_on(struct dentry
*dentry
)
771 return call_int_hook(quota_on
, 0, dentry
);
774 int security_syslog(int type
)
776 return call_int_hook(syslog
, 0, type
);
779 int security_settime64(const struct timespec64
*ts
, const struct timezone
*tz
)
781 return call_int_hook(settime
, 0, ts
, tz
);
784 int security_vm_enough_memory_mm(struct mm_struct
*mm
, long pages
)
786 struct security_hook_list
*hp
;
787 int cap_sys_admin
= 1;
791 * The module will respond with a positive value if
792 * it thinks the __vm_enough_memory() call should be
793 * made with the cap_sys_admin set. If all of the modules
794 * agree that it should be set it will. If any module
795 * thinks it should not be set it won't.
797 list_for_each_entry(hp
, &security_hook_heads
.vm_enough_memory
, list
) {
798 rc
= hp
->hook
.vm_enough_memory(mm
, pages
);
804 return __vm_enough_memory(mm
, pages
, cap_sys_admin
);
807 int security_bprm_set_creds(struct linux_binprm
*bprm
)
809 return call_int_hook(bprm_set_creds
, 0, bprm
);
812 int security_bprm_check(struct linux_binprm
*bprm
)
816 ret
= call_int_hook(bprm_check_security
, 0, bprm
);
819 return ima_bprm_check(bprm
);
822 void security_bprm_committing_creds(struct linux_binprm
*bprm
)
824 call_void_hook(bprm_committing_creds
, bprm
);
827 void security_bprm_committed_creds(struct linux_binprm
*bprm
)
829 call_void_hook(bprm_committed_creds
, bprm
);
832 int security_bprm_secureexec(struct linux_binprm
*bprm
)
834 return call_int_hook(bprm_secureexec
, 0, bprm
);
837 int security_sb_alloc(struct super_block
*sb
)
839 int rc
= lsm_superblock_alloc(sb
);
843 return call_int_hook(sb_alloc_security
, 0, sb
);
846 void security_sb_free(struct super_block
*sb
)
848 call_void_hook(sb_free_security
, sb
);
849 kfree(sb
->s_security
);
850 sb
->s_security
= NULL
;
853 int security_sb_copy_data(char *orig
, char *copy
)
855 return call_int_hook(sb_copy_data
, 0, orig
, copy
);
857 EXPORT_SYMBOL(security_sb_copy_data
);
859 int security_sb_remount(struct super_block
*sb
, void *data
)
861 return call_int_hook(sb_remount
, 0, sb
, data
);
864 int security_sb_kern_mount(struct super_block
*sb
, int flags
, void *data
)
866 return call_int_hook(sb_kern_mount
, 0, sb
, flags
, data
);
869 int security_sb_show_options(struct seq_file
*m
, struct super_block
*sb
)
871 return call_int_hook(sb_show_options
, 0, m
, sb
);
874 int security_sb_statfs(struct dentry
*dentry
)
876 return call_int_hook(sb_statfs
, 0, dentry
);
879 int security_sb_mount(const char *dev_name
, const struct path
*path
,
880 const char *type
, unsigned long flags
, void *data
)
882 return call_int_hook(sb_mount
, 0, dev_name
, path
, type
, flags
, data
);
885 int security_sb_umount(struct vfsmount
*mnt
, int flags
)
887 return call_int_hook(sb_umount
, 0, mnt
, flags
);
890 int security_sb_pivotroot(const struct path
*old_path
, const struct path
*new_path
)
892 return call_int_hook(sb_pivotroot
, 0, old_path
, new_path
);
895 int security_sb_set_mnt_opts(struct super_block
*sb
,
896 struct security_mnt_opts
*opts
,
897 unsigned long kern_flags
,
898 unsigned long *set_kern_flags
)
900 return call_int_hook(sb_set_mnt_opts
,
901 opts
->num_mnt_opts
? -EOPNOTSUPP
: 0, sb
,
902 opts
, kern_flags
, set_kern_flags
);
904 EXPORT_SYMBOL(security_sb_set_mnt_opts
);
906 int security_sb_clone_mnt_opts(const struct super_block
*oldsb
,
907 struct super_block
*newsb
,
908 unsigned long kern_flags
,
909 unsigned long *set_kern_flags
)
911 return call_int_hook(sb_clone_mnt_opts
, 0, oldsb
, newsb
,
912 kern_flags
, set_kern_flags
);
914 EXPORT_SYMBOL(security_sb_clone_mnt_opts
);
916 int security_sb_parse_opts_str(char *options
, struct security_mnt_opts
*opts
)
918 return call_int_hook(sb_parse_opts_str
, 0, options
, opts
);
920 EXPORT_SYMBOL(security_sb_parse_opts_str
);
922 int security_inode_alloc(struct inode
*inode
)
924 int rc
= lsm_inode_alloc(inode
);
928 return call_int_hook(inode_alloc_security
, 0, inode
);
931 static void inode_free_by_rcu(struct rcu_head
*head
)
934 * The rcu head is at the start of the inode blob
939 void security_inode_free(struct inode
*inode
)
941 integrity_inode_free(inode
);
942 call_void_hook(inode_free_security
, inode
);
944 * The inode may still be referenced in a path walk and
945 * a call to security_inode_permission() can be made
946 * after inode_free_security() is called. Ideally, the VFS
947 * wouldn't do this, but fixing that is a much harder
948 * job. For now, simply free the i_security via RCU, and
949 * leave the current inode->i_security pointer intact.
950 * The inode will be freed after the RCU grace period too.
952 if (inode
->i_security
!= NULL
) {
953 call_rcu((struct rcu_head
*)inode
->i_security
,
955 inode
->i_security
= NULL
;
959 int security_dentry_init_security(struct dentry
*dentry
, int mode
,
960 const struct qstr
*name
, void **ctx
,
963 return call_int_hook(dentry_init_security
, -EOPNOTSUPP
, dentry
, mode
,
966 EXPORT_SYMBOL(security_dentry_init_security
);
968 int security_dentry_create_files_as(struct dentry
*dentry
, int mode
,
970 const struct cred
*old
, struct cred
*new)
972 return call_int_hook(dentry_create_files_as
, 0, dentry
, mode
,
975 EXPORT_SYMBOL(security_dentry_create_files_as
);
977 int security_inode_init_security(struct inode
*inode
, struct inode
*dir
,
978 const struct qstr
*qstr
,
979 const initxattrs initxattrs
, void *fs_data
)
981 struct xattr new_xattrs
[MAX_LSM_EVM_XATTR
+ 1];
982 struct xattr
*lsm_xattr
, *evm_xattr
, *xattr
;
985 if (unlikely(IS_PRIVATE(inode
)))
989 return call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
,
990 dir
, qstr
, NULL
, NULL
, NULL
);
991 memset(new_xattrs
, 0, sizeof(new_xattrs
));
992 lsm_xattr
= new_xattrs
;
993 ret
= call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
, dir
, qstr
,
996 &lsm_xattr
->value_len
);
1000 evm_xattr
= lsm_xattr
+ 1;
1001 ret
= evm_inode_init_security(inode
, lsm_xattr
, evm_xattr
);
1004 ret
= initxattrs(inode
, new_xattrs
, fs_data
);
1006 for (xattr
= new_xattrs
; xattr
->value
!= NULL
; xattr
++)
1007 kfree(xattr
->value
);
1008 return (ret
== -EOPNOTSUPP
) ? 0 : ret
;
1010 EXPORT_SYMBOL(security_inode_init_security
);
1012 int security_old_inode_init_security(struct inode
*inode
, struct inode
*dir
,
1013 const struct qstr
*qstr
, const char **name
,
1014 void **value
, size_t *len
)
1016 if (unlikely(IS_PRIVATE(inode
)))
1018 return call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
, dir
,
1019 qstr
, name
, value
, len
);
1021 EXPORT_SYMBOL(security_old_inode_init_security
);
1023 #ifdef CONFIG_SECURITY_PATH
1024 int security_path_mknod(const struct path
*dir
, struct dentry
*dentry
, umode_t mode
,
1027 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1029 return call_int_hook(path_mknod
, 0, dir
, dentry
, mode
, dev
);
1031 EXPORT_SYMBOL(security_path_mknod
);
1033 int security_path_mkdir(const struct path
*dir
, struct dentry
*dentry
, umode_t mode
)
1035 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1037 return call_int_hook(path_mkdir
, 0, dir
, dentry
, mode
);
1039 EXPORT_SYMBOL(security_path_mkdir
);
1041 int security_path_rmdir(const struct path
*dir
, struct dentry
*dentry
)
1043 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1045 return call_int_hook(path_rmdir
, 0, dir
, dentry
);
1047 EXPORT_SYMBOL_GPL(security_path_rmdir
);
1049 int security_path_unlink(const struct path
*dir
, struct dentry
*dentry
)
1051 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1053 return call_int_hook(path_unlink
, 0, dir
, dentry
);
1055 EXPORT_SYMBOL(security_path_unlink
);
1057 int security_path_symlink(const struct path
*dir
, struct dentry
*dentry
,
1058 const char *old_name
)
1060 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1062 return call_int_hook(path_symlink
, 0, dir
, dentry
, old_name
);
1064 EXPORT_SYMBOL_GPL(security_path_symlink
);
1066 int security_path_link(struct dentry
*old_dentry
, const struct path
*new_dir
,
1067 struct dentry
*new_dentry
)
1069 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
))))
1071 return call_int_hook(path_link
, 0, old_dentry
, new_dir
, new_dentry
);
1073 EXPORT_SYMBOL_GPL(security_path_link
);
1075 int security_path_rename(const struct path
*old_dir
, struct dentry
*old_dentry
,
1076 const struct path
*new_dir
, struct dentry
*new_dentry
,
1079 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
)) ||
1080 (d_is_positive(new_dentry
) && IS_PRIVATE(d_backing_inode(new_dentry
)))))
1083 if (flags
& RENAME_EXCHANGE
) {
1084 int err
= call_int_hook(path_rename
, 0, new_dir
, new_dentry
,
1085 old_dir
, old_dentry
);
1090 return call_int_hook(path_rename
, 0, old_dir
, old_dentry
, new_dir
,
1093 EXPORT_SYMBOL(security_path_rename
);
1095 int security_path_truncate(const struct path
*path
)
1097 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1099 return call_int_hook(path_truncate
, 0, path
);
1101 EXPORT_SYMBOL_GPL(security_path_truncate
);
1103 int security_path_chmod(const struct path
*path
, umode_t mode
)
1105 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1107 return call_int_hook(path_chmod
, 0, path
, mode
);
1109 EXPORT_SYMBOL_GPL(security_path_chmod
);
1111 int security_path_chown(const struct path
*path
, kuid_t uid
, kgid_t gid
)
1113 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1115 return call_int_hook(path_chown
, 0, path
, uid
, gid
);
1117 EXPORT_SYMBOL_GPL(security_path_chown
);
1119 int security_path_chroot(const struct path
*path
)
1121 return call_int_hook(path_chroot
, 0, path
);
1125 int security_inode_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
1127 if (unlikely(IS_PRIVATE(dir
)))
1129 return call_int_hook(inode_create
, 0, dir
, dentry
, mode
);
1131 EXPORT_SYMBOL_GPL(security_inode_create
);
1133 int security_inode_link(struct dentry
*old_dentry
, struct inode
*dir
,
1134 struct dentry
*new_dentry
)
1136 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
))))
1138 return call_int_hook(inode_link
, 0, old_dentry
, dir
, new_dentry
);
1141 int security_inode_unlink(struct inode
*dir
, struct dentry
*dentry
)
1143 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1145 return call_int_hook(inode_unlink
, 0, dir
, dentry
);
1148 int security_inode_symlink(struct inode
*dir
, struct dentry
*dentry
,
1149 const char *old_name
)
1151 if (unlikely(IS_PRIVATE(dir
)))
1153 return call_int_hook(inode_symlink
, 0, dir
, dentry
, old_name
);
1156 int security_inode_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
1158 if (unlikely(IS_PRIVATE(dir
)))
1160 return call_int_hook(inode_mkdir
, 0, dir
, dentry
, mode
);
1162 EXPORT_SYMBOL_GPL(security_inode_mkdir
);
1164 int security_inode_rmdir(struct inode
*dir
, struct dentry
*dentry
)
1166 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1168 return call_int_hook(inode_rmdir
, 0, dir
, dentry
);
1171 int security_inode_mknod(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
, dev_t dev
)
1173 if (unlikely(IS_PRIVATE(dir
)))
1175 return call_int_hook(inode_mknod
, 0, dir
, dentry
, mode
, dev
);
1178 int security_inode_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1179 struct inode
*new_dir
, struct dentry
*new_dentry
,
1182 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
)) ||
1183 (d_is_positive(new_dentry
) && IS_PRIVATE(d_backing_inode(new_dentry
)))))
1186 if (flags
& RENAME_EXCHANGE
) {
1187 int err
= call_int_hook(inode_rename
, 0, new_dir
, new_dentry
,
1188 old_dir
, old_dentry
);
1193 return call_int_hook(inode_rename
, 0, old_dir
, old_dentry
,
1194 new_dir
, new_dentry
);
1197 int security_inode_readlink(struct dentry
*dentry
)
1199 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1201 return call_int_hook(inode_readlink
, 0, dentry
);
1203 EXPORT_SYMBOL_GPL(security_inode_readlink
);
1205 int security_inode_follow_link(struct dentry
*dentry
, struct inode
*inode
,
1208 if (unlikely(IS_PRIVATE(inode
)))
1210 return call_int_hook(inode_follow_link
, 0, dentry
, inode
, rcu
);
1213 int security_inode_permission(struct inode
*inode
, int mask
)
1215 if (unlikely(IS_PRIVATE(inode
)))
1217 return call_int_hook(inode_permission
, 0, inode
, mask
);
1219 EXPORT_SYMBOL_GPL(security_inode_permission
);
1221 int security_inode_setattr(struct dentry
*dentry
, struct iattr
*attr
)
1225 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1227 ret
= call_int_hook(inode_setattr
, 0, dentry
, attr
);
1230 return evm_inode_setattr(dentry
, attr
);
1232 EXPORT_SYMBOL_GPL(security_inode_setattr
);
1234 int security_inode_getattr(const struct path
*path
)
1236 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1238 return call_int_hook(inode_getattr
, 0, path
);
1241 int security_inode_setxattr(struct dentry
*dentry
, const char *name
,
1242 const void *value
, size_t size
, int flags
)
1246 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1249 * SELinux and Smack integrate the cap call,
1250 * so assume that all LSMs supplying this call do so.
1252 ret
= call_int_hook(inode_setxattr
, 1, dentry
, name
, value
, size
,
1256 ret
= cap_inode_setxattr(dentry
, name
, value
, size
, flags
);
1259 ret
= ima_inode_setxattr(dentry
, name
, value
, size
);
1262 return evm_inode_setxattr(dentry
, name
, value
, size
);
1265 void security_inode_post_setxattr(struct dentry
*dentry
, const char *name
,
1266 const void *value
, size_t size
, int flags
)
1268 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1270 call_void_hook(inode_post_setxattr
, dentry
, name
, value
, size
, flags
);
1271 evm_inode_post_setxattr(dentry
, name
, value
, size
);
1274 int security_inode_getxattr(struct dentry
*dentry
, const char *name
)
1276 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1278 return call_int_hook(inode_getxattr
, 0, dentry
, name
);
1281 int security_inode_listxattr(struct dentry
*dentry
)
1283 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1285 return call_int_hook(inode_listxattr
, 0, dentry
);
1288 int security_inode_removexattr(struct dentry
*dentry
, const char *name
)
1292 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1295 * SELinux and Smack integrate the cap call,
1296 * so assume that all LSMs supplying this call do so.
1298 ret
= call_int_hook(inode_removexattr
, 1, dentry
, name
);
1300 ret
= cap_inode_removexattr(dentry
, name
);
1303 ret
= ima_inode_removexattr(dentry
, name
);
1306 return evm_inode_removexattr(dentry
, name
);
1309 int security_inode_need_killpriv(struct dentry
*dentry
)
1311 return call_int_hook(inode_need_killpriv
, 0, dentry
);
1314 int security_inode_killpriv(struct dentry
*dentry
)
1316 return call_int_hook(inode_killpriv
, 0, dentry
);
1319 int security_inode_getsecurity(struct inode
*inode
, const char *name
, void **buffer
, bool alloc
)
1321 struct security_hook_list
*hp
;
1324 if (unlikely(IS_PRIVATE(inode
)))
1327 * Only one module will provide an attribute with a given name.
1329 list_for_each_entry(hp
, &security_hook_heads
.inode_getsecurity
, list
) {
1330 rc
= hp
->hook
.inode_getsecurity(inode
, name
, buffer
, alloc
);
1331 if (rc
!= -EOPNOTSUPP
)
1337 int security_inode_setsecurity(struct inode
*inode
, const char *name
, const void *value
, size_t size
, int flags
)
1339 struct security_hook_list
*hp
;
1342 if (unlikely(IS_PRIVATE(inode
)))
1345 * Only one module will provide an attribute with a given name.
1347 list_for_each_entry(hp
, &security_hook_heads
.inode_setsecurity
, list
) {
1348 rc
= hp
->hook
.inode_setsecurity(inode
, name
, value
, size
,
1350 if (rc
!= -EOPNOTSUPP
)
1356 int security_inode_listsecurity(struct inode
*inode
, char *buffer
, size_t buffer_size
)
1358 if (unlikely(IS_PRIVATE(inode
)))
1360 return call_int_hook(inode_listsecurity
, 0, inode
, buffer
, buffer_size
);
1362 EXPORT_SYMBOL(security_inode_listsecurity
);
1364 void security_inode_getsecid(struct inode
*inode
, u32
*secid
)
1366 call_void_hook(inode_getsecid
, inode
, secid
);
1369 int security_inode_copy_up(struct dentry
*src
, struct cred
**new)
1371 return call_int_hook(inode_copy_up
, 0, src
, new);
1373 EXPORT_SYMBOL(security_inode_copy_up
);
1375 int security_inode_copy_up_xattr(const char *name
)
1377 return call_int_hook(inode_copy_up_xattr
, -EOPNOTSUPP
, name
);
1379 EXPORT_SYMBOL(security_inode_copy_up_xattr
);
1381 int security_file_permission(struct file
*file
, int mask
)
1385 ret
= call_int_hook(file_permission
, 0, file
, mask
);
1389 return fsnotify_perm(file
, mask
);
1391 EXPORT_SYMBOL_GPL(security_file_permission
);
1393 int security_file_alloc(struct file
*file
)
1395 int rc
= lsm_file_alloc(file
);
1399 return call_int_hook(file_alloc_security
, 0, file
);
1402 void security_file_free(struct file
*file
)
1404 call_void_hook(file_free_security
, file
);
1406 kfree(file
->f_security
);
1407 file
->f_security
= NULL
;
1410 int security_file_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1412 return call_int_hook(file_ioctl
, 0, file
, cmd
, arg
);
1415 static inline unsigned long mmap_prot(struct file
*file
, unsigned long prot
)
1418 * Does we have PROT_READ and does the application expect
1419 * it to imply PROT_EXEC? If not, nothing to talk about...
1421 if ((prot
& (PROT_READ
| PROT_EXEC
)) != PROT_READ
)
1423 if (!(current
->personality
& READ_IMPLIES_EXEC
))
1426 * if that's an anonymous mapping, let it.
1429 return prot
| PROT_EXEC
;
1431 * ditto if it's not on noexec mount, except that on !MMU we need
1432 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
1434 if (!path_noexec(&file
->f_path
)) {
1436 if (file
->f_op
->mmap_capabilities
) {
1437 unsigned caps
= file
->f_op
->mmap_capabilities(file
);
1438 if (!(caps
& NOMMU_MAP_EXEC
))
1442 return prot
| PROT_EXEC
;
1444 /* anything on noexec mount won't get PROT_EXEC */
1448 int security_mmap_file(struct file
*file
, unsigned long prot
,
1449 unsigned long flags
)
1452 ret
= call_int_hook(mmap_file
, 0, file
, prot
,
1453 mmap_prot(file
, prot
), flags
);
1456 return ima_file_mmap(file
, prot
);
1458 EXPORT_SYMBOL_GPL(security_mmap_file
);
1460 int security_mmap_addr(unsigned long addr
)
1462 return call_int_hook(mmap_addr
, 0, addr
);
1465 int security_file_mprotect(struct vm_area_struct
*vma
, unsigned long reqprot
,
1468 return call_int_hook(file_mprotect
, 0, vma
, reqprot
, prot
);
1471 int security_file_lock(struct file
*file
, unsigned int cmd
)
1473 return call_int_hook(file_lock
, 0, file
, cmd
);
1476 int security_file_fcntl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1478 return call_int_hook(file_fcntl
, 0, file
, cmd
, arg
);
1481 void security_file_set_fowner(struct file
*file
)
1483 call_void_hook(file_set_fowner
, file
);
1486 int security_file_send_sigiotask(struct task_struct
*tsk
,
1487 struct fown_struct
*fown
, int sig
)
1489 return call_int_hook(file_send_sigiotask
, 0, tsk
, fown
, sig
);
1492 int security_file_receive(struct file
*file
)
1494 return call_int_hook(file_receive
, 0, file
);
1497 int security_file_open(struct file
*file
, const struct cred
*cred
)
1501 ret
= call_int_hook(file_open
, 0, file
, cred
);
1505 return fsnotify_perm(file
, MAY_OPEN
);
1508 int security_task_create(unsigned long clone_flags
)
1510 return call_int_hook(task_create
, 0, clone_flags
);
1513 int security_task_alloc(struct task_struct
*task
, unsigned long clone_flags
)
1515 int rc
= lsm_task_alloc(task
);
1519 return call_int_hook(task_alloc
, 0, task
, clone_flags
);
1522 void security_task_free(struct task_struct
*task
)
1524 call_void_hook(task_free
, task
);
1526 kfree(task
->security
);
1527 task
->security
= NULL
;
1530 int security_cred_alloc_blank(struct cred
*cred
, gfp_t gfp
)
1532 int rc
= lsm_cred_alloc(cred
, gfp
);
1537 return call_int_hook(cred_alloc_blank
, 0, cred
, gfp
);
1540 void security_cred_free(struct cred
*cred
)
1542 call_void_hook(cred_free
, cred
);
1544 kfree(cred
->security
);
1545 cred
->security
= NULL
;
1548 int security_prepare_creds(struct cred
*new, const struct cred
*old
, gfp_t gfp
)
1550 int rc
= lsm_cred_alloc(new, gfp
);
1555 return call_int_hook(cred_prepare
, 0, new, old
, gfp
);
1558 void security_transfer_creds(struct cred
*new, const struct cred
*old
)
1560 call_void_hook(cred_transfer
, new, old
);
1563 int security_kernel_act_as(struct cred
*new, u32 secid
)
1565 return call_int_hook(kernel_act_as
, 0, new, secid
);
1568 int security_kernel_create_files_as(struct cred
*new, struct inode
*inode
)
1570 return call_int_hook(kernel_create_files_as
, 0, new, inode
);
1573 int security_kernel_module_request(char *kmod_name
)
1575 return call_int_hook(kernel_module_request
, 0, kmod_name
);
1578 int security_kernel_read_file(struct file
*file
, enum kernel_read_file_id id
)
1582 ret
= call_int_hook(kernel_read_file
, 0, file
, id
);
1585 return ima_read_file(file
, id
);
1587 EXPORT_SYMBOL_GPL(security_kernel_read_file
);
1589 int security_kernel_post_read_file(struct file
*file
, char *buf
, loff_t size
,
1590 enum kernel_read_file_id id
)
1594 ret
= call_int_hook(kernel_post_read_file
, 0, file
, buf
, size
, id
);
1597 return ima_post_read_file(file
, buf
, size
, id
);
1599 EXPORT_SYMBOL_GPL(security_kernel_post_read_file
);
1601 int security_task_fix_setuid(struct cred
*new, const struct cred
*old
,
1604 return call_int_hook(task_fix_setuid
, 0, new, old
, flags
);
1607 int security_task_setpgid(struct task_struct
*p
, pid_t pgid
)
1609 return call_int_hook(task_setpgid
, 0, p
, pgid
);
1612 int security_task_getpgid(struct task_struct
*p
)
1614 return call_int_hook(task_getpgid
, 0, p
);
1617 int security_task_getsid(struct task_struct
*p
)
1619 return call_int_hook(task_getsid
, 0, p
);
1622 void security_task_getsecid(struct task_struct
*p
, u32
*secid
)
1625 call_void_hook(task_getsecid
, p
, secid
);
1627 EXPORT_SYMBOL(security_task_getsecid
);
1629 int security_task_setnice(struct task_struct
*p
, int nice
)
1631 return call_int_hook(task_setnice
, 0, p
, nice
);
1634 int security_task_setioprio(struct task_struct
*p
, int ioprio
)
1636 return call_int_hook(task_setioprio
, 0, p
, ioprio
);
1639 int security_task_getioprio(struct task_struct
*p
)
1641 return call_int_hook(task_getioprio
, 0, p
);
1644 int security_task_prlimit(const struct cred
*cred
, const struct cred
*tcred
,
1647 return call_int_hook(task_prlimit
, 0, cred
, tcred
, flags
);
1650 int security_task_setrlimit(struct task_struct
*p
, unsigned int resource
,
1651 struct rlimit
*new_rlim
)
1653 return call_int_hook(task_setrlimit
, 0, p
, resource
, new_rlim
);
1656 int security_task_setscheduler(struct task_struct
*p
)
1658 return call_int_hook(task_setscheduler
, 0, p
);
1661 int security_task_getscheduler(struct task_struct
*p
)
1663 return call_int_hook(task_getscheduler
, 0, p
);
1666 int security_task_movememory(struct task_struct
*p
)
1668 return call_int_hook(task_movememory
, 0, p
);
1671 int security_task_kill(struct task_struct
*p
, struct siginfo
*info
,
1674 return call_int_hook(task_kill
, 0, p
, info
, sig
, secid
);
1677 #ifdef CONFIG_SECURITY_STACKING
1678 static char *nolsm
= "-default";
1681 static int lsm_task_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
1682 unsigned long arg4
, unsigned long arg5
)
1684 char *lsm
= lsm_of_task(current
);
1685 char buffer
[SECURITY_NAME_MAX
+ 1];
1686 __user
char *optval
= (__user
char *)arg2
;
1687 __user
int *optlen
= (__user
int *)arg3
;
1688 struct security_hook_list
*hp
;
1693 case PR_GET_DISPLAY_LSM
:
1695 if (lsm
[0] == '\0') {
1699 dlen
= strlen(lsm
) + 1;
1702 if (copy_to_user(optval
, lsm
, dlen
))
1704 if (put_user(dlen
, optlen
))
1707 case PR_SET_DISPLAY_LSM
:
1709 if (len
> SECURITY_NAME_MAX
)
1711 if (copy_from_user(buffer
, optval
, len
))
1714 /* verify the requested LSM is registered */
1715 list_for_each_entry(hp
, &security_hook_heads
.getprocattr
, list
) {
1716 if (!strcmp(buffer
, hp
->lsm
)) {
1717 strcpy(lsm
, hp
->lsm
);
1721 if (!strncmp(buffer
, nolsm
, NOLSMLEN
))
1734 int security_task_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
1735 unsigned long arg4
, unsigned long arg5
)
1739 struct security_hook_list
*hp
;
1741 #ifdef CONFIG_SECURITY_STACKING
1742 rc
= lsm_task_prctl(option
, arg2
, arg3
, arg4
, arg5
);
1747 list_for_each_entry(hp
, &security_hook_heads
.task_prctl
, list
) {
1748 thisrc
= hp
->hook
.task_prctl(option
, arg2
, arg3
, arg4
, arg5
);
1749 if (thisrc
!= -ENOSYS
) {
1758 void security_task_to_inode(struct task_struct
*p
, struct inode
*inode
)
1760 call_void_hook(task_to_inode
, p
, inode
);
1763 int security_ipc_permission(struct kern_ipc_perm
*ipcp
, short flag
)
1765 return call_int_hook(ipc_permission
, 0, ipcp
, flag
);
1768 void security_ipc_getsecid(struct kern_ipc_perm
*ipcp
, u32
*secid
)
1771 call_void_hook(ipc_getsecid
, ipcp
, secid
);
1774 int security_msg_msg_alloc(struct msg_msg
*msg
)
1776 int rc
= lsm_msg_msg_alloc(msg
);
1780 return call_int_hook(msg_msg_alloc_security
, 0, msg
);
1783 void security_msg_msg_free(struct msg_msg
*msg
)
1785 call_void_hook(msg_msg_free_security
, msg
);
1786 kfree(msg
->security
);
1787 msg
->security
= NULL
;
1790 int security_msg_queue_alloc(struct msg_queue
*msq
)
1792 int rc
= lsm_ipc_alloc(&msq
->q_perm
);
1796 return call_int_hook(msg_queue_alloc_security
, 0, msq
);
1799 void security_msg_queue_free(struct msg_queue
*msq
)
1801 struct kern_ipc_perm
*kip
= &msq
->q_perm
;
1803 call_void_hook(msg_queue_free_security
, msq
);
1804 kfree(kip
->security
);
1805 kip
->security
= NULL
;
1808 int security_msg_queue_associate(struct msg_queue
*msq
, int msqflg
)
1810 return call_int_hook(msg_queue_associate
, 0, msq
, msqflg
);
1813 int security_msg_queue_msgctl(struct msg_queue
*msq
, int cmd
)
1815 return call_int_hook(msg_queue_msgctl
, 0, msq
, cmd
);
1818 int security_msg_queue_msgsnd(struct msg_queue
*msq
,
1819 struct msg_msg
*msg
, int msqflg
)
1821 return call_int_hook(msg_queue_msgsnd
, 0, msq
, msg
, msqflg
);
1824 int security_msg_queue_msgrcv(struct msg_queue
*msq
, struct msg_msg
*msg
,
1825 struct task_struct
*target
, long type
, int mode
)
1827 return call_int_hook(msg_queue_msgrcv
, 0, msq
, msg
, target
, type
, mode
);
1830 int security_shm_alloc(struct shmid_kernel
*shp
)
1832 int rc
= lsm_ipc_alloc(&shp
->shm_perm
);
1836 return call_int_hook(shm_alloc_security
, 0, shp
);
1839 void security_shm_free(struct shmid_kernel
*shp
)
1841 struct kern_ipc_perm
*kip
= &shp
->shm_perm
;
1843 call_void_hook(shm_free_security
, shp
);
1844 kfree(kip
->security
);
1845 kip
->security
= NULL
;
1848 int security_shm_associate(struct shmid_kernel
*shp
, int shmflg
)
1850 return call_int_hook(shm_associate
, 0, shp
, shmflg
);
1853 int security_shm_shmctl(struct shmid_kernel
*shp
, int cmd
)
1855 return call_int_hook(shm_shmctl
, 0, shp
, cmd
);
1858 int security_shm_shmat(struct shmid_kernel
*shp
, char __user
*shmaddr
, int shmflg
)
1860 return call_int_hook(shm_shmat
, 0, shp
, shmaddr
, shmflg
);
1863 int security_sem_alloc(struct sem_array
*sma
)
1865 int rc
= lsm_ipc_alloc(&sma
->sem_perm
);
1869 return call_int_hook(sem_alloc_security
, 0, sma
);
1872 void security_sem_free(struct sem_array
*sma
)
1874 struct kern_ipc_perm
*kip
= &sma
->sem_perm
;
1876 call_void_hook(sem_free_security
, sma
);
1877 kfree(kip
->security
);
1878 kip
->security
= NULL
;
1881 int security_sem_associate(struct sem_array
*sma
, int semflg
)
1883 return call_int_hook(sem_associate
, 0, sma
, semflg
);
1886 int security_sem_semctl(struct sem_array
*sma
, int cmd
)
1888 return call_int_hook(sem_semctl
, 0, sma
, cmd
);
1891 int security_sem_semop(struct sem_array
*sma
, struct sembuf
*sops
,
1892 unsigned nsops
, int alter
)
1894 return call_int_hook(sem_semop
, 0, sma
, sops
, nsops
, alter
);
1897 void security_d_instantiate(struct dentry
*dentry
, struct inode
*inode
)
1899 if (unlikely(inode
&& IS_PRIVATE(inode
)))
1901 call_void_hook(d_instantiate
, dentry
, inode
);
1903 EXPORT_SYMBOL(security_d_instantiate
);
1905 int security_getprocattr(struct task_struct
*p
, const char *lsm
, char *name
,
1908 #ifdef CONFIG_SECURITY_STACKING
1909 char *speclsm
= lsm_of_task(p
);
1911 struct security_hook_list
*hp
;
1918 * "context" requires work here in addition to what
1919 * the modules provide.
1921 if (strcmp(name
, "context") == 0) {
1924 list_for_each_entry(hp
,
1925 &security_hook_heads
.getprocattr
, list
) {
1926 if (lsm
!= NULL
&& strcmp(lsm
, hp
->lsm
))
1928 trc
= hp
->hook
.getprocattr(p
, "context", &vp
);
1936 if (*value
== NULL
) {
1939 cp
= kasprintf(GFP_KERNEL
, "%s,%s", *value
, vp
);
1951 return strlen(*value
);
1955 list_for_each_entry(hp
, &security_hook_heads
.getprocattr
, list
) {
1956 if (lsm
!= NULL
&& strcmp(lsm
, hp
->lsm
))
1958 #ifdef CONFIG_SECURITY_STACKING
1959 if (!lsm
&& speclsm
&& speclsm
[0] && strcmp(speclsm
, hp
->lsm
))
1962 rc
= hp
->hook
.getprocattr(p
, name
, value
);
1969 int security_setprocattr(const char *lsm
, const char *name
, void *value
,
1972 #ifdef CONFIG_SECURITY_STACKING
1973 char *speclsm
= lsm_of_task(current
);
1974 struct lsm_value
*lsm_value
= NULL
;
1979 struct security_hook_list
*hp
;
1985 * If lsm is NULL look at all the modules to find one
1986 * that processes name. If lsm is not NULL only look at
1989 * "context" is handled directly here.
1991 if (strcmp(name
, "context") == 0) {
1993 temp
= kmemdup(value
, size
+ 1, GFP_KERNEL
);
1998 cp
= strrchr(temp
, '\'');
2003 #ifdef CONFIG_SECURITY_STACKING
2004 lsm_value
= kzalloc(sizeof(*lsm_value
) * LSM_MAX_MAJOR
,
2011 count
= lsm_parse_context(temp
, lsm_value
);
2015 for (count
--; count
>= 0; count
--) {
2016 list_for_each_entry(hp
,
2017 &security_hook_heads
.setprocattr
, list
) {
2019 if (lsm
&& strcmp(lsm
, hp
->lsm
))
2021 if (!strcmp(hp
->lsm
, lsm_value
[count
].lsm
)) {
2022 rc
= hp
->hook
.setprocattr("context",
2023 lsm_value
[count
].data
,
2024 strlen(lsm_value
[count
].data
));
2028 if (rc
< 0 || (lsm
&& rc
>0))
2031 #else /* CONFIG_SECURITY_STACKING */
2032 cp
= strstr(temp
, "='");
2036 tvalue
= strchr(cp
+ 2, '\'');
2039 list_for_each_entry(hp
, &security_hook_heads
.setprocattr
,
2041 if (lsm
== NULL
|| !strcmp(lsm
, hp
->lsm
)) {
2042 rc
= hp
->hook
.setprocattr(name
, tvalue
, size
);
2046 #endif /* CONFIG_SECURITY_STACKING */
2049 #ifdef CONFIG_SECURITY_STACKING
2057 list_for_each_entry(hp
, &security_hook_heads
.setprocattr
, list
) {
2058 if (lsm
&& strcmp(lsm
, hp
->lsm
))
2060 #ifdef CONFIG_SECURITY_STACKING
2061 if (!lsm
&& speclsm
&& speclsm
[0] && strcmp(speclsm
, hp
->lsm
))
2064 rc
= hp
->hook
.setprocattr(name
, value
, size
);
2071 int security_netlink_send(struct sock
*sk
, struct sk_buff
*skb
)
2073 return call_int_hook(netlink_send
, 0, sk
, skb
);
2076 int security_ismaclabel(const char *name
)
2078 return call_int_hook(ismaclabel
, 0, name
);
2080 EXPORT_SYMBOL(security_ismaclabel
);
2082 int security_secid_to_secctx(u32 secid
, char **secdata
, u32
*seclen
)
2084 return call_int_hook(secid_to_secctx
, -EOPNOTSUPP
, secid
, secdata
,
2087 EXPORT_SYMBOL(security_secid_to_secctx
);
2089 int security_secctx_to_secid(const char *secdata
, u32 seclen
, u32
*secid
)
2092 return call_int_hook(secctx_to_secid
, 0, secdata
, seclen
, secid
);
2094 EXPORT_SYMBOL(security_secctx_to_secid
);
2096 void security_release_secctx(char *secdata
, u32 seclen
)
2098 #ifdef CONFIG_SECURITY_STACKING
2099 char *speclsm
= lsm_of_task(current
);
2101 struct security_hook_list
*hp
;
2103 list_for_each_entry(hp
, &security_hook_heads
.release_secctx
, list
) {
2104 #ifdef CONFIG_SECURITY_STACKING
2105 if (speclsm
[0] && strcmp(hp
->lsm
, speclsm
))
2108 hp
->hook
.release_secctx(secdata
, seclen
);
2112 EXPORT_SYMBOL(security_release_secctx
);
2114 void security_inode_invalidate_secctx(struct inode
*inode
)
2116 call_void_hook(inode_invalidate_secctx
, inode
);
2118 EXPORT_SYMBOL(security_inode_invalidate_secctx
);
2120 int security_inode_notifysecctx(struct inode
*inode
, void *ctx
, u32 ctxlen
)
2122 return call_int_hook(inode_notifysecctx
, 0, inode
, ctx
, ctxlen
);
2124 EXPORT_SYMBOL(security_inode_notifysecctx
);
2126 int security_inode_setsecctx(struct dentry
*dentry
, void *ctx
, u32 ctxlen
)
2128 return call_int_hook(inode_setsecctx
, 0, dentry
, ctx
, ctxlen
);
2130 EXPORT_SYMBOL(security_inode_setsecctx
);
2132 int security_inode_getsecctx(struct inode
*inode
, void **ctx
, u32
*ctxlen
)
2134 return call_int_hook(inode_getsecctx
, -EOPNOTSUPP
, inode
, ctx
, ctxlen
);
2136 EXPORT_SYMBOL(security_inode_getsecctx
);
2138 #ifdef CONFIG_SECURITY_NETWORK
2140 int security_unix_stream_connect(struct sock
*sock
, struct sock
*other
, struct sock
*newsk
)
2142 return call_int_hook(unix_stream_connect
, 0, sock
, other
, newsk
);
2144 EXPORT_SYMBOL(security_unix_stream_connect
);
2146 int security_unix_may_send(struct socket
*sock
, struct socket
*other
)
2148 return call_int_hook(unix_may_send
, 0, sock
, other
);
2150 EXPORT_SYMBOL(security_unix_may_send
);
2152 int security_socket_create(int family
, int type
, int protocol
, int kern
)
2154 return call_int_hook(socket_create
, 0, family
, type
, protocol
, kern
);
2157 int security_socket_post_create(struct socket
*sock
, int family
,
2158 int type
, int protocol
, int kern
)
2160 return call_int_hook(socket_post_create
, 0, sock
, family
, type
,
2164 int security_socket_bind(struct socket
*sock
, struct sockaddr
*address
, int addrlen
)
2166 return call_int_hook(socket_bind
, 0, sock
, address
, addrlen
);
2169 int security_socket_connect(struct socket
*sock
, struct sockaddr
*address
, int addrlen
)
2171 return call_int_hook(socket_connect
, 0, sock
, address
, addrlen
);
2174 int security_socket_listen(struct socket
*sock
, int backlog
)
2176 return call_int_hook(socket_listen
, 0, sock
, backlog
);
2179 int security_socket_accept(struct socket
*sock
, struct socket
*newsock
)
2181 return call_int_hook(socket_accept
, 0, sock
, newsock
);
2184 int security_socket_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int size
)
2186 return call_int_hook(socket_sendmsg
, 0, sock
, msg
, size
);
2189 int security_socket_recvmsg(struct socket
*sock
, struct msghdr
*msg
,
2190 int size
, int flags
)
2192 return call_int_hook(socket_recvmsg
, 0, sock
, msg
, size
, flags
);
2195 int security_socket_getsockname(struct socket
*sock
)
2197 return call_int_hook(socket_getsockname
, 0, sock
);
2200 int security_socket_getpeername(struct socket
*sock
)
2202 return call_int_hook(socket_getpeername
, 0, sock
);
2205 int security_socket_getsockopt(struct socket
*sock
, int level
, int optname
)
2207 return call_int_hook(socket_getsockopt
, 0, sock
, level
, optname
);
2210 int security_socket_setsockopt(struct socket
*sock
, int level
, int optname
)
2212 return call_int_hook(socket_setsockopt
, 0, sock
, level
, optname
);
2215 int security_socket_shutdown(struct socket
*sock
, int how
)
2217 return call_int_hook(socket_shutdown
, 0, sock
, how
);
2220 int security_sock_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
2222 return call_int_hook(socket_sock_rcv_skb
, 0, sk
, skb
);
2224 EXPORT_SYMBOL(security_sock_rcv_skb
);
2226 int security_socket_getpeersec_stream(struct socket
*sock
, char __user
*optval
,
2227 int __user
*optlen
, unsigned len
)
2229 #ifdef CONFIG_SECURITY_STACKING
2230 struct security_hook_list
*hp
;
2231 char *lsm
= lsm_of_task(current
);
2233 list_for_each_entry(hp
, &security_hook_heads
.socket_getpeersec_stream
,
2235 if (!lsm
|| !lsm
[0] || !strcmp(lsm
, hp
->lsm
))
2236 return hp
->hook
.socket_getpeersec_stream(sock
, optval
,
2239 return -ENOPROTOOPT
;
2241 return call_int_hook(socket_getpeersec_stream
, -ENOPROTOOPT
, sock
,
2242 optval
, optlen
, len
);
2246 int security_socket_getpeersec_dgram(struct socket
*sock
, struct sk_buff
*skb
, u32
*secid
)
2248 return call_int_hook(socket_getpeersec_dgram
, -ENOPROTOOPT
, sock
,
2251 EXPORT_SYMBOL(security_socket_getpeersec_dgram
);
2253 int security_sk_alloc(struct sock
*sk
, int family
, gfp_t priority
)
2255 int rc
= lsm_sock_alloc(sk
, priority
);
2259 return call_int_hook(sk_alloc_security
, 0, sk
, family
, priority
);
2262 void security_sk_free(struct sock
*sk
)
2264 call_void_hook(sk_free_security
, sk
);
2265 kfree(sk
->sk_security
);
2266 sk
->sk_security
= NULL
;
2269 void security_sk_clone(const struct sock
*sk
, struct sock
*newsk
)
2271 call_void_hook(sk_clone_security
, sk
, newsk
);
2273 EXPORT_SYMBOL(security_sk_clone
);
2275 void security_sk_classify_flow(struct sock
*sk
, struct flowi
*fl
)
2277 call_void_hook(sk_getsecid
, sk
, &fl
->flowi_secid
);
2279 EXPORT_SYMBOL(security_sk_classify_flow
);
2281 void security_req_classify_flow(const struct request_sock
*req
, struct flowi
*fl
)
2283 call_void_hook(req_classify_flow
, req
, fl
);
2285 EXPORT_SYMBOL(security_req_classify_flow
);
2287 void security_sock_graft(struct sock
*sk
, struct socket
*parent
)
2289 call_void_hook(sock_graft
, sk
, parent
);
2291 EXPORT_SYMBOL(security_sock_graft
);
2293 int security_inet_conn_request(struct sock
*sk
,
2294 struct sk_buff
*skb
, struct request_sock
*req
)
2296 return call_int_hook(inet_conn_request
, 0, sk
, skb
, req
);
2298 EXPORT_SYMBOL(security_inet_conn_request
);
2300 void security_inet_csk_clone(struct sock
*newsk
,
2301 const struct request_sock
*req
)
2303 call_void_hook(inet_csk_clone
, newsk
, req
);
2306 void security_inet_conn_established(struct sock
*sk
,
2307 struct sk_buff
*skb
)
2309 call_void_hook(inet_conn_established
, sk
, skb
);
2312 int security_secmark_relabel_packet(u32 secid
)
2314 return call_int_hook(secmark_relabel_packet
, 0, secid
);
2316 EXPORT_SYMBOL(security_secmark_relabel_packet
);
2318 void security_secmark_refcount_inc(void)
2320 call_void_hook(secmark_refcount_inc
);
2322 EXPORT_SYMBOL(security_secmark_refcount_inc
);
2324 void security_secmark_refcount_dec(void)
2326 call_void_hook(secmark_refcount_dec
);
2328 EXPORT_SYMBOL(security_secmark_refcount_dec
);
2330 int security_tun_dev_alloc_security(void **security
)
2332 return call_int_hook(tun_dev_alloc_security
, 0, security
);
2334 EXPORT_SYMBOL(security_tun_dev_alloc_security
);
2336 void security_tun_dev_free_security(void *security
)
2338 call_void_hook(tun_dev_free_security
, security
);
2340 EXPORT_SYMBOL(security_tun_dev_free_security
);
2342 int security_tun_dev_create(void)
2344 return call_int_hook(tun_dev_create
, 0);
2346 EXPORT_SYMBOL(security_tun_dev_create
);
2348 int security_tun_dev_attach_queue(void *security
)
2350 return call_int_hook(tun_dev_attach_queue
, 0, security
);
2352 EXPORT_SYMBOL(security_tun_dev_attach_queue
);
2354 int security_tun_dev_attach(struct sock
*sk
, void *security
)
2356 return call_int_hook(tun_dev_attach
, 0, sk
, security
);
2358 EXPORT_SYMBOL(security_tun_dev_attach
);
2360 int security_tun_dev_open(void *security
)
2362 return call_int_hook(tun_dev_open
, 0, security
);
2364 EXPORT_SYMBOL(security_tun_dev_open
);
2366 #endif /* CONFIG_SECURITY_NETWORK */
2368 #ifdef CONFIG_SECURITY_INFINIBAND
2370 int security_ib_pkey_access(void *sec
, u64 subnet_prefix
, u16 pkey
)
2372 return call_int_hook(ib_pkey_access
, 0, sec
, subnet_prefix
, pkey
);
2374 EXPORT_SYMBOL(security_ib_pkey_access
);
2376 int security_ib_endport_manage_subnet(void *sec
, const char *dev_name
, u8 port_num
)
2378 return call_int_hook(ib_endport_manage_subnet
, 0, sec
, dev_name
, port_num
);
2380 EXPORT_SYMBOL(security_ib_endport_manage_subnet
);
2382 int security_ib_alloc_security(void **sec
)
2384 return call_int_hook(ib_alloc_security
, 0, sec
);
2386 EXPORT_SYMBOL(security_ib_alloc_security
);
2388 void security_ib_free_security(void *sec
)
2390 call_void_hook(ib_free_security
, sec
);
2392 EXPORT_SYMBOL(security_ib_free_security
);
2393 #endif /* CONFIG_SECURITY_INFINIBAND */
2395 #ifdef CONFIG_SECURITY_NETWORK_XFRM
2397 int security_xfrm_policy_alloc(struct xfrm_sec_ctx
**ctxp
,
2398 struct xfrm_user_sec_ctx
*sec_ctx
,
2401 return call_int_hook(xfrm_policy_alloc_security
, 0, ctxp
, sec_ctx
, gfp
);
2403 EXPORT_SYMBOL(security_xfrm_policy_alloc
);
2405 int security_xfrm_policy_clone(struct xfrm_sec_ctx
*old_ctx
,
2406 struct xfrm_sec_ctx
**new_ctxp
)
2408 return call_int_hook(xfrm_policy_clone_security
, 0, old_ctx
, new_ctxp
);
2411 void security_xfrm_policy_free(struct xfrm_sec_ctx
*ctx
)
2413 call_void_hook(xfrm_policy_free_security
, ctx
);
2415 EXPORT_SYMBOL(security_xfrm_policy_free
);
2417 int security_xfrm_policy_delete(struct xfrm_sec_ctx
*ctx
)
2419 return call_int_hook(xfrm_policy_delete_security
, 0, ctx
);
2422 int security_xfrm_state_alloc(struct xfrm_state
*x
,
2423 struct xfrm_user_sec_ctx
*sec_ctx
)
2425 return call_int_hook(xfrm_state_alloc
, 0, x
, sec_ctx
);
2427 EXPORT_SYMBOL(security_xfrm_state_alloc
);
2429 int security_xfrm_state_alloc_acquire(struct xfrm_state
*x
,
2430 struct xfrm_sec_ctx
*polsec
, u32 secid
)
2432 return call_int_hook(xfrm_state_alloc_acquire
, 0, x
, polsec
, secid
);
2435 int security_xfrm_state_delete(struct xfrm_state
*x
)
2437 return call_int_hook(xfrm_state_delete_security
, 0, x
);
2439 EXPORT_SYMBOL(security_xfrm_state_delete
);
2441 void security_xfrm_state_free(struct xfrm_state
*x
)
2443 call_void_hook(xfrm_state_free_security
, x
);
2446 int security_xfrm_policy_lookup(struct xfrm_sec_ctx
*ctx
, u32 fl_secid
, u8 dir
)
2448 return call_int_hook(xfrm_policy_lookup
, 0, ctx
, fl_secid
, dir
);
2451 int security_xfrm_state_pol_flow_match(struct xfrm_state
*x
,
2452 struct xfrm_policy
*xp
,
2453 const struct flowi
*fl
)
2455 struct security_hook_list
*hp
;
2459 * Since this function is expected to return 0 or 1, the judgment
2460 * becomes difficult if multiple LSMs supply this call. Fortunately,
2461 * we can use the first LSM's judgment because currently only SELinux
2462 * supplies this call.
2464 * For speed optimization, we explicitly break the loop rather than
2467 list_for_each_entry(hp
, &security_hook_heads
.xfrm_state_pol_flow_match
,
2469 rc
= hp
->hook
.xfrm_state_pol_flow_match(x
, xp
, fl
);
2475 int security_xfrm_decode_session(struct sk_buff
*skb
, u32
*secid
)
2477 return call_int_hook(xfrm_decode_session
, 0, skb
, secid
, 1);
2480 void security_skb_classify_flow(struct sk_buff
*skb
, struct flowi
*fl
)
2482 int rc
= call_int_hook(xfrm_decode_session
, 0, skb
, &fl
->flowi_secid
,
2487 EXPORT_SYMBOL(security_skb_classify_flow
);
2489 #endif /* CONFIG_SECURITY_NETWORK_XFRM */
2493 int security_key_alloc(struct key
*key
, const struct cred
*cred
,
2494 unsigned long flags
)
2496 int rc
= lsm_key_alloc(key
);
2500 return call_int_hook(key_alloc
, 0, key
, cred
, flags
);
2503 void security_key_free(struct key
*key
)
2505 call_void_hook(key_free
, key
);
2506 kfree(key
->security
);
2507 key
->security
= NULL
;
2510 int security_key_permission(key_ref_t key_ref
,
2511 const struct cred
*cred
, unsigned perm
)
2513 return call_int_hook(key_permission
, 0, key_ref
, cred
, perm
);
2516 int security_key_getsecurity(struct key
*key
, char **_buffer
)
2519 return call_int_hook(key_getsecurity
, 0, key
, _buffer
);
2522 #endif /* CONFIG_KEYS */
2526 int security_audit_rule_init(u32 field
, u32 op
, char *rulestr
, void **lsmrule
)
2528 return call_int_hook(audit_rule_init
, 0, field
, op
, rulestr
, lsmrule
);
2531 int security_audit_rule_known(struct audit_krule
*krule
)
2533 return call_int_hook(audit_rule_known
, 0, krule
);
2536 void security_audit_rule_free(void *lsmrule
)
2538 call_void_hook(audit_rule_free
, lsmrule
);
2541 int security_audit_rule_match(u32 secid
, u32 field
, u32 op
, void *lsmrule
,
2542 struct audit_context
*actx
)
2544 return call_int_hook(audit_rule_match
, 0, secid
, field
, op
, lsmrule
,
2547 #endif /* CONFIG_AUDIT */