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 #ifdef CONFIG_SECURITY_STACKING
67 = CONFIG_SECURITY_DEFAULT_DISPLAY_NAME
70 static char default_display_lsm
[SECURITY_NAME_MAX
+ 1];
72 static void __init
do_security_initcalls(void)
75 call
= __security_initcall_start
;
76 while (call
< __security_initcall_end
) {
83 * security_init - initializes the security framework
85 * This should be called early in the kernel initialization sequence.
87 int __init
security_init(void)
90 struct list_head
*list
= (struct list_head
*) &security_hook_heads
;
92 for (i
= 0; i
< sizeof(security_hook_heads
) / sizeof(struct list_head
);
94 INIT_LIST_HEAD(&list
[i
]);
95 pr_info("Security Framework initialized\n");
98 * Load minor LSMs, with the capability module always first.
100 capability_add_hooks();
105 * The first call to a module specific init function
106 * updates the blob size requirements.
108 do_security_initcalls();
111 * The second call to a module specific init function
112 * adds hooks to the hook lists and does any other early
113 * initializations required.
115 do_security_initcalls();
117 #ifdef CONFIG_SECURITY_LSM_DEBUG
118 pr_info("LSM: cred blob size = %d\n", blob_sizes
.lbs_cred
);
119 pr_info("LSM: file blob size = %d\n", blob_sizes
.lbs_file
);
120 pr_info("LSM: inode blob size = %d\n", blob_sizes
.lbs_inode
);
121 pr_info("LSM: ipc blob size = %d\n", blob_sizes
.lbs_ipc
);
123 pr_info("LSM: key blob size = %d\n", blob_sizes
.lbs_key
);
124 #endif /* CONFIG_KEYS */
125 pr_info("LSM: msg_msg blob size = %d\n", blob_sizes
.lbs_msg_msg
);
126 pr_info("LSM: sock blob size = %d\n", blob_sizes
.lbs_sock
);
127 pr_info("LSM: superblock blob size = %d\n", blob_sizes
.lbs_superblock
);
128 pr_info("LSM: task blob size = %d\n", blob_sizes
.lbs_task
);
129 #endif /* CONFIG_SECURITY_LSM_DEBUG */
134 /* Save user chosen LSM */
135 static int __init
choose_lsm(char *str
)
137 strncpy(chosen_lsms
, str
, SECURITY_CHOSEN_NAMES_MAX
);
138 pr_info("LSM: command line set '%s' security module(s).\n",
142 __setup("security=", choose_lsm
);
144 static int __init
choose_display_lsm(char *str
)
146 strncpy(chosen_display_lsm
, str
, SECURITY_NAME_MAX
);
147 pr_info("LSM: command line set default display lsm %s'\n",
151 __setup("security.display=", choose_display_lsm
);
153 static bool match_last_lsm(const char *list
, const char *lsm
)
157 if (WARN_ON(!list
|| !lsm
))
159 last
= strrchr(list
, ',');
161 /* Pass the comma, strcmp() will check for '\0' */
165 return !strcmp(last
, lsm
);
168 static int lsm_append(char *new, char **result
)
172 if (*result
== NULL
) {
173 *result
= kstrdup(new, GFP_KERNEL
);
175 /* Check if it is the last registered name */
176 if (match_last_lsm(*result
, new))
178 cp
= kasprintf(GFP_KERNEL
, "%s,%s", *result
, new);
188 * security_module_enable - Load given security module on boot ?
189 * @module: the name of the module
190 * @stacked: indicates that the module wants to be stacked
192 * Each LSM must pass this method before registering its own operations
193 * to avoid security registration races. This method may also be used
194 * to check if your LSM is currently loaded during kernel initialization.
200 * - The passed LSM is the one chosen by user at boot time,
201 * - or the passed LSM is configured as the default and the user did not
202 * choose an alternate LSM at boot time.
204 * Otherwise, return false.
206 #ifdef CONFIG_SECURITY_STACKING
207 static bool __init
cmp_lsms(const char *lsm
)
209 const char *str
= chosen_lsms
;
211 int len
= strlen(lsm
);
213 if (len
> SECURITY_NAME_MAX
) {
214 pr_info("LSM: security module name '%s' exceeds limit\n", lsm
);
217 for (split
= strchr(str
, ','); split
; split
= strchr(str
, ',')) {
218 if ((len
== split
- str
) && !strncmp(lsm
, str
, split
- str
))
222 if ((len
== strlen(str
)) && !strncmp(lsm
, str
, strlen(str
)))
228 bool __init
security_module_enable(const char *lsm
, const bool stacked
)
230 #ifdef CONFIG_SECURITY_STACKING
232 * Module defined on the command line security=XXXX
234 if (strcmp(chosen_lsms
, MODULE_STACK
)) {
236 /* set to first LSM registered and then override */
237 if (!*default_display_lsm
)
238 strcpy(default_display_lsm
, lsm
);
239 else if (*chosen_display_lsm
&& !strcmp(chosen_display_lsm
, lsm
)) {
240 strcpy(default_display_lsm
, lsm
);
241 pr_info("LSM: default display lsm '%s'\n", default_display_lsm
);
248 * Module configured as stacked.
250 if (stacked
&& !*default_display_lsm
)
251 strcpy(default_display_lsm
, lsm
);
252 else if (stacked
&& *chosen_display_lsm
&& !strcmp(chosen_display_lsm
, lsm
)) {
253 strcpy(default_display_lsm
, lsm
);
254 pr_info("LSM: default display lsm '%s'\n", default_display_lsm
);
259 if (strcmp(lsm
, chosen_lsms
) == 0) {
260 strcpy(default_display_lsm
, lsm
);
268 * Keep the order of major modules for mapping secids.
270 static int lsm_next_major
;
273 * security_add_hooks - Add a modules hooks to the hook lists.
274 * @hooks: the hooks to add
275 * @count: the number of hooks to add
276 * @lsm: the name of the security module
278 * Each LSM has to register its hooks with the infrastructure.
280 void __init
security_add_hooks(struct security_hook_list
*hooks
, int count
,
284 int lsm_index
= lsm_next_major
++;
286 #ifdef CONFIG_SECURITY_LSM_DEBUG
287 pr_info("LSM: Security module %s gets index %d\n", lsm
, lsm_index
);
289 for (i
= 0; i
< count
; i
++) {
291 hooks
[i
].lsm_index
= lsm_index
;
292 list_add_tail_rcu(&hooks
[i
].list
, hooks
[i
].head
);
294 if (lsm_append(lsm
, &lsm_names
) < 0)
295 panic("%s - Cannot get early memory.\n", __func__
);
298 int call_lsm_notifier(enum lsm_event event
, void *data
)
300 return atomic_notifier_call_chain(&lsm_notifier_chain
, event
, data
);
302 EXPORT_SYMBOL(call_lsm_notifier
);
304 int register_lsm_notifier(struct notifier_block
*nb
)
306 return atomic_notifier_chain_register(&lsm_notifier_chain
, nb
);
308 EXPORT_SYMBOL(register_lsm_notifier
);
310 int unregister_lsm_notifier(struct notifier_block
*nb
)
312 return atomic_notifier_chain_unregister(&lsm_notifier_chain
, nb
);
314 EXPORT_SYMBOL(unregister_lsm_notifier
);
317 * lsm_cred_alloc - allocate a composite cred blob
318 * @cred: the cred that needs a blob
319 * @gfp: allocation type
321 * Allocate the cred blob for all the modules
323 * Returns 0, or -ENOMEM if memory can't be allocated.
325 int lsm_cred_alloc(struct cred
*cred
, gfp_t gfp
)
327 #ifdef CONFIG_SECURITY_LSM_DEBUG
329 pr_info("%s: Inbound cred blob is not NULL.\n", __func__
);
331 if (blob_sizes
.lbs_cred
== 0)
334 cred
->security
= kzalloc(blob_sizes
.lbs_cred
, gfp
);
335 if (cred
->security
== NULL
)
341 * lsm_early_cred - during initialization allocate a composite cred blob
342 * @cred: the cred that needs a blob
344 * Allocate the cred blob for all the modules if it's not already there
346 void lsm_early_cred(struct cred
*cred
)
351 panic("%s: NULL cred.\n", __func__
);
352 if (cred
->security
!= NULL
)
354 rc
= lsm_cred_alloc(cred
, GFP_KERNEL
);
356 panic("%s: Early cred alloc failed.\n", __func__
);
359 static void __init
lsm_set_size(int *need
, int *lbs
)
371 * security_add_blobs - Report blob sizes
372 * @needed: the size of blobs needed by the module
374 * Each LSM has to register its blobs with the infrastructure.
375 * The "needed" data tells the infrastructure how much memory
376 * the module requires for each of its blobs. On return the
377 * structure is filled with the offset that module should use
378 * from the blob pointer.
380 void __init
security_add_blobs(struct lsm_blob_sizes
*needed
)
382 lsm_set_size(&needed
->lbs_cred
, &blob_sizes
.lbs_cred
);
383 lsm_set_size(&needed
->lbs_file
, &blob_sizes
.lbs_file
);
384 lsm_set_size(&needed
->lbs_ipc
, &blob_sizes
.lbs_ipc
);
385 lsm_set_size(&needed
->lbs_key
, &blob_sizes
.lbs_key
);
386 lsm_set_size(&needed
->lbs_msg_msg
, &blob_sizes
.lbs_msg_msg
);
387 lsm_set_size(&needed
->lbs_sock
, &blob_sizes
.lbs_sock
);
388 lsm_set_size(&needed
->lbs_superblock
, &blob_sizes
.lbs_superblock
);
389 lsm_set_size(&needed
->lbs_task
, &blob_sizes
.lbs_task
);
391 * The inode blob gets an rcu_head in addition to
392 * what the modules might need.
394 if (needed
->lbs_inode
&& blob_sizes
.lbs_inode
== 0)
395 blob_sizes
.lbs_inode
= sizeof(struct rcu_head
);
396 lsm_set_size(&needed
->lbs_inode
, &blob_sizes
.lbs_inode
);
400 * lsm_file_alloc - allocate a composite file blob
401 * @file: the file that needs a blob
403 * Allocate the file blob for all the modules
405 * Returns 0, or -ENOMEM if memory can't be allocated.
407 int lsm_file_alloc(struct file
*file
)
409 #ifdef CONFIG_SECURITY_LSM_DEBUG
410 if (file
->f_security
)
411 pr_info("%s: Inbound file blob is not NULL.\n", __func__
);
413 if (blob_sizes
.lbs_file
== 0)
416 file
->f_security
= kzalloc(blob_sizes
.lbs_file
, GFP_KERNEL
);
417 if (file
->f_security
== NULL
)
422 #ifdef CONFIG_SECURITY_STACKING
423 static inline char *lsm_of_task(struct task_struct
*task
)
425 #ifdef CONFIG_SECURITY_LSM_DEBUG
426 if (task
->security
== NULL
)
427 pr_info("%s: task has no lsm name.\n", __func__
);
429 return task
->security
;
433 #ifdef CONFIG_SECURITY_STACKING
440 * lsm_parse_context - break a compound "context" into module data
441 * @cxt: the initial data, which will be modified
442 * @vlist: an array to receive the results
444 * Returns the number of entries, or -EINVAL if the cxt is unworkable.
446 static int lsm_parse_context(char *cxt
, struct lsm_value
*vlist
)
454 for (i
= 0; i
< LSM_MAX_MAJOR
; i
++) {
455 data
= strstr(lsm
, "='");
460 cp
= strchr(data
, '\'');
465 vlist
[i
].data
= data
;
478 #endif /* CONFIG_SECURITY_STACKING */
481 * lsm_task_alloc - allocate a composite task blob
482 * @task: the task that needs a blob
484 * Allocate the task blob for all the modules
486 * Returns 0, or -ENOMEM if memory can't be allocated.
488 int lsm_task_alloc(struct task_struct
*task
)
490 #ifdef CONFIG_SECURITY_LSM_DEBUG
492 pr_info("%s: Inbound task blob is not NULL.\n", __func__
);
494 if (blob_sizes
.lbs_task
== 0)
497 task
->security
= kzalloc(blob_sizes
.lbs_task
, GFP_KERNEL
);
498 if (task
->security
== NULL
)
501 /* inherit current display lsm */
502 #ifdef CONFIG_SECURITY_STACKING
503 if (current
->security
)
504 strcpy(task
->security
, lsm_of_task(current
));
506 strcpy(task
->security
, default_display_lsm
);
512 * lsm_inode_alloc - allocate a composite inode blob
513 * @inode: the inode that needs a blob
515 * Allocate the inode blob for all the modules
517 * Returns 0, or -ENOMEM if memory can't be allocated.
519 int lsm_inode_alloc(struct inode
*inode
)
521 #ifdef CONFIG_SECURITY_LSM_DEBUG
522 if (inode
->i_security
)
523 pr_info("%s: Inbound inode blob is not NULL.\n", __func__
);
525 if (blob_sizes
.lbs_inode
== 0)
528 inode
->i_security
= kzalloc(blob_sizes
.lbs_inode
, GFP_KERNEL
);
529 if (inode
->i_security
== NULL
)
535 * lsm_early_inode - during initialization allocate a composite inode blob
536 * @inode: the inode that needs a blob
538 * Allocate the inode blob for all the modules if it's not already there
540 void lsm_early_inode(struct inode
*inode
)
545 panic("%s: NULL inode.\n", __func__
);
546 if (inode
->i_security
!= NULL
)
548 rc
= lsm_inode_alloc(inode
);
550 panic("%s: Early inode alloc failed.\n", __func__
);
554 * lsm_ipc_alloc - allocate a composite ipc blob
555 * @kip: the ipc that needs a blob
557 * Allocate the ipc blob for all the modules
559 * Returns 0, or -ENOMEM if memory can't be allocated.
561 int lsm_ipc_alloc(struct kern_ipc_perm
*kip
)
563 #ifdef CONFIG_SECURITY_LSM_DEBUG
565 pr_info("%s: Inbound ipc blob is not NULL.\n", __func__
);
567 if (blob_sizes
.lbs_ipc
== 0)
570 kip
->security
= kzalloc(blob_sizes
.lbs_ipc
, GFP_KERNEL
);
571 if (kip
->security
== NULL
)
578 * lsm_key_alloc - allocate a composite key blob
579 * @key: the key that needs a blob
581 * Allocate the key blob for all the modules
583 * Returns 0, or -ENOMEM if memory can't be allocated.
585 int lsm_key_alloc(struct key
*key
)
587 #ifdef CONFIG_SECURITY_LSM_DEBUG
589 pr_info("%s: Inbound key blob is not NULL.\n", __func__
);
591 if (blob_sizes
.lbs_key
== 0)
594 key
->security
= kzalloc(blob_sizes
.lbs_key
, GFP_KERNEL
);
595 if (key
->security
== NULL
)
599 #endif /* CONFIG_KEYS */
602 * lsm_msg_msg_alloc - allocate a composite msg_msg blob
603 * @mp: the msg_msg that needs a blob
605 * Allocate the ipc blob for all the modules
607 * Returns 0, or -ENOMEM if memory can't be allocated.
609 int lsm_msg_msg_alloc(struct msg_msg
*mp
)
611 #ifdef CONFIG_SECURITY_LSM_DEBUG
613 pr_info("%s: Inbound msg_msg blob is not NULL.\n", __func__
);
615 if (blob_sizes
.lbs_msg_msg
== 0)
618 mp
->security
= kzalloc(blob_sizes
.lbs_msg_msg
, GFP_KERNEL
);
619 if (mp
->security
== NULL
)
625 * lsm_sock_alloc - allocate a composite sock blob
626 * @sock: the sock that needs a blob
627 * @priority: allocation mode
629 * Allocate the sock blob for all the modules
631 * Returns 0, or -ENOMEM if memory can't be allocated.
633 int lsm_sock_alloc(struct sock
*sock
, gfp_t priority
)
635 #ifdef CONFIG_SECURITY_LSM_DEBUG
636 if (sock
->sk_security
)
637 pr_info("%s: Inbound sock blob is not NULL.\n", __func__
);
639 if (blob_sizes
.lbs_sock
== 0)
642 sock
->sk_security
= kzalloc(blob_sizes
.lbs_sock
, priority
);
643 if (sock
->sk_security
== NULL
)
649 * lsm_superblock_alloc - allocate a composite superblock blob
650 * @sb: the superblock that needs a blob
652 * Allocate the superblock blob for all the modules
654 * Returns 0, or -ENOMEM if memory can't be allocated.
656 int lsm_superblock_alloc(struct super_block
*sb
)
658 #ifdef CONFIG_SECURITY_LSM_DEBUG
660 pr_info("%s: Inbound superblock blob is not NULL.\n", __func__
);
662 if (blob_sizes
.lbs_superblock
== 0)
665 sb
->s_security
= kzalloc(blob_sizes
.lbs_superblock
, GFP_KERNEL
);
666 if (sb
->s_security
== NULL
)
672 * Hook list operation macros.
675 * This is a hook that does not return a value.
678 * This is a hook that returns a value.
681 #define call_void_hook(FUNC, ...) \
683 struct security_hook_list *P; \
685 list_for_each_entry(P, &security_hook_heads.FUNC, list) \
686 P->hook.FUNC(__VA_ARGS__); \
689 #define call_int_hook(FUNC, IRC, ...) ({ \
692 struct security_hook_list *P; \
694 list_for_each_entry(P, &security_hook_heads.FUNC, list) { \
695 RC = P->hook.FUNC(__VA_ARGS__); \
703 /* Security operations */
705 int security_binder_set_context_mgr(struct task_struct
*mgr
)
707 return call_int_hook(binder_set_context_mgr
, 0, mgr
);
710 int security_binder_transaction(struct task_struct
*from
,
711 struct task_struct
*to
)
713 return call_int_hook(binder_transaction
, 0, from
, to
);
716 int security_binder_transfer_binder(struct task_struct
*from
,
717 struct task_struct
*to
)
719 return call_int_hook(binder_transfer_binder
, 0, from
, to
);
722 int security_binder_transfer_file(struct task_struct
*from
,
723 struct task_struct
*to
, struct file
*file
)
725 return call_int_hook(binder_transfer_file
, 0, from
, to
, file
);
728 int security_ptrace_access_check(struct task_struct
*child
, unsigned int mode
)
730 return call_int_hook(ptrace_access_check
, 0, child
, mode
);
733 int security_ptrace_traceme(struct task_struct
*parent
)
735 return call_int_hook(ptrace_traceme
, 0, parent
);
738 int security_capget(struct task_struct
*target
,
739 kernel_cap_t
*effective
,
740 kernel_cap_t
*inheritable
,
741 kernel_cap_t
*permitted
)
743 return call_int_hook(capget
, 0, target
,
744 effective
, inheritable
, permitted
);
747 int security_capset(struct cred
*new, const struct cred
*old
,
748 const kernel_cap_t
*effective
,
749 const kernel_cap_t
*inheritable
,
750 const kernel_cap_t
*permitted
)
752 return call_int_hook(capset
, 0, new, old
,
753 effective
, inheritable
, permitted
);
756 int security_capable(const struct cred
*cred
, struct user_namespace
*ns
,
759 return call_int_hook(capable
, 0, cred
, ns
, cap
, SECURITY_CAP_AUDIT
);
762 int security_capable_noaudit(const struct cred
*cred
, struct user_namespace
*ns
,
765 return call_int_hook(capable
, 0, cred
, ns
, cap
, SECURITY_CAP_NOAUDIT
);
768 int security_quotactl(int cmds
, int type
, int id
, struct super_block
*sb
)
770 return call_int_hook(quotactl
, 0, cmds
, type
, id
, sb
);
773 int security_quota_on(struct dentry
*dentry
)
775 return call_int_hook(quota_on
, 0, dentry
);
778 int security_syslog(int type
)
780 return call_int_hook(syslog
, 0, type
);
783 int security_settime64(const struct timespec64
*ts
, const struct timezone
*tz
)
785 return call_int_hook(settime
, 0, ts
, tz
);
788 int security_vm_enough_memory_mm(struct mm_struct
*mm
, long pages
)
790 struct security_hook_list
*hp
;
791 int cap_sys_admin
= 1;
795 * The module will respond with a positive value if
796 * it thinks the __vm_enough_memory() call should be
797 * made with the cap_sys_admin set. If all of the modules
798 * agree that it should be set it will. If any module
799 * thinks it should not be set it won't.
801 list_for_each_entry(hp
, &security_hook_heads
.vm_enough_memory
, list
) {
802 rc
= hp
->hook
.vm_enough_memory(mm
, pages
);
808 return __vm_enough_memory(mm
, pages
, cap_sys_admin
);
811 int security_bprm_set_creds(struct linux_binprm
*bprm
)
813 return call_int_hook(bprm_set_creds
, 0, bprm
);
816 int security_bprm_check(struct linux_binprm
*bprm
)
820 ret
= call_int_hook(bprm_check_security
, 0, bprm
);
823 return ima_bprm_check(bprm
);
826 void security_bprm_committing_creds(struct linux_binprm
*bprm
)
828 call_void_hook(bprm_committing_creds
, bprm
);
831 void security_bprm_committed_creds(struct linux_binprm
*bprm
)
833 call_void_hook(bprm_committed_creds
, bprm
);
836 int security_bprm_secureexec(struct linux_binprm
*bprm
)
838 return call_int_hook(bprm_secureexec
, 0, bprm
);
841 int security_sb_alloc(struct super_block
*sb
)
843 int rc
= lsm_superblock_alloc(sb
);
847 return call_int_hook(sb_alloc_security
, 0, sb
);
850 void security_sb_free(struct super_block
*sb
)
852 call_void_hook(sb_free_security
, sb
);
853 kfree(sb
->s_security
);
854 sb
->s_security
= NULL
;
857 int security_sb_copy_data(char *orig
, char *copy
)
859 return call_int_hook(sb_copy_data
, 0, orig
, copy
);
861 EXPORT_SYMBOL(security_sb_copy_data
);
863 int security_sb_remount(struct super_block
*sb
, void *data
)
865 return call_int_hook(sb_remount
, 0, sb
, data
);
868 int security_sb_kern_mount(struct super_block
*sb
, int flags
, void *data
)
870 return call_int_hook(sb_kern_mount
, 0, sb
, flags
, data
);
873 int security_sb_show_options(struct seq_file
*m
, struct super_block
*sb
)
875 return call_int_hook(sb_show_options
, 0, m
, sb
);
878 int security_sb_statfs(struct dentry
*dentry
)
880 return call_int_hook(sb_statfs
, 0, dentry
);
883 int security_sb_mount(const char *dev_name
, const struct path
*path
,
884 const char *type
, unsigned long flags
, void *data
)
886 return call_int_hook(sb_mount
, 0, dev_name
, path
, type
, flags
, data
);
889 int security_sb_umount(struct vfsmount
*mnt
, int flags
)
891 return call_int_hook(sb_umount
, 0, mnt
, flags
);
894 int security_sb_pivotroot(const struct path
*old_path
, const struct path
*new_path
)
896 return call_int_hook(sb_pivotroot
, 0, old_path
, new_path
);
899 int security_sb_set_mnt_opts(struct super_block
*sb
,
900 struct security_mnt_opts
*opts
,
901 unsigned long kern_flags
,
902 unsigned long *set_kern_flags
)
904 return call_int_hook(sb_set_mnt_opts
,
905 opts
->num_mnt_opts
? -EOPNOTSUPP
: 0, sb
,
906 opts
, kern_flags
, set_kern_flags
);
908 EXPORT_SYMBOL(security_sb_set_mnt_opts
);
910 int security_sb_clone_mnt_opts(const struct super_block
*oldsb
,
911 struct super_block
*newsb
,
912 unsigned long kern_flags
,
913 unsigned long *set_kern_flags
)
915 return call_int_hook(sb_clone_mnt_opts
, 0, oldsb
, newsb
,
916 kern_flags
, set_kern_flags
);
918 EXPORT_SYMBOL(security_sb_clone_mnt_opts
);
920 int security_sb_parse_opts_str(char *options
, struct security_mnt_opts
*opts
)
922 return call_int_hook(sb_parse_opts_str
, 0, options
, opts
);
924 EXPORT_SYMBOL(security_sb_parse_opts_str
);
926 int security_inode_alloc(struct inode
*inode
)
928 int rc
= lsm_inode_alloc(inode
);
932 return call_int_hook(inode_alloc_security
, 0, inode
);
935 static void inode_free_by_rcu(struct rcu_head
*head
)
938 * The rcu head is at the start of the inode blob
943 void security_inode_free(struct inode
*inode
)
945 integrity_inode_free(inode
);
946 call_void_hook(inode_free_security
, inode
);
948 * The inode may still be referenced in a path walk and
949 * a call to security_inode_permission() can be made
950 * after inode_free_security() is called. Ideally, the VFS
951 * wouldn't do this, but fixing that is a much harder
952 * job. For now, simply free the i_security via RCU, and
953 * leave the current inode->i_security pointer intact.
954 * The inode will be freed after the RCU grace period too.
956 if (inode
->i_security
!= NULL
) {
957 call_rcu((struct rcu_head
*)inode
->i_security
,
959 inode
->i_security
= NULL
;
963 int security_dentry_init_security(struct dentry
*dentry
, int mode
,
964 const struct qstr
*name
, void **ctx
,
967 return call_int_hook(dentry_init_security
, -EOPNOTSUPP
, dentry
, mode
,
970 EXPORT_SYMBOL(security_dentry_init_security
);
972 int security_dentry_create_files_as(struct dentry
*dentry
, int mode
,
974 const struct cred
*old
, struct cred
*new)
976 return call_int_hook(dentry_create_files_as
, 0, dentry
, mode
,
979 EXPORT_SYMBOL(security_dentry_create_files_as
);
981 int security_inode_init_security(struct inode
*inode
, struct inode
*dir
,
982 const struct qstr
*qstr
,
983 const initxattrs initxattrs
, void *fs_data
)
985 struct xattr new_xattrs
[MAX_LSM_EVM_XATTR
+ 1];
986 struct xattr
*lsm_xattr
, *evm_xattr
, *xattr
;
989 if (unlikely(IS_PRIVATE(inode
)))
993 return call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
,
994 dir
, qstr
, NULL
, NULL
, NULL
);
995 memset(new_xattrs
, 0, sizeof(new_xattrs
));
996 lsm_xattr
= new_xattrs
;
997 ret
= call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
, dir
, qstr
,
1000 &lsm_xattr
->value_len
);
1004 evm_xattr
= lsm_xattr
+ 1;
1005 ret
= evm_inode_init_security(inode
, lsm_xattr
, evm_xattr
);
1008 ret
= initxattrs(inode
, new_xattrs
, fs_data
);
1010 for (xattr
= new_xattrs
; xattr
->value
!= NULL
; xattr
++)
1011 kfree(xattr
->value
);
1012 return (ret
== -EOPNOTSUPP
) ? 0 : ret
;
1014 EXPORT_SYMBOL(security_inode_init_security
);
1016 int security_old_inode_init_security(struct inode
*inode
, struct inode
*dir
,
1017 const struct qstr
*qstr
, const char **name
,
1018 void **value
, size_t *len
)
1020 if (unlikely(IS_PRIVATE(inode
)))
1022 return call_int_hook(inode_init_security
, -EOPNOTSUPP
, inode
, dir
,
1023 qstr
, name
, value
, len
);
1025 EXPORT_SYMBOL(security_old_inode_init_security
);
1027 #ifdef CONFIG_SECURITY_PATH
1028 int security_path_mknod(const struct path
*dir
, struct dentry
*dentry
, umode_t mode
,
1031 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1033 return call_int_hook(path_mknod
, 0, dir
, dentry
, mode
, dev
);
1035 EXPORT_SYMBOL(security_path_mknod
);
1037 int security_path_mkdir(const struct path
*dir
, struct dentry
*dentry
, umode_t mode
)
1039 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1041 return call_int_hook(path_mkdir
, 0, dir
, dentry
, mode
);
1043 EXPORT_SYMBOL(security_path_mkdir
);
1045 int security_path_rmdir(const struct path
*dir
, struct dentry
*dentry
)
1047 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1049 return call_int_hook(path_rmdir
, 0, dir
, dentry
);
1051 EXPORT_SYMBOL_GPL(security_path_rmdir
);
1053 int security_path_unlink(const struct path
*dir
, struct dentry
*dentry
)
1055 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1057 return call_int_hook(path_unlink
, 0, dir
, dentry
);
1059 EXPORT_SYMBOL(security_path_unlink
);
1061 int security_path_symlink(const struct path
*dir
, struct dentry
*dentry
,
1062 const char *old_name
)
1064 if (unlikely(IS_PRIVATE(d_backing_inode(dir
->dentry
))))
1066 return call_int_hook(path_symlink
, 0, dir
, dentry
, old_name
);
1068 EXPORT_SYMBOL_GPL(security_path_symlink
);
1070 int security_path_link(struct dentry
*old_dentry
, const struct path
*new_dir
,
1071 struct dentry
*new_dentry
)
1073 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
))))
1075 return call_int_hook(path_link
, 0, old_dentry
, new_dir
, new_dentry
);
1077 EXPORT_SYMBOL_GPL(security_path_link
);
1079 int security_path_rename(const struct path
*old_dir
, struct dentry
*old_dentry
,
1080 const struct path
*new_dir
, struct dentry
*new_dentry
,
1083 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
)) ||
1084 (d_is_positive(new_dentry
) && IS_PRIVATE(d_backing_inode(new_dentry
)))))
1087 if (flags
& RENAME_EXCHANGE
) {
1088 int err
= call_int_hook(path_rename
, 0, new_dir
, new_dentry
,
1089 old_dir
, old_dentry
);
1094 return call_int_hook(path_rename
, 0, old_dir
, old_dentry
, new_dir
,
1097 EXPORT_SYMBOL(security_path_rename
);
1099 int security_path_truncate(const struct path
*path
)
1101 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1103 return call_int_hook(path_truncate
, 0, path
);
1105 EXPORT_SYMBOL_GPL(security_path_truncate
);
1107 int security_path_chmod(const struct path
*path
, umode_t mode
)
1109 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1111 return call_int_hook(path_chmod
, 0, path
, mode
);
1113 EXPORT_SYMBOL_GPL(security_path_chmod
);
1115 int security_path_chown(const struct path
*path
, kuid_t uid
, kgid_t gid
)
1117 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1119 return call_int_hook(path_chown
, 0, path
, uid
, gid
);
1121 EXPORT_SYMBOL_GPL(security_path_chown
);
1123 int security_path_chroot(const struct path
*path
)
1125 return call_int_hook(path_chroot
, 0, path
);
1129 int security_inode_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
1131 if (unlikely(IS_PRIVATE(dir
)))
1133 return call_int_hook(inode_create
, 0, dir
, dentry
, mode
);
1135 EXPORT_SYMBOL_GPL(security_inode_create
);
1137 int security_inode_link(struct dentry
*old_dentry
, struct inode
*dir
,
1138 struct dentry
*new_dentry
)
1140 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
))))
1142 return call_int_hook(inode_link
, 0, old_dentry
, dir
, new_dentry
);
1145 int security_inode_unlink(struct inode
*dir
, struct dentry
*dentry
)
1147 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1149 return call_int_hook(inode_unlink
, 0, dir
, dentry
);
1152 int security_inode_symlink(struct inode
*dir
, struct dentry
*dentry
,
1153 const char *old_name
)
1155 if (unlikely(IS_PRIVATE(dir
)))
1157 return call_int_hook(inode_symlink
, 0, dir
, dentry
, old_name
);
1160 int security_inode_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
1162 if (unlikely(IS_PRIVATE(dir
)))
1164 return call_int_hook(inode_mkdir
, 0, dir
, dentry
, mode
);
1166 EXPORT_SYMBOL_GPL(security_inode_mkdir
);
1168 int security_inode_rmdir(struct inode
*dir
, struct dentry
*dentry
)
1170 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1172 return call_int_hook(inode_rmdir
, 0, dir
, dentry
);
1175 int security_inode_mknod(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
, dev_t dev
)
1177 if (unlikely(IS_PRIVATE(dir
)))
1179 return call_int_hook(inode_mknod
, 0, dir
, dentry
, mode
, dev
);
1182 int security_inode_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1183 struct inode
*new_dir
, struct dentry
*new_dentry
,
1186 if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry
)) ||
1187 (d_is_positive(new_dentry
) && IS_PRIVATE(d_backing_inode(new_dentry
)))))
1190 if (flags
& RENAME_EXCHANGE
) {
1191 int err
= call_int_hook(inode_rename
, 0, new_dir
, new_dentry
,
1192 old_dir
, old_dentry
);
1197 return call_int_hook(inode_rename
, 0, old_dir
, old_dentry
,
1198 new_dir
, new_dentry
);
1201 int security_inode_readlink(struct dentry
*dentry
)
1203 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1205 return call_int_hook(inode_readlink
, 0, dentry
);
1207 EXPORT_SYMBOL_GPL(security_inode_readlink
);
1209 int security_inode_follow_link(struct dentry
*dentry
, struct inode
*inode
,
1212 if (unlikely(IS_PRIVATE(inode
)))
1214 return call_int_hook(inode_follow_link
, 0, dentry
, inode
, rcu
);
1217 int security_inode_permission(struct inode
*inode
, int mask
)
1219 if (unlikely(IS_PRIVATE(inode
)))
1221 return call_int_hook(inode_permission
, 0, inode
, mask
);
1223 EXPORT_SYMBOL_GPL(security_inode_permission
);
1225 int security_inode_setattr(struct dentry
*dentry
, struct iattr
*attr
)
1229 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1231 ret
= call_int_hook(inode_setattr
, 0, dentry
, attr
);
1234 return evm_inode_setattr(dentry
, attr
);
1236 EXPORT_SYMBOL_GPL(security_inode_setattr
);
1238 int security_inode_getattr(const struct path
*path
)
1240 if (unlikely(IS_PRIVATE(d_backing_inode(path
->dentry
))))
1242 return call_int_hook(inode_getattr
, 0, path
);
1245 int security_inode_setxattr(struct dentry
*dentry
, const char *name
,
1246 const void *value
, size_t size
, int flags
)
1250 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1253 * SELinux and Smack integrate the cap call,
1254 * so assume that all LSMs supplying this call do so.
1256 ret
= call_int_hook(inode_setxattr
, 1, dentry
, name
, value
, size
,
1260 ret
= cap_inode_setxattr(dentry
, name
, value
, size
, flags
);
1263 ret
= ima_inode_setxattr(dentry
, name
, value
, size
);
1266 return evm_inode_setxattr(dentry
, name
, value
, size
);
1269 void security_inode_post_setxattr(struct dentry
*dentry
, const char *name
,
1270 const void *value
, size_t size
, int flags
)
1272 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1274 call_void_hook(inode_post_setxattr
, dentry
, name
, value
, size
, flags
);
1275 evm_inode_post_setxattr(dentry
, name
, value
, size
);
1278 int security_inode_getxattr(struct dentry
*dentry
, const char *name
)
1280 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1282 return call_int_hook(inode_getxattr
, 0, dentry
, name
);
1285 int security_inode_listxattr(struct dentry
*dentry
)
1287 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1289 return call_int_hook(inode_listxattr
, 0, dentry
);
1292 int security_inode_removexattr(struct dentry
*dentry
, const char *name
)
1296 if (unlikely(IS_PRIVATE(d_backing_inode(dentry
))))
1299 * SELinux and Smack integrate the cap call,
1300 * so assume that all LSMs supplying this call do so.
1302 ret
= call_int_hook(inode_removexattr
, 1, dentry
, name
);
1304 ret
= cap_inode_removexattr(dentry
, name
);
1307 ret
= ima_inode_removexattr(dentry
, name
);
1310 return evm_inode_removexattr(dentry
, name
);
1313 int security_inode_need_killpriv(struct dentry
*dentry
)
1315 return call_int_hook(inode_need_killpriv
, 0, dentry
);
1318 int security_inode_killpriv(struct dentry
*dentry
)
1320 return call_int_hook(inode_killpriv
, 0, dentry
);
1323 int security_inode_getsecurity(struct inode
*inode
, const char *name
, void **buffer
, bool alloc
)
1325 struct security_hook_list
*hp
;
1328 if (unlikely(IS_PRIVATE(inode
)))
1331 * Only one module will provide an attribute with a given name.
1333 list_for_each_entry(hp
, &security_hook_heads
.inode_getsecurity
, list
) {
1334 rc
= hp
->hook
.inode_getsecurity(inode
, name
, buffer
, alloc
);
1335 if (rc
!= -EOPNOTSUPP
)
1341 int security_inode_setsecurity(struct inode
*inode
, const char *name
, const void *value
, size_t size
, int flags
)
1343 struct security_hook_list
*hp
;
1346 if (unlikely(IS_PRIVATE(inode
)))
1349 * Only one module will provide an attribute with a given name.
1351 list_for_each_entry(hp
, &security_hook_heads
.inode_setsecurity
, list
) {
1352 rc
= hp
->hook
.inode_setsecurity(inode
, name
, value
, size
,
1354 if (rc
!= -EOPNOTSUPP
)
1360 int security_inode_listsecurity(struct inode
*inode
, char *buffer
, size_t buffer_size
)
1362 if (unlikely(IS_PRIVATE(inode
)))
1364 return call_int_hook(inode_listsecurity
, 0, inode
, buffer
, buffer_size
);
1366 EXPORT_SYMBOL(security_inode_listsecurity
);
1368 void security_inode_getsecid(struct inode
*inode
, u32
*secid
)
1370 call_void_hook(inode_getsecid
, inode
, secid
);
1373 int security_inode_copy_up(struct dentry
*src
, struct cred
**new)
1375 return call_int_hook(inode_copy_up
, 0, src
, new);
1377 EXPORT_SYMBOL(security_inode_copy_up
);
1379 int security_inode_copy_up_xattr(const char *name
)
1381 return call_int_hook(inode_copy_up_xattr
, -EOPNOTSUPP
, name
);
1383 EXPORT_SYMBOL(security_inode_copy_up_xattr
);
1385 int security_file_permission(struct file
*file
, int mask
)
1389 ret
= call_int_hook(file_permission
, 0, file
, mask
);
1393 return fsnotify_perm(file
, mask
);
1395 EXPORT_SYMBOL_GPL(security_file_permission
);
1397 int security_file_alloc(struct file
*file
)
1399 int rc
= lsm_file_alloc(file
);
1403 return call_int_hook(file_alloc_security
, 0, file
);
1406 void security_file_free(struct file
*file
)
1408 call_void_hook(file_free_security
, file
);
1410 kfree(file
->f_security
);
1411 file
->f_security
= NULL
;
1414 int security_file_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1416 return call_int_hook(file_ioctl
, 0, file
, cmd
, arg
);
1419 static inline unsigned long mmap_prot(struct file
*file
, unsigned long prot
)
1422 * Does we have PROT_READ and does the application expect
1423 * it to imply PROT_EXEC? If not, nothing to talk about...
1425 if ((prot
& (PROT_READ
| PROT_EXEC
)) != PROT_READ
)
1427 if (!(current
->personality
& READ_IMPLIES_EXEC
))
1430 * if that's an anonymous mapping, let it.
1433 return prot
| PROT_EXEC
;
1435 * ditto if it's not on noexec mount, except that on !MMU we need
1436 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
1438 if (!path_noexec(&file
->f_path
)) {
1440 if (file
->f_op
->mmap_capabilities
) {
1441 unsigned caps
= file
->f_op
->mmap_capabilities(file
);
1442 if (!(caps
& NOMMU_MAP_EXEC
))
1446 return prot
| PROT_EXEC
;
1448 /* anything on noexec mount won't get PROT_EXEC */
1452 int security_mmap_file(struct file
*file
, unsigned long prot
,
1453 unsigned long flags
)
1456 ret
= call_int_hook(mmap_file
, 0, file
, prot
,
1457 mmap_prot(file
, prot
), flags
);
1460 return ima_file_mmap(file
, prot
);
1462 EXPORT_SYMBOL_GPL(security_mmap_file
);
1464 int security_mmap_addr(unsigned long addr
)
1466 return call_int_hook(mmap_addr
, 0, addr
);
1469 int security_file_mprotect(struct vm_area_struct
*vma
, unsigned long reqprot
,
1472 return call_int_hook(file_mprotect
, 0, vma
, reqprot
, prot
);
1475 int security_file_lock(struct file
*file
, unsigned int cmd
)
1477 return call_int_hook(file_lock
, 0, file
, cmd
);
1480 int security_file_fcntl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1482 return call_int_hook(file_fcntl
, 0, file
, cmd
, arg
);
1485 void security_file_set_fowner(struct file
*file
)
1487 call_void_hook(file_set_fowner
, file
);
1490 int security_file_send_sigiotask(struct task_struct
*tsk
,
1491 struct fown_struct
*fown
, int sig
)
1493 return call_int_hook(file_send_sigiotask
, 0, tsk
, fown
, sig
);
1496 int security_file_receive(struct file
*file
)
1498 return call_int_hook(file_receive
, 0, file
);
1501 int security_file_open(struct file
*file
, const struct cred
*cred
)
1505 ret
= call_int_hook(file_open
, 0, file
, cred
);
1509 return fsnotify_perm(file
, MAY_OPEN
);
1512 int security_task_create(unsigned long clone_flags
)
1514 return call_int_hook(task_create
, 0, clone_flags
);
1517 int security_task_alloc(struct task_struct
*task
, unsigned long clone_flags
)
1519 int rc
= lsm_task_alloc(task
);
1523 return call_int_hook(task_alloc
, 0, task
, clone_flags
);
1526 void security_task_free(struct task_struct
*task
)
1528 call_void_hook(task_free
, task
);
1530 kfree(task
->security
);
1531 task
->security
= NULL
;
1534 int security_cred_alloc_blank(struct cred
*cred
, gfp_t gfp
)
1536 int rc
= lsm_cred_alloc(cred
, gfp
);
1541 return call_int_hook(cred_alloc_blank
, 0, cred
, gfp
);
1544 void security_cred_free(struct cred
*cred
)
1546 call_void_hook(cred_free
, cred
);
1548 kfree(cred
->security
);
1549 cred
->security
= NULL
;
1552 int security_prepare_creds(struct cred
*new, const struct cred
*old
, gfp_t gfp
)
1554 int rc
= lsm_cred_alloc(new, gfp
);
1559 return call_int_hook(cred_prepare
, 0, new, old
, gfp
);
1562 void security_transfer_creds(struct cred
*new, const struct cred
*old
)
1564 call_void_hook(cred_transfer
, new, old
);
1567 int security_kernel_act_as(struct cred
*new, u32 secid
)
1569 return call_int_hook(kernel_act_as
, 0, new, secid
);
1572 int security_kernel_create_files_as(struct cred
*new, struct inode
*inode
)
1574 return call_int_hook(kernel_create_files_as
, 0, new, inode
);
1577 int security_kernel_module_request(char *kmod_name
)
1579 return call_int_hook(kernel_module_request
, 0, kmod_name
);
1582 int security_kernel_read_file(struct file
*file
, enum kernel_read_file_id id
)
1586 ret
= call_int_hook(kernel_read_file
, 0, file
, id
);
1589 return ima_read_file(file
, id
);
1591 EXPORT_SYMBOL_GPL(security_kernel_read_file
);
1593 int security_kernel_post_read_file(struct file
*file
, char *buf
, loff_t size
,
1594 enum kernel_read_file_id id
)
1598 ret
= call_int_hook(kernel_post_read_file
, 0, file
, buf
, size
, id
);
1601 return ima_post_read_file(file
, buf
, size
, id
);
1603 EXPORT_SYMBOL_GPL(security_kernel_post_read_file
);
1605 int security_task_fix_setuid(struct cred
*new, const struct cred
*old
,
1608 return call_int_hook(task_fix_setuid
, 0, new, old
, flags
);
1611 int security_task_setpgid(struct task_struct
*p
, pid_t pgid
)
1613 return call_int_hook(task_setpgid
, 0, p
, pgid
);
1616 int security_task_getpgid(struct task_struct
*p
)
1618 return call_int_hook(task_getpgid
, 0, p
);
1621 int security_task_getsid(struct task_struct
*p
)
1623 return call_int_hook(task_getsid
, 0, p
);
1626 void security_task_getsecid(struct task_struct
*p
, u32
*secid
)
1629 call_void_hook(task_getsecid
, p
, secid
);
1631 EXPORT_SYMBOL(security_task_getsecid
);
1633 int security_task_setnice(struct task_struct
*p
, int nice
)
1635 return call_int_hook(task_setnice
, 0, p
, nice
);
1638 int security_task_setioprio(struct task_struct
*p
, int ioprio
)
1640 return call_int_hook(task_setioprio
, 0, p
, ioprio
);
1643 int security_task_getioprio(struct task_struct
*p
)
1645 return call_int_hook(task_getioprio
, 0, p
);
1648 int security_task_prlimit(const struct cred
*cred
, const struct cred
*tcred
,
1651 return call_int_hook(task_prlimit
, 0, cred
, tcred
, flags
);
1654 int security_task_setrlimit(struct task_struct
*p
, unsigned int resource
,
1655 struct rlimit
*new_rlim
)
1657 return call_int_hook(task_setrlimit
, 0, p
, resource
, new_rlim
);
1660 int security_task_setscheduler(struct task_struct
*p
)
1662 return call_int_hook(task_setscheduler
, 0, p
);
1665 int security_task_getscheduler(struct task_struct
*p
)
1667 return call_int_hook(task_getscheduler
, 0, p
);
1670 int security_task_movememory(struct task_struct
*p
)
1672 return call_int_hook(task_movememory
, 0, p
);
1675 int security_task_kill(struct task_struct
*p
, struct siginfo
*info
,
1678 return call_int_hook(task_kill
, 0, p
, info
, sig
, secid
);
1681 #ifdef CONFIG_SECURITY_STACKING
1682 static char *nolsm
= "-default";
1685 static bool is_registered_lsm(const char *str
, size_t size
)
1687 struct security_hook_list
*hp
;
1689 list_for_each_entry(hp
, &security_hook_heads
.getprocattr
, list
) {
1690 if (size
== strlen(hp
->lsm
) && !strncmp(str
, hp
->lsm
, size
))
1697 static bool set_lsm_of_current(const char *str
, size_t size
)
1699 char *lsm
= lsm_of_task(current
);
1701 if (is_registered_lsm(str
, size
)) {
1702 strncpy(lsm
, str
, size
);
1704 } else if (size
== NOLSMLEN
&& !strncmp(str
, nolsm
, size
)) {
1712 static int lsm_task_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
1713 unsigned long arg4
, unsigned long arg5
)
1715 char *lsm
= lsm_of_task(current
);
1716 char buffer
[SECURITY_NAME_MAX
+ 1];
1717 __user
char *optval
= (__user
char *)arg2
;
1718 __user
int *optlen
= (__user
int *)arg3
;
1723 case PR_GET_DISPLAY_LSM
:
1725 if (lsm
[0] == '\0') {
1729 dlen
= strlen(lsm
) + 1;
1732 if (copy_to_user(optval
, lsm
, dlen
))
1734 if (put_user(dlen
, optlen
))
1737 case PR_SET_DISPLAY_LSM
:
1739 if (len
> SECURITY_NAME_MAX
)
1741 if (copy_from_user(buffer
, optval
, len
))
1744 /* verify the requested LSM is registered */
1745 if (!set_lsm_of_current(buffer
, len
))
1755 int security_task_prctl(int option
, unsigned long arg2
, unsigned long arg3
,
1756 unsigned long arg4
, unsigned long arg5
)
1760 struct security_hook_list
*hp
;
1762 #ifdef CONFIG_SECURITY_STACKING
1763 rc
= lsm_task_prctl(option
, arg2
, arg3
, arg4
, arg5
);
1768 list_for_each_entry(hp
, &security_hook_heads
.task_prctl
, list
) {
1769 thisrc
= hp
->hook
.task_prctl(option
, arg2
, arg3
, arg4
, arg5
);
1770 if (thisrc
!= -ENOSYS
) {
1779 void security_task_to_inode(struct task_struct
*p
, struct inode
*inode
)
1781 call_void_hook(task_to_inode
, p
, inode
);
1784 int security_ipc_permission(struct kern_ipc_perm
*ipcp
, short flag
)
1786 return call_int_hook(ipc_permission
, 0, ipcp
, flag
);
1789 void security_ipc_getsecid(struct kern_ipc_perm
*ipcp
, u32
*secid
)
1792 call_void_hook(ipc_getsecid
, ipcp
, secid
);
1795 int security_msg_msg_alloc(struct msg_msg
*msg
)
1797 int rc
= lsm_msg_msg_alloc(msg
);
1801 return call_int_hook(msg_msg_alloc_security
, 0, msg
);
1804 void security_msg_msg_free(struct msg_msg
*msg
)
1806 call_void_hook(msg_msg_free_security
, msg
);
1807 kfree(msg
->security
);
1808 msg
->security
= NULL
;
1811 int security_msg_queue_alloc(struct msg_queue
*msq
)
1813 int rc
= lsm_ipc_alloc(&msq
->q_perm
);
1817 return call_int_hook(msg_queue_alloc_security
, 0, msq
);
1820 void security_msg_queue_free(struct msg_queue
*msq
)
1822 struct kern_ipc_perm
*kip
= &msq
->q_perm
;
1824 call_void_hook(msg_queue_free_security
, msq
);
1825 kfree(kip
->security
);
1826 kip
->security
= NULL
;
1829 int security_msg_queue_associate(struct msg_queue
*msq
, int msqflg
)
1831 return call_int_hook(msg_queue_associate
, 0, msq
, msqflg
);
1834 int security_msg_queue_msgctl(struct msg_queue
*msq
, int cmd
)
1836 return call_int_hook(msg_queue_msgctl
, 0, msq
, cmd
);
1839 int security_msg_queue_msgsnd(struct msg_queue
*msq
,
1840 struct msg_msg
*msg
, int msqflg
)
1842 return call_int_hook(msg_queue_msgsnd
, 0, msq
, msg
, msqflg
);
1845 int security_msg_queue_msgrcv(struct msg_queue
*msq
, struct msg_msg
*msg
,
1846 struct task_struct
*target
, long type
, int mode
)
1848 return call_int_hook(msg_queue_msgrcv
, 0, msq
, msg
, target
, type
, mode
);
1851 int security_shm_alloc(struct shmid_kernel
*shp
)
1853 int rc
= lsm_ipc_alloc(&shp
->shm_perm
);
1857 return call_int_hook(shm_alloc_security
, 0, shp
);
1860 void security_shm_free(struct shmid_kernel
*shp
)
1862 struct kern_ipc_perm
*kip
= &shp
->shm_perm
;
1864 call_void_hook(shm_free_security
, shp
);
1865 kfree(kip
->security
);
1866 kip
->security
= NULL
;
1869 int security_shm_associate(struct shmid_kernel
*shp
, int shmflg
)
1871 return call_int_hook(shm_associate
, 0, shp
, shmflg
);
1874 int security_shm_shmctl(struct shmid_kernel
*shp
, int cmd
)
1876 return call_int_hook(shm_shmctl
, 0, shp
, cmd
);
1879 int security_shm_shmat(struct shmid_kernel
*shp
, char __user
*shmaddr
, int shmflg
)
1881 return call_int_hook(shm_shmat
, 0, shp
, shmaddr
, shmflg
);
1884 int security_sem_alloc(struct sem_array
*sma
)
1886 int rc
= lsm_ipc_alloc(&sma
->sem_perm
);
1890 return call_int_hook(sem_alloc_security
, 0, sma
);
1893 void security_sem_free(struct sem_array
*sma
)
1895 struct kern_ipc_perm
*kip
= &sma
->sem_perm
;
1897 call_void_hook(sem_free_security
, sma
);
1898 kfree(kip
->security
);
1899 kip
->security
= NULL
;
1902 int security_sem_associate(struct sem_array
*sma
, int semflg
)
1904 return call_int_hook(sem_associate
, 0, sma
, semflg
);
1907 int security_sem_semctl(struct sem_array
*sma
, int cmd
)
1909 return call_int_hook(sem_semctl
, 0, sma
, cmd
);
1912 int security_sem_semop(struct sem_array
*sma
, struct sembuf
*sops
,
1913 unsigned nsops
, int alter
)
1915 return call_int_hook(sem_semop
, 0, sma
, sops
, nsops
, alter
);
1918 void security_d_instantiate(struct dentry
*dentry
, struct inode
*inode
)
1920 if (unlikely(inode
&& IS_PRIVATE(inode
)))
1922 call_void_hook(d_instantiate
, dentry
, inode
);
1924 EXPORT_SYMBOL(security_d_instantiate
);
1926 int security_getprocattr(struct task_struct
*p
, const char *lsm
, char *name
,
1929 #ifdef CONFIG_SECURITY_STACKING
1930 char *speclsm
= lsm_of_task(p
);
1932 struct security_hook_list
*hp
;
1939 * "context" requires work here in addition to what
1940 * the modules provide.
1942 if (strcmp(name
, "context") == 0) {
1945 list_for_each_entry(hp
,
1946 &security_hook_heads
.getprocattr
, list
) {
1947 if (lsm
!= NULL
&& strcmp(lsm
, hp
->lsm
))
1949 trc
= hp
->hook
.getprocattr(p
, "context", &vp
);
1957 if (*value
== NULL
) {
1960 cp
= kasprintf(GFP_KERNEL
, "%s,%s", *value
, vp
);
1972 return strlen(*value
);
1974 } else if (strcmp(name
, "display_lsm") == 0) {
1975 *value
= kstrdup(current
->security
, GFP_KERNEL
);
1978 return strlen(*value
);
1981 list_for_each_entry(hp
, &security_hook_heads
.getprocattr
, list
) {
1982 if (lsm
!= NULL
&& strcmp(lsm
, hp
->lsm
))
1984 #ifdef CONFIG_SECURITY_STACKING
1985 if (!lsm
&& speclsm
&& speclsm
[0] && strcmp(speclsm
, hp
->lsm
))
1988 rc
= hp
->hook
.getprocattr(p
, name
, value
);
1995 int security_setprocattr(const char *lsm
, const char *name
, void *value
,
1998 #ifdef CONFIG_SECURITY_STACKING
1999 char *speclsm
= lsm_of_task(current
);
2000 struct lsm_value
*lsm_value
= NULL
;
2005 struct security_hook_list
*hp
;
2014 * If lsm is NULL look at all the modules to find one
2015 * that processes name. If lsm is not NULL only look at
2018 * "context" is handled directly here.
2020 if (strcmp(name
, "context") == 0) {
2022 temp
= kmemdup(value
, size
+ 1, GFP_KERNEL
);
2027 cp
= strrchr(temp
, '\'');
2032 #ifdef CONFIG_SECURITY_STACKING
2033 lsm_value
= kzalloc(sizeof(*lsm_value
) * LSM_MAX_MAJOR
,
2040 count
= lsm_parse_context(temp
, lsm_value
);
2044 for (count
--; count
>= 0; count
--) {
2045 list_for_each_entry(hp
,
2046 &security_hook_heads
.setprocattr
, list
) {
2048 if (lsm
&& strcmp(lsm
, hp
->lsm
))
2050 if (!strcmp(hp
->lsm
, lsm_value
[count
].lsm
)) {
2051 rc
= hp
->hook
.setprocattr("context",
2052 lsm_value
[count
].data
,
2053 strlen(lsm_value
[count
].data
));
2057 if (rc
< 0 || (lsm
&& rc
>0))
2060 #else /* CONFIG_SECURITY_STACKING */
2061 cp
= strstr(temp
, "='");
2065 tvalue
= strchr(cp
+ 2, '\'');
2068 list_for_each_entry(hp
, &security_hook_heads
.setprocattr
,
2070 if (lsm
== NULL
|| !strcmp(lsm
, hp
->lsm
)) {
2071 rc
= hp
->hook
.setprocattr(name
, tvalue
, size
);
2075 #endif /* CONFIG_SECURITY_STACKING */
2078 #ifdef CONFIG_SECURITY_STACKING
2084 } else if (strcmp(name
, "display_lsm") == 0) {
2085 #ifdef CONFIG_SECURITY_STACKING
2086 if (set_lsm_of_current(value
, size
))
2092 list_for_each_entry(hp
, &security_hook_heads
.setprocattr
, list
) {
2093 if (lsm
&& strcmp(lsm
, hp
->lsm
))
2095 #ifdef CONFIG_SECURITY_STACKING
2096 if (!lsm
&& speclsm
&& speclsm
[0] && strcmp(speclsm
, hp
->lsm
))
2099 rc
= hp
->hook
.setprocattr(name
, value
, size
);
2106 int security_netlink_send(struct sock
*sk
, struct sk_buff
*skb
)
2108 return call_int_hook(netlink_send
, 0, sk
, skb
);
2111 int security_ismaclabel(const char *name
)
2113 return call_int_hook(ismaclabel
, 0, name
);
2115 EXPORT_SYMBOL(security_ismaclabel
);
2117 int security_secid_to_secctx(u32 secid
, char **secdata
, u32
*seclen
)
2119 return call_int_hook(secid_to_secctx
, -EOPNOTSUPP
, secid
, secdata
,
2122 EXPORT_SYMBOL(security_secid_to_secctx
);
2124 int security_secctx_to_secid(const char *secdata
, u32 seclen
, u32
*secid
)
2127 return call_int_hook(secctx_to_secid
, 0, secdata
, seclen
, secid
);
2129 EXPORT_SYMBOL(security_secctx_to_secid
);
2131 void security_release_secctx(char *secdata
, u32 seclen
)
2133 #ifdef CONFIG_SECURITY_STACKING
2134 char *speclsm
= lsm_of_task(current
);
2136 struct security_hook_list
*hp
;
2138 list_for_each_entry(hp
, &security_hook_heads
.release_secctx
, list
) {
2139 #ifdef CONFIG_SECURITY_STACKING
2140 if (speclsm
[0] && strcmp(hp
->lsm
, speclsm
))
2143 hp
->hook
.release_secctx(secdata
, seclen
);
2147 EXPORT_SYMBOL(security_release_secctx
);
2149 void security_inode_invalidate_secctx(struct inode
*inode
)
2151 call_void_hook(inode_invalidate_secctx
, inode
);
2153 EXPORT_SYMBOL(security_inode_invalidate_secctx
);
2155 int security_inode_notifysecctx(struct inode
*inode
, void *ctx
, u32 ctxlen
)
2157 return call_int_hook(inode_notifysecctx
, 0, inode
, ctx
, ctxlen
);
2159 EXPORT_SYMBOL(security_inode_notifysecctx
);
2161 int security_inode_setsecctx(struct dentry
*dentry
, void *ctx
, u32 ctxlen
)
2163 return call_int_hook(inode_setsecctx
, 0, dentry
, ctx
, ctxlen
);
2165 EXPORT_SYMBOL(security_inode_setsecctx
);
2167 int security_inode_getsecctx(struct inode
*inode
, void **ctx
, u32
*ctxlen
)
2169 return call_int_hook(inode_getsecctx
, -EOPNOTSUPP
, inode
, ctx
, ctxlen
);
2171 EXPORT_SYMBOL(security_inode_getsecctx
);
2173 #ifdef CONFIG_SECURITY_NETWORK
2175 int security_unix_stream_connect(struct sock
*sock
, struct sock
*other
, struct sock
*newsk
)
2177 return call_int_hook(unix_stream_connect
, 0, sock
, other
, newsk
);
2179 EXPORT_SYMBOL(security_unix_stream_connect
);
2181 int security_unix_may_send(struct socket
*sock
, struct socket
*other
)
2183 return call_int_hook(unix_may_send
, 0, sock
, other
);
2185 EXPORT_SYMBOL(security_unix_may_send
);
2187 int security_socket_create(int family
, int type
, int protocol
, int kern
)
2189 return call_int_hook(socket_create
, 0, family
, type
, protocol
, kern
);
2192 int security_socket_post_create(struct socket
*sock
, int family
,
2193 int type
, int protocol
, int kern
)
2195 return call_int_hook(socket_post_create
, 0, sock
, family
, type
,
2199 int security_socket_bind(struct socket
*sock
, struct sockaddr
*address
, int addrlen
)
2201 return call_int_hook(socket_bind
, 0, sock
, address
, addrlen
);
2204 int security_socket_connect(struct socket
*sock
, struct sockaddr
*address
, int addrlen
)
2206 return call_int_hook(socket_connect
, 0, sock
, address
, addrlen
);
2209 int security_socket_listen(struct socket
*sock
, int backlog
)
2211 return call_int_hook(socket_listen
, 0, sock
, backlog
);
2214 int security_socket_accept(struct socket
*sock
, struct socket
*newsock
)
2216 return call_int_hook(socket_accept
, 0, sock
, newsock
);
2219 int security_socket_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int size
)
2221 return call_int_hook(socket_sendmsg
, 0, sock
, msg
, size
);
2224 int security_socket_recvmsg(struct socket
*sock
, struct msghdr
*msg
,
2225 int size
, int flags
)
2227 return call_int_hook(socket_recvmsg
, 0, sock
, msg
, size
, flags
);
2230 int security_socket_getsockname(struct socket
*sock
)
2232 return call_int_hook(socket_getsockname
, 0, sock
);
2235 int security_socket_getpeername(struct socket
*sock
)
2237 return call_int_hook(socket_getpeername
, 0, sock
);
2240 int security_socket_getsockopt(struct socket
*sock
, int level
, int optname
)
2242 return call_int_hook(socket_getsockopt
, 0, sock
, level
, optname
);
2245 int security_socket_setsockopt(struct socket
*sock
, int level
, int optname
)
2247 return call_int_hook(socket_setsockopt
, 0, sock
, level
, optname
);
2250 int security_socket_shutdown(struct socket
*sock
, int how
)
2252 return call_int_hook(socket_shutdown
, 0, sock
, how
);
2255 int security_sock_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
2257 return call_int_hook(socket_sock_rcv_skb
, 0, sk
, skb
);
2259 EXPORT_SYMBOL(security_sock_rcv_skb
);
2261 int security_socket_getpeersec_stream(struct socket
*sock
, char __user
*optval
,
2262 int __user
*optlen
, unsigned len
)
2264 #ifdef CONFIG_SECURITY_STACKING
2265 struct security_hook_list
*hp
;
2266 char *lsm
= lsm_of_task(current
);
2268 list_for_each_entry(hp
, &security_hook_heads
.socket_getpeersec_stream
,
2270 if (!lsm
|| !lsm
[0] || !strcmp(lsm
, hp
->lsm
))
2271 return hp
->hook
.socket_getpeersec_stream(sock
, optval
,
2274 return -ENOPROTOOPT
;
2276 return call_int_hook(socket_getpeersec_stream
, -ENOPROTOOPT
, sock
,
2277 optval
, optlen
, len
);
2281 int security_socket_getpeersec_dgram(struct socket
*sock
, struct sk_buff
*skb
, u32
*secid
)
2283 return call_int_hook(socket_getpeersec_dgram
, -ENOPROTOOPT
, sock
,
2286 EXPORT_SYMBOL(security_socket_getpeersec_dgram
);
2288 int security_sk_alloc(struct sock
*sk
, int family
, gfp_t priority
)
2290 int rc
= lsm_sock_alloc(sk
, priority
);
2294 return call_int_hook(sk_alloc_security
, 0, sk
, family
, priority
);
2297 void security_sk_free(struct sock
*sk
)
2299 call_void_hook(sk_free_security
, sk
);
2300 kfree(sk
->sk_security
);
2301 sk
->sk_security
= NULL
;
2304 void security_sk_clone(const struct sock
*sk
, struct sock
*newsk
)
2306 call_void_hook(sk_clone_security
, sk
, newsk
);
2308 EXPORT_SYMBOL(security_sk_clone
);
2310 void security_sk_classify_flow(struct sock
*sk
, struct flowi
*fl
)
2312 call_void_hook(sk_getsecid
, sk
, &fl
->flowi_secid
);
2314 EXPORT_SYMBOL(security_sk_classify_flow
);
2316 void security_req_classify_flow(const struct request_sock
*req
, struct flowi
*fl
)
2318 call_void_hook(req_classify_flow
, req
, fl
);
2320 EXPORT_SYMBOL(security_req_classify_flow
);
2322 void security_sock_graft(struct sock
*sk
, struct socket
*parent
)
2324 call_void_hook(sock_graft
, sk
, parent
);
2326 EXPORT_SYMBOL(security_sock_graft
);
2328 int security_inet_conn_request(struct sock
*sk
,
2329 struct sk_buff
*skb
, struct request_sock
*req
)
2331 return call_int_hook(inet_conn_request
, 0, sk
, skb
, req
);
2333 EXPORT_SYMBOL(security_inet_conn_request
);
2335 void security_inet_csk_clone(struct sock
*newsk
,
2336 const struct request_sock
*req
)
2338 call_void_hook(inet_csk_clone
, newsk
, req
);
2341 void security_inet_conn_established(struct sock
*sk
,
2342 struct sk_buff
*skb
)
2344 call_void_hook(inet_conn_established
, sk
, skb
);
2347 int security_secmark_relabel_packet(u32 secid
)
2349 return call_int_hook(secmark_relabel_packet
, 0, secid
);
2351 EXPORT_SYMBOL(security_secmark_relabel_packet
);
2353 void security_secmark_refcount_inc(void)
2355 call_void_hook(secmark_refcount_inc
);
2357 EXPORT_SYMBOL(security_secmark_refcount_inc
);
2359 void security_secmark_refcount_dec(void)
2361 call_void_hook(secmark_refcount_dec
);
2363 EXPORT_SYMBOL(security_secmark_refcount_dec
);
2365 int security_tun_dev_alloc_security(void **security
)
2367 return call_int_hook(tun_dev_alloc_security
, 0, security
);
2369 EXPORT_SYMBOL(security_tun_dev_alloc_security
);
2371 void security_tun_dev_free_security(void *security
)
2373 call_void_hook(tun_dev_free_security
, security
);
2375 EXPORT_SYMBOL(security_tun_dev_free_security
);
2377 int security_tun_dev_create(void)
2379 return call_int_hook(tun_dev_create
, 0);
2381 EXPORT_SYMBOL(security_tun_dev_create
);
2383 int security_tun_dev_attach_queue(void *security
)
2385 return call_int_hook(tun_dev_attach_queue
, 0, security
);
2387 EXPORT_SYMBOL(security_tun_dev_attach_queue
);
2389 int security_tun_dev_attach(struct sock
*sk
, void *security
)
2391 return call_int_hook(tun_dev_attach
, 0, sk
, security
);
2393 EXPORT_SYMBOL(security_tun_dev_attach
);
2395 int security_tun_dev_open(void *security
)
2397 return call_int_hook(tun_dev_open
, 0, security
);
2399 EXPORT_SYMBOL(security_tun_dev_open
);
2401 #endif /* CONFIG_SECURITY_NETWORK */
2403 #ifdef CONFIG_SECURITY_INFINIBAND
2405 int security_ib_pkey_access(void *sec
, u64 subnet_prefix
, u16 pkey
)
2407 return call_int_hook(ib_pkey_access
, 0, sec
, subnet_prefix
, pkey
);
2409 EXPORT_SYMBOL(security_ib_pkey_access
);
2411 int security_ib_endport_manage_subnet(void *sec
, const char *dev_name
, u8 port_num
)
2413 return call_int_hook(ib_endport_manage_subnet
, 0, sec
, dev_name
, port_num
);
2415 EXPORT_SYMBOL(security_ib_endport_manage_subnet
);
2417 int security_ib_alloc_security(void **sec
)
2419 return call_int_hook(ib_alloc_security
, 0, sec
);
2421 EXPORT_SYMBOL(security_ib_alloc_security
);
2423 void security_ib_free_security(void *sec
)
2425 call_void_hook(ib_free_security
, sec
);
2427 EXPORT_SYMBOL(security_ib_free_security
);
2428 #endif /* CONFIG_SECURITY_INFINIBAND */
2430 #ifdef CONFIG_SECURITY_NETWORK_XFRM
2432 int security_xfrm_policy_alloc(struct xfrm_sec_ctx
**ctxp
,
2433 struct xfrm_user_sec_ctx
*sec_ctx
,
2436 return call_int_hook(xfrm_policy_alloc_security
, 0, ctxp
, sec_ctx
, gfp
);
2438 EXPORT_SYMBOL(security_xfrm_policy_alloc
);
2440 int security_xfrm_policy_clone(struct xfrm_sec_ctx
*old_ctx
,
2441 struct xfrm_sec_ctx
**new_ctxp
)
2443 return call_int_hook(xfrm_policy_clone_security
, 0, old_ctx
, new_ctxp
);
2446 void security_xfrm_policy_free(struct xfrm_sec_ctx
*ctx
)
2448 call_void_hook(xfrm_policy_free_security
, ctx
);
2450 EXPORT_SYMBOL(security_xfrm_policy_free
);
2452 int security_xfrm_policy_delete(struct xfrm_sec_ctx
*ctx
)
2454 return call_int_hook(xfrm_policy_delete_security
, 0, ctx
);
2457 int security_xfrm_state_alloc(struct xfrm_state
*x
,
2458 struct xfrm_user_sec_ctx
*sec_ctx
)
2460 return call_int_hook(xfrm_state_alloc
, 0, x
, sec_ctx
);
2462 EXPORT_SYMBOL(security_xfrm_state_alloc
);
2464 int security_xfrm_state_alloc_acquire(struct xfrm_state
*x
,
2465 struct xfrm_sec_ctx
*polsec
, u32 secid
)
2467 return call_int_hook(xfrm_state_alloc_acquire
, 0, x
, polsec
, secid
);
2470 int security_xfrm_state_delete(struct xfrm_state
*x
)
2472 return call_int_hook(xfrm_state_delete_security
, 0, x
);
2474 EXPORT_SYMBOL(security_xfrm_state_delete
);
2476 void security_xfrm_state_free(struct xfrm_state
*x
)
2478 call_void_hook(xfrm_state_free_security
, x
);
2481 int security_xfrm_policy_lookup(struct xfrm_sec_ctx
*ctx
, u32 fl_secid
, u8 dir
)
2483 return call_int_hook(xfrm_policy_lookup
, 0, ctx
, fl_secid
, dir
);
2486 int security_xfrm_state_pol_flow_match(struct xfrm_state
*x
,
2487 struct xfrm_policy
*xp
,
2488 const struct flowi
*fl
)
2490 struct security_hook_list
*hp
;
2494 * Since this function is expected to return 0 or 1, the judgment
2495 * becomes difficult if multiple LSMs supply this call. Fortunately,
2496 * we can use the first LSM's judgment because currently only SELinux
2497 * supplies this call.
2499 * For speed optimization, we explicitly break the loop rather than
2502 list_for_each_entry(hp
, &security_hook_heads
.xfrm_state_pol_flow_match
,
2504 rc
= hp
->hook
.xfrm_state_pol_flow_match(x
, xp
, fl
);
2510 int security_xfrm_decode_session(struct sk_buff
*skb
, u32
*secid
)
2512 return call_int_hook(xfrm_decode_session
, 0, skb
, secid
, 1);
2515 void security_skb_classify_flow(struct sk_buff
*skb
, struct flowi
*fl
)
2517 int rc
= call_int_hook(xfrm_decode_session
, 0, skb
, &fl
->flowi_secid
,
2522 EXPORT_SYMBOL(security_skb_classify_flow
);
2524 #endif /* CONFIG_SECURITY_NETWORK_XFRM */
2528 int security_key_alloc(struct key
*key
, const struct cred
*cred
,
2529 unsigned long flags
)
2531 int rc
= lsm_key_alloc(key
);
2535 return call_int_hook(key_alloc
, 0, key
, cred
, flags
);
2538 void security_key_free(struct key
*key
)
2540 call_void_hook(key_free
, key
);
2541 kfree(key
->security
);
2542 key
->security
= NULL
;
2545 int security_key_permission(key_ref_t key_ref
,
2546 const struct cred
*cred
, unsigned perm
)
2548 return call_int_hook(key_permission
, 0, key_ref
, cred
, perm
);
2551 int security_key_getsecurity(struct key
*key
, char **_buffer
)
2554 return call_int_hook(key_getsecurity
, 0, key
, _buffer
);
2557 #endif /* CONFIG_KEYS */
2561 int security_audit_rule_init(u32 field
, u32 op
, char *rulestr
, void **lsmrule
)
2563 return call_int_hook(audit_rule_init
, 0, field
, op
, rulestr
, lsmrule
);
2566 int security_audit_rule_known(struct audit_krule
*krule
)
2568 return call_int_hook(audit_rule_known
, 0, krule
);
2571 void security_audit_rule_free(void *lsmrule
)
2573 call_void_hook(audit_rule_free
, lsmrule
);
2576 int security_audit_rule_match(u32 secid
, u32 field
, u32 op
, void *lsmrule
,
2577 struct audit_context
*actx
)
2579 return call_int_hook(audit_rule_match
, 0, secid
, field
, op
, lsmrule
,
2582 #endif /* CONFIG_AUDIT */